【发布时间】:2014-01-01 15:32:58
【问题描述】:
#include <stdio.h>
#include <stdlib.h>
#define WINVER 0x0500
#include <windows.h>
/// Glabal Handle
HANDLE StdHandle;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
StdHandle = GetStdHandle(STD_OUTPUT_HANDLE); // Console window
MSG Msg ;
while (GetMessage(&Msg, NULL, 0, 0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam ;
}
LRESULT CALLBACK WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_KEYDOWN:
if(wParam == VK_LCONTROL)
printf ("LSHIFT");
break;
return 0 ;
}
return DefWindowProc(hWnd, msg, wParam, lParam) ;
}
此代码可以使用 mingw32-GCC 编译,不会出现任何警告和错误。
如果按下左控件,它应该打印出“LSHIFT”,但它没有。
为什么?
【问题讨论】:
-
你在 WM_DESTROY 中错过了一次休息
-
@Digital_Reality 谢谢,我编辑了。但是还是不行。