其实和创建一个窗口的程序是一样的,但创建的函数不同,消息处理上有点不同.
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
MSG msg ;
WNDCLASS wndclass ;
InitCommonControls();
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = DLGWINDOWEXTRA ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (hInstance, szAppName);
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) (COLOR_BTNFACE+1) ;
wndclass.lpszMenuName = szAppName ;
wndclass.lpszClassName = szAppName ;
if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("This program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
//注意这里的szAppName它是对话框资源的名称,是TCHAR[]字符串数组
//当然你还可以用函数MAKEINTRESOURCE(IDC_DIALOG)来转换成TCHAR数组
hMainDlg = CreateDialog(hInstance,szAppName,NULL,(DLGPROC)WndProc);
ShowWindow (hMainDlg, iCmdShow) ;
UpdateWindow (hMainDlg) ;
//以下就是消息上的区别,仔细看一下和普通窗口有什么不同
while (GetMessage (&msg, NULL, 0, 0) )
{
if (!IsWindow(hMainDlg) || !IsDialogMessage(hMainDlg, &msg))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
}
其它代码就和创建普通窗口一样了,原理很简单,详细请看源代码
下载源代码