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

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 […]

Written By
CodeGuru Staff
CodeGuru Staff
Apr 17, 1999
2 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

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

    CodeGuru Logo

    CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

    Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

    Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.