title: WM_MOUSEMOVE LParam low-order Overflow
body: <p>When i receive a <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms645616%28v=vs.85%29.aspx" rel="nofollow">WM_MOUSEMOVE</a> message in WndProc the lParam contains the cursor coordinates. I translate this parameter into a <code>Point</code> structure:</p>
  
  <pre><code>Friend Shared Function LParamToPoint(ByVal lParam As IntPtr) As Point
      Return New Point(LOWORD(lParam.ToInt32()), HIWORD(lParam.ToInt32()))
  End Function
  
  Friend Shared Function HIWORD(ByVal value As Integer) As Short
      Return CShort((value &gt;&gt; 16))
  End Function
  
  Friend Shared Function LOWORD(ByVal value As Integer) As Short
      Return CShort((value And UShort.MaxValue))
  End Function
  </code></pre>
  
  <p>My problem is that when the x-coordinate of the cursor becomes negative the LOWORD function fails with an overflow exception. According to MSDN you should use the <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms632654%28v=vs.85%29.aspx" rel="nofollow">GET_X_LPARAM</a> and <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms632655%28v=vs.85%29.aspx" rel="nofollow">GET_Y_LPARAM</a> macros not the HI/LO WORD macros. But no such functions are available in vb.net.</p>
  
  <p>So what to do?</p>