回复 2楼 吹水佬
打错了 是击中..
就是用资源管理器建了个菜单 然后菜单项wparam在273(菜单击中是的消息)的WM_COMMAND消息中 居然是65535 而我头文件中定义的是40001 ...于是很迷惑 是什么产生了这个问题.
用断点发现这个问题后 就把头文件的定义改成了65535后虽然可以运行. 但却依旧不明白问题所在.后来把原来的id删掉后 有重新命名了菜单按钮后.头文件又重新生成的值已经回复正常.代码也恢复正常..
但我依旧不明白问题所在.问题所在地方我在代码中注释了.
#include<windows.h>
#include"resource.h"
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
BOOL CALLBACK DlgProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASS wndclass;
HWND hwnd;
MSG msg;
static TCHAR szname[] = TEXT("About2");
wndclass.style = CS_VREDRAW | CS_HREDRAW;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hIcon = LoadIcon(hInstance, szname);
wndclass.hInstance = hInstance;
wndclass.lpfnWndProc = WndProc;
wndclass.lpszClassName = szname;
wndclass.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);
if (!RegisterClass(&wndclass))
{
MessageBox(NULL, TEXT("CUOLE"), szname, MB_OKCANCEL);
}
hwnd = CreateWindow(szname, TEXT("ABOUT BOX DEMO PROGRAM"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
{
PAINTSTRUCT ps;
static HINSTANCE hinstance;
switch (message)
{
case WM_CREATE:
hinstance=((LPCREATESTRUCT)lparam)->hInstance;
//hinstance=
GetModuleHandle(NULL);
return 0;
case WM_COMMAND:
switch (LOWORD(wparam))// 问题在这里 当菜单被击中时 这个wparam值居然是65535.头文件中定义是40001
{
case ID_HLEP_ABOUT:
if (DialogBox(hinstance, MAKEINTRESOURCE(IDD_DIALOG1), hwnd, DlgProc))
InvalidateRect(hwnd, NULL, TRUE);
return 0;
}
return 0;
case WM_PAINT:
BeginPaint(hwnd, &ps);
EndPaint(hwnd, &ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, message, wparam, lparam);
}
BOOL CALLBACK DlgProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
{
switch (message)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
switch (LOWORD(wparam))
{
case IDOK:
case IDCANCEL:
EndDialog(hwnd, 0);
return TRUE;
}
break;
}
return FALSE;
}