Re: ShowCursor(FALSE) should hide cursor!
- From: "Robby" <Robby@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 27 Dec 2005 22:26:02 -0800
Thanks guys....
I think I am a little confused. The help of ShowCursor took me to
CreateCursor,GetCursor,LoadCursor,LoadImage,SetCursor and ShowCursor!
And my book doesn't even have WM_SETCURSOR in the index!
I know that maybe my example seems a little wierd, however I am learning at
the speed of the examples of my book. The full example is an easy one, so if
you would like I can include it in a future post!
In my program, Petzold is using three (3) functions, ShowCursor, LoadCursor
and SetCursor. At this point, I don't want to go ahead of myself and I just
want to learn the differences between these 3 functions only.
Although, I fully appreciate your post and I would like to confirm to myself
that I am not absorbing this in a misleading way.
The way I am understanding this, is that LoadCursor loads the specified
cursor resource from the executable (.EXE) file associated with an
application instance. (In plain english, it loads a cursor type for the
current window!) Right!
SetCursor, sets the cursor shape. The cursor must have been created by the
CreateCursor function or loaded by the LoadCursor or LoadImage function.
So, so far, load the cursor with LoadCursor and then set its shape! Right!
ShowCursor, shows the cursor. If I say, ShowCursor(True) the internal
display counter increments. If I say, ShowCursor(FALSE) the internal display
counter decrements. And any time the counter is negative, the cursor is
hidden.(I have experimented with this and I am surprised in that why Windows
chose this mechanism. (Why not simply say, ShowCursor(True) shows the cursor
and ShowCursor(FALSE) hides the cursor. Why must we add this "internal
counter and hide if negative stuff!")
Anyways, I am sure there is a reason, but right now it is beyond me!
OH yea, and also I understood that if you set the hCursor in WIndow class to
NULL, the DefWindowProc will not load a cursor when the window receives
WM_SETCURSOR messages. I guess that in this case you must set the cursor
yourself as my sample did in WM_PAINT.
I thankyou Doug and Alexander for your time and input, if there is anything
I said that is misleading, please get back.
Happy holidays!
--
Best regards
Robert
"Doug Harrison [MVP]" wrote:
> On Mon, 26 Dec 2005 12:56:02 -0800, "Robby"
> <Robby@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
>
> >Hello,
> >
> >I am currently learning the CONNECT.C program on P. 277 of chapter 7 of
> >Petzold's book. My question is:
> >
> >Why is it that after the WM_PAINT messge is processed, the cursor is still
> >visible? Here is the fragment of code:
> >
> >case WM_PAINT:
> > hdc = BeginPaint(hwnd,&ps);
> >
> > SetCursor(LoadCursor(NULL,IDC_WAIT));
> > ShowCursor(TRUE);
> >
> > for(i = 0; i < iCount - 1; i++)
> > for(j = i + 1; j < iCount; j++)
> > {
> > MoveToEx(hdc,pt[i].x,pt[i].y,NULL);
> > LineTo (hdc,pt[j].x,pt[j].y);
> > }
> >
> > ShowCursor(FALSE);
> > SetCursor(LoadCursor(NULL,IDC_CROSS));
> >
> >
> > EndPaint(hwnd,&ps);
> > return 0;
> >
> >So, It seems that when the WM_PAINT begins, it sets the cursor to an hour
> >glass and shows the cursor as so:
> >
> > SetCursor(LoadCursor(NULL,IDC_WAIT));
> > ShowCursor(TRUE);
> >
> >And at the end of the WM_PAINT code the cursor is hidden and set to an arrow
> >by:
> >
> > ShowCursor(FALSE);
> > SetCursor(LoadCursor(NULL,IDC_ARROW));
> >
> >BUT BY NOW, THE CURSOR SHOUL BE HIDDEN ????
> >Then why is it still visible. Further more, I have read the set Cursor help
> >on msdn and it says:
>
> Read the ShowCursor documentation. It explains that the cursor visibility
> is governed by a counter, and that the cursor is displayed if the show
> count is >= 0. This WM_PAINT handler will have no net effect on cursor
> visibility, though it will cause the cursor to be displayed for the
> duration of the message, provided it started out with a show count of -1.
>
> >"The cursor is a shared resource. A window should set the cursor shape only
> >when the cursor is in its client area or when the window is capturing mouse
> >input. In systems without a mouse, the window should restore the previous
> >cursor before the cursor leaves the client area or before it relinquishes
> >control to another window.
> >
> >If your application must set the cursor while it is in a window, make sure
> >the class cursor for the specified window's class is set to NULL. If the
> >class cursor is not NULL, the system restores the class cursor each time the
> >mouse is moved. "
>
> Understand that the system restores the cursor in response to WM_SETCURSOR
> messages, which are processed when your message loop retrieves them. Thus,
> SetCursor tends to be undone whenever you drop back into your message loop.
>
> >So I set the following property for the Window's classes member data hCursor
> >as so:
> >
> >wndclass.hCursor = NULL;
> >
> >But the cursor is still visible. ?????
>
> Yes, doing that doesn't say your window doesn't use a cursor; it just tells
> Windows not to set the class cursor in DefWindowProc when the window
> receives WM_SETCURSOR messages.
>
> The example you pasted above is a little strange. Ordinarily, you wouldn't
> call ShowCursor when you set and restore the cursor; you'd let its current
> visibility determine whether or not it should be displayed. Moreover,
> unless you knew the show count wasn't < -1, you wouldn't expect a single
> ShowCursor(true) to have any effect. Also, you wouldn't change the cursor
> in WM_PAINT, unless you had a really, really lengthy paint operation to
> perform.
>
> --
> Doug Harrison
> Visual C++ MVP
>
.
- Follow-Ups:
- Re: ShowCursor(FALSE) should hide cursor!
- From: Doug Harrison [MVP]
- Re: ShowCursor(FALSE) should hide cursor!
- References:
- ShowCursor(FALSE) should hide cursor!
- From: Robby
- Re: ShowCursor(FALSE) should hide cursor!
- From: Doug Harrison [MVP]
- ShowCursor(FALSE) should hide cursor!
- Prev by Date: Re: where is a copy of atlstr.h ??
- Next by Date: Re: Template for POD types only
- Previous by thread: Re: ShowCursor(FALSE) should hide cursor!
- Next by thread: Re: ShowCursor(FALSE) should hide cursor!
- Index(es):
Relevant Pages
|
|