C语言WM_COMMAND接收不到控件消息,只显示窗口不显示对话框?
#include<windows.h>#include<stdio.h>
#include"resource.h"
static HINSTANCE hInst;
BOOL CALLBACK DlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDOK:
case IDCANCEL:
EndDialog(hDlg, 0);
return TRUE;
}
break;
}
return FALSE;
}
void Dialog(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
switch (LOWORD(wParam))
{
case IDD_DIALOG1:
DialogBox(hInst, (char*)IDD_DIALOG1, hWnd, DlgProc);
break;
}
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT msgID, WPARAM wParam, LPARAM lParam)
{
switch (msgID)
{
case WM_COMMAND:
Dialog(hWnd,msgID,wParam,lParam);
break;
case WM_CREATE:
hInst = ((LPCREATESTRUCT)lParam)->hInstance;
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hWnd, msgID, wParam, lParam);
}
int main()
{
{
HINSTANCE hInstance = GetModuleHandle(NULL);
WNDCLASS wc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 3);
wc.hCursor = NULL;
wc.hIcon = NULL;
wc.hInstance = hInstance;
wc.lpfnWndProc = WndProc;
wc.lpszClassName = "main";
wc.lpszMenuName = NULL;
wc.style = CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wc);
HWND hWnd = CreateWindowEx(0, "main", "Mordem Scanning", WS_OVERLAPPEDWINDOW, 100, 100, 900, 900, NULL, NULL, hInstance, NULL);
ShowWindow(hWnd, SW_SHOW);
UpdateWindow(hWnd);
MSG nMsg = { 0 };
while (1)
{
if (PeekMessage(&nMsg, hWnd, 0, 0, PM_NOREMOVE))
{
if (GetMessage(&nMsg, hWnd, 0, 0))
{
TranslateMessage(&nMsg);
DispatchMessage(&nMsg);
}
else
{
return 0;
}
}
else
{
}
}
}
}