当CreateProcess创建2个进程时,如何等待子进程。 run32dll进程创建内部Windows照片查看器进程 [英] How to wait for child process when CreateProcess creates 2 process viz. run32dll process which creates internally windows photo viewer Process

查看:136
本文介绍了当CreateProcess创建2个进程时,如何等待子进程。 run32dll进程创建内部Windows照片查看器进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用CreateProcess()创建了一个使用Windows照片查看器打开图像的过程。由于Windows照片查看器不是.exe,它使用run32dll.exe运行,因此创建了2个进程。所以run32成为父进程,windows照片查看器是子进程。
现在我想等待创建子进程。怎么做...

I have created process using CreateProcess() to open image using windows photo viewer. Since windows photo viewer is not .exe, it run with run32dll.exe, hence creating 2 process. so run32 becomes the parent process and windows photo viewer is child process. Now I want to wait for child process to be created. How to do this...

我已经分享了代码片段...

I have shared the code snippet ...

STARTUPINFO si;

  ;    PROCESS_INFORMATION pi;

     ZeroMemory(& si,sizeof(si));

     si.cb = sizeof(si);

     ZeroMemory(& pi,sizeof(pi));

STARTUPINFO si;
    PROCESS_INFORMATION pi;
    ZeroMemory(&si, sizeof(si));
    si.cb = sizeof(si);
    ZeroMemory(&pi, sizeof(pi));

    CString appSt = L" rundll32 \" C:\\Program Files \\ Windows Phone Viewer \\PhotoViewer.dll \" ImageView_Fullscreen D:\\\\Results\\1.png" ;; $

    CString appSt = L"rundll32 \"C:\\Program Files\\Windows Photo Viewer\\PhotoViewer.dll\" ImageView_Fullscreen D:\\\\Results\\1.png";

CreateProcess(NULL,   //要执行的计划的名称

          CT2W(appSt),               //命令行

          NULL,                       //流程句柄不可继承

          NULL,                       //线程句柄无法继承

          TRUE,                      // S et处理继承为FALSE

             0,                          //没有创作标志

             NULL,                      //使用父母的环境块

             NULL,                      //使用父母的起始目录


            &安培; SI,                       //指向STARTUPINFO结构的指针

            & pi);

CreateProcess(NULL,   // Name of program to execute
            CT2W(appSt),              // Command line
            NULL,                      // Process handle not inheritable
            NULL,                      // Thread handle not inheritable
            TRUE,                     // Set handle inheritance to FALSE
            0,                         // No creation flags
            NULL,                      // Use parent's environment block
            NULL,                      // Use parent's starting directory
            &si,                       // Pointer to STARTUPINFO structure
            &pi);

WaitForSingleObject(pi.hProcess,INFINITE); //等待无限时间。

WaitForSingleObject(pi.hProcess, INFINITE); //its waiting for infinite time.

推荐答案

您好,

您可以查看是否使用FindWindow在Windows中打开照片查看器窗口:

https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-findwindowa

you could check if the photo Viewer window is opened in Windows, with FindWindow: https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-findwindowa

bool bBreakWait = false;
int nloop=0;
while (!bBreakWait)
{
   nloop++;
   Sleep(1000);
   if (FindWindow(NULL ,_T("window title")) != NULL)
      bBreakWait=true;
   else if (nloop > 10) // break the loop if the window is never opened so there is no endless loop
      bBreakWait=true;
}

检查任务管理器以了解照片查看器进程的名称。然后,您可以将其用于"窗口标题"。 (我不使用照片查看器,因此您必须自己查找名称。)

Check the task manager to know the name of the photo Viewer process. Then you can use it for "window title". (I don't use photo viewer, so you must look for the name yourself).

问候,Guido


这篇关于当CreateProcess创建2个进程时,如何等待子进程。 run32dll进程创建内部Windows照片查看器进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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