半抄半写了个简单windows程序,出现个问题
我希望在按下ESC键后程序退出,但是窗口销毁了,进程中却仍然能看到程序占用内存。请大家告诉我哪部分资源没有释放?代码如下:
#include <windows.h>
#include <windowsx.h>
LRESULT CALLBACK WindowProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd){
HWND hwnd;
WNDCLASSEX wc;
MSG msg;
memset(&wc,0,sizeof(wc));
wc.cbSize=sizeof(wc);
wc.style=CS_HREDRAW|CS_VREDRAW;
wc.lpfnWndProc = WindowProc;//指向消息处理函数的指针
wc.cbClsExtra=0; wc.cbWndExtra=0;
wc.hInstance=hInstance;
wc.hIcon = LoadIcon( hInstance,"IDI_APP_ICON" );
wc.hIconSm= LoadIcon(hInstance,"IDI_APP_ICON");
wc.hCursor= LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszClassName="SpinStudioMainWindow";
wc.lpszMenuName=NULL;
RegisterClassEx(&wc);
hwnd= CreateWindowEx(0,"SpinStudioMainWindow","MyWindow",WS_POPUP,0,0,640,480,NULL,NULL,hInstance,NULL);
if(!hwnd){
::MessageBox(NULL,"窗口创建失败","MyWindow",MB_ICONSTOP);
return FALSE;
}
ShowWindow(hwnd,nShowCmd);
UpdateWindow(hwnd);
while(TRUE){
if(GetMessage(&msg,NULL,0,0)){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return TRUE;
}
LRESULT CALLBACK WindowProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam){
switch(uMsg){
case WM_PAINT:
{
PAINTSTRUCT ps;
BeginPaint(hwnd,&ps);
char buf[]="Hello World!!";
TextOut(ps.hdc,0,0,buf,strlen(buf));
EndPaint(hwnd,&ps);
}
return(1);
case WM_KEYDOWN: //击键消息
switch ( wParam ){
case VK_ESCAPE:
PostMessage ( hwnd, WM_CLOSE, 0, 0 ) ;
break ;
}
break ;
case WM_CLOSE:{
MessageBox(NULL,"Goodbey!!","MyWindow",MB_DEFBUTTON1);
DestroyWindow(hwnd);
break;
}
case WM_DESTROY:{
PostQuitMessage(0);
break;
}
}
return DefWindowProc ( hwnd, uMsg, wParam, lParam ) ;
}