Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Help!!! How to change Cursor Permanent ???

Help!!! How to change Cursor Permanent ???

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
5 Posts 4 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    VikramDelhi i
    wrote on last edited by
    #1

    Hi I want to change the default cursor in my app. I tried following code. bool m_bcursor; BOOL CTestDlg::OnInitDialog() { CDialog::OnInitDialog(); // TODO: Add extra initialization here lhCursor = AfxGetApp()->LoadCursor(IDC_CURSOR); SetCursor(lhCursor); m_bcursor = true; //set to true return TRUE; // return TRUE unless you set the focus to a control } BOOL CTestDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) { // TODO: Add your message handler code here and/or call default if(m_bcursor) return true; else return CDialog::OnSetCursor(pWnd, nHitTest, message); } But whenever I open About Dialog, cursor it changed to default cursor. What should I do to change cursor the moment my main dialog gets focus?

    J 1 Reply Last reply
    0
    • V VikramDelhi i

      Hi I want to change the default cursor in my app. I tried following code. bool m_bcursor; BOOL CTestDlg::OnInitDialog() { CDialog::OnInitDialog(); // TODO: Add extra initialization here lhCursor = AfxGetApp()->LoadCursor(IDC_CURSOR); SetCursor(lhCursor); m_bcursor = true; //set to true return TRUE; // return TRUE unless you set the focus to a control } BOOL CTestDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) { // TODO: Add your message handler code here and/or call default if(m_bcursor) return true; else return CDialog::OnSetCursor(pWnd, nHitTest, message); } But whenever I open About Dialog, cursor it changed to default cursor. What should I do to change cursor the moment my main dialog gets focus?

      J Offline
      J Offline
      Jack Puppy
      wrote on last edited by
      #2

      You need to set the cursor each time the OnSetCursor message is triggered. Dump the boolean member variable, and make the handle to the cursor a member variable of the dialog box: HCURSOR m_hCursor; Initialize it in the constructor: CMyDialog::CMyDialog() : m_hCursor(NULL) { m_hCursor = AfxGetApp()->LoadCursor(IDC_MYCURSOR); } and in OnSetCursor()... if (m_hCursor != NULL) { SetCursor(m_hCursor); return TRUE; } // default stuff here

      :cool: Pssst. You see that little light on your monitor? That's actually a government installed spy camera. Smile and wave to big brother!

      J G V 3 Replies Last reply
      0
      • J Jack Puppy

        You need to set the cursor each time the OnSetCursor message is triggered. Dump the boolean member variable, and make the handle to the cursor a member variable of the dialog box: HCURSOR m_hCursor; Initialize it in the constructor: CMyDialog::CMyDialog() : m_hCursor(NULL) { m_hCursor = AfxGetApp()->LoadCursor(IDC_MYCURSOR); } and in OnSetCursor()... if (m_hCursor != NULL) { SetCursor(m_hCursor); return TRUE; } // default stuff here

        :cool: Pssst. You see that little light on your monitor? That's actually a government installed spy camera. Smile and wave to big brother!

        J Offline
        J Offline
        John R Shaw
        wrote on last edited by
        #3

        Good advice! But you do not need to maintain a copy of the cursor handle. From MSDN: "The LoadCursor function loads the cursor resource only if it has not been loaded; otherwise, it retrieves the handle to the existing resource." In other words, the system maintains a copy of the cursor handle for you. SetCursor(AfxGetApp()->LoadCursor(IDC_MYCURSOR)); The cursor is a resource included in the .exe (or sytem resoruces). Therefore, you do not need to test the handle. If the handle returned is not valid then there is a much bigger problem involved (and the program has locked up or crashed, do to lack of memory). INTP

        1 Reply Last reply
        0
        • J Jack Puppy

          You need to set the cursor each time the OnSetCursor message is triggered. Dump the boolean member variable, and make the handle to the cursor a member variable of the dialog box: HCURSOR m_hCursor; Initialize it in the constructor: CMyDialog::CMyDialog() : m_hCursor(NULL) { m_hCursor = AfxGetApp()->LoadCursor(IDC_MYCURSOR); } and in OnSetCursor()... if (m_hCursor != NULL) { SetCursor(m_hCursor); return TRUE; } // default stuff here

          :cool: Pssst. You see that little light on your monitor? That's actually a government installed spy camera. Smile and wave to big brother!

          G Offline
          G Offline
          gamitech
          wrote on last edited by
          #4

          can you write the W32 api code for changing a cursor. I never got to do it. . .. I hate cursors :) gabby

          1 Reply Last reply
          0
          • J Jack Puppy

            You need to set the cursor each time the OnSetCursor message is triggered. Dump the boolean member variable, and make the handle to the cursor a member variable of the dialog box: HCURSOR m_hCursor; Initialize it in the constructor: CMyDialog::CMyDialog() : m_hCursor(NULL) { m_hCursor = AfxGetApp()->LoadCursor(IDC_MYCURSOR); } and in OnSetCursor()... if (m_hCursor != NULL) { SetCursor(m_hCursor); return TRUE; } // default stuff here

            :cool: Pssst. You see that little light on your monitor? That's actually a government installed spy camera. Smile and wave to big brother!

            V Offline
            V Offline
            VikramDelhi i
            wrote on last edited by
            #5

            hi Jack Rabbit:rose: thanks a lot. it worked for me.:)

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups