title: Reset cursor in WM_SETCURSOR handler properly
body: <h2>INTRODUCTION AND RELEVANT INFORMATION:</h2>
  
  <p>I have made an application that needs to change the look of a cursor into hand when mouse hovers above the static control, but resets it to a normal cursor otherwise.</p>
  
  <p>My initial application was in full screen mode, but recently terms have changed and it must have a resizable window.</p>
  
  <p>This means that my handler for <code>WM_SETCURSOR</code> must be rewritten to reflect newly introduced changes.</p>
  
  <p>Cursors are loaded in <code>WM_CREATE</code>, and I have defined class cursor, like this:</p>
  
  <pre><code>   // cursors 
     case WM_CREATE:
        hCursorHand = LoadCursor( NULL, IDC_HAND );
        hCursorArrow = LoadCursor( NULL, IDC_ARROW );
        // other stuff
  </code></pre>
  
  <p>In my class:</p>
  
  <pre><code>   WNDCLASSEX wc;
     // ...
     wc.hCursor = hCursorArrow;
     //...
  </code></pre>
  
  <p>This is my old <code>WM_CURSOR</code> handler ( code is simplified for clarity purposes ):</p>
  
  <pre><code>   case WM_SETCURSOR:
          if( (HWND)wParam == GetDlgItem( hwnd, 4000 ) ) 
               SetCursor(hCursorHand);
          else
               SetCursor(hCursorArrow);
          return TRUE;
  </code></pre>
  
  <p>If cursor hovers above static control, then my handler changes it to hand, else sets it to default cursor ( arrow ).</p>
  
  <p>Bellow is the picture I have sketched in Paint that displays the desired look of the cursor when it hovers above static control, it is on the client area, and when user resizes window. </p>
  
  <p><img src="https://i.stack.imgur.com/gsb7t.png" alt="enter image description here"></p>
  
  <p>If additional code snippets are required, ask and I will edit my post, but for now, they are omitted to keep the post short and concise.</p>
  
  <p>I work on Windows XP, using MS Visual Studio C++ and pure Win32 API. </p>
  
  <h2>MY  EFFORTS TO SOLVE PROBLEM:</h2>
  
  <p>Bellow are the code snippets that I have tried, but they all failed:</p>
  
  <p>First snippet:</p>
  
  <pre><code>   case WM_SETCURSOR:
          if( (HWND)wParam == GetDlgItem( hwnd, 4000 ) ) 
          {
               SetCursor(hCursorHand); 
               return TRUE; 
          }
          else
               return DefWindowProc( hWnd, msg, lParam, wParam );
  </code></pre>
  
  <p>Second Snippet:</p>
  
  <pre><code>   case WM_SETCURSOR:
          if( (HWND)wParam == GetDlgItem( hwnd, 4000 ) ) 
          {
               SetCursor(hCursorHand); 
               return TRUE; 
          }
          break; // based on MSDN example
  </code></pre>
  
  <p>Third snippet:</p>
  
  <pre><code>   case WM_SETCURSOR:
          if( (HWND)wParam == GetDlgItem( hwnd, 4000 ) ) 
          {
               SetCursor(hCursorHand); 
               return TRUE; 
          }
          else
               return FALSE;
  </code></pre>
  
  <p>These set cursor to hand no matter where it is.</p>
  
  <p>If I leave my <code>WM_SETCURSOR</code> handler unchanged, the only problem I get is that instead of sizing arrows, I get regular arrow ( as the cursor’s look ) when I hover over the border,  but window can be sized.</p>
  
  <p>If I comment out my <code>WM_SETCURSOR</code> handler, sizing arrows and cursor arrow appear properly, but cursor doesn’t change into hand when hovers above static control ( which is logical, since there is no <code>WM_SETCURSOR</code> handler to change it ).</p>
  
  <p>I have browsed through SO archive, looked on MSDN, CodeProject , DaniWeb, Cprogramming and CodeGuru, but had no success.</p>
  
  <p>Looking through those, I have found an example where people compare low word of the  <code>lParam</code> against hit test code.</p>
  
  <p>Looking through MSDN I have found link for hit test values ( <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms645618%28v=vs.85%29.aspx" rel="noreferrer">http://msdn.microsoft.com/en-us/library/windows/desktop/ms645618%28v=vs.85%29.aspx</a> ) and I have found link for cursor types (<a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms648391%28v=vs.85%29.aspx" rel="noreferrer">http://msdn.microsoft.com/en-us/library/windows/desktop/ms648391%28v=vs.85%29.aspx</a> ).</p>
  
  <p>Currently I am reading them, because I think that I will have to load additional cursor resources, take several comparisons of hit test values, and then use those resources to set cursor look accordingly.</p>
  
  <h2>QUESTION:</h2>
  
  <p>I really would like my <code>WM_SETCURSOR</code> handler to look like this:</p>
  
  <pre><code>   case WM_SETCURSOR:
          if( (HWND)wParam == GetDlgItem( hwnd, 4000 ) ) 
          {
               SetCursor(hCursorHand); 
               return TRUE;
          }
          else
               // reset cursor's look to default
  </code></pre>
  
  <p>so I ask the community to instruct me on how to do this.</p>
  
  <p>If this isn’t possible, then I will consider using multiple <code>if</code> statements to check the hit test code, and set cursor’s look accordingly.</p>
  
  <p>Of course, if there is better solution for my problem, please suggest it, I will consider it as well.</p>
  
  <p>Thank you.</p>
  
  <p>Regards.</p>