单独建立对话框
单独建立对话框[align=center][/align]
下面的代码是单独建立非模态对话框的程序:
从中可以体会对话框的建立和窗口建立的区别。
/*--------------------------------- CreateDialog.cpp---Create About Dialog for myself. 2011 12 19 ---------------------------------*/#include <Windows.h>#include "resource.h"BOOL CALLBACK AboutDlgProc(HWND,UINT,WPARAM,LPARAM);int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance, PSTR szCmdLine,int iCmdShow){MSG msg;CreateDialog(hInstance, TEXT ("AboutDialog"), NULL, AboutDlgProc) ;//Add By HEWEI 2011 12 19/*下面这几句是消息循环:系统获得消息,然后应用程序通过GetMessage获得消息,在派遣到相应的回调函数*///End HEWEIwhile(GetMessage(&msg,NULL,0,0)){TranslateMessage(&msg);DispatchMessage(&msg);}return msg.wParam;}BOOL CALLBACK AboutDlgProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam){ switch (message) { case WM_INITDIALOG : return TRUE ; case WM_COMMAND : switch (LOWORD (wParam)) { case IDC_OK : case IDCANCEL : EndDialog (hDlg, 0) ; PostQuitMessage (0) ; //这句是通知系统关闭此线程 return TRUE ; } break ; default: DefWindowProc (hDlg, message, wParam, lParam) ; } return FALSE ;}