title: Move a window partially off the top of the screen
body: <p>I'm trying move a window partially off the top of the screen.  However, Windows' default behavior will pop it back down after I'm done moving it.  Yes, I understand why this particular functionality exists; however, I still don't want it for my window.  Then I notice that I can use <code>SetWindowPos</code> to set a window partially off the top of the screen, and it won't pops back down.  For example <code>SetWindowPos(...., -100, -100, ....)</code> will set my window above the screen 100 pixels, and it will stay there.  </p>
  
  <p>So, instead of moving my window normally (like sending <code>SendMessage(hwnd, WM_SYSCOMMAND, SC_MOVE | 0x0002, 0);</code>, I want to use <code>SetWindowPos</code> to move.  My idea is to handle <code>WM_MOUSEMOVE</code> and check the left mouse button is down.  If the left mouse button is down, I call <code>SetWindowPos</code> with some math done to current mouse position, previous mouse positions, and pass it through <code>SetWindowPos</code>.  </p>
  
  <p>So far I have it working but not very well.  First, if the mouse is move fast, it won't work at all.  Second, when the mouse moves slowly, the window would shakes as it moves.  </p>
  
  <p>Here is my WinProc: </p>
  
  <pre><code>LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  {
      static int lastMouseX = 0; 
      static int lastMouseY = 0; 
      switch (message)         /* handle the messages */
      {
      case WM_LBUTTONDOWN:
          lastMouseX = LOWORD(lParam); 
          lastMouseY = HIWORD(lParam); 
          break;
      //case WM_NCMOUSEMOVE: 
      case WM_MOUSEMOVE: 
          if(wParam == MK_LBUTTON)
          {
              int currentMouseX = LOWORD(lParam); 
              int currentMouseY = HIWORD(lParam); 
              int deltaX = currentMouseX - lastMouseX; 
              int deltaY = currentMouseY - lastMouseY; 
              RECT prc; 
              GetWindowRect(hwnd, &amp;prc);
              SetWindowPos(hwnd, NULL, prc.left + deltaX, prc.top + deltaY, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE);
              lastMouseX = currentMouseX; 
              lastMouseY = currentMouseY;
          }
          break; 
      case WM_DESTROY:
          PostQuitMessage (0);    /* send a WM_QUIT to the message queue */
          break;
  
      default:           /* for messages that we don't deal with */
          return DefWindowProc (hwnd, message, wParam, lParam);
      }
  
      return 0;
  }
  </code></pre>
  
  <p>Here is the full code <a href="http://pastebin.com/9A8iV5GW" rel="nofollow">http://pastebin.com/9A8iV5GW</a></p>
  
  <p>Further inspecting windows messages, I see exactly where Windows moves the window back down but I still don't know what I need to do.  I know it can be done, because I have seen it done in other apps.  </p>
  
  <pre><code>&lt;--I stop moving here with WM_LBUTTONUP --&gt;  
  &lt;windowMessage id="514" name="WM_LBUTTONUP"&gt;
    &lt;wParam&gt;0x00000000&lt;/wParam&gt;
    &lt;lParam&gt;0x0049009E&lt;/lParam&gt;
    &lt;returnValue&gt;0x00000000&lt;/returnValue&gt;
  &lt;-- And here is when windows moves it back down --&gt;  
  &lt;/windowMessage&gt;&lt;windowMessage id="534" name="WM_MOVING"&gt;
    &lt;wParam&gt;0x00000009&lt;/wParam&gt;
    &lt;lParam&gt;0x003FF220&lt;/lParam&gt;
    &lt;returnValue&gt;0x00000000&lt;/returnValue&gt;
  &lt;/windowMessage&gt;&lt;windowMessage id="70" name="WM_WINDOWPOSCHANGING"&gt;
    &lt;wParam&gt;0x00000000&lt;/wParam&gt;
    &lt;lParam&gt;0x003FEF98&lt;/lParam&gt;
    &lt;returnValue&gt;0x00000000&lt;/returnValue&gt;
  &lt;/windowMessage&gt;&lt;windowMessage id="36" name="WM_GETMINMAXINFO"&gt;
    &lt;wParam&gt;0x00000000&lt;/wParam&gt;
    &lt;lParam&gt;0x003FEC20&lt;/lParam&gt;
    &lt;returnValue&gt;0x00000000&lt;/returnValue&gt;
  &lt;/windowMessage&gt;&lt;windowMessage id="71" name="WM_WINDOWPOSCHANGED"&gt;
    &lt;wParam&gt;0x00000000&lt;/wParam&gt;
    &lt;lParam&gt;0x003FEF98&lt;/lParam&gt;
    &lt;returnValue&gt;0x00000000&lt;/returnValue&gt;
  &lt;/windowMessage&gt;&lt;windowMessage id="533" name="WM_CAPTURECHANGED"&gt;
    &lt;wParam&gt;0x00000000&lt;/wParam&gt;
    &lt;lParam&gt;0x00000000&lt;/lParam&gt;
    &lt;returnValue&gt;0x00000000&lt;/returnValue&gt;
  &lt;/windowMessage&gt;&lt;windowMessage id="70" name="WM_WINDOWPOSCHANGING"&gt;
    &lt;wParam&gt;0x00000000&lt;/wParam&gt;
    &lt;lParam&gt;0x003FF210&lt;/lParam&gt;
    &lt;returnValue&gt;0x00000000&lt;/returnValue&gt;
  &lt;/windowMessage&gt;&lt;windowMessage id="562" name="WM_EXITSIZEMOVE"&gt;
    &lt;wParam&gt;0x00000000&lt;/wParam&gt;
    &lt;lParam&gt;0x00000000&lt;/lParam&gt;
    &lt;returnValue&gt;0x00000000&lt;/returnValue&gt;
  &lt;/windowMessage&gt;
  </code></pre>