简体   繁体   English

Win32 应用程序不被破坏

[英]Win32 Application is not destroyed

I am in the process of learning the Win32 API.我正在学习 Win32 API。 I have a problem where the window is visibly closed but the application is running in the background (I can see this using the Windows 10 task manager).我有一个问题,窗口明显关闭,但应用程序在后台运行(我可以使用 Windows 10 任务管理器看到这一点)。 Here is my code that closes the window:这是我关闭窗口的代码:

case WM_CLOSE:
    DestroyWindow(hwnd);
break;

case WM_DESTROY:
    PostQuitMessage(0);
break;

My application is called a.exe and you can see it in this screenshot I took of the Windows 10 task manager.我的应用程序名为 a.exe,您可以在我截取的 Windows 10 任务管理器屏幕截图中看到它。

这是一个.exe

Read the docs :阅读文档

"The PostQuitMessage function posts a WM_QUIT message to the thread's message queue and returns immediately; the function simply indicates to the system that the thread is requesting to quit at some time in the future. When the thread retrieves the WM_QUIT message from its message queue, it should exit its message loop and return control to the system. The exit value returned to the system must be the wParam parameter of the WM_QUIT message. “PostQuitMessage 函数将 WM_QUIT 消息发布到线程的消息队列并立即返回;该函数只是向系统指示该线程在未来某个时间请求退出。当线程从其消息队列中检索 WM_QUIT 消息时,它应该退出它的消息循环并将控制权返回给系统。返回给系统的退出值必须是 WM_QUIT 消息的 wParam 参数。

The WM_QUIT message is not associated with a window and therefore will never be received through a window's window procedure. WM_QUIT 消息与窗口无关,因此永远不会通过窗口的窗口过程接收到。 It is retrieved only by the GetMessage or PeekMessage functions."它只能由 GetMessage 或 PeekMessage 函数检索。”

See think link also.另请参阅思考链接

I have discovered the issue.我发现了这个问题。 Thanks for all the help but the window was actually being closed but the console was still open in the background.感谢所有帮助,但窗口实际上已关闭,但控制台仍在后台打开。 I was running:我之前在跑步:

FreeConsole();

and that was hiding the console.那是隐藏控制台。 When I closed the window the console kept running and I am now closing the console as well and it works.当我关闭窗口时,控制台继续运行,我现在也在关闭控制台并且它可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM