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. How to Add an Event Handler for Toolbar Button in VC++7

How to Add an Event Handler for Toolbar Button in VC++7

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorial
3 Posts 3 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.
  • E Offline
    E Offline
    Exceter
    wrote on last edited by
    #1

    :~

    X 1 Reply Last reply
    0
    • E Exceter

      :~

      X Offline
      X Offline
      xxhimanshu
      wrote on last edited by
      #2

      ;)hi, do it like this!!!!!!!!!!!!!! Open the header file for your view (double-click the class name in Class View), this is CDisableToolbarView in the example. Okay; we need to write the declarations for our three functions; these would be as so: afx_msg void OnToolbarButtonClick(); That's all we need in our header, so we can close that and open our cpp file. For each of the three functions declared above, we need to create a function defintition like the one below. void CToolbarView::OnToolbarButtonClick() { MessageBox("Red clicked"); } Toward the top of the cpp file you will see a block of code starting with BEGIN_MESSAGE_MAP. Within these lines we can hook the click events up to our functions. Between the BEGIN_MESSAGE_MAP and END_MESSAGE_MAP lines, add the following three lines: ON_BN_CLICKED(ID_TBRED,OnToolbarButtonClick) thats it.. cheers Himanshu

      R 1 Reply Last reply
      0
      • X xxhimanshu

        ;)hi, do it like this!!!!!!!!!!!!!! Open the header file for your view (double-click the class name in Class View), this is CDisableToolbarView in the example. Okay; we need to write the declarations for our three functions; these would be as so: afx_msg void OnToolbarButtonClick(); That's all we need in our header, so we can close that and open our cpp file. For each of the three functions declared above, we need to create a function defintition like the one below. void CToolbarView::OnToolbarButtonClick() { MessageBox("Red clicked"); } Toward the top of the cpp file you will see a block of code starting with BEGIN_MESSAGE_MAP. Within these lines we can hook the click events up to our functions. Between the BEGIN_MESSAGE_MAP and END_MESSAGE_MAP lines, add the following three lines: ON_BN_CLICKED(ID_TBRED,OnToolbarButtonClick) thats it.. cheers Himanshu

        R Offline
        R Offline
        Rage
        wrote on last edited by
        #3

        You may also try the easy solution : Add your button in the ressource editor. Doubleclick on it to open properties. Give it a name (for instance ID_OPENFILE). Close the window, go open the class wizard. Select your button name in the list on the right and handle the corresponding message. All the stuff given by Himanshu will be added automatically. Oh, BTW, Himanshu, feel free to put your code into a <pre> environment, it is far more readable. ;P ~RaGE();

        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