title: SetWindowPos moves window to different position every time
body: <p>I have a Windows application (which I am writing in C#) that starts with a maximized window without borders.</p>
  
  <p>When the user clicks on a button in the application, I want to restore the window (that is, remove the maximized state), resize it to a certain size and move it to the bottom-right corner of the screen.</p>
  
  <p>My problem is that the call to <code>SetWindowPos()</code>, while resizing the window correctly, does not always place it in the bottom-right corner of the screen. Sometimes it does, yet some other times the window is placed elsewhere on the screen (almost as if it were "jumping" around, for a reason which I ignore).</p>
  
  <p>What am I doing wrong?</p>
  
  <p>Here is my code. Note that I pass -1 as second parameter to SetWindowPos because I want my window to be on top of every other window.</p>
  
  <pre><code>public void MoveAppWindowToBottomRight()
  {
      Process process = Process.GetCurrentProcess();
  
      IntPtr handler = process.MainWindowHandle;
  
      ShowWindow(handler, 9); // SW_RESTORE = 9
      int x = (int)(System.Windows.SystemParameters.PrimaryScreenWidth - 380);
      int y = (int)(System.Windows.SystemParameters.PrimaryScreenHeight - 250);
  
      NativePoint point = new NativePoint { x = x, y = y };
  
      ClientToScreen(handler, ref point);
      SetWindowPos(handler, -1, point.x, point.y, 380, 250, 0);            
  }
  
  [StructLayout(LayoutKind.Sequential)]
  public struct NativePoint
  {
      public int x;
      public int y;
  }
  </code></pre>