1、/D:/daima/guidgen/aboutdlg.hclass CAboutDlg : public CDialogImplpublic:enum IDD = IDD_ABOUTBOX ;BEGIN_MSG_MAP(CAboutDlg)MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)COMMAND_ID_HANDLER(IDOK, OnCloseCmd)COMMAND_ID_HANDLER(IDCANCEL, OnCloseCmd)END_MSG_MAP()LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wP
2、aram*/, LPARAM /*lParam*/, BOOLreturn TRUE;LRESULT OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOLreturn 0;/D:/daima/guidgen/GuidGen.cpp/ GuidGen.cpp : /#include “stdatl.h“#include #include #include #include #include “resource.h“#include “aboutdlg.h“#include “maindlg.h“CAppModule _
3、Module;int Run(LPTSTR /*lpCmdLine*/ = NULL, int nCmdShow = SW_SHOWDEFAULT)CMessageLoop theLoop;_Module.AddMessageLoop(CMainDlg dlgMain;if(dlgMain.Create(NULL) = NULL)ATLTRACE(_T(“Main dialog creation failed!n“);return 0;dlgMain.ShowWindow(nCmdShow);int nRet = theLoop.Run();_Module.RemoveMessageLoop(
4、);return nRet;int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpCmdLine, int nCmdShow)#if (_WIN32_IE = 0x0300)INITCOMMONCONTROLSEX iccx;iccx.dwSize = sizeof(iccx);iccx.dwICC = ICC_BAR_CLASSES; / change to support other controls:InitCommonControlsEx(#else:InitCommonContr
5、ols();#endif_Module.Init(NULL, hInstance);int nRet = Run(lpCmdLine, nCmdShow);_Module.Term();return nRet;/D:/daima/guidgen/GuidGen.rc/Microsoft Developer Studio generated resource script./#include “resource.h“#define APSTUDIO_READONLY_SYMBOLS/ Generated from the TEXTINCLUDE 2 resource./#include “atl
6、res.h“/#undef APSTUDIO_READONLY_SYMBOLS/ English (U.S.) resources#if !defined(AFX_RESOURCE_DLL) | defined(AFX_TARG_ENU)#ifdef _WIN32LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US#pragma code_page(1252)#endif /_WIN32#ifdef APSTUDIO_INVOKED/ TEXTINCLUDE/1 TEXTINCLUDE DISCARDABLE BEGIN“resource.h0“END2 TEXT
7、INCLUDE DISCARDABLE BEGIN“#include “atlres.h“rn“0“END3 TEXTINCLUDE DISCARDABLE BEGIN“CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST “resGuidGen.exe.manifest“rn“0“END#endif / APSTUDIO_INVOKED/ Dialog/IDD_ABOUTBOX DIALOG DISCARDABLE 0, 0, 187, 102STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMEN
8、UCAPTION “About“FONT 8, “MS Sans Serif“BEGINDEFPUSHBUTTON “OK“,IDOK,130,81,50,14CTEXT “ATL GUIDGEN Application v1.0nn(c) Copyright 1998“,IDC_STATIC,25,57,78,32ICON IDR_MAINFRAME,IDC_STATIC,55,26,20,20GROUPBOX “,IDC_STATIC,7,7,115,88ENDIDD_GUIDGEN_DIALOG DIALOG DISCARDABLE 0, 0, 246, 193STYLE WS_MINI
9、MIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENUCAPTION “Create GUID“FONT 8, “MS Sans Serif“BEGINLTEXT “Choose the desired format below, then select “Copy“ to copy the results to the clipboard (the results can then be pasted into your source code). Choose “Exit“ when done.“,IDC_STATIC,6,6,178,37GROUPBOX
10、 “ GUID Format “,IDC_STATIC,4,43,178,73CONTROL “rn“IDS_STRING105 “/ %08lX-%04X-%04x-%02X%02X-%02X%02X%02X%02X%02X%02XrnDEFINE_GUID(, rn0x%lx, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x);rn“IDS_STRING106 “/ %08lX-%04X-%04x-%02X%02X-%02X%02X%02X%02X%02X%02Xrnstatic const GUID = rn 0x%l
11、x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x ;rn“IDS_STRING107 “%08lX-%04X-%04x-%02X%02X-%02X%02X%02X%02X%02X%02Xrn“ENDSTRINGTABLE DISCARDABLE BEGINIDP_ERR_CREATE_GUID “Unable to create new GUID.“IDP_ERR_OPEN_CLIP “Clipboard is busy. Unable to copy result to clipboard.“IDS_ABOUTBOX
12、“rn“IDS_STRING105 “/ %08lX-%04X-%04x-%02X%02X-%02X%02X%02X%02X%02X%02XrnDEFINE_GUID(, rn0x%lx, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x);rn“IDS_STRING106 “/ %08lX-%04X-%04x-%02X%02X-%02X%02X%02X%02X%02X%02Xrnstatic const GUID = rn 0x%lx, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x
13、%x, 0x%x, 0x%x ;rn“IDS_STRING107 “%08lX-%04X-%04x-%02X%02X-%02X%02X%02X%02X%02X%02Xrn“ENDSTRINGTABLE DISCARDABLE BEGINIDP_ERR_CREATE_GUID “Unable to create new GUID.“IDP_ERR_OPEN_CLIP “Clipboard is busy. Unable to copy result to clipboard.“IDS_ABOUTBOX “int m_nGuidType;GUID m_guid;CMainDlg() : m_nGu
14、idType(0)virtual BOOL PreTranslateMessage(MSG* pMsg)return :IsDialogMessage(m_hWnd, pMsg);void UpdateData()m_nGuidType = 0;m_nGuidType = IsDlgButtonChecked(IDC_RADIO2) ? 1 : m_nGuidType;m_nGuidType = IsDlgButtonChecked(IDC_RADIO3) ? 2 : m_nGuidType;m_nGuidType = IsDlgButtonChecked(IDC_RADIO4) ? 3 :
15、m_nGuidType;_ASSERTE(m_nGuidType = 0 SysMenu.AppendMenu(MF_STRING, IDM_ABOUTBOX, szAboutMenu);SysMenu.Detach();/ register object for message filteringCMessageLoop* pLoop = _Module.GetMessageLoop();pLoop-AddMessageFilter(this);CRegKey reg;long lRet = reg.Open(HKEY_CURRENT_USER, _T(“SoftwareMicrosoftA
16、TLSamplesGUIDGEN“), KEY_READ);if(lRet = ERROR_SUCCESS)DWORD dwVal;#if (_ATL_VER = 0x0700)lRet = reg.QueryDWORDValue(_T(“GUID Type“), dwVal);#elselRet = reg.QueryValue(dwVal, _T(“GUID Type“);#endifif(lRet = ERROR_SUCCESS)m_nGuidType = (int)dwVal;CheckRadioButton(IDC_RADIO1, IDC_RADIO4, IDC_RADIO1 + m
17、_nGuidType);if(!NewGUID()CloseDialog(IDABORT);DisplayGUID();return TRUE;void GetFormattedGuid(TCHAR* rString)/ load appropriate formatting stringTCHAR szBuf256;:LoadString(_Module.GetResourceInstance(), IDS_FORMATS+m_nGuidType, szBuf, 255);wsprintf(rString, szBuf, / first copy.m_guid.Data1, m_guid.D
18、ata2, m_guid.Data3, m_guid.Data40, m_guid.Data41, m_guid.Data42, m_guid.Data43,m_guid.Data44, m_guid.Data45, m_guid.Data46, m_guid.Data47,/ second copy.m_guid.Data1, m_guid.Data2, m_guid.Data3, m_guid.Data40, m_guid.Data41, m_guid.Data42, m_guid.Data43,m_guid.Data44, m_guid.Data45, m_guid.Data46, m_
19、guid.Data47);void DisplayGUID()TCHAR szBuf512;GetFormattedGuid(szBuf);SetDlgItemText(IDC_RESULTS, szBuf);BOOL NewGUID()m_guid = GUID_NULL;:CoCreateGuid(if(m_guid = GUID_NULL)TCHAR szBuf256;:LoadString(_Module.GetResourceInstance(), IDP_ERR_CREATE_GUID, szBuf, 255);MessageBox(szBuf, _T(“GUIDGen“), MB
20、_OK);return FALSE;return TRUE;LRESULT OnNewGUID(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOLDisplayGUID();return 0;LRESULT OnSelChange(WORD wNotifyCode, WORD /*wID*/, HWND /*hWndCtl*/, BOOLDisplayGUID();return 0;LRESULT OnOK(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOLif(
21、!OpenClipboard()TCHAR szBuf256;:LoadString(_Module.GetResourceInstance(), IDP_ERR_OPEN_CLIP, szBuf, 255);MessageBox(szBuf, _T(“GUIDGen“), MB_OK);return 0;TCHAR strResult512;GetFormattedGuid(strResult);int nTextLen = (lstrlen(strResult) + 1) * sizeof(TCHAR);HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE
22、, nTextLen);if(hGlobal != NULL)LPVOID lpText = GlobalLock(hGlobal);memcpy(lpText, strResult, nTextLen);EmptyClipboard();GlobalUnlock(hGlobal);#ifdef _UNICODESetClipboardData(CF_UNICODETEXT, hGlobal);#elseSetClipboardData(CF_TEXT, hGlobal);#endifCloseClipboard();return 0;LRESULT OnCancel(WORD /*wNoti
23、fyCode*/, WORD wID, HWND /*hWndCtl*/, BOOLlong lRet = reg.Open(HKEY_CURRENT_USER, _T(“SoftwareMicrosoftATLSamplesGUIDGen“), KEY_WRITE);if(lRet != ERROR_SUCCESS)lRet = reg.Open(HKEY_CURRENT_USER, _T(“SoftwareMicrosoft“), KEY_WRITE);if(lRet = ERROR_SUCCESS)CRegKey reg1;lRet = reg1.Create(reg.m_hKey, _
24、T(“ATL“), REG_NONE, REG_OPTION_NON_VOLATILE, KEY_WRITE);if(lRet = ERROR_SUCCESS)CRegKey reg2;lRet = reg2.Create(reg1.m_hKey, _T(“Samples“), REG_NONE, REG_OPTION_NON_VOLATILE, KEY_WRITE);if(lRet = ERROR_SUCCESS)CRegKey reg3;lRet = reg3.Create(reg2.m_hKey, _T(“GUIDGen“), REG_NONE, REG_OPTION_NON_VOLAT
25、ILE, KEY_WRITE);reg.Close();lRet = reg.Open(HKEY_CURRENT_USER, _T(“SoftwareMicrosoftATLSamplesGUIDGen“), KEY_WRITE);if(lRet = ERROR_SUCCESS)DWORD dwVal = m_nGuidType;#if (_ATL_VER = 0x0700)reg.SetDWORDValue(_T(“GUID Type“), dwVal);#elsereg.SetValue(dwVal, _T(“GUID Type“);#endifCloseDialog(wID);retur
26、n 0;void CloseDialog(int nVal)DestroyWindow();:PostQuitMessage(nVal);LRESULT OnSysCommand(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOLif(uCmdType dlg.DoModal();elsebHandled = FALSE;return 0;/_AFX_INSERT_LOCATION/ Microsoft Developer Studio will insert additional declarations immediately bef
27、ore the previous line.#endif / !defined(AFX_MAINDLG_H_6920296A_4C3F_11D1_AA9A_000000000000_INCLUDED_)/D:/daima/guidgen/resource.h/_NO_DEPENDENCIES/ Microsoft Developer Studio generated include file./ Used by GuidGen.rc/#define IDM_ABOUTBOX 0x0010#define IDD_ABOUTBOX 100#define IDD_GUIDGEN_DIALOG 102
28、#define IDP_ERR_INIT_OLE 102#define IDS_FORMATS 104#define IDS_STRING105 105#define IDS_STRING106 106#define IDS_STRING107 107#define IDR_MAINFRAME 128#define IDC_RADIO1 1000#define IDC_RADIO2 1001#define IDC_RADIO3 1002#define IDC_RADIO4 1003#define IDC_RESULTS 1004#define IDC_NEWGUID 1005#define I
29、DP_ERR_CREATE_GUID 2000#define IDP_ERR_OPEN_CLIP 2001#define IDS_ABOUTBOX 2002/ Next default values for new objects/ #ifdef APSTUDIO_INVOKED#ifndef APSTUDIO_READONLY_SYMBOLS#define _APS_NEXT_RESOURCE_VALUE 201#define _APS_NEXT_COMMAND_VALUE 32772#define _APS_NEXT_CONTROL_VALUE 1000#define _APS_NEXT_
30、SYMED_VALUE 102#endif#endif/D:/daima/guidgen/resourcece.h/_NO_DEPENDENCIES/ Microsoft Developer Studio generated include file./ Used by GuidGen.rc/#define IDM_ABOUTBOX 0x0010#define IDD_ABOUTBOX 100#define IDD_GUIDGEN_DIALOG 102#define IDP_ERR_INIT_OLE 102#define IDS_FORMATS 104#define IDS_STRING105
31、 105#define IDS_STRING106 106#define IDS_STRING107 107#define IDR_MAINFRAME 128#define IDC_RADIO1 1000#define IDC_RADIO2 1001#define IDC_RADIO3 1002#define IDC_RADIO4 1003#define IDC_RESULTS 1004#define IDC_NEWGUID 1005#define IDP_ERR_CREATE_GUID 2000#define IDP_ERR_OPEN_CLIP 2001#define IDS_ABOUTBO
32、X 2002/ Next default values for new objects/ #ifdef APSTUDIO_INVOKED#ifndef APSTUDIO_READONLY_SYMBOLS#define _APS_NEXT_RESOURCE_VALUE 201#define _APS_NEXT_COMMAND_VALUE 32772#define _APS_NEXT_CONTROL_VALUE 1000#define _APS_NEXT_SYMED_VALUE 102#endif#endif/D:/daima/guidgen/stdatl.cpp/ stdatl.cpp : so
33、urce file that includes just the standard includes/ GuidGen.pch will be the pre-compiled header/ stdatl.obj will contain the pre-compiled type information#include “stdatl.h“#if (_ATL_VER #endif /(_ATL_VER #include extern CAppModule _Module;#include /_AFX_INSERT_LOCATION/ Microsoft Developer Studio will insert additional declarations immediately before the previous line./