Setting Desktop location of window from process

Hi folks,
I have a small application .net application written in c# which starts an other software. Now I have the process and want to set the location of the main window on my desktop. After setting the location I want to set the WindowStyle to maximized.
Background Info: I have an environment with two monitors and depending on some variables I want to start the second application on the first or second monitor in fullscreen mode.

Thanks in advance!
Bruce
LVL 6
Bruce_1975Asked:
Who is Participating?
 
Daniel JungesConnect With a Mentor Commented:
[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
...
...
System.Diagnostics.Process myApp = System.Diagnostics.Process.Start( .... );
SetWindowPos( myApp.MainWindowHandle, IntPtr.Zero, ...


0
 
Bruce_1975Author Commented:
Hi jungles,
thx for the solution to my first problem (setting the position). It gave me the right direction to figure out how to maximize the window:


[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
...
...
System.Diagnostics.Process myApp = System.Diagnostics.Process.Start( .... );
 
// just set the position, no resize of window
SetWindowPos( myApp.MainWindowHandle, new IntPtr(0), myX, myY, 0, 0, 0x0001);
 
// set WindowStyle to maximized
ShowWindow(myApp.MainWindowHandle, 3);

Open in new window

0
 
Bruce_1975Author Commented:
Thx for your help!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.