Windows Toolbars
Posted: Sat Mar 08, 2003 10:12 am
I'm trying to create a C++ class that hides the hideously ugly and complicated (either by bad design or inadequate documentation) Windows toolbar API. I'm running into a slight problem, however. I have two versions of an AddButton function, one of them takes a string and the other does not. What I want is for the non-string version to add a button with no text underneath and for the string version to add a button with text. However, given the following implementations:
if I call the string version and pass the text "Test" and then call the non-string version to add another button, both buttons will have "Test" underneath.
This problem applies specifically to mixing the string and non-string versions, because it works fine if they are not mixed. I tried setting the iString member of the TBBUTTON structure to -1 in the non-string AddButton and it seems to work. What I want to know is if that is legal as a way to specify "no string for this button" or if it can cause problems. Anybody know?
Code: Select all
void APIWrap::CToolbarCtrl::AddButton(int nIndex, int nCommandID,
APIWrap::CBitmap& bmpButtonImage)
{
this->AddBitmap(bmpButtonImage.GetHBITMAP());
TBBUTTON tbb;
ZeroMemory(&tbb, sizeof(tbb));
tbb.iBitmap = m_pmapBitmaps->GetItem(bmpButtonImage.GetHBITMAP());
tbb.idCommand = nCommandID;
tbb.fsState = TBSTATE_ENABLED;
tbb.fsStyle = TBSTYLE_BUTTON;
this->InsertButton(nIndex, tbb);
}
void APIWrap::CToolbarCtrl::AddButton(int nIndex, int nCommandID,
APIWrap::CBitmap& bmpButtonImage,
const APIWrap::CString& strButtonText)
{
this->AddBitmap(bmpButtonImage.GetHBITMAP());
this->AddString(strButtonText);
TBBUTTON tbb;
ZeroMemory(&tbb, sizeof(tbb));
tbb.iBitmap = m_pmapBitmaps->GetItem(bmpButtonImage.GetHBITMAP());
tbb.idCommand = nCommandID;
tbb.fsState = TBSTATE_ENABLED;
tbb.fsStyle = TBSTYLE_BUTTON;
tbb.iString = m_pmapStrings->GetItem(strButtonText);
this->InsertButton(nIndex, tbb);
}
This problem applies specifically to mixing the string and non-string versions, because it works fine if they are not mixed. I tried setting the iString member of the TBBUTTON structure to -1 in the non-string AddButton and it seems to work. What I want to know is if that is legal as a way to specify "no string for this button" or if it can cause problems. Anybody know?