我插入IsDialogMessage()
了我的主循环,以便在选项卡控件(在我的真实代码中)中的选项卡键工作,但WM_CHAR
消息停止工作。WM_KEYDOWN
仍在工作,但我计划处理原始字符WM_CHAR
和组合键,WM_KEYDOWN
因此我将同时处理键盘输入。为什么它停止工作?我错过了什么?
这是完整的代码:
#pragma comment(lib, "user32.lib")
#define WIN32_LEAN_AND_MEAN
#define UNICODE
#define _UNICODE
#include <windows.h>
#include <assert.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
HWND hMainWindow;
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
PWSTR lpCmdLine, int nCmdShow) {
MSG msg = {0};
WNDCLASSW wc = {0};
wc.lpszClassName = L"window1";
wc.hInstance = hInstance;
wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
wc.lpfnWndProc = WndProc;
wc.hCursor = LoadCursor(0, IDC_ARROW);
if(!RegisterClass(&wc)) {
assert(!"register window failed!");
}
hMainWindow = CreateWindow(wc.lpszClassName, L"dear window",
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
100, 100, 330, 270, 0, 0, hInstance, 0);
while (GetMessage(&msg, NULL, 0, 0))
{
if (!IsDialogMessage(hMainWindow, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int) msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg,
WPARAM wParam, LPARAM lParam) {
switch(msg) {
case WM_CREATE:
CreateWindowW(L"Static", L"this is label1",
WS_CHILD | WS_VISIBLE | SS_LEFT,
20, 20, 300, 230,
hwnd, (HMENU) 1, NULL, NULL);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_CHAR:
{
static wchar_t buffer[2] = {0};
buffer[0] = wParam;
MessageBox(0, buffer, L"you typed", MB_OK);
}
break;
}
return DefWindowProcW(hwnd, msg, wParam, lParam);
}