Activate MDI window

Category: visual studio parallelcpp


flaviu_ on Wed, 02 Sep 2020 10:10:12

I have an MDI app, which start as hidden, and an icon is shown in system tray. After a time (few seconds), from that system tray icon is show up a notification balloon. And when I click on this balloon, I call this code:

void CMainFrame::On0Restore()
	// TODO: Add your command handler code here


But instead MDI app to be restore and activated, it is only restored, but not activated, and the taskbar icon is flashing several times:

The system tray icon has a right click menu, and this menu has Restore item. When user choose this system tray menu item, the MDI window is restored and activated correctly, this menu item also call CMainFrame::On0Restore. But when this CMaiFrame::On0Restore is called from balloon click, this code is run correctly. Why this simple code is not run as I expect every time ?

One important note: this issue is present ONLY if you run the app from Window Explorer, like in real situation. When you run this app from Visual Studio, everything is going alright.

I attach a sample project that illustrate the problem:!AtSPCxnvttzehDceOBTEmJ_Ll0T8?e=354DPT


Viorel_ on Wed, 02 Sep 2020 18:28:12

Try this handler:

void CMainFrame::On0Restore( )


   AllowSetForegroundWindow( GetCurrentProcessId( ) );

   ShowWindow( SW_SHOW );

   SetForegroundWindow( );