473,396 Members | 2,030 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 1609

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: serge calderara | last post by:
Dear all, I have an application which is suppose to start another executable process. As soon as that process is running, I need to retrive its handle. The problem of the particular process I am...
3
by: Richard L Rosenheim | last post by:
I have the application's form (MainForm) along with a 2nd form (Form2). If the user minimizes MainForm, I also minimize Form2. And when the user restores the application, I also restore Form2. ...
1
by: mac | last post by:
Hi everyone I need your help just want to know why my webforms doest maximize i paste the script on the onload event <head runat="server"> <title>Untitled Page</title> </head>
1
by: codejunkie | last post by:
Hi, I am running a suite of tests of a WIN 32 application. Every test launches the same application, checks if the Application has a Main Window handle and then proceeds. However i am noticing...
3
by: papalarge | last post by:
I have a VB.NET application that consists of a toolbar and a subwindow that I want to function together and not independently. So when I give focus to one, I want to make sure that the other is...
3
by: kannabiran | last post by:
Hi, I used this below code to maximize window its works fine..but the maximixe icon it doesnt changed its remains as the single box alone..i need a box overlap icon while maximizing the...
6
by: David In NH | last post by:
Hi All: I've got an application that uses a browser window to display help text for the program. When the user presses a button, a help window appears (maximized) in the user's default browser....
2
by: siddharthkhare | last post by:
Hi All, I am launching a IE using following code. ======================================================================= m_IeProcess = new Process(); m_IeProcess.StartInfo.WindowStyle =...
0
by: =?Utf-8?B?RXJpYw==?= | last post by:
My program is a call duty planning tool. It has a splitter with the two panels horizontally split. The upper panel has a month selector, 3 buttons, 3 labels and a datagridview. The lower panel has...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.