Link to home
Start Free TrialLog in
Avatar of laptop1vn
laptop1vn

asked on

How to activate MDI program on TOP MOST (MFC)?

I have MDI program, MFC, with one exe file, ex: mypro.exe

When I click mypro.exe, it run, and I program it to run one time only. (that is, when click second time or more to myprog.exe, it do not run because it's running already!)

But I want: when click second time or more, if IT not ON TOP MOST, It will become ON TOP MOST!

How to do that!

Thanks!
ASKER CERTIFIED SOLUTION
Avatar of alb66
alb66
Flag of Italy image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>>>> when click second time or more, if IT not ON TOP MOST, It will become ON TOP MOST!

Before terminating your second instance you could send a WM_ACTIVATE message to the top level window of your first instance. You could get the hwnd of the first instance either by enumerating the processes or the top level windows. Or if you have a p2p connection to your first instance anyhow (depends on how you found out that a previous instance exists) you could use that p2p to trigger your predecessor to make itself topmost (normally a SetFocus or handling the WM_ACTIVATE should be sufficient to get it top-most).