DispatchMessage声明如下:
WINUSERAPI
LRESULT
WINAPI
DispatchMessageA(
__in CONST MSG *lpMsg);
WINUSERAPI
LRESULT
WINAPI
DispatchMessageW(
__in CONST MSG *lpMsg);
#def UNICODE
# DispatchMessage DispatchMessageW
#
# DispatchMessage DispatchMessageA
#end // !UNICODE
lpMsg是指向想向消息处理WindowProc发送消息
这个例子如下:
#001 //主入口
#002 //
#003 // 蔡军生 2007/07/19
#004 // QQ: 9073204
#005 //
#006 APIENTRY _tWinMain(HINSTANCE hInstance,
#007 HINSTANCE hPrevInstance,
#008 LPTSTR lpCmdLine,
#009 nCmdShow)
#010 {
#011 UNREFERENCED_PARAMETER(hPrevInstance);
#012 UNREFERENCED_PARAMETER(lpCmdLine);
#013
#014 //
#015 MSG msg;
#016 HACCEL hAccelTable;
#017
#018 // 加载全局串
#019 LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
#020 LoadString(hInstance, IDC_TESTWIN, szWindowClass, MAX_LOADSTRING);
#021 MyRegisterClass(hInstance);
#022
#023 // 应用化:
#024 (!InitInstance (hInstance, nCmdShow))
#025 {
#026 FALSE;
#027 }
#028
#029 hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_TESTWIN));
#030
#031 // 消息循环:
#032 BOOL bRet;
#033 while ( (bRet = GetMessage(&msg, NULL, 0, 0)) != 0)
#034 {
#035 (bRet -1)
#036 {
#037 //处理出错
#038
#039 }
#040 (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
#041 {
#042 TranslateMessage(&msg);
#043 DispatchMessage(&msg);
#044 }
#045 }
#046
#047 () msg.wParam;
#048 }
#049
第43行就是DispatchMessage发送消息
最新评论