首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

问个很弱智的有关问题 先回答先结贴给分

2012-04-11 
问个很弱智的问题 先回答先结贴给分!代码如下:C/C++ code#include windows.h#pragma comment(lib,winmm

问个很弱智的问题 先回答先结贴给分!
代码如下:

C/C++ code
#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);}


请问为什么我按下esc键没有退出程序呢?

[解决办法]
case WM_KEYDOWN:
{
if(GetAsyncKeyState(VK_ESCAPE)&0x8000) //问题在这!!
{
PostQuitMessage(0);
}
return 0;
}
[解决办法]
[cdoe=C/C++]
wndclass.lpszClassName = "CLASS";
...
hwnd = CreateWindowEx(NULL,"Class"...
[/code]

热点排行