|
Thanks for posting this article! Note that the original code assumes the buttons have a size of 24 by 24 pixels. The following change addresses this issue.
diff -u -r1.2 EnBitmap.cpp
--- EnBitmap.cpp 23 Jan 2009 08:10:04 -0000 1.2
+++ EnBitmap.cpp 23 Jan 2009 09:29:24 -0000
@@ -388,19 +388,22 @@
void CToolBar24::SetFullColorImage(UINT ID, COLORREF rgbBack)
{
m_bmToolbar.LoadBitmap(ID);
- m_imgToolbar.Create(24, 24, ILC_COLOR24|ILC_MASK, 1, 1);
+ BITMAP bmp;
+ m_bmToolbar.GetBitmap(&bmp);
+ int nimg = this->GetToolBarCtrl().GetImageList()->GetImageCount();
+ m_imgToolbar.Create(bmp.bmWidth / nimg, bmp.bmHeight, ILC_COLOR24|ILC_MASK, 1, 1);
m_imgToolbar.Add(&m_bmToolbar, rgbBack);
GetToolBarCtrl().SetHotImageList(&m_imgToolbar);
m_bmToolbarDis.LoadBitmap(ID);
m_bmToolbarDis.MakeDisabled(RGB(255, 0, 255));
- m_imgToolbarDis.Create(24, 24, ILC_COLOR24|ILC_MASK, 1, 1);
+ m_imgToolbarDis.Create(bmp.bmWidth / nimg, bmp.bmHeight, ILC_COLOR24|ILC_MASK, 1, 1);
m_imgToolbarDis.Add(&m_bmToolbarDis, rgbBack);
GetToolBarCtrl().SetDisabledImageList(&m_imgToolbarDis);
m_bmToolbarNA.LoadBitmap(ID);
m_bmToolbarNA.MakeNotActive(RGB(255, 0, 255));
- m_imgToolbarNA.Create(24, 24, ILC_COLOR24|ILC_MASK, 1, 1);
+ m_imgToolbarNA.Create(bmp.bmWidth / nimg, bmp.bmHeight, ILC_COLOR24|ILC_MASK, 1, 1);
m_imgToolbarNA.Add(&m_bmToolbarNA, rgbBack);
GetToolBarCtrl().SetImageList(&m_imgToolbarNA);
}
|
|
|
|
|
I absolutely love this toolbar - thank you very much!
Mike
|
|
|
|
|
me too!
Thank you again!!
Keith K. S. Lee
In Taiwan
|
|
|
|
|
can any one help me out to add new image in to exising toolbar.
When I am opening existing 24 bit toolbar in to MS .Net 2003 enviornment toolbar editor to add new toolbar button with 24 bit image its modifies exiting images to 8 bit.can any one help me out for these?
Rajan Kapadia
|
|
|
|
|
Hi Rajan,
First of all - what you are trying to point out is a problem. Having said that it is a problem - the author has presented a working solution for that. In addition he also presents a way where your TRUECOLOR toolbar would have Inactive and Disabled images.
If you have run the demo provided by the author, you already see that he has TRUECOLOR icons displayed on to the toolbar.
To get a backgrounder on how does all this work (24 bit (or more) icons on the toolbar) - please browse to; http://www.codeproject.com/docking/toolbar_hotbuttons.asp[^]
HTH
Best regards,
Yogesh Dhakad
|
|
|
|
|
This can be accomplished through API AfxGetGrayBitmap( )
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
|
|
|
|
|
I was using a similar approach to 24-bit toolbars before discovering this code, but found that my own implementation and this one share the same bug. Has anybody experienced this problem, and hopefully found a workaround? Here is the problem:
1. Create one or more "checkbox"-style buttons on the toolbar by setting the TBSTYLE_CHECK flag for some buttons.
2. For testing purposes, have an easy way to cause those buttons to be enabled/disabled.
3. Disable the buttons, and notice that the disabled image is used properly.
4. Re-enable the buttons.
5. Now click some of the TBSTYLE_CHECK buttons so they're pressed down, and disable the buttons again.
UH OH: Now you notice that although the buttons are disabled (they can't be clicked or toggled), the images used are the regular ones instead of the Disabled ones.
I have tested this in several ways, and as it turns out, it apparently has nothing to do with whether the images are 24-bit or not. It is simply, if you call CToolBarCtrl::SetDisabledImageList to specify a disabled image list for a tool bar ctrl, then those images will NOT be used when rendering a pushed-down but disabled TBSTYLE_CHECK-style button. If you just let Windows come up with its own disabled image (which looks crappy when your actual images are 24-bit), then at least it draws the disabled version in this case.
Has anyone noticed this problem, or found a workaround for it??
|
|
|
|
|
Update: More info on this. I found a Microsoft knowledge base article about this; I guess it's a known issue, but they're apparently not concerned about fixing it: KB231893
So, does anybody know how you could go about custom-drawing the toolbar buttons (when they're both TBSTATE_CHECKED && !TBSTATE_ENABLED) in order to work around this issue? I really am not sure how to start on that one. Thanks for anybody pointing me in the right direction.
|
|
|
|
|
I programmed you course broad way. Problem it was not but, the problem from the hazard which changes the size of the image inserted the following code.
m_wndToolBar.SetSizes(CSize(55,55),CSize(55-7,55-6));
But the image does not change and it does to do how?
|
|
|
|
|
|
This is a C++ progject. It can't be used in VB.NET unless it can be turned into a managed C++ project. If you're new to programming, you'd do better to learn your language than trying to integrate code snippets off the web at this point. You'd do even better to abandon VB.NET for C#, but that's another story.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Hi there.
I just created a Toolbar and added my own Bitmaps with CImageList´s to it, in order to set the Diasabled Buttons. When i call the EnableButton Function the Button remains enabled and the Command ID is still used. How can i disable a button in here completely?
Here the code from my derived Toolbar:
<br />
BOOL CBar::CreateEx(CWnd* pParentWnd)<br />
{<br />
if ( !CToolBar::CreateEx(pParentWnd,TBSTYLE_FLAT,WS_CHILD | WS_VISIBLE | CBRS_ALIGN_ANY | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC, CRect(0,0,0,0), ID_TOOLBAR_CHARTOPTIONEN))<br />
return FALSE;<br />
return Create();<br />
}<br />
<br />
BOOL CBar::Create()<br />
{<br />
if( m_ilToolbar.GetSafeHandle()==NULL )<br />
m_ilToolbar.Create(16, 15, ILC_MASK | ILC_COLOR32, 14, 0);<br />
if( m_ilToolbarDisabled.GetSafeHandle()==NULL )<br />
m_ilToolbarDisabled.Create(16, 15, ILC_MASK | ILC_COLOR32, 14, 0);<br />
<br />
m_bitmapTB.LoadBitmap(IDB_TB_CHART_OPTIONS);<br />
m_bitmapTBDisabled.LoadBitmap(IDB_TB_CHART_OPTIONS_DISABLED);<br />
<br />
m_ilToolbar.Add(&m_bitmapTB, RGB(192, 192, 192));<br />
m_ilToolbarDisabled.Add(&m_bitmapTBDisabled, RGB(192, 192, 192));<br />
<br />
GetToolBarCtrl().SetImageList(&m_ilToolbar);<br />
GetToolBarCtrl().SetDisabledImageList(&m_ilToolbarDisabled);<br />
<br />
SetWindowText("Chart-Funktionen");<br />
EnableDocking(CBRS_ALIGN_TOP | CBRS_ALIGN_LEFT | CBRS_ALIGN_RIGHT);<br />
<br />
SetButtons(NULL, 16);<br />
<br />
SetButtonInfo(0, IDC_TBCHOPT_BIDASK, TBSTYLE_CHECK, 0);<br />
SetButtonInfo(1, IDC_TBCHOPT_MARKTTIEFE, TBSTYLE_CHECK, 1);<br />
SetButtonInfo(2, IDC_TBCHOPT_PIVOT, TBSTYLE_CHECK, 2);<br />
SetButtonInfo(3, IDC_TBCHOPT_HANDELSSPANNE, TBSTYLE_CHECK, 3);<br />
SetButtonInfo(4, IDC_TBCHOPT_MARKIERUNGEN, TBSTYLE_CHECK, 4);<br />
SetButtonInfo(5, IDC_TBCHOPT_VORTAG, TBSTYLE_CHECK, 5);<br />
SetButtonInfo(6, IDC_TBCHOPT_VOLUMEN, TBSTYLE_CHECK, 6);<br />
SetButtonInfo(7, IDC_TBCHOPT_STOPZIEL, TBSTYLE_CHECK, 7);<br />
SetButtonInfo(8, IDC_TBCHOPT_UEBERWACHUNG, TBSTYLE_CHECK, 8);<br />
SetButtonInfo(9, NULL, TBBS_SEPARATOR, 5);<br />
SetButtonInfo(10, IDC_TBCHOPT_CHARTARTLINIEN, TBBS_CHECKGROUP, 9);<br />
SetButtonInfo(11, IDC_TBCHOPT_CHARTARTBALKEN, TBBS_CHECKGROUP, 10);<br />
SetButtonInfo(12, IDC_TBCHOPT_CHARTARTKERZEN, TBBS_CHECKGROUP, 11);<br />
SetButtonInfo(13, IDC_TBCHOPT_CHARTARTSTUFEN, TBBS_CHECKGROUP, 12);<br />
SetButtonInfo(14, NULL, TBBS_SEPARATOR, 5);<br />
SetButtonInfo(15, IDC_TBCHOPT_EINSTELLUNGEN, TBSTYLE_BUTTON, 13);<br />
<br />
return TRUE;<br />
}<br />
In the MainFrame the call to disable it is this:
This is a Function which is called by the
BOOL CMainFrame::OnCommand(WPARAM wParam, LPARAM lParam)
Function. There is a switch for the WPARAM. So nothing improtant here.
<br />
void CMainFrame::UpdateToolbars(BYTE lParam)<br />
{<br />
m_wndChartFunktionenBar.GetToolBarCtrl().EnableButton(IDC_TBCHOPT_BIDASK, FALSE);<br />
m_wndChartFunktionenBar.GetToolBarCtrl().Indeterminate(IDC_TBCHOPT_BIDASK, TRUE);<br />
}<br />
The Button is grayed (due to the Indeterminate Function) but it is still enabled, whereas the EnableButton Function returned Success. ???
The Command ID (IDC_TBCHOPT_BIDASK) is still processed. What do i have to do here?
Is the problem the Bitmaps for the Toolbars? When creating a default Project MFC is using a
m_wndToolBar.LoadToolBar(IDR_MAINFRAME)
call. And all is processed by the document-view implementation. So anyone can help me here?
|
|
|
|
|
In fact I have never tried to work with toolbar this way. Common MFC method is using ON_UPDATE handler.
|
|
|
|
|
Ok, here i have a solution, but it is not much "explainable" for me. Flame me, i´m not that experienced with it.
I just did a simple override for this in the header:
protected:<br />
afx_msg void OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHndler);
and the implementation does the following... nothing...
void CBar::OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHndler)<br />
{<br />
}<br />
Now i can enable/disable the button and a click on it does not visibly push the button, nor sends the message to the MainFrame. Works fine for me now, but do u have a simple and explainable soultion to this? I guess now that u either need a separate Message-Handler in the derived ToolBar Class for all ID´s used in it, or use the implementation i used above, which generally catches all CommandUI Messages.
But why the MainFrame gets the Message, when the Button is Enabled, although i do nothing in the CBar::OnUpdateCmdUI is a mystery to me. But perhaps i´m not experienced enough to understand.
|
|
|
|
|
Please note that you are not using recommended method for toolbar handling. How do you handle commands? I can explain what is going on - in every idle cycle framework calls OnUpdateUI handler for each ID. If you have not proceed ON_UPDATE handler, default is used, which enables button. That's what you have done, by supplying empty handler.
|
|
|
|
|
I copied the 4 files to my project
but :
MainFrm.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall CEnBitmap::~CEnBitmap(void)" (??1CEnBitmap@@UAE@XZ)
MainFrm.obj : error LNK2001: unresolved external symbol "public: __thiscall CEnBitmap::CEnBitmap(unsigned long)" (??0CEnBitmap@@QAE@K@Z)
MainFrm.obj : error LNK2001: unresolved external symbol "public: void __thiscall CToolBar24::SetFullColorImage(unsigned int,unsigned long)" (?SetFullColorImage@CToolBar24@@QAEXIK@Z)
why???
|
|
|
|
|
Have you added both .cpp files to project via Project/Add Files command? What is your VS version?
Igor Green
http://www.grigsoft.com
Compare It! + Synchronize It! : Files and folders comparison never was easier!
|
|
|
|
|
Ah,sorry,you are right
I had forgot that
Thank you!
|
|
|
|
|
first of all, thank you for your wonderful CToolBar24 class
but i got the problem which is.
my program's toolbar using CToolBar24 in my computer is looked perfect.
but the position of the bitmap in toolbar is wrong when i run same program in another machine
what can i do !?
thank
|
|
|
|
|
Sorry, I have missed notification of your post.
What is Windows version in both cases? And how is image different?
Probably you can contact me directly to discuss the problem.
Igor Green
http://www.grigsoft.com[^]
Compare It! + Synchronize It! : Files and folders comparison never was easier!
|
|
|
|
|
Nice article. But when I use it in my application, I found the background color of the tolbar bitmap (RGB(192,192,192)) was not transparent. In the NoActive mode, the background is a little lighter, and the background is white in the Disabled mode. I'm tring to look into the code, but I haven't figured out what was wrong yet. Could somebody help me? Thanks a lot.
|
|
|
|
|
Hmm, how does it look in sample application on your PC?
And which OS are you using? Note that gray color itself should not be used anywhere - if it is gray on your toolbar bitmap, you have to use same color in SetFullColorImage. You can contact me personally on this topic - supportATgrigsoft.com.
Igor Green
http://www.grigsoft.com[^]
Compare It! + Synchronize It! : Files and folders comparison never was easier!
|
|
|
|
|
Replace in
CToolBar24::SetFullColorImage
like that:
m_bmToolbarDis.MakeDisabled(rgbBack);
and
m_bmToolbarNA.MakeNotActive(rgbBack);
|
|
|
|
|
What you mentioned is a bug in the original code, but it's not the reason for my problem.
Anyway, if I change the bg color of the toolbar image to (255,0,255), the problem is gone.
|
|
|
|
|
In the function SetFullColorImage() you need to change the lines:
m_bmToolbar.LoadBitmap(ID);
m_imgToolbar.Create(24, 24, ILC_COLOR24|ILC_MASK, 1, 1);
m_imgToolbar.Add(&m_bmToolbar, rgbBack);
GetToolBarCtrl().SetHotImageList(&m_imgToolbar);
m_bmToolbarDis.LoadBitmap(ID);
- m_bmToolbarDis.MakeDisabled(RGB(255, 0, 255));
+ m_bmToolbarDis.MakeDisabled(rgbBack);
m_imgToolbarDis.Create(24, 24, ILC_COLOR24|ILC_MASK, 1, 1);
m_imgToolbarDis.Add(&m_bmToolbarDis, rgbBack);
GetToolBarCtrl().SetDisabledImageList(&m_imgToolbarDis);
m_bmToolbarNA.LoadBitmap(ID);
- m_bmToolbarNA.MakeNotActive(RGB(255, 0, 255));
+ m_imgToolbarDis.Add(&m_bmToolbarDis, rgbBack);
m_imgToolbarNA.Create(24, 24, ILC_COLOR24|ILC_MASK, 1, 1);
m_imgToolbarNA.Add(&m_bmToolbarNA, rgbBack);
GetToolBarCtrl().SetImageList(&m_imgToolbarNA);
|
|
|
|
|