#include <windows.h> // Windows的头文件
#include <stdio.h>LRESULT CALLBACK WinSunProc(
HWND hwnd,      // handle to window
UINT uMsg,      // message identifier
WPARAM wParam,  // first message parameter
LPARAM lParam   // second message parameter
);
int WINAPI WinMain( HINSTANCE hInstance, 
 HINSTANCE hPrevInstance, 
 LPSTR lpCmdLine, 
 int nShowCmd )
{
WNDCLASS wc;
wc.cbClsExtra=0;
wc.cbWndExtra=0;
wc.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wc.hCursor=LoadCursor(NULL,IDC_CROSS);
wc.hIcon=LoadIcon(NULL,IDI_ERROR);
wc.hInstance=NULL;
wc.lpfnWndProc=WinSunProc;
wc.lpszClassName="CC";
wc.lpszMenuName=NULL;
wc.style= CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wc); HWND hwnd;
hwnd=CreateWindow("CC","我的第一个程序",WS_OVERLAPPEDWINDOW,
0,0,400,600,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd); MSG msg;

while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
} return 0;
}LRESULT CALLBACK WinSunProc(
HWND hwnd,      // handle to window
UINT uMsg,      // message identifier
WPARAM wParam,  // first message parameter
LPARAM lParam   // second message parameter
)
{
switch (uMsg)
{
case WM_CHAR: 
char szChar[20];
sprintf(szChar,"this is %d",wParam);
MessageBox(hwnd,szChar,"CC",0);
break;
case WM_LBUTTONDOWN:
break;
case WM_PAINT:
break;
case WM_CLOSE:
if (IDYES==MessageBox(hwnd,"是否真的关闭?","CC",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default :
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}上面的红色
当我点击窗口右上角的叉叉,对话框并没有弹出来,这是为什么?
谢谢

解决方案 »

  1.   

    试试if (IDYES==MessageBox(NULL,"是否真的关闭?","CC",MB_YESNO))
    因为你正在关闭hwnd,你又把它作为父窗口,可能会有问题?
      

  2.   

    其实窗口已经显示了,只是在绘图的时候有问题:把WM_PAINT消息处理一下就可以了。case WM_PAINT:
    {
    PAINTSTRUCT ps;
    BeginPaint(hwnd,&ps);
    EndPaint(hwnd,&ps); }
    break;
      

  3.   

    感谢!!!
    出来了,确实如此,谢谢Gdtr
    结账