Link to home
Start Free TrialLog in
Avatar of Bruce_1975
Bruce_1975

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of Daniel Junges
Daniel Junges
Flag of Brazil image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bruce_1975
Bruce_1975

ASKER

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

Thx for your help!