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. ToolBar Button and Cursor in MFC

ToolBar Button and Cursor in MFC

Scheduled Pinned Locked Moved C / C++ / MFC
c++help
3 Posts 2 Posters 0 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.
  • S Offline
    S Offline
    suzie100
    wrote on last edited by
    #1

    I am a newbie to MFC and want to do the following: I have a button added to a toolbar. I have also added the following in my code for the function to be executed once the Button is clicked: ON_COMMAND(ID_BUTTONRUN, OnRunTests)What I want is when the button is clicked I want the button state to be disabled and the cursor to look like a Hourglass untill the OnRunTests() is completed. I tried the :ON_UPDATE_COMMAND_UI(ID_BUTTONRUN, OnToolbarRunUpdate) but this got executed only after the OnRunTests() completed which is not what I want. Is there a way for me to change the cursor and the button state as soon as the OnRunTests() is entered and change it back when it is done. Any help and guidance will be appreciated.

    K 1 Reply Last reply
    0
    • S suzie100

      I am a newbie to MFC and want to do the following: I have a button added to a toolbar. I have also added the following in my code for the function to be executed once the Button is clicked: ON_COMMAND(ID_BUTTONRUN, OnRunTests)What I want is when the button is clicked I want the button state to be disabled and the cursor to look like a Hourglass untill the OnRunTests() is completed. I tried the :ON_UPDATE_COMMAND_UI(ID_BUTTONRUN, OnToolbarRunUpdate) but this got executed only after the OnRunTests() completed which is not what I want. Is there a way for me to change the cursor and the button state as soon as the OnRunTests() is entered and change it back when it is done. Any help and guidance will be appreciated.

      K Offline
      K Offline
      khan
      wrote on last edited by
      #2

      In resource.h: #define WM_DOSOMETHING 12345//or whatever In mainfrm.h, add a custom-message handler: afx_msg LRESULT OnDoSomething(WPARAM,LPARAM); In the BEGIN_MESSAGE_MAP macro in mainfrm.cpp: ON_MESSAGE(WM_DOSOMETHING,OnDoSomething) In the implementation for OnDoSomething: LRESULT CMainFrame::OnDoSomething(WPARAM,LPARAM) { m_wndToolBar.GetToolBarCtrl().EnableButton(ID_EDIT_COPY,FALSE); m_wndToolBar.RedrawWindow(); return 0; } In your view class: void CWhateverView::OnUpdateEditCopy(CCmdUI* pCmdUI) { if (m_bDisable) pCmdUI->Enable(FALSE); else pCmdUI->Enable(TRUE); } In your function for long operation: void CWhateverView::OnEditCopy() { m_bDisable = TRUE; BeginWaitCursor(); AfxGetApp()->GetMainWnd()->SendMessage(WM_DOSOMETHING); //long operation begin... int i, j,k; for (i = 0; i < 10000; i++) for (j = 0; j < 10000; j++) for (k = 0; k < 5; k++) { } //long operation end. m_bDisable = FALSE; } And don't forget to declare m_bDisable in CWhateverView.h and initialize it as m_bDisable = FALSE; in the class constructor. this is this.

      S 1 Reply Last reply
      0
      • K khan

        In resource.h: #define WM_DOSOMETHING 12345//or whatever In mainfrm.h, add a custom-message handler: afx_msg LRESULT OnDoSomething(WPARAM,LPARAM); In the BEGIN_MESSAGE_MAP macro in mainfrm.cpp: ON_MESSAGE(WM_DOSOMETHING,OnDoSomething) In the implementation for OnDoSomething: LRESULT CMainFrame::OnDoSomething(WPARAM,LPARAM) { m_wndToolBar.GetToolBarCtrl().EnableButton(ID_EDIT_COPY,FALSE); m_wndToolBar.RedrawWindow(); return 0; } In your view class: void CWhateverView::OnUpdateEditCopy(CCmdUI* pCmdUI) { if (m_bDisable) pCmdUI->Enable(FALSE); else pCmdUI->Enable(TRUE); } In your function for long operation: void CWhateverView::OnEditCopy() { m_bDisable = TRUE; BeginWaitCursor(); AfxGetApp()->GetMainWnd()->SendMessage(WM_DOSOMETHING); //long operation begin... int i, j,k; for (i = 0; i < 10000; i++) for (j = 0; j < 10000; j++) for (k = 0; k < 5; k++) { } //long operation end. m_bDisable = FALSE; } And don't forget to declare m_bDisable in CWhateverView.h and initialize it as m_bDisable = FALSE; in the class constructor. this is this.

        S Offline
        S Offline
        suzie100
        wrote on last edited by
        #3

        Thanks so much for your explaination and sample. It reall helped me. One question is : when I do BeginWaitCursor() it shows the hourglass for a fleeting second and again changes back to the arrow cursor. It does not stay as hourglass for the entire lengthy operation. Any help how to fix that?

        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