cocos2dx 在windows上实现键盘输入(3)
来源:未知 责任编辑:责任编辑 发表时间:2013-12-18 11:33 点击:次
p> {
p> keyChar = wParam;
p> InvalidateRect(hWnd,NULL,TRUE);
p> }
p> break;
p> case WM_DESTROY:
p> {
p> PostQuitMessage(NULL);
p> }
p> break;
p>
p> default:
p> return DefWindowProc(hWnd, Msg, wParam, lParam );
p> }
p> return 0;
p>}
p>
p>int WINAPI WinMain( HINSTANCE hInstance,
p> HINSTANCE hPrevInstance,
p> LPSTR lpCmdLine,
p> int nCmdShow
p>)
p>{
p> MSG stMsg;
p> WNDCLASSEX stdWndClass;
p> RtlZeroMemory(&stdWndClass, sizeof(stdWndClass));
p> stdWndClass.hCursor = LoadCursor(0,IDC_ARROW);
p> stdWndClass.cbSize = sizeof(stdWndClass);
p> stdWndClass.style = CS_HREDRAW|CS_VREDRAW;
p> stdWndClass.lpfnWndProc = ProcWinMain;
p> stdWndClass.hbrBackground = (HBRUSH)COLOR_WINDOW;
p> stdWndClass.lpszClassName = szClassName;
p> stdWndClass.hInstance = hInstance;
p>
p> RegisterClassEx(&stdWndClass);
p>
p> hWinMain = CreateWindowEx(WS_EX_CLIENTEDGE,szClassName,szCaptionMain,\
p> WS_OVERLAPPEDWINDOW,100,100,600,400,NULL,NULL,hInstance,NULL);
p>
p> if(!hWinMain)
p> return 0;
p>
p> ShowWindow(hWinMain,SW_SHOWNORMAL);
p> UpdateWindow(hWinMain);
p>
p>
p> while(GetMessage(&stMsg,NULL,0,0))
p> {
p> TranslateMessage(&stMsg);
p> DispatchMessage(&stMsg);
p> }
p>
p> return stMsg.wParam;
p>}
p>
p>分析:
p>
p>WPARAM keyChar = 0x20;
p>这个变量将保存从键盘接收到的字符。因为它是在窗口过程中通过WPARAM型变量传送的,所以我们简单地把它定义为WPARAM型。由于我们的窗口在初次刷新时(也即刚被创建的那一次)是没有键盘输入的所以我们把他设成空格符(20h),这样显示时您就什么都看不见。
p> case WM_CHAR:
p> {
p> keyChar = wParam;
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>