Click here to Skip to main content
15,885,435 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my main application,I'mm calling a process named A.This process is calling another application B.Problem is,the process A is always top on my main window,but when process B starts it is situated behind my main window.It is occurring not every time I am doing the operation,but sometime.

After calling application A,I have applied wait for exit and then I am making main window thread to sleep(this is required in my case),in the mean time application B is started by A.This B process window sometime is behind the main window.

can any one suggest me to do anything?
Posted
Comments
Fredrik Bornander 16-Oct-14 6:44am    
WinForms or WPF or something else?
souvikcode 17-Oct-14 3:00am    
winform.

1 solution

Note that this is a copy of a solution from MSDN, cx and cy may not be needed for your particular case...

Try this if windows forms:

Process process = Process.Start(psi);
IntPtr windowHandle = process.MainWindowHandle;

RECT r;
GetWindowRect(new HandleRef(this, windowHandle), out r);

int cx = r.Right - r.Left;
int cy = r.Bottom - r.Top;

cx -= 20;
cy -= 20;

SetWindowPos(windowHandle, (IntPtr) SpecialWindowHandles.HWND_TOPMOST, r.Left, r.Top, cx, cy, SetWindowPosFlags.SWP_SHOWWINDOW);


If this helps, please take time to accept the solution.
 
Share this answer
 
Comments
souvikcode 17-Oct-14 3:04am    
I have seen this before but problem is I am not starting process B.I'm starting process A from my application and it is calling B.So to handle B I have to write code on A which is not possible.I think I can make you understand.
Sinisa Hajnal 17-Oct-14 3:09am    
Well, you can still get process B by GetProcessByName or some other function, right?

Conversely, if you minimize app A (if you have such control) B window will be visible. See if there is a flag HIDEWINDOW and use that for process A, again process B will remain visible.
souvikcode 17-Oct-14 3:45am    
I can not handle process A,this is actually installer exe.I have minimized the main application window after closing App A so that app B is visible,but when I run the whole thing from a folder,the main app is minimized and app B is maximized but it is then behind the folder window (i.e,folder is opened and all exes are there).If I minimize folder window then I can see app B.

You are right,I can get process B by getprocess by name.But When app A is closed then app B is started right?But if machine has low processor speed,then my main application's getprocessbyname() function is firing before and then app B is started.So it can not find B.That's why I am making main thread to sleep for 3 sec and then getprocessbyname().So if I handle process B then it will be handled after 3sec,right?But in the mean time process B is started.So it becomes behind.

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