A "How to" on placing a Toolbar on a dialog

Last week I had to create a toolbar on a dialog. I have never done this before and I was in too much of a hurry to want to figure it all out for myself. I turned to the code guru for help. I did find a lot of good information, but what I really needed was a no frills, straight forward example. Often I see other people searching for a basic example of a toolbar on a dialog in the discussion board. The attached source is a simple, straight forward example. The source is complete, just open the dsp and compile.

The code is documented. These steps show how how I created the application and non code pieces.

  • 1. Use the App Wizard to create a dialog based executable named DlgToolBar.
  • 2. On the dialog drop an owner drawn button. 'Owner Draw' is a property under
  • the styles tab. I will use the default name IDC_BUTTON1. Resize the button to the approximate size you want the tool bar.
  • 3. Insert a tool bar and add 5 buttons. Rename the buttons ID_BUTTON1, ID_BUTTON2 ... ID_BUTTON_5. The name of our example toolbar is IDR_TOOLBAR1. (Go to the resource tab and right click on the top folder to add a tool bar.)
  • 4. Click on one of the five buttons you just created and press Alt-Enter. Change the height to 30 and the width to 40.
  • 5. Open DlgToolBarDlg.h and add the class defination CbuttonOwnerDraw. This class will manage the owner drawn button and the messages from the toolbar.
  • 6. The rest of the code is pretty straight forward.
  • Other information:

    This is just a how to sample. It is not UNICODE. I maintain no rights or restrictions on the code. This example is not better or even as good as some of the dialogs other people have submitted. I do believe it is about as simple as possible.

    Download demo project - 15 KB

    Date Last Updated: April 3, 1999



    Comments

    • Can i do the same within a child Dialog

      Posted by Legacy on 02/18/2004 12:00am

      Originally posted by: Ahryman40k

      If i do the same thing on dialog which have Child style, the toolbar is always disable, how can i enable it again ???

      Reply
    • Check the MS sample too...

      Posted by Legacy on 04/18/1999 12:00am

      Originally posted by: Paul Selormey

      The MS sample program CMNCTRL1 or "CMNCTRL1: Demonstrates Common Control MFC Classes, Part 1" gives you a property sheet page with two toolbar demos. You may wish to take a look at this too.

      Please you set the CCS_ADJUSTABLE toolbar style without
      handling the customizing dialog routines.

      Bye,
      Paul.

      Reply
    Leave a Comment
    • Your email address will not be published. All fields are required.

    Top White Papers and Webcasts

    • The operational costs of managing an x86 base are taxing IT budgets, making it difficult to fund and staff new initiatives. Today's IT organization must seek efficiencies in its operations and shift to a more agile infrastructure that's flexible enough to adapt to future changes in the business. Read this Q & A session with Jed Scaramella, research manager for IDC's Enterprise Platforms and Data Center Trends, to learn how the integrated nature of the blade platform delivers critically needed efficiencies …

    • Live Event Date: May 6, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT While you likely have very good reasons for remaining on WinXP after end of support -- an estimated 20-30% of worldwide devices still are -- the bottom line is your security risk is now significant. In the absence of security patches, attackers will certainly turn their attention to this new opportunity. Join Lumension Vice President Paul Zimski in this one-hour webcast to discuss risk and, more importantly, 5 pragmatic risk mitigation techniques …

    Most Popular Programming Stories

    More for Developers

    Latest Developer Headlines

    RSS Feeds