By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,516 Members | 1,369 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,516 IT Pros & Developers. It's quick & easy.

Maximizing and bringing another process main window on top

P: n/a
We have an app which must be single instance. When we start the app we
check if it is already running (using the Process object in the
System.Diagnostics namespace) locating it by the name of the process.
It is not the problem. When it is already running we have to maximize
the already started application and bring it on top of other windows.

When we find our process we get the main window handle from the Process
object:
IntPtr hWnd = alreadyStartedAppProcess.MainWindowHandle;

We try to maximize it using Win32 API, using methods like :

1)
public static extern int SendMessage(int hWnd, uint Msg, int wParam,
int lParam);

in that way:
SendMessage(hwnd, WM_SYSCOMMAND, WM_MAXIMIZE | WM_SETFOCUS, 0);

//obtained from http://blogs.wwwcoder.com/ThePowderRanger/
Using it in that way only maximizing works.

2)
public static extern bool ShowWindow(int hWnd,int nCmdShow);

in that way:
ShowWindow(hWnd, SW_SHOWMAXIMIZED);

//info about ShowWindow can be found on
//http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowfunctions/showwindow.asp

Using it in that way has the desired effect except in the case when our
already started app window is already maximized. Then it does not
appear on top of the other windows.

3)
We have found a workaround which is something like:

ShowWindow(hWnd, SW_RESTORE);
ShowWindow(hWnd, SW_SHOWMAXIMIZED);

which has the desired effect in all cases. The problem with it is that
we want to avoid unneccessary resizing of the form, which happens in
the above two calls.

if you have any suggestions please help
thanks in advance

Mar 17 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.