 |
|
|
Hi, How do I show a button a button in pressed state using CMFCToolbar. I remember I can be done quite easily using CToolBar by just using the SetCheck function I am trying to change the style of the button to TBBS_CHECKBOX initially when the button is created and then xor the style with TBBS_CHECKED when the button is pressed but somehow it is not working So any body has any idea? Thanks Farhat
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I have 3 toolbars in the mainframe. I want to put them as below:
[Toolbar1][Toolbar3] [Toolbar2]
Please somebody tell me how to I do reach the goal? I just know the DockControlBar is the key and align flag(maybe). I have tried calculated the rect of toolbar to the position in top of MainFrame, but the toolbar look like to be aligned to top. Even I changed the toolbar's align flag to be bottom. The toolbar2 also cannot align to the toolbar1 to the left and side by side.
source code from the website: (I just addd third toobar) http://www.codeproject.com/KB/toolbars/toolbar_docking.aspx
[pre] int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1) return -1; // if (!m_wndToolBar1.Create(this) || !m_wndToolBar1.LoadToolBar(IDR_MAINFRAME)) { TRACE0("Failed to create toolbar\n"); return -1; // fail to create }
m_wndToolBar1.ModifyStyle(0, TBSTYLE_FLAT);
// if (!m_wndToolBar2.Create(this) || !m_wndToolBar2.LoadToolBar(IDR_WINDOW)) { TRACE0("Failed to create toolbar\n"); return -1; // fail to create }
m_wndToolBar2.ModifyStyle(0, TBSTYLE_FLAT);
// if (!m_wndToolBar3.Create(this) || !m_wndToolBar3.LoadToolBar(IDR_WINDOW)) { TRACE0("Failed to create toolbar\n"); return -1; // fail to create }
m_wndToolBar3.ModifyStyle(0, TBSTYLE_FLAT);
// if (!m_wndStatusBar.Create(this) || !m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT))) { TRACE0("Failed to create status bar\n"); return -1; // fail to create }
// TODO: Delete these three lines if you don't want the toolbar to // be dockable m_wndToolBar1.EnableDocking(CBRS_ALIGN_ANY); m_wndToolBar2.EnableDocking(CBRS_ALIGN_ANY); m_wndToolBar3.EnableDocking(CBRS_ALIGN_ANY); EnableDocking(CBRS_ALIGN_ANY); DockControlBar(&m_wndToolBar1); DockControlBarLeftOf(&m_wndToolBar2,&m_wndToolBar1); DockControlBarLeftOf(&m_wndToolBar3,&m_wndToolBar2);
return 0; }
void CMainFrame::DockControlBarLeftOf(CToolBar* Bar, CToolBar* LeftOf) { CRect rect; DWORD dw; UINT n; // get MFC to adjust the dimensions of all docked ToolBars // so that GetWindowRect will be accurate RecalcLayout(TRUE); LeftOf->GetWindowRect(&rect); rect.OffsetRect(1,0); dw=LeftOf->GetBarStyle(); n = 0; n = (dw&CBRS_ALIGN_TOP) ? AFX_IDW_DOCKBAR_TOP : n; n = (dw&CBRS_ALIGN_BOTTOM && n==0) ? AFX_IDW_DOCKBAR_BOTTOM : n; n = (dw&CBRS_ALIGN_LEFT && n==0) ? AFX_IDW_DOCKBAR_LEFT : n; n = (dw&CBRS_ALIGN_RIGHT && n==0) ? AFX_IDW_DOCKBAR_RIGHT : n; // When we take the default parameters on rect, DockControlBar will dock // each Toolbar on a seperate line. By calculating a rectangle, we // are simulating a Toolbar being dragged to that location and docked. DockControlBar(Bar,n,&rect); } [/pre]
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi,
I wanted to dock a CMFCMenuBar to the left of a CMFCToolBar. I have tried this solution with CMFCToolbar instead of CToolBar but it doesnt work. I have tried DockPaneLeftOf as well. This works, but the toolbar gets placed way far to the left and the contents go off the screen. How do i fix this?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
|
Hi, I want to dock ToolBar To its original position after an event like click of button or in mouse down.similar like When double click on floating toolbar. Is it possible? Waiting for your early.
-- modified at 1:03 Tuesday 11th September, 2007
Trupti
|
| Sign In·View Thread·PermaLink | 2.67/5 (2 votes) |
|
|
|
 |
|
|
Hi All,
How to remove the empty spaces in front of toolbar2 if uncheck view->toolbar ? In other word, How can I move toolbar2 to where toolbar used to be automatically if I uncheck view->toolbar? Right now, it is just leave an empty space there.
Thanks, JD
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
Hi, Thanks for a simple and effective article. I have following problem, if you create toolbar(1st) with TBSTYLE_LIST, and set some caption to 1st and 2nd toolbar button, like
m_wndToolBar1.SetButtonText(0,"ABC"); m_wndToolBar1.SetButtonText(1,"XYZ"); the only last button of toolbar 1 is shown with only partial text on it.
Regards Abhi Lahare
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
The docking toolbar will be automatically repositioned, if the mainframe window is resized. For example, the docking toolbars in this example will occupy two rows if the main frame window gets smaller and smaller.
If we don't want it to work like that, how do we change the code?
Mary
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Agreed, how can we block this behavior? Also, although the bars may be initially positioned side by side, it is still possible to float them, then redock them interactively so they snap on top of eachother again.
Anyway we can say either align side by side or don't align at all?
Thanks
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
The code works great 
However, I've noticed that I get some minor pixel artifacts. To correct this, I post a pair of commands to hide, then show the toolbars.
You'll need a Menu item (under the View menu, for example) to toggle the Toolbar. Then, assuming the toolbar is initially visible, send a pair of commands like so:
PostMessage(WM_COMMAND, ID_VIEW_TOGGLExxx); PostMessage(WM_COMMAND, ID_VIEW_TOGGLExxx);
Where the ID_VIEW_TOGGLExxx is the menu command Id that you assigned to your toolbar.
Assuming you have the proper command handlers to toggle the ShowWindow() state, this clears up the artifacts.
Bob Ciora
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I came across this problem a while ago, and was already on a new project before I had a chance to figure it out. I've bookmarked this article in case I have to do this again 
Bob Ciora
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Has anyone gotten this to work with toolbar classes derived from CToolBar. The classes each have buttons and a combo box. I am unable to dock them side by side. The are placed one on top of the other despite anything I try.
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
Hi,
change the function as follow:
original -> void DockControlBarLeftOf(CToolBar* Bar, CToolBar* LeftOf)
modified -> void DockControlBarLeftOf(CControlBar* Bar, CControlBar* LeftOf)
That way you can doc all types of controlbars.
|
| Sign In·View Thread·PermaLink | 4.20/5 (2 votes) |
|
|
|
 |
|
|
Hi there, Hi This has worked for me as well but there is a line or sperator between the toolbars. Is there anyway to get rid of this? I need to have the 2 toolbars look like a single toolbar as one of the toolbars has button text an the other hasn't thus the need the use this method any help much appreciated....
Steve
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi!
I had the same problem when I created a toolbar. You have to create your own toolbarclass and override the NcPaint() function.
Please have a look at this: http://www.codeproject.com/docking/headertoolbar.asp
Take a look at the void CHeaderToolbar::OnNcPaint() function and you'll get rid of those ugly borders 
===================== Lars [Large] Werner lars@werner.no http://lars.werner.no =====================
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
|
Hi,
Thank you for your code. It's easy, simple and practical.  Howewer, I'm trying a trouble when I'm trying to display only the toolbar2, after I've unchecked both toolbars.
I've created a new option menu ( Toolbar2 ) in the View option for his application sample.
Running the sample, when I hide the toolbars and I redim the dialog, the area where the toolbars were placed is hidden. If I try to display the toolbar, it works fine. However, if I try to display the toolbar2 (without display the toolbar), nothing is displayed.
Could you help me, please ? 
Thanks in advance, Ajr
Code used to show and to hide the Toolbar2 if ( m_wndToolBar2.IsWindowVisible() ) m_wndToolBar2.ShowWindow( SW_HIDE ); else m_wndToolBar2.ShowWindow( SW_SHOW );
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi did you resolve this problem? I have been tracing through MFC looking at what I think might be the same issue... I have multiple toolbars which are dynamically shown or hidden, and when you go between the various states, it sometimes refuses to dock the toolbar in the requested rectangle and puts it into the next row.
I think this is caused by the code in MFC's CDocBar::Insert routine. This seems to determine which row to put the toolbar into, overriding the requested rectangle. Seems to work when all toolbars are present, but when you start turning them on and off funny things happen. It runs through all the toolbars and if it finds a pBar that is not pBar->IsVisible(), then it treats it like the end of a row. I wondered if you have to do something special for non-visible toolbars before calling this Docking routine? Any comments?
DaveB
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Heres the method I use to show/hide multiple toolbars:
First create a menu item, ID_VIEW_TOOLBAR2 for example. Then specify this as your second toolbar's ID: m_wndToolbar2.Create (this, WS_CHILD | WS_VISIBLE | CBRS_TOP, ID_VIEW_TOOLBAR2);
Then add the following to your CMainFrame's message map: ON_COMMAND_EX(ID_VIEW_TOOLBAR2, OnBarCheck) ON_UPDATE_COMMAND_UI(ID_VIEW_TOOLBAR2, OnUpdateControlBarMenu)
Those two functions are in the CFrameWnd class I think. I hope this helps!
KJD
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
How to Docking More than Three Toolbars Side-By-Side??
The following code work wrong!!!!!!
[code] m_wndToolBar1.EnableDocking(CBRS_ALIGN_ANY); m_wndToolBar2.EnableDocking(CBRS_ALIGN_ANY); m_wndToolBar3.EnableDocking(CBRS_ALIGN_ANY); EnableDocking(CBRS_ALIGN_ANY); DockControlBar(&m_wndToolBar1); DockControlBarLeftOf(&m_wndToolBar2,&m_wndToolBar1); DockControlBarLeftOf(&m_wndToolBar3,&m_wndToolBar2); [/code]
|
| Sign In·View Thread·PermaLink | 1.80/5 (5 votes) |
|
|
|
 |