Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make a window topmost using a window handle

Tags:

After launching an application using the Process class I'd like to make that window topmost. Currently, my app is the topmost window so when i launch the other app it doesn't display. One thing that came to mind is that I could set topmost = false for my application before launching the process, the problem with this is I want to give the process ample time to load up before displaying it to the user, so I'd like more control over when I switch the other application to the topmost.

like image 709
James Cadd Avatar asked Oct 06 '09 22:10

James Cadd


1 Answers

You need to use P/Invoke with SetWindowPos to accopmlish this:

[DllImport("user32.dll")] static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);  static readonly IntPtr HWND_TOPMOST = new IntPtr(-1); const UInt32 SWP_NOSIZE = 0x0001; const UInt32 SWP_NOMOVE = 0x0002; const UInt32 SWP_SHOWWINDOW = 0x0040;  // Call this way: SetWindowPos(theWindowHandle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW); 
like image 200
Reed Copsey Avatar answered Sep 22 '22 19:09

Reed Copsey