Article ID: 131991 - View products that this article applies to.
This article was previously published under Q131991
Note Microsoft Visual C++ .NET (2002) supports both the managed code model that is provided by the Microsoft .NET Framework and the unmanaged native Microsoft Windows code model. The information in this article applies only to unmanaged Visual C++ code.
Note Microsoft Visual C++ 2005 supports both the managed code model that is provided by the .NET Framework and the unmanaged native Windows code model.
In a Windows-based application, a window is always created based on a window class. The window class identifies several characteristics of the windows based on it, including the default mouse pointer (cursor). In some cases, an application may want to change the pointer associated with certain windows that it creates. This article describes three methods an MFC application can use to display different pointers at different times.
Here are some situations when you might want an MFC application to display different pointers at different times:
Three methodsHere are three ways an application can change the mouse pointer in a window:
Code to illustrate the three methodsThe following code shows by example how to change the mouse pointer of a CView derived class window by using the three methods. m_ChangeCursor is a member variable of CMyView class and is of type BOOL. It indicates whether a different pointer type needs to be displayed.
Method oneChange the mouse pointer for the CMyView object by overriding CWnd::OnSetCursor() function. Use ClassWizard to establish the message map function CMyView::OnSetCursor() for Windows message WM_SETCURSOR and supply the body of the function as follows:
Method twoRegister your own window class containing the desired mouse pointer by using either the AfxRegisterClass() or AfxRegisterWndClass() function. Then create the view window based on the registered window class. For more information on registering window classes in MFC, please see MFC Tech Note 1, "Window Class Registration."
Method threeCall the BeginWaitCursor() and EndWaitCursor() functions to change the mouse pointer.
NoteCWinApp::DoWaitCursor(1) and CWinApp::DoWaitCursor(-1) work similarly to BeginWaitCursor() and EndWaitCursor(), respectively.
Note If calls to BeginWaitCursor() and EndWaitCursor() are not in the same handler, you must override OnSetCursor as follows:
In this example, set m_ChangeCursor to TRUE just before the call to BeginWaitCursor(), and set it back to FALSE after the call to EndWaitCursor().
Article ID: 131991 - Last Review: November 21, 2006 - Revision: 4.1
Contact us for more help