![]() |
Desktop Development »
Toolbars & Docking windows »
Toolbars
Intermediate
CToolbarDialog - dialog with floating toolbarBy Lucian BarbulescuA CDialog derived class that contains a floating toolbar. |
VC6, VC7Win2K, MFC, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||

This article shows how to add a floating/docking toolbar to a dialog.
In MSDN, there is a sample (dlgcbr32) in which is presented a way to add a fixed toolbar to a dialog. I have extended that example and created a CDialog derived class that contains a toolbar which can be either fixed, floating or hidden. The floating toolbar effect is obtained by dynamically creating a modeless dialog box which contains a fixed toolbar.
To use the code, you must do the following steps:
CToolbarDialog: #include "ToolbarDialog.h" class CTDDlg : public CToolbarDialog
Also make sure that you pass at least the ID of the toolbar resource you want to use to the CToolbarDialog constructor. This constructor has four parameters: the first two are the dialog ID and parent (just like CDialog), the third is the ID of the toolbar resource and the fourth is the initial state of the toolbar. Possible values are:
TS_HIDDEN //toolbar is not shown TS_FLOATING //toolbar is floating TS_LEFT //toolbar is fixed in the left size of the dialog TS_TOP //toolbar is fixed at the top of the dialog TS_RIGHT //toolbar is fixed in the right size of the dialog TS_BOTTOM //toolbar is fixed at the bottom of the dialog
Here is an example:
CTDDlg::CTDDlg(CWnd* pParent /*=NULL*/) :CToolbarDialog(CTDDlg::IDD, pParent,IDR_TOOLBAR1,TS_HIDDEN)
virtual LONG ToolbarButtonCommand(UINT uButtonID);
This function receives as parameter the ID of the toolbar button that was pressed. By implementing this function, you can add handlers to the toolbar buttons.
Example:
LONG CTDDlg::ToolbarButtonCommand(UINT uButtonID)
{
CString msg;
msg.Format("Button with ID %d was pressed in toolbar",uButtonID);
AfxMessageBox(msg);
return 0;
}
PositionToolbar(DWORD dwPosition). The values the parameter can have are the ones described earlier.
For example, to show the toolbar floating, just add the following function call to your code:
PositionToolbar(TS_FLOATING);
UpdateCommandUI handlers to your dialog and edit the methods as you would, in every Frame/View application.
For example:
ON_UPDATE_COMMAND_UI_RANGE(ID_BUTTON32771,ID_BUTTON32775,OnUpdateBtn) void CTDDlg::OnUpdateBtn(CCmdUI* pCmd) { if(pCmd->m_nID == ID_BUTTON32771) pCmd->Enable(FALSE); }
You now have a dialog that support floating toolbars.
I have tested this class only on Windows 2000, but I think it will also work on Win9x and WinXP.
UPDATE_COMMAND_UI does not work (thanks to =[ Abin ]= for informing me about this bug)You are free to use this software in any personal or freeware application. If you use this software in any shareware or commercial application, you MUST get my permission first. If you modify it or extend it, please to consider posting new code here for everyone to share. This software is provided "as is" with no expressed or implied warranty. I accept no liability for any damage or loss of business that this software may cause.
General
News
Question
Answer
Joke
Rant
Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+PgUp/PgDown to switch pages.
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 6 Apr 2004 Editor: Smitha Vijayan |
Copyright 2004 by Lucian Barbulescu Everything else Copyright © CodeProject, 1999-2010 Web18 | Advertise on the Code Project |