[英]Get handle to process for a Metro app
從桌面應用程序,我使用ActivateApplication啟動一個metro應用程序,我想將out參數進程id轉換為進程句柄,以便我可以使用WaitForSingleObjectEx或GetExitCodeProcess 。 我看到OpenProcess應該完全符合我的要求,但它不起作用。 返回的句柄始終為null。 我猜兩種可能性之一:
您可能想嘗試這個,循環瀏覽窗口並比較進程ID以找到正確的句柄。
HWND GetProcessWindow( DWORD processId )
{
// Now need to run a loop to get the correct window for process.
bool bFound = false;
HWND prevWindow = 0;
while ( ! bFound ) {
HWND desktopWindow = GetDesktopWindow();
if ( ! desktopWindow )
break;
HWND nextWindow = FindWindowEx( desktopWindow, prevWindow, NULL, NULL );
if ( ! nextWindow )
break;
// Check whether window belongs to the correct process.
DWORD procId = -1;
GetWindowThreadProcessId( nextWindow, &procId );
if ( procId == processId ) {
// Add additional checks. In my case, I had to bring the window to front so these checks were necessary.
wchar_t windowText[ 1024 ];
if ( IsWindowVisible( nextWindow ) && ! IsIconic( nextWindow ) && GetWindowText( nextWindow, ( LPWSTR )windowText, sizeof( windowText ) / sizeof( wchar_t ) )
&& ! GetParent( nextWindow ) )
return nextWindow;
}
prevWindow = nextWindow;
}
return 0;
}
參考: https : //social.msdn.microsoft.com/forums/windowsdesktop/en-us/7e25e104-36cb-41ac-8f36-0e4c6b6146a3/finding-hwnd-of-metro-app-using-win32-api
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.