Re: ShowCursor(FALSE) should hide cursor!
- From: "Doug Harrison [MVP]" <dsh@xxxxxxxx>
- Date: Mon, 26 Dec 2005 15:52:07 -0600
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: Robby
- Re: ShowCursor(FALSE) should hide cursor!
- References:
- ShowCursor(FALSE) should hide cursor!
- From: Robby
- ShowCursor(FALSE) should hide cursor!
- Prev by Date: Re: Convert to VB code. Please help me!!!!
- Next by Date: Re: VC2005 Pro: IDE (Compiler ?) can't find Stdafx.h
- Previous by thread: Re: ShowCursor(FALSE) should hide cursor!
- Next by thread: Re: ShowCursor(FALSE) should hide cursor!
- Index(es):
Relevant Pages
|
|