Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 434937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T20:19:32+00:00 2026-05-12T20:19:32+00:00

I created a simple class to hide the details of creating a toolbar in

  • 0

I created a simple class to hide the details of creating a toolbar in win32 API but I don’t like the toolbars it is producing. (See image for clarification. I don’t have reputation points so I have just posted a link)

http://i35.tinypic.com/1zmfeip.jpg

I have no idea now the black background is coming into my application.
Here is the class declaration in file CToolBar.h

#ifndef _CTOOLBAR_H
#define _CTOOLBAR_H

#include<windows.h>
#include<commctrl.h>

class CToolBar
{
public:
       CToolBar();//constructor
       ~CToolBar();//destructor

       void AddButton(int iconID, int command);//add Both a button, its icon and its command ID
       void Show();//display the toolbar
       void Initialise(HINSTANCE hInst, HWND hParent);
protected:
          HINSTANCE m_hInst;
          HWND m_hParent;
          HWND m_hToolBar;
          HIMAGELIST m_hImageList;
          TBBUTTON m_Tbb[4];  //toolbar buttons
          int m_numberButtons;     
};
#endif

here is the implementation in file CToolBar.cpp

//CToolBar.cpp
#include "CToolBar.h"
#include<windows.h>
#include<commctrl.h>

CToolBar::CToolBar()//the constructor
{
    m_hImageList=ImageList_Create(32, 32, ILC_COLOR32, 0, 15);//returns NULL if the function fails
   //finish other initialisations
   InitCommonControls();//initialise commctrl.dll whatever.. or else your toolbar wont appear
  }

void CToolBar::Initialise(HINSTANCE hInst, HWND hParent)
{
  m_hInst=hInst;
  m_hParent=hParent; 

  m_hToolBar=CreateWindowEx(
                WS_EX_PALETTEWINDOW ,
                TOOLBARCLASSNAME,
                "",
                WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS |WS_VISIBLE|TBSTYLE_BUTTON | TBSTYLE_TOOLTIPS | CCS_ADJUSTABLE | CCS_TOP ,
                0, 0,
                0, 0,
                m_hParent,
       NULL,
                m_hInst,
                0);
}

CToolBar::~CToolBar()//destructor
{
 ImageList_Destroy(m_hImageList);
}

void CToolBar::AddButton(int iconID, int command)
{
     HICON hIcon = LoadIcon(m_hInst, MAKEINTRESOURCE(iconID));
     ImageList_AddIcon(m_hImageList, hIcon);
     DeleteObject(hIcon); 

if(iconID!= -1)//-1 means the separator. The rest are mere buttons
{     
     m_Tbb[m_numberButtons].iBitmap =m_numberButtons;
     m_Tbb[m_numberButtons].idCommand = command;
     m_Tbb[m_numberButtons].fsState = TBSTATE_ENABLED;
     m_Tbb[m_numberButtons].fsStyle = TBSTYLE_BUTTON; 
     m_Tbb[m_numberButtons].dwData = 0; 
     m_Tbb[m_numberButtons].iString = 0;
}
else//ie if (iconID== -1) ; then display the separator. the command value is ignored
{
     m_Tbb[m_numberButtons].iBitmap =-1;
     m_Tbb[m_numberButtons].idCommand = 0;
     m_Tbb[m_numberButtons].fsState = TBSTATE_ENABLED;
     m_Tbb[m_numberButtons].fsStyle = TBSTYLE_SEP; 
     m_Tbb[m_numberButtons].dwData = 0; 
     m_Tbb[m_numberButtons].iString = 0;

}     

     m_numberButtons++;

}

void CToolBar::Show()
{  
SendMessage(m_hToolBar, TB_SETIMAGELIST , (WPARAM)0, (LPARAM)m_hImageList);
SendMessage(m_hToolBar, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);//message for backward 
//compatibility
SendMessage(m_hToolBar, TB_ADDBUTTONS, m_numberButtons, (LPARAM)m_Tbb);   
SendMessage(m_hToolBar,WM_SIZE,0,0);

ShowWindow(m_hToolBar, SW_SHOW);
}

How i used the class
in main.cpp, i created a global instance of the class.

CToolBar myToolBar; 

in the callback procedure, under WM_CREATE, I used some member functions.

case WM_CREATE:
     myToolBar.Initialise(g_hInst,hwnd);
     myToolBar.AddButton(IDI_OPEN, ID_OPEN);
     myToolBar.AddButton(IDI_MAIN,ID_OPEN);//Separator button
     myToolBar.AddButton(IDI_CLOSE, ID_CLOSE);
     myToolBar.AddButton(IDI_CLOSEALL, ID_CLOSE);
     myToolBar.Show();
     break;

That’s about it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T20:19:32+00:00Added an answer on May 12, 2026 at 8:19 pm

    Try modifying the flags parameter of ImageList_Create to include ILC_MASK as well

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created a simple class that shows what I am trying to do without
I created a simple class in C++ which has a private dynamic array. In
I've created a simple class and got a little problem: I just want to
i have created a simple public ref class in the vc++ project, which is
I've created a simple buffer manager class to be used with asyncroneous sockets. This
I created a simple WCF demo: Server Side: namespace ServerSide { class Program {
I'm trying to create a simple extensible class in javascript but when setting property
I feel like the answer to this question is really simple, but I really
I feel like this should be really really simple, but I'm completely stuck! In
I created a simple class to pass to the sort method of a Juce

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.