老师们好!两节之间,先祝老师们节日快乐!我是初学者,这是我的第一个程序,想实现一个简单的窗口,按ESC键推出(很可怜的要求呀!)只是不想用MFC(想打牢一点基础),遍译时说有错误,我对了书,书上是这样的呀,我已经被折磨了两天了,请那位老师帮我看看,谢谢了!
#include <windows.h>
HWND qd_hwnd;
WNDCLASS qd_wc;
MSG qd_msg;
LRESULT CALLBACK WndProc(HWND qd_hwnd,
UINT &qd_msg,
WPARAM wParam,
LPARAM lParam );
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hprevInstance,
LPSTR lpCmdLine,int nShowCmd)
{
static TCHAR QiDong[]=TEXT("qidongWin32");
qd_wc.style =CS_NOCLOSE;
qd_wc.lpfnWndProc =WndProc;//******编译时说这一条有问题,但是我核对了书的呀..
qd_wc.cbClsExtra =0;
qd_wc.cbWndExtra =0;
qd_wc.hInstance =hInstance;
qd_wc.hIcon =NULL;
qd_wc.hCursor =NULL;
qd_wc.hbrBackground =(HBRUSH)GetStockObject(WHITE_BRUSH);
qd_wc.lpszMenuName =NULL;
qd_wc.lpszClassName =QiDong;
if(! RegisterClass (&qd_wc))
{
MessageBox (NULL,TEXT("RegisterClass Fail!"),0,0);
return 0;
}
qd_hwnd = CreateWindow
( QiDong,
TEXT(" "),
WS_CAPTION,
0,
0,
600,
400,
0,
0,
hInstance,
0
);
ShowWindow(qd_hwnd,nShowCmd);
UpdateWindow(qd_hwnd);
while (GetMessage (&qd_msg, NULL, 0, 0))
TranslateMessage (&qd_msg) ;
DispatchMessage (&qd_msg) ;
return qd_msg.lParam;
}
LRESULT WINAPI wndProc( HWND qd_hwnd,
UINT &qd_msg,
WPARAM wParam,
LPARAM lParam )
{
switch (qd_msg)
{
case WM_KEYDOWN:
if(wParam == VK_ESCAPE)
PostMessage(qd_hwnd, WM_CLOSE, 0, 0);
break;
default:
return DefWindowProc(qd_hwnd,qd_msg,wParam,lParam);
}
return 0;
}