Activate CMFCPropertySheet Application
-
Hallo,
ich habe ein PropertySheet Dialog Applikation, welche sich von ShowWindow(SW_HIDE) wieder auf den Desktop schieben soll. Mein Versuch
this == das CMyPropertySheet
DWORD dwForegroundThread = ::GetWindowThreadProcessId(::GetForegroundWindow(), NULL); DWORD dwCurrentThread = ::GetCurrentThreadId(); if (dwForegroundThread != dwCurrentThread) { if (AttachThreadInput(dwForegroundThread, dwCurrentThread, TRUE)) { this->SetWindowPos(&CWnd::wndTopMost, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW); this->SetWindowPos(&CWnd::wndNoTopMost, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW); AttachThreadInput(dwForegroundThread, dwCurrentThread, FALSE); } }obiges bringt mir die App zwar auf den Desktop, aber deaktiviert. Wie aktiviere ich diese programmtechnisch ?
Danke schon mal fürs lesen
-Uwe
-
Hier drei Links zum dem Thema:
Foreground activation permission
SetForegroundWindow
BringWindowToTopIch benutze folgenden Code:
void win32_show_process_main_window( HWND wnd, int command ) { HWND const fg_wnd = ::GetForegroundWindow(); DWORD const fg_thread_id = ::GetWindowThreadProcessId( fg_wnd, nullptr ); DWORD const my_thread_id = ::GetCurrentThreadId(); if( ::IsWindow( wnd ) ) { ::AttachThreadInput( fg_thread_id, my_thread_id, TRUE ); ::SetWindowPos( wnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE ); ::SetWindowPos( wnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE ); ::SetForegroundWindow( wnd ); ::SetFocus( wnd); ::SetActiveWindow( wnd ); ::AttachThreadInput( fg_thread_id, my_thread_id, FALSE ); if( ::IsIconic( wnd ) ) { ::ShowWindow( wnd, SW_RESTORE ); } ::ShowWindow( wnd, command ); ::BringWindowToTop( wnd ); } }
-
Hi DocShoe,
vielen Dank für Deinen Beitrag!
Leider funktioniert das bei mir nicht. Der Tastaturfocus ist/bleibt woanders. Das kann der Desktop sein, oder ein anderes unbeteiligtes Programm.Wenn ich meinen Code so ergänze
DWORD dwForegroundThread = ::GetWindowThreadProcessId(::GetForegroundWindow(), NULL); DWORD dwCurrentThread = ::GetCurrentThreadId(); if (dwForegroundThread != dwCurrentThread) { if (AttachThreadInput(dwForegroundThread, dwCurrentThread, TRUE)) { this->SetWindowPos(&CWnd::wndTopMost, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW); this->SetWindowPos(&CWnd::wndNoTopMost, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW); COXMessageBoxDialog dlgMessageBox(this, _T("Einen Moment bitte"), _T("DTPdfQuery"), MB_NO_SOUND); dlgMessageBox.SetTimeout(1, FALSE, TRUE); dlgMessageBox.DoModal(); AttachThreadInput(dwForegroundThread, dwCurrentThread, FALSE); } }dann funktioniert das mit der Übernahme des Tastaturfocus. Die MessageBox hat eine Lebenszeit von 1ms und erscheint nicht (bemerkbar) auf dem Bildschirm. Das habe ich schon einige Wochen auf unsere diverse TerminalServer2019 am laufen. Nur diese Vorgehensweise gefällt mir nicht so gut.
Nochmals danke für Deine Hilfe
-Uwe