倒数第七行用了:
case WM_DESTROY:
PostQuitMessage(0);
本以为这段可以关闭进程的,但是在关闭这个程序运行的窗口之后我在资源管理器的进程中依然发现了wins这个进程在运行。
请问如何关闭进程。
下边是发生这个问题的个小程序。
谢谢回复的人。
#include <windows.h>
#include <stdio.h>
LRESULT CALLBACK WinCccProc(
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 wndcls;
wndcls.cbClsExtra=0;
wndcls.cbWndExtra=0;
wndcls.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndcls.hCursor=LoadCursor(NULL,IDC_APPSTARTING);
wndcls.hIcon=LoadIcon(NULL,IDI_EXCLAMATION);
wndcls.hInstance=hInstance;
wndcls.lpfnWndProc=WinCccProc;
wndcls.lpszClassName="hello world!";
wndcls.lpszMenuName=NULL; //可能要删除的,应该变为NULL,稍后测试之后决定是否更改。
wndcls.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndcls);
HWND hwnd;
hwnd=CreateWindow("hello world!","我爱我老婆",WS_OVERLAPPEDWINDOW,0,0,600,400,NULL,NULL,
hInstance,NULL);
ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
MSG msg;
while (GetMessage(&msg, hwnd, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WinCccProc(
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,"这个数字是 %d",wParam);
MessageBox(hwnd,szChar,"hello world!",0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"鼠标左键单击","hello world!",0);
HDC hdc;
hdc=GetDC(hwnd);
TextOut(hdc,0,50,"这次是鼠标左键单击",strlen("这次是鼠标左键单击"));
ReleaseDC(hwnd,hdc);
break;
case WM_RBUTTONDOWN:
MessageBox(hwnd,"鼠标右键单击","hello world!",0);
hdc=GetDC(hwnd);
TextOut(hdc,0,100,"这次是鼠标右键单击",strlen("这次是鼠标右键单击"));
ReleaseDC(hwnd,hdc);
break;
case WM_PAINT:
HDC hDC;
PAINTSTRUCT ps;
hDC=BeginPaint(hwnd,&ps);
TextOut(hDC,0,0,"桌面显示的是什么就是什么了!",strlen("桌面显示的是什么就是什么了!"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"是否真的要关闭?","hello world!",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}