www.digitalmars.com         C & C++   DMDScript  

c++.mfc - Cursor

reply "Phill" <phillbert pacific.net.au> writes:
Hi there

I am trying to  use my own cursor throughout the
entire program.
I have the following code:
==============================
HCURSOR hCursor;
    hCursor = AfxGetApp()->LoadCursor(IDC_CURSOR2);
    SetCursor(hCursor);
==============================
While this code works fine if I use it while catching a key or mouse event
and
also in the onDraw method, I cannot get it to stay after the window
repaints. Ive tried
onCreate also but this has no effect.

Any help would be appreciated .
Im new to this, as you can see

Phill.
Mar 14 2003
parent reply "Matthew Wilson" <dmd synesis.com.au> writes:
When the mouse is moved over a window, it is sent the WM_SETCURSOR message.
(Actually, the parent window is sent the message first, and if it does not
return TRUE, the message is sent to the actual window itself. Naturally this
is the case for multiple levels of parent/child windows.)

If the window (or parent) does return TRUE, it is expected that it calls
SetCursor. If not, the system deduces a cursor to set, based upon whether in
client area, whether a cursor was registered as part of the window class,
etc. etc. (See the documentation for WM_SETCURSOR).

The catch is revealed in the documentation for SetCursor:

"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. "

In this case, if it is your window you should handle the WM_SETCURSOR
message and do something like the following:

BOOL CSomeWnd::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
    if(nHitTest == NTCLIENT &&
       ... some condition, meaning that you want the cursor ...)
  {
     ::SetCursor(AfxGetApp()->LoadCursor(IDC_CURSOR2));
  }
  else
  {
      return C<ParentWnd>::OnSetCursor(pWnd, nHitTest, message);
  }
}


"Phill" <phillbert pacific.net.au> wrote in message
news:b4ua6t$o8q$1 digitaldaemon.com...
 Hi there

 I am trying to  use my own cursor throughout the
 entire program.
 I have the following code:
 ==============================
 HCURSOR hCursor;
     hCursor = AfxGetApp()->LoadCursor(IDC_CURSOR2);
     SetCursor(hCursor);
 ==============================
 While this code works fine if I use it while catching a key or mouse event
 and
 also in the onDraw method, I cannot get it to stay after the window
 repaints. Ive tried
 onCreate also but this has no effect.

 Any help would be appreciated .
 Im new to this, as you can see

 Phill.
Mar 14 2003
parent reply "Phill" <phillbert pacific.net.au> writes:
Thanks very much for your help!
With your help this got the results I wanted.

BOOL CMainFrame::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{

  if(TRUE){
         HCURSOR hCursor;
         hCursor = AfxGetApp()->LoadCursor(IDC_CURSOR2);
        SetCursor(hCursor);
        return TRUE;
  }


   return CFrameWnd::OnSetCursor(pWnd, nHitTest, message);
}


"Matthew Wilson" <dmd synesis.com.au> wrote in message
news:b4uha5$t6m$1 digitaldaemon.com...
 When the mouse is moved over a window, it is sent the WM_SETCURSOR
message.
 (Actually, the parent window is sent the message first, and if it does not
 return TRUE, the message is sent to the actual window itself. Naturally
this
 is the case for multiple levels of parent/child windows.)

 If the window (or parent) does return TRUE, it is expected that it calls
 SetCursor. If not, the system deduces a cursor to set, based upon whether
in
 client area, whether a cursor was registered as part of the window class,
 etc. etc. (See the documentation for WM_SETCURSOR).

 The catch is revealed in the documentation for SetCursor:

 "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. "

 In this case, if it is your window you should handle the WM_SETCURSOR
 message and do something like the following:

 BOOL CSomeWnd::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
 {
     if(nHitTest == NTCLIENT &&
        ... some condition, meaning that you want the cursor ...)
   {
      ::SetCursor(AfxGetApp()->LoadCursor(IDC_CURSOR2));
   }
   else
   {
       return C<ParentWnd>::OnSetCursor(pWnd, nHitTest, message);
   }
 }


 "Phill" <phillbert pacific.net.au> wrote in message
 news:b4ua6t$o8q$1 digitaldaemon.com...
 Hi there

 I am trying to  use my own cursor throughout the
 entire program.
 I have the following code:
 ==============================
 HCURSOR hCursor;
     hCursor = AfxGetApp()->LoadCursor(IDC_CURSOR2);
     SetCursor(hCursor);
 ==============================
 While this code works fine if I use it while catching a key or mouse
event
 and
 also in the onDraw method, I cannot get it to stay after the window
 repaints. Ive tried
 onCreate also but this has no effect.

 Any help would be appreciated .
 Im new to this, as you can see

 Phill.
Mar 15 2003
parent "Matthew Wilson" <dmd synesis.com.au> writes:
You're most welcome. :)

"Phill" <phillbert pacific.net.au> wrote in message
news:b4v2l3$1dc6$1 digitaldaemon.com...
 Thanks very much for your help!
 With your help this got the results I wanted.

 BOOL CMainFrame::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
 {

   if(TRUE){
          HCURSOR hCursor;
          hCursor = AfxGetApp()->LoadCursor(IDC_CURSOR2);
         SetCursor(hCursor);
         return TRUE;
   }


    return CFrameWnd::OnSetCursor(pWnd, nHitTest, message);
 }


 "Matthew Wilson" <dmd synesis.com.au> wrote in message
 news:b4uha5$t6m$1 digitaldaemon.com...
 When the mouse is moved over a window, it is sent the WM_SETCURSOR
message.
 (Actually, the parent window is sent the message first, and if it does
not
 return TRUE, the message is sent to the actual window itself. Naturally
this
 is the case for multiple levels of parent/child windows.)

 If the window (or parent) does return TRUE, it is expected that it calls
 SetCursor. If not, the system deduces a cursor to set, based upon
whether
 in
 client area, whether a cursor was registered as part of the window
class,
 etc. etc. (See the documentation for WM_SETCURSOR).

 The catch is revealed in the documentation for SetCursor:

 "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. "

 In this case, if it is your window you should handle the WM_SETCURSOR
 message and do something like the following:

 BOOL CSomeWnd::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
 {
     if(nHitTest == NTCLIENT &&
        ... some condition, meaning that you want the cursor ...)
   {
      ::SetCursor(AfxGetApp()->LoadCursor(IDC_CURSOR2));
   }
   else
   {
       return C<ParentWnd>::OnSetCursor(pWnd, nHitTest, message);
   }
 }


 "Phill" <phillbert pacific.net.au> wrote in message
 news:b4ua6t$o8q$1 digitaldaemon.com...
 Hi there

 I am trying to  use my own cursor throughout the
 entire program.
 I have the following code:
 ==============================
 HCURSOR hCursor;
     hCursor = AfxGetApp()->LoadCursor(IDC_CURSOR2);
     SetCursor(hCursor);
 ==============================
 While this code works fine if I use it while catching a key or mouse
event
 and
 also in the onDraw method, I cannot get it to stay after the window
 repaints. Ive tried
 onCreate also but this has no effect.

 Any help would be appreciated .
 Im new to this, as you can see

 Phill.
Mar 15 2003