Activate MDI window

Flaviu_ 911 Reputation points
2020-09-02T10:08:55.493+00:00

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  
  
	ShowWindow(SW_RESTORE);  
	SetForegroundWindow();  
	SetActiveWindow();  
}  

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

22203-image.png

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: https://1drv.ms/u/s!AtSPCxnvttzehDceOBTEmJ_Ll0T8?e=354DPT

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,574 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,518 questions
{count} votes

Accepted answer
  1. Castorix31 81,461 Reputation points
    2020-09-02T14:36:47.913+00:00

    I tested on Windows 10, 1909
    The window is activated, but the icon is flashing
    To remove the flashing, I did :

    DWORD dwProcessId = 0;
    GetWindowThreadProcessId(m_hWnd, &dwProcessId);
    AllowSetForegroundWindow(dwProcessId);
    ::SetForegroundWindow(m_hWnd);
    
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful