• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2085
  • Last Modified:

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
0
Bruce_1975
Asked:
Bruce_1975
  • 2
1 Solution
 
Daniel JungesCommented:
[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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now