-2

I have a wxWidgets windows application, I am launching annother application upon click a certain button on my appication, This new launched application behaves like to modal window and my application is sent back, But when user use Alt+Tab or click my appliction icon, My application comes to front, whereas child application which is already opened should have been shown

I figured how to bring an application to front, Now i would like to know if i can set a callback to parent application which will be called whenever application is activated (either through Alt+Tab or task bar icon or any other way), So i can bring my child application to front at this time.Is there a windwos API for this?

StraightCirle
  • 182
  • 2
  • 12

1 Answers1

1

WM_ACTIVATE

Sent to both the window being activated and the window being deactivated. If the windows use the same input queue, the message is sent synchronously, first to the window procedure of the top-level window being deactivated, then to the window procedure of the top-level window being activated. If the windows use different input queues, the message is sent asynchronously, so the window is activated immediately.

case WM_ACTIVATE: 
{ 
     // test if window is being activated 
     if(LOWORD(wParam)!=WA_INACTIVE) 
     { 
          // application is being activated 
     } 
     else 
     { 
          // application is being deactivated 
     } 
} 
break;

EDIT:

If you want to use a hook to monitor whether the window is switched, you can refer to this link.

Capture switch window event (window focus) (Alt+TAB)

Strive Sun
  • 5,988
  • 1
  • 9
  • 26
  • How to register for this message? – StraightCirle May 21 '19 at 09:57
  • @StraightCirle It can be placed directly in the callback function of the parent application. – Strive Sun May 21 '19 at 10:01
  • Sorry for the naive question here, I am new to windows API. So what is the api and register for WM_ACTIVE event? I tried with SetWinEventHook() but was not successful – StraightCirle May 21 '19 at 10:19
  • @StraightCirle You don't need to use `SetWinEventHook()` or register for WM_ACTIVE event. All you need to do is to add `WM_ACTIVATE` message in WndProc , see [this](https://stackoverflow.com/a/7301529/11128312). – Strive Sun Apr 21 '20 at 05:26