v 0. Pasted by net3ton as csharp at 2007-03-29 13:06:14 MSK and set expiration to never.
v 1. Edited by Semaj as cpp at 2007-09-23 05:58:56 MSK and set expiration to 2007-09-26 05:58:56 MSK.
v 1. Edited by Anonymous as cpp at 2009-10-24 01:47:38 MSK and set expiration to 2009-10-24 13:47:38 MSK.
v 2. Edited by Anonymous as cpp at 2009-10-24 01:47:40 MSK and set expiration to never.
v 3. Edited by null as cpp at 2010-07-07 17:28:01 MSK and set expiration to never.

Paste will expire never.

  1. private void btnDoSome_Click(object sender, EventArgs e)
  2. {
  3.     IntPtr hWnd = WinApi.DeepFindWindow("DesktopExplorerWindow");
  4.     if (hWnd != IntPtr.Zero)
  5.     {
  6.         WinApi.SetWindowPos(hWnd, IntPtr.Zero, 0, 128,240, 320, 0);
  7.     }
  8. }
  9.  
  10. class WinApi
  11. {
  12.     public const int GW_HWNDFIRST = 0;
  13.     public const int GW_HWNDNEXT = 2;
  14.  
  15.     [DllImport("coredll.dll", EntryPoint = "GetActiveWindow")]
  16.     internal static extern IntPtr GetActiveWindow();
  17.  
  18.     [DllImport("coredll.dll", EntryPoint = "GetParent")]
  19.     internal static extern IntPtr GetParent(IntPtr hWnd);
  20.  
  21.     [DllImport("coredll.dll", EntryPoint = "GetClassName")]
  22.     internal static extern int GetClassName(IntPtr hWnd, [Out] StringBuilder lpString, int nMaxCount);
  23.  
  24.     [DllImport("coredll.dll", EntryPoint = "SetWindowPos")]
  25.     internal static extern bool SetWindowPos(IntPtr hWnd, IntPtr hwndParent, int X, int Y, int CX, int CY, uint uFlags);
  26.  
  27.     public static IntPtr DeepFindWindow(string sClassName)
  28.     {
  29.         IntPtr hWnd = GetActiveWindow();
  30.         hWnd = GetWindow(hWnd, GW_HWNDFIRST);
  31.  
  32.         while (hWnd != IntPtr.Zero)
  33.         {
  34.             IntPtr hWndPar = GetParent(hWnd);
  35.             if (hWndPar == IntPtr.Zero)
  36.             {
  37.                 StringBuilder strBClass = new StringBuilder(64);
  38.                 GetClassName(hWnd, strBClass, 64);
  39.                 if (strBClass.ToString() == sClassName) return hWnd;
  40.             }
  41.             hWnd = GetWindow(hWnd, GW_HWNDNEXT);
  42.         }
  43.  
  44.         return IntPtr.Zero;
  45.     }
  46. }