新手学习windows编程,遇到问题了,求教!
不知道为什么,没有出现窗口。。。
- C/C++ code
#include <windows.h>LRESULT CALLBACK WindowProc( HWND hwnd, // handle to window UINT uMsg, // message identifier WPARAM wParam, // first message parameter LPARAM lParam // second message parameter);int WINAPI WinMain( HINSTANCE hInstance, // handle to current instance HINSTANCE hPrevInstance, // handle to previous instance LPSTR lpCmdLine, // command line int nCmdShow // show state){ WNDCLASS wndclass; wndclass.cbClsExtra=0; wndclass.cbWndExtra=0; wndclass.hbrBackground=(HBRUSH) GetStockObject (WHITE_BRUSH); wndclass.hCursor=NULL; wndclass.hIcon=NULL; wndclass.hInstance=hInstance; wndclass.lpfnWndProc=WindowProc; wndclass.lpszClassName="my first"; wndclass.style=CS_VREDRAW | CS_HREDRAW; wndclass.lpszMenuName=NULL; RegisterClass(&wndclass); HWND hwnd=CreateWindow( "my first", // registered class name NULL, // window name WS_BORDER, // window style 0, // horizontal position of window 0, // vertical position of window 20, // window width 20, // window height NULL, // handle to parent or owner window NULL, // menu handle or child identifier hInstance, // handle to application instance NULL // window-creation data ); ShowWindow( hwnd, // handle to window SW_MAXIMIZE // show state ); UpdateWindow( hwnd // handle to window ); MSG msg; while(GetMessage( &msg, // message information hwnd, // handle to window NULL, // first message NULL // last message ) ) { TranslateMessage (&msg) ; DispatchMessage (&msg) ; } return 0;}LRESULT CALLBACK WindowProc( HWND hwnd, // handle to window UINT uMsg, // message identifier WPARAM wParam, // first message parameter LPARAM lParam // second message parameter){ switch(uMsg) { case WM_LBUTTONDOWN: MessageBox( hwnd, // handle to owner window "lbuttondown", // text in message box "zhq message box title", // message box title MB_OK // message box style ); return 0; case WM_DESTROY: PostQuitMessage (0) ; return 0; } return 0;}[解决办法]
case WM_DESTROY:
PostQuitMessage (0) ;
return 0;
添加下面一句
- C/C++ code
default: //执行默认的消息处理 return(DefWindowProc(hwnd,uMsg,wParam,lParam));