问题
I want to Post messages directly to the HWND that's owned by COM in my process. How do I get the HWND that COM is using in single-threaded-apartment mode?
回答1:
Try this:
HWND prevWindow = NULL;
HWND hwnd;
for ( ;; )
{
hwnd = FindWindowEx( HWND_MESSAGE, prevWindow, L"OleMainThreadWndClass", NULL );
if ( !hwnd )
break;
if ( GetWindowThreadProcessId( hwnd, NULL ) == GetCurrentThreadId() )
break;
prevWindow = hwnd;
WCHAR className[255];
*className = 0;
::GetClassName( hwnd, className, 255 );
}
Let me know if it works.
来源:https://stackoverflow.com/questions/45385193/how-do-i-determine-the-internal-hwnd-used-by-com-in-my-current-process