关于ShellExcute的问题

tanyajun 2003-10-16 11:53:20
我怎么才能得到用ShellExcute打开的程序的HWND?
...全文
101 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
vcforever 2003-10-16
  • 打赏
  • 举报
回复
先通过下面的函数根据第一个参数得到模块的名称
DWORD GetModuleFileName(
HMODULE hModule, // 你的程序中的HINSTANCE
LPTSTR lpFilename, // 存放模块名称的缓冲区
DWORD nSize // 缓冲区的大小
);
然后在通过下面的函数得到你需要的HWND
HWND FindWindow(
LPCTSTR lpClassName, // 类名称
LPCTSTR lpWindowName // 窗口名称
);

祝你成功!


flyelf 2003-10-16
  • 打赏
  • 举报
回复
用EnumThreadWindows可以获取窗口句柄
tanyajun 2003-10-16
  • 打赏
  • 举报
回复
我想从ShellExcute得到的HINSTANCE有办法得到HWND吗?
如果我不知道程序的Class和Name怎么能用FindWindow得到HWND?
feeboby 2003-10-16
  • 打赏
  • 举报
回复
FindWindow()
蒋晟 2003-10-16
  • 打赏
  • 举报
回复
Note ShellExecuteEx does not always return an hProcess, even if a process is launched as the result of the call. For example, an hProcess does not return when you use SEE_MASK_INVOKEIDLIST to invoke IContextMenu.

to obtain information of the process created by CreateProcess,get information from the PROCESS_INFORMATION structure returned by CreateProcess.
Creating Processes
The CreateProcess function creates a new process, which runs independently of the creating process. However, for simplicity, the relationship is referred to as a parent-child relationship.


The following code fragment demonstrates how to create a process.

void main( VOID )
{
STARTUPINFO si;
PROCESS_INFORMATION pi;

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

// Start the child process.
if( !CreateProcess( NULL, // No module name (use command line).
"MyChildProcess", // Command line.
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
FALSE, // 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 ) // Pointer to PROCESS_INFORMATION structure.
)
{
ErrorExit( "CreateProcess failed." );
}

// Wait until child process exits.
WaitForSingleObject( pi.hProcess, INFINITE );

// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
}
If CreateProcess succeeds, it returns a PROCESS_INFORMATION structure containing handles and identifiers for the new process and its primary thread. The thread and process handles are created with full access rights, although access can be restricted if you specify security descriptors. When you no longer need these handles, close them by using the CloseHandle function.

u can get the toplevel of the main thread by using function EnumWindows and GetWindowThreadProcessId

Command what is yours
Conquer what is not
quanch 2003-10-16
  • 打赏
  • 举报
回复
To obtain information about the application that is launched as a result of calling ShellExecute, use ShellExecuteEx.
用ShellExecuteEx试试。

15,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧