Re: ShowCursor(FALSE) should hide cursor!



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
.



Relevant Pages

  • Re: convert hyperlink to email address
    ... If the Project Explorer is not showing, ... A blank window should open up to the right. ... then you can close the VBE. ... won't be any changes (except the flashing cursor moving down to the next ...
    (microsoft.public.excel.programming)
  • Re: Customising Word for Visually-Impaired
    ... the application will grab hold of the cursor and do its own thing with it. ... perhaps a black-bordered window around the insertion point to draw attention ... But I've found it impossible to get the handle of the Word window ... Control Panel> Accessibility Options> Display> Cursor Width ...
    (microsoft.public.windowsxp.accessibility)
  • RE: hide cursor for kiosk application (powerpoint)
    ... you use a WebBrowser control to display ... PowerPoint document and you'd like to hide the cursor on the WebBrowser. ... I watch the messages of the paneClassDC "Slide Show" window. ... Microsoft Online Community Support ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: Detecting button push
    ... David Olsson wrote: ... > I have a window with a number of buttons (created using CreateWindow ... mouse button while the cursor is in the client area of a window. ... Value of the high-order word of lParam. ...
    (microsoft.public.win32.programmer.ui)
  • Re: MFC: Drag & Drop ohne die Maus zu verwenden?
    ... >> system will direct mouse input to the specified window only if a mouse ... > Prozess bekommt IMHO keine Nachricht das der Cursor über seinem Fenster ... Ich bin da auf einen Artikel gestossen mit mouse_event, ...
    (microsoft.public.de.vc)