父进程崩溃时关闭子窗口及其进程 [英] Closing child window and it's process when parent process crashes

查看:244
本文介绍了父进程崩溃时关闭子窗口及其进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个进程,其主窗口通过删除窗口边框,MoveWindow和SetParent嵌入到调用进程的主窗口中。



我可以当调用进程正常关闭时,使用TerminateProcess关闭嵌入式窗口的进程,但如果调用进程崩溃时出现此程序已停止工作的Windows消息,则子窗口的进程仍将在后台无形中运行资源。



关闭流程的唯一方法是在任务管理器的流程选项卡中手动关闭它,任何方法来解决这个问题,以便一切都能正常关闭崩溃?



谢谢。

I am creating a process whose main window is then embedded in the calling process' main window by removing the window border, MoveWindow, and SetParent.

I can use TerminateProcess to close the process of the embedded window when the calling process is closed properly, but if the calling process crashes with a "this program has stopped working" Windows message, the child window's process will still be running invisibly in the background eating up resources.

The only way to close the process is by closing it manually in the processes tab of the task manager, Any way to fix this so that everything closes properly even during a crash?

Thanks.

推荐答案

您可以考虑做的事情是实施定期检查机制。子进程将检查其父进程的HWND是否为有效的HWND。您可以设置一个根据需要经常触发的计时器。



您可以使用以下内容:

Something you could consider doing, is to implement a regular checking mechanism. The child process would check if the HWND of its parent is a valid HWND. You could set a timer that fired as often as required.

You could use something like the following:
case WM_TIMER:
{
    UINT_PTR wTimerId = wParam;
    switch (wTimerId)
    {
        case checkIfParentAliveTimerId:
        {
            HWND parent = GetParent(hwnd);
            if (IsWindow(parent) == false)
            {
                // parent handle doesn't point to a valid window.
                // initiate clean-up and exit here
            }
        }
        break;
    }
}
return 0;


这篇关于父进程崩溃时关闭子窗口及其进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆