Cursors

I have this code from Programming Windows and I don't get why SetCursor is called twice. Doesn't it do the same thing in both calls? Why not just leave it as only ShowCursor(FALSE)?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
case WM_SIZE:
          cxClient = LOWORD (lParam) ;
          cyClient = HIWORD (lParam) ;

          hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)) ;
          ShowCursor (TRUE) ;
          
          if (hRgnClip)
               DeleteObject (hRgnClip) ;
          
          hRgnTemp[0] = CreateEllipticRgn (0, cyClient / 3,
                                           cxClient / 2, 2 * cyClient / 3) ;
          hRgnTemp[1] = CreateEllipticRgn (cxClient / 2, cyClient / 3,
                                           cxClient, 2 * cyClient / 3) ;
          hRgnTemp[2] = CreateEllipticRgn (cxClient / 3, 0,
                                           2 * cxClient / 3, cyClient / 2) ;
          hRgnTemp[3] = CreateEllipticRgn (cxClient / 3, cyClient / 2,
                                           2 * cxClient / 3, cyClient) ;
          hRgnTemp[4] = CreateRectRgn (0, 0, 1, 1) ;
          hRgnTemp[5] = CreateRectRgn (0, 0, 1, 1) ;
          hRgnClip    = CreateRectRgn (0, 0, 1, 1) ;

          CombineRgn (hRgnTemp[4], hRgnTemp[0], hRgnTemp[1], RGN_OR) ;
          CombineRgn (hRgnTemp[5], hRgnTemp[2], hRgnTemp[3], RGN_OR) ;
          CombineRgn (hRgnClip,    hRgnTemp[4], hRgnTemp[5], RGN_XOR) ;
          
          for (i = 0 ; i < 6 ; i++)
               DeleteObject (hRgnTemp[i]) ;
          
          SetCursor (hCursor) ;
          ShowCursor (FALSE) ;
          return 0 ;
Last edited on
The first time you call it, the cursor state is changed to IDC_WAIT and the old cursor state
is stored in hCursor. The second call is required so that the old cursor state is restored.
See http://msdn.microsoft.com/en-us/library/ms648393(VS.85).aspx, section "Return Value". That explains what is contained in hCursor, which should make the answer clear to you.
Topic archived. No new replies allowed.