我编写了一个简单的窗口程序,检查多遍怎么也检查不出错误来,请VC高手看看,指出其中的错误或找出原因。小弟不胜感激……源程序如下:
#include <windows.h>
#include <stdio.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, // pointer to command line
int nCmdShow // show state of window
)
{
WNDCLASS wincls;
wincls.cbClsExtra=0;
wincls.cbClsExtra=0;
wincls.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wincls.hCursor=LoadCursor(NULL,IDC_ARROW);
wincls.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wincls.hInstance=hInstance;
wincls.lpfnWndProc=WindowProc;
wincls.lpszClassName="CUIT";
wincls.lpszMenuName=NULL;
wincls.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wincls);
HWND hwnd;
hwnd=CreateWindow(
"CUIT", // pointer to registered class name
"Culture", // pointer to window name
WS_OVERLAPPEDWINDOW, // window style
CW_USEDEFAULT, // horizontal position of window
0, // vertical position of window
600, // window width
400, // window height
NULL, // handle to parent or owner window
NULL, // handle to menu or child-window identifier
hInstance, // handle to application instance
NULL // pointer to window-creation data
);
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
)
{
HDC hdc;
PAINTSTRUCT ps;
switch(uMsg)
{
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
TextOut(hdc,0,0,"XXX编写",strlen("XXX编写"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"是否真的结束?","Culture",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}
编译完全通过,只是运行时没有窗口弹出,在任务管理器里有相应的进程运行,不知道为什么,请指教。