问个很弱智的问题 先回答先结贴给分!
代码如下:
#include <windows.h>#pragma comment(lib,"winmm.lib")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 ){ WNDCLASSEX wndclass; wndclass.cbClsExtra = 0; wndclass.cbSize = sizeof(WNDCLASSEX); wndclass.cbWndExtra = 0; wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION); wndclass.hInstance = hInstance; wndclass.lpfnWndProc = WindowProc; wndclass.lpszClassName = "CLASS"; wndclass.lpszMenuName = NULL; wndclass.style = CS_HREDRAW | CS_VREDRAW; if(!RegisterClassEx(&wndclass)) { MessageBox(NULL,"Class Registration Failed!","Error",0); return 0; } HWND hwnd; hwnd = CreateWindowEx(NULL,"Class","TEST",WS_OVERLAPPEDWINDOW,0,0,600,400,NULL,NULL,hInstance,NULL); ShowWindow(hwnd, SW_SHOWNORMAL); UpdateWindow(hwnd); MSG msg; while(GetMessage(&msg,NULL,0,0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam;}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_CREATE: { PlaySound("Window_open.wav",NULL,SND_FILENAME | SND_ASYNC); return 0; } case WM_PAINT: { PAINTSTRUCT ps; BeginPaint(hwnd,&ps); EndPaint(hwnd,&ps); return 0; } case WM_DESTROY: { PostQuitMessage(0); return 0; } case WM_KEYUP: { if(GetAsyncKeyState(VK_ESCAPE) & 0x8000) //问题在这!! { PostQuitMessage(0); } return 0; } } return DefWindowProc(hwnd,uMsg,wParam,lParam);}