Maximise or show a window without giving it focus

  • Thread starter Thread starter PaulR
  • Start date Start date
You have to use interop. Import the ShowWindow method from user32 and call
the method with the SW_SHOWNOAVTIVATE constant.

[DllImport("User32.dll")]

public extern static int ShowWindow( System.IntPtr hWnd, short cmdShow);

[Flags()]

public enum ShowWindow

{

SW_HIDE = 0,

SW_SHOWNORMAL = 1,

SW_NORMAL = 1,

SW_SHOWMINIMIZED = 2,

SW_SHOWMAXIMIZED = 3,

SW_MAXIMIZE = 3,

SW_SHOWNOACTIVATE = 4,

SW_SHOW = 5,

SW_MINIMIZE = 6,

SW_SHOWMINNOACTIVE = 7,

SW_SHOWNA = 8,

SW_RESTORE = 9,

SW_SHOWDEFAULT = 10,

SW_FORCEMINIMIZE = 11,

SW_MAX = 11

}

The call below does the job

ShowWindow(myWindow.Handle,(short)ShowWindow.SW_SHOWNOACTIVATE);


--
Bob Powell [MVP]
C#, System.Drawing


Check out the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Buy quality Windows Forms tools
http://www.bobpowell.net/xray_tools.htm

New Tips and Tricks include creating transparent controls
and how to do double buffering.
 
Back
Top