问题描述
- 关于无法创建w32窗口的问题
-
#include
#includeLRESULT _stdcall WndProc (HWND, UINT, WPARAM, LPARAM);
int _stdcall _tWinMain ( HINSTANCE hInstance, HINSTANCE hPrevInstance, PTSTR szCmdLine, int iCmdShow)
{
WNDCLASSEX wndClassEx;
wndClassEx.cbSize = sizeof(WNDCLASSEX);
wndClassEx.style = CS_HREDRAW | CS_VREDRAW;
wndClassEx.lpfnWndProc = WndProc;
wndClassEx.cbClsExtra = 0;
wndClassEx.cbWndExtra = 0;
wndClassEx.hInstance = hInstance;
wndClassEx.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wndClassEx.hCursor = LoadCursor (NULL,IDC_ARROW);
wndClassEx.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
wndClassEx.lpszMenuName = NULL;
wndClassEx.lpszClassName = L"SimWinClass";
wndClassEx.hIconSm = NULL;if(!RegisterClassEx(&wndClassEx)) { MessageBox(NULL,L"注册窗口类失败!",L"SimpleWinApp",0); return 0; } HWND hwnd = NULL; hwnd = CreateWindowEx( NULL, L"SimWinApp", L"SimpleWinApp", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL ); if(hwnd == NULL) { MessageBox(NULL, L"创建窗口失败", L"SimpleWinApp",0); return 0; } ShowWindow( hwnd, iCmdShow ); UpdateWindow( hwnd ); MSG msg; while( GetMessage( &msg, NULL, 0, 0)) { TranslateMessage( &msg ); DispatchMessage( &msg ); } return msg.wParam ;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wparam, LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
break;case WM_KEYDOWN: if( wparam == VK_ESCAPE) PostQuitMessage (0); break; case WM_DESTROY: PostQuitMessage (0); break; } return DefWindowProc(hwnd, message, wparam, lParam);
}
代码如上,基础窗口创建显示创建失败,句柄无法获取,求解答
解决方案
用WINAPI,别用_stdcall,64位的WINAPI是_fastcall
另外关于win32创建窗口:
http://blog.csdn.net/zuishikonghuan/article/details/46378475
解决方案二:
CreatWindowEx()里的窗口类名写错了。