读书人

帮忙看一下这段代码有什么有关问题

发布时间: 2012-01-29 21:39:32 作者: rapoo

帮忙看一下这段代码有什么问题
#include <windows.h>
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd){
static TCHAR szAppName[] = TEXT( "TextOuta ");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
wndclass.style= CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc= WndProc;
wndclass.hIcon= LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor= LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground= (HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.cbClsExtra= 0;
wndclass.cbWndExtra= 0;
wndclass.hInstance= hInstance;
wndclass.lpszClassName= szAppName;
wndclass.lpszMenuName= NULL;
if( !RegisterClass( &wndclass ) ){
MessageBox(NULL,TEXT( "This application needs Windows NT! "),szAppName,MB_ICONERROR);
return 0;
}
hwnd = CreateWindow(szAppName,
TEXT( "Text out "),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hwnd,nShowCmd);
UpdateWindow(hwnd);
while( GetMessage(&msg,hwnd,0,0) ){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam){
/*HDC hdc;
PAINTSTRUCT ps;
switch(message){
case WM_CREATE:
return 0;
case WM_PAINT:
hdc = BeginPaint(hwnd,&ps);
//SetTextAlign(hdc,TA_TOP | TA_RIGHT);
//TextOut(hdc,100,100,TEXT( "HELLO WORLD "),11);
EndPaint(hwnd,&ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}*/
return DefWindowProc(hwnd,message,wParam,lParam);
}
窗口关闭了,但是进程还在,而且CPU占用率为100%

[解决办法]
while( GetMessage(&msg,hwnd,0,0) ){

while( GetMessage(&msg,NULL,0,0) ){

读书人网 >VC/MFC

热点推荐