How to change an application mouse cursor !

Posted on 2004-10-29
Last Modified: 2013-11-20
I have an MDI application.

How can I change the mouse cursor of the global application.

By default, the cursor is an arrow but I want to change it

I have try to use SetClassLong(m_hWnd, GCL_HCURSOR, hMyCursor), but works only for the owner view of the m_hWnd. That meens, that if I go to an other view, the cursor return to default.

Can someone help me !
Question by:mike_marquet
    LVL 43

    Expert Comment

    I think you have to do that (SetClassLong) for each window class in your app.

    The system automatically displays the class cursor (the cursor associated with the window to which the cursor is pointing).

    Author Comment

    I think there is an other solution but how ?

    Doing this for each windows is to lot of works.
    LVL 43

    Expert Comment

    I don't know any other method.
    I know it is crude but you will only have a few different window classes (OnCreate of each class?).
    LVL 6

    Expert Comment

    by:Amritpal Singh
    there are two methods
    first one changes the cursor dynamically
    second one changes it at the time of creation

     BOOL CMyView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
                if ( m_ChangeCursor )
                      return TRUE;

                return CView::OnSetCursor(pWnd, nHitTest, message);
     BOOL CMyView::PreCreateWindow(CREATESTRUCT& cs)
              cs.lpszClass = AfxRegisterWndClass(
                CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW, // use any window styles
                (HBRUSH) (COLOR_WINDOW + 1));         // background brush

              return CView::PreCreateWindow(cs)

    Author Comment

    I must do it dynamically but using OnSetCursor message is also a lot of work because I must do it for all views in my application (I know this method). But my question is how to change it for the global application using a simple method (1 function only, ex. : SetApplCursor which not exist).

    If there is no other simple solution, then I must do such a work
    LVL 43

    Accepted Solution

    You have an MDI app
    Use the SetClassLong call in the OnCreate of the following classes you have inherited
    CMainFrame, CChildFrame, CView
    Plus the OnInitDialog of any dialog classes you add.  By my counting that is 3 (4, 5) lines of code.  (I agree one line would be simpler).

    ps. Personally I dislike apps that change the settings (albeit temporarily) of my system.   Talking as the end user.  I have customised my PC to display the cursors I want.  Why the **** does this exe not display them.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Suggested Solutions

    This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
    Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
    This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
    In this Experts Exchange video Micro Tutorial, I'm going to show how small business owners who use Google Apps can save money by setting up what is called a catch-all email address in their Gmail accounts. By using the catch-all feature, small busin…

    846 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    5 Experts available now in Live!

    Get 1:1 Help Now