static HICON hIcon1 = LoadIcon(hApp, MAKEINTRESOURCE(IDI_ICON1));
SendMessage(hMainWnd, WM_SETICON, ICON_BIG, (LPARAM)hIcon1); //任务栏 alt + tab
SendMessage(hMainWnd, WM_SETICON, ICON_SMALL, (LPARAM)hIcon1); //标题栏 程序exe图标
<1> HWNDCreateDialog( HINSTANCE hInstance, // handle to module
LPCTSTRlpTemplate, // dialog box template name
HWNDhWndParent, // handle to owner window
DLGPROClpDialogFunc // dialog box procedure);
<2> HWND CreateDialogIndirect( HINSTANCE hInstance, // handle to module
LPCDLGTEMPLATE lpTemplate, //dialog box template
HWND hWndParent, // handle to owner window
DLGPROC lpDialogFunc //dialog box procedure);
<3> HWND CreateDialogIndirectParam( HINSTANCE hInstance, // handle to module
LPCDLGTEMPLATE lpTemplate, // dialog box template
HWND hWndParent, // handle to owner window
DLGPROC lpDialogFunc, // dialog box procedure
LPARAM lParamInit // initialization value);
<4> HWND CreateDialogParam( HINSTANCE hInstance, // handle to module
LPCTSTR lpTemplateName, //dialog box template
HWND hWndParent, // handle to owner window
DLGPROC lpDialogFunc, //dialog box procedure
LPARAM dwInitParam //initialization value);
参数跟非模态对话框一致。CreateDialogParam会调用CreateWindowExe去创建一个窗口,所以这样的对话框其实就是窗口。当然单独一个对话框可以没有父窗口直接单独存在。
2 含有父窗口的对话框程序
3 自定义窗口类(无父窗口)的对话框程序
<1>在脚本中指定对话框的类型以及各种控件假定脚本名称为new.dlg
<2>然后在rc文件中添加脚本
<3>在WinMain函数注册窗口类
注意这里的CreateDialog的最后一个参数DLGPROC为NULL,因为在窗口类中指定了窗口过程函数。
- int WINAPI WinMain (HINSTANCE hInstance, HINSTANCEhPrevInstance,PSTR szCmdLine, intiCmdShow)
- {
- staticTCHAR szAppName[] = TEXT ("HexCalc");
- HWND hwnd ;
- MSG msg ;
- WNDCLASS wndclass ;
- wndclass.style = CS_HREDRAW | CS_VREDRAW ;
- wndclass.lpfnWndProc = WndProc ;
- wndclass.cbClsExtra = 0 ;
- wndclass.cbWndExtra = DLGWINDOWEXTRA ; // note here
- wndclass.hInstance = hInstance ;
- wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
- wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
- wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
- wndclass.lpszMenuName = NULL ;
- wndclass.lpszClassName =szAppName ;
- if(!RegisterClass (&wndclass))
- {
- MessageBox ( NULL, TEXT ("Thisprogram requires Windows NT!"), szAppName, MB_ICONERROR) ;
- return0 ;
- }
- hwnd =CreateDialog(hInstance,szAppName,NULL,NULL); //note here
- ShowWindow (hwnd, iCmdShow) ;
- UpdateWindow (hwnd) ;
- while(GetMessage (&msg, NULL, 0, 0))
- {
- TranslateMessage (&msg) ;
- DispatchMessage (&msg) ;
- }
- returnmsg.wParam ;
- }
12 从资源加载(无父窗口)的对话框程序
- LRESULT CALLBACKWndProc(HWND,UINT,WPARAM,LPARAM) ;
- int WINAPI WinMain (HINSTANCE hInstance, HINSTANCEhPrevInstance,PSTR szCmdLine, intiCmdShow)
- {
- HWND hwnd ;
- MSG msg ;
- //hwnd =CreateDialog(hInstance,MAKEINTRESOURCE(IDD_DIALOG1),NULL,(DLGPROC)WndProc);
- hwnd =CreateDialogParam(hInstance,MAKEINTRESOURCE(IDD_DIALOG1),NULL,(DLGPROC)WndProc,NULL);
- ShowWindow (hwnd, iCmdShow) ;
- UpdateWindow (hwnd) ;
- while(GetMessage (&msg, NULL, 0, 0))
- {
- TranslateMessage (&msg) ;
- DispatchMessage (&msg) ;
- }
- returnmsg.wParam ;
- }
生成的单独对话框程序如下图所示:
转自:http://blog.csdn.net/ddupd/article/details/24491201