在我的程序中有如下代码:
HINSTANCE Ret;//开始切换服务
Ret = ShellExecute(m_hWnd,"open",StrApp1Path,"","",SW_SHOWNORMAL);问题1:如何得到ShellExecute启动的应用程序的进程句柄?
问题2:怎么得到相关的窗口句柄?要求不用查找窗体标题的方法(这样没有普遍性),如FindWindow,EnumWindows等函数.最好直接能从进程得到与其相关的窗体句柄.

解决方案 »

  1.   

    1.用CreateProcess,最后一个参数里包含了你要的句柄
    2.FindWindow,再通过GetWindowThreadProcessId验证是否属于你刚才创建的进程
      

  2.   

    BOOL ShellExecuteEx(
        LPSHELLEXECUTEINFO lpExecInfo
    );
      

  3.   

    BOOL ShellExecuteEx(
        LPSHELLEXECUTEINFO lpExecInfo
    );
    typedef struct _SHELLEXECUTEINFO{
        DWORD cbSize; 
        ULONG fMask; 
        HWND hwnd; 
        LPCTSTR lpVerb; 
        LPCTSTR lpFile; 
        LPCTSTR lpParameters; 
        LPCTSTR lpDirectory; 
        int nShow; 
        HINSTANCE hInstApp; 
     
        // Optional members 
        LPVOID lpIDList; 
        LPCSTR lpClass; 
        HKEY hkeyClass; 
        DWORD dwHotKey; 
    union {
    HANDLE hIcon;
    HANDLE hMonitor;
    };
        HANDLE hProcess; 
    } SHELLEXECUTEINFO, *LPSHELLEXECUTEINFO; 
      

  4.   

    怎么没人来???
    to:zhaolaoxin(), vcforever(霓裳羽衣)
    hInstApp不是返回进程的句柄hInstApp 
    If the function succeeds, it sets this member to a value greater than 32. If the function fails, it is set to an SE_ERR_XXX error value that indicates the cause of the failure. Although hInstApp is declared as an HINSTANCE for compatibility with 16-bit Windows applications, it is not a true HINSTANCE. It can be cast only to an integer and compared to either 32 or the following SE_ERR_XXX error codes.
      

  5.   

    下面是我从msdn上拷过来的If the function succeeds, it sets the hInstApp member of the SHELLEXECUTEINFO structure to the instance handle to the application that the function started. If the function fails, hInstApp is one of the SE_ERR_ error values indicating the cause of the failure. (An instance handle will always be greater than 32 and an error value less than 32.) Note that the SE_ERR_ error values are for compatibility with the ShellExecute function; use theGetLastError function to retrieve error information. 这好像可以得到,不过我建议各位还是用实践来证明一下