Click here to Skip to main content
15,886,422 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am having two EXE. Each having two different forms

EXE 1 --> FORM 1, FORM 2

EXE 2 --> FORM 1, FORM 2


Why I complete a process on FORM 1 of EXE 1,
I am doing some process on EXE 2 and opening FORM 2 on EXE 2



C#
IntPtr hWnd = this.Handle;

if (hWnd != IntPtr.Zero)
{
    SetForegroundWindow(hWnd);
    ShowWindow(hWnd, int.Parse("9"));
}



But my required form is not on the top.
How to do so
Posted
Updated 3-Sep-14 8:25am
v2

1 solution

In the simplest case, you can use combination of SetActiveWindow with SetForegroundWindow. However, it works poorly in one case: the moment of time when the window to be activated opens a modal dialog.

So, the comprehensive solution is this: first, using the main window handle, you have to find the handle of this dialog, if any. This is done using the function GetLastActivePopup. This function will return either the handle of the dialog, or the handle of the main window which you already know. Activate that window.

Please see:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms633507%28v=vs.85%29.aspx[^],
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646311%28v=vs.85%29.aspx[^],
http://msdn.microsoft.com/en-us/library/windows/desktop/ms633539%28v=vs.85%29.aspx[^].

—SA
 
Share this answer
 
Comments
CPallini 3-Sep-14 12:33pm    
5.
Sergey Alexandrovich Kryukov 3-Sep-14 13:26pm    
Thank you, Carlo.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900