code_junkie

Window “on desktop”

Nov 12th, 2011
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using System.Windows;
  4. using System.Windows.Interop;
  5.  
  6. [DllImport("user32.dll")]
  7. static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X,
  8. int Y, int cx, int cy, uint uFlags);
  9.  
  10. const UInt32 SWP_NOSIZE = 0x0001;
  11. const UInt32 SWP_NOMOVE = 0x0002;
  12. const UInt32 SWP_NOACTIVATE = 0x0010;
  13.  
  14. static readonly IntPtr HWND_BOTTOM = new IntPtr(1);
  15.  
  16. public static void SetBottom(Window window)
  17. {
  18. IntPtr hWnd = new WindowInteropHelper(window).Handle;
  19. SetWindowPos(hWnd, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
  20. }
  21.  
  22. [DllImport("user32.dll")]
  23. static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
  24. [DllImport("user32.dll", SetLastError = true)]
  25. static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
  26.  
  27. public static void SetOnDesktop(Window window)
  28. {
  29. IntPtr hWnd = new WindowInteropHelper(window).Handle;
  30. IntPtr hWndProgMan = FindWindow("Progman", "Program Manager");
  31. SetParent(hWnd, hWndProgMan);
  32. }
Add Comment
Please, Sign In to add comment