469,625 Members | 1,134 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,625 developers. It's quick & easy.

Maximizing and bringing another process main window on top

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
0 1410

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Richard L Rosenheim | last post: by
1 post views Thread by mac | last post: by
6 posts views Thread by David In NH | last post: by
2 posts views Thread by siddharthkhare | last post: by
reply views Thread by =?Utf-8?B?RXJpYw==?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.