|
By default, MFC doesn't have a clue how to pass command messages into child views of this bar. So I added some code here and there to help it:
BOOL CSizingTabCtrlBar::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{
POSITION pos = m_views.GetHeadPosition();
while (pos)
{
TCB_ITEM * pMember = m_views.GetNext(pos);
if (pMember->pWnd->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
return TRUE;
}
return CWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}
This code tries to handle the command message from menus etc in child views first, and if noone cares, passes it into control bar itself as usually.
The only other piece of code to support this goes into the CMainFrame:
BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{
if (barThis.OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
return TRUE;
if (barThat.OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
return TRUE;
return CMDIFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}
barThis and barThat are tab control bars with views that must respond to some command. Now you can add usual menu command handlers to view classes and they will receive the message. The only thing is that if two views can handle the same message, only first view will see it, second will have no idea of what is going on.
|
|
|
|
|
Good code to start with. I couldn't combine it with Christi's latest version of CSizingControlBar, so I combined CSizingTabCtrlBar with older version of CSizingControlBar into single class. Works great.
However, even in the original version there was a problem: If I add a view into the CSizingTabCtrlBar after it is already created, it doesn't show properly until I resize the bar. The easy workaround was to call OnSize() after adding a view.
I added protected members to CSizingTabCtrlBar:
int m_cx;
int m_cy;
UINT m_type;
They hold last parameters passed to OnSize so I can safely call the function again.
Code added to OnSize() after CControlBar::OnSize(nType, cx, cy);:
// store last size so we can resize after adding a tab
// extra check, if m_cx is 0xFDFDFDFD the thing is shutting down
if (m_cx != 0xFDFDFDFD)
{
m_cx = cx;
m_cy = cy;
m_type = nType;
}
The last change to the class was in AddView() right before returning TRUE:
OnSize(m_type, m_cx, m_cy);
That takes care of the view that is added after the bar is already displayed.
|
|
|
|
|
I have made some mods to support tabs on top (without TCS_BOTTOM attribute) and multiline tabs (with TCS_MULTILINE attribute). Maybe some pixels deviations, but works.
void CSizingTabCtrlBar::OnSize(UINT nType, int cx, int cy) <br />
{<br />
CSizingControlBar::OnSize(nType, cx, cy);<br />
<br />
CRect rect;<br />
this->GetClientRect(&rect);<br />
int bottom = (IsHorz() || IsFloating()) ? cy - 14 : cy - 18;<br />
m_tabctrl.MoveWindow(7, 7, rect.Width()-7, bottom);<br />
<br />
m_tabctrl.GetItemRect(0, &rect);<br />
int height = rect.Height() * m_tabctrl.GetRowCount();<br />
<br />
bool isBottom = (m_tabctrl.GetStyle() & TCS_BOTTOM) ? true : false; <br />
CWnd *pWnd;<br />
for (POSITION pos=m_views.GetHeadPosition(); pos; m_views.GetNext(pos)) {<br />
pWnd=m_views.GetAt(pos)->pWnd;<br />
if (isBottom)<br />
pWnd->MoveWindow(9, 9+3, cx-14, bottom-height-7-3);<br />
else<br />
pWnd->MoveWindow(9, 9+height+3, cx-14, bottom-height-7);<br />
}<br />
}
Best regards,
Jaime
|
|
|
|
|
void CSizingTabCtrlBar::OnSize(UINT nType, int cx, int cy)
{
CSizingControlBar::OnSize(nType, cx, cy);
int bottom = (IsHorz() || IsFloating()) ? cy - 14 : cy - 18;
m_tabctrl.MoveWindow(7, 7, cx-7, bottom);
CRect rect;
m_tabctrl.GetItemRect(0, &rect);
int height = rect.Height() * m_tabctrl.GetRowCount();
bool isBottom = (m_tabctrl.GetStyle() & TCS_BOTTOM) ? true : false;
for (POSITION pos=m_views.GetHeadPosition(); pos; m_views.GetNext(pos))
m_views.GetAt(pos)->pWnd->MoveWindow(10, isBottom?10:height+12, cx-13, bottom-height-8);
}
Jaime
|
|
|
|
|
I am working on a SDI. When i click any place on the formviews that i added to tab control bar, some buttons on toolbar are disabled. how can i fix this?
|
|
|
|
|
The sample project does not work on VC6.0 . When I change it to fit VC6.0, it is so nice. But it does not repaint when the main window is maximized or minimized. Please update a newer version, Dirk Clemens.
|
|
|
|
|
hy, at first sorry for my bad englisch. i'm still learning
So my problem is, my prog crashed when i click on X.
History:
I have made a Tree in the first tab. When i doubleclick on a Item, my prog get the text from the Item an write the text in the Document.
This works fine & without problems.
But click i now on X for closed my prog i became a warning Debug Assertion Failed!
The Debug show me the file "\VC98\MFC\SRC\WINFRAME.CPP"
and the function
<br />
<br />
void CFrameWnd::DestroyDockBars()<br />
{<br />
CPtrList listDockBars;<br />
POSITION pos = m_listControlBars.GetHeadPosition();<br />
while (pos != NULL)<br />
{<br />
CDockBar* pDockBar = (CDockBar*)m_listControlBars.GetNext(pos);<br />
ASSERT(pDockBar != NULL);<br />
if (pDockBar->IsDockBar())<br />
listDockBars.AddTail(pDockBar);<br />
}<br />
pos = listDockBars.GetHeadPosition();<br />
while (pos != NULL)<br />
{<br />
CDockBar* pDockBar = (CDockBar*)listDockBars.GetNext(pos);<br />
if (pDockBar->m_bFloating)<br />
{<br />
CFrameWnd* pFrameWnd = pDockBar->GetParentFrame();<br />
ASSERT_VALID(pFrameWnd);<br />
pFrameWnd->DestroyWindow();<br />
}<br />
else<br />
pDockBar->DestroyWindow();<br />
}<br />
}
the line in Debug how is wrong is by ASSERT(pDockBar != NULL);
in Debug pDockBar 0x00000000 {CDockBar hWnd = ???}
but start i my prog and closed it before i doubleclick on TreeView first Tab, my prog closed without warning.
And i can write into Doc & close my prog without warning.
The prog only crashed if i doubleclick on the TreeView and close it than.
can someone help me please
|
|
|
|
|
Hi,
I've been reading ppl struggling with drawing bugs, the flaw was in CSizingTabCtrlBar::OnSize, actually the tab wnd was covering the whole bar.
The layout code below sounds mutch better.
Define margins as needed and,
Enjoy!
void CSizingTabCtrlBar::OnSize(UINT nType, int cx, int cy)
{
CSizingControlBar::OnSize(nType, cx, cy);
CRect crect;
GetClientRect(crect);
crect.DeflateRect(TAB_XMARGIN,VIEW_YMARGIN,TAB_XMARGIN,TAB_YMARGIN);
CRect trect;
m_tabctrl.GetItemRect(0,trect);
trect = CRect(TAB_XMARGIN,(crect.Height() - TAB_YMARGIN) - trect.Height(),crect.Width() - 2 * TAB_XMARGIN, crect.Height() - TAB_YMARGIN);
m_tabctrl.MoveWindow(trect);
CRect vrect = crect;
vrect.DeflateRect(VIEW_XMARGIN,VIEW_YMARGIN,VIEW_XMARGIN,VIEW_YMARGIN + trect.Height() + TAB_YMARGIN);
CWnd *pWnd;
for (POSITION pos=m_views.GetHeadPosition(); pos; m_views.GetNext(pos))
{
pWnd = m_views.GetAt(pos)->pWnd;
pWnd->MoveWindow(vrect);
}
}
|
|
|
|
|
In your function:
TAB_XMARGIN
TAB_YMARGIN
VIEW_XMARGIN
VIEW_YMARGIN
are all undefined.
|
|
|
|
|
They just are placeholders ..
Just put whatever value/CONSTANT/variable you need/want...
|
|
|
|
|
I think here is a copy and paste error:
crect.DeflateRect(TAB_XMARGIN,VIEW_YMARGIN,TAB_XMARGIN,TAB_YMARGIN);
I replaced that with TAB_YMARGIN which worked fine.
|
|
|
|
|
Thanks for useful code. There are two small issues with controlbar when it is floating. The first one appears when closing main app, the second one when closing floating bar and focus was set in one of its view. The possible solution for first problem is to dock bar before exit:
void CMainFrame::OnClose()
{
if(m_wndSTCBar.IsFloating())
DockControlBar(&m_wndSTCBar, AFX_IDW_DOCKBAR_LEFT);
CFrameWnd::OnClose();
}
The possible solution to second issue is to set focus to MainFrame view when floating bar is being closed:
void CSizingTabCtrlBar::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos)
{
if ( IsFloating() && (lpwndpos->flags & SWP_HIDEWINDOW) )
{
CMainFrame *pFrame = (CMainFrame*)GetTopLevelFrame();
pFrame->SetActiveView(pFrame->m_cActiveView);
}
CSizingControlBar::OnWindowPosChanging(lpwndpos);
}
where m_cActiveView is a CView* object that need to be pointed to MainFrame View.
|
|
|
|
|
Is it possible to dock the window to the top or bottom of the frame
|
|
|
|
|
I have used this class, but i am faced with one problem,
I have a SDI application, and i have two other docking views, one on the left, and one in the bottom,
I have to refresh the tree controls, periodically say after every 4-5 seconds, and i access the Doc class, to get the data from there.
The problem is, that it all works fine, however when i click on the left tabcontrol view, the Doc pointer retrieved is NULL, and the application crashes, I cannot guess why a mouse click would cause such a behaviour,
I have also noticed, that if the dockign window is not docked and is floating the click of the mouse will not crash the prob, and the Doc pointer is retrieved correct,
What might be the reason to it ?
I guess it has some ting to do the way messages are routed from the windows ?![Confused | :confused:](https://www.codeproject.com/script/Forums/Images/smiley_confused.gif)
|
|
|
|
|
the sizing control tab bar doesn't seem to give up the wheel mouse when i click in another view (CScollView). Any ideas how to make it give up the wheel mouse?
thx steve
|
|
|
|
|
When I click on the X after making the bar float how do I show it again. It doesnt seem to act lick a normal toolbar.
D-MD
|
|
|
|
|
//when you click Button named "show/hide this Wnd"
void CMainFrame::OnButtonInfospace()
{
// TODO: Add your command handler code here
if (m_WndShowHDX.IsWindowVisible() == TRUE)
ShowControlBar(&m_WndShowHDX, FALSE, FALSE); //hide the Wnd
else
ShowControlBar(&m_WndShowHDX, TRUE, FALSE);//show the Wnd
RecalcLayout();
}
void CMainFrame::OnUpdateButtonInfospace(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetRadio(m_WndShowHDX.IsWindowVisible());
}
xiaobin
|
|
|
|
|
Hi, I found <big>it does not work well in VS.net 2003</big> ,It compile well but not run well !May anyone help me to solve it?
Thank you!!
|
|
|
|
|
I found a similar problem.
I open the demo by vs2003 and convert the version by vs2003, I found it works good.
But if I create a new solution by vs2003 and add the CSizingTabCtrlBar into it, it can't work properly when maximizing the window, the size of the tabctrl is wrong.
I can't solve this problem, may anyone know how to do?
3x!
|
|
|
|
|
The update problem of the views is caused occurs because they are given the wrong parent window.
replacing:
if (!pWnd->Create(NULL, NULL, dwStyle, rect, this, 0, pContext))<br />
with
if (!pWnd->Create(NULL, NULL, dwStyle, rect, &m_tabctrl, 0, pContext))
solves the problem.
http://www.codeguru.com/mfc/comments/27713.shtml
|
|
|
|
|
Right, but requires also a small change in layout in OnSize. Here a full OnSize function (with a change from post above and new positions)
void CSizingTabCtrlBar::OnSize(UINT nType, int cx, int cy)
{
CSizingControlBar::OnSize(nType, cx, cy);
int bottom = (IsHorzDocked() || IsFloating()) ? cy - 14 : cy - 18;
m_tabctrl.MoveWindow(7, 7, cx - 14, bottom);
CWnd *pWnd;
for (POSITION pos=m_views.GetHeadPosition(); pos; m_views.GetNext(pos))
{
pWnd=m_views.GetAt(pos)->pWnd;
pWnd->MoveWindow(2, 9, cx-21, bottom-36);
}
}
Philip Patrick
Web-site: www.stpworks.com
"Two beer or not two beer?" Shakesbeer
|
|
|
|
|
this change is ok, but what if the font changes? or the tab size changes? a better fix would be:
void CSizingTabCtrlBar::OnSize(UINT nType, int cx, int cy)<br>
{<br>
CSizingControlBar::OnSize(nType, cx, cy);<br><br>
int bottom = (IsHorzDocked() || IsFloating()) ? cy - 14 : cy - 18;<br><br>
m_tabctrl.MoveWindow(7, 7, cx - 14, bottom);<br><br>
CRect r;<br>
m_tabctrl.GetClientRect(&r);<br>
m_tabctrl.AdjustRect(FALSE, &r);<br><br>
CWnd *pWnd;<br>
for (POSITION pos=m_views.GetHeadPosition(); pos; m_views.GetNext(pos))<br>
{<br>
pWnd=m_views.GetAt(pos)->pWnd;<br>
pWnd->MoveWindow(r.top, r.left, r.Width(), r.Height());<br>
}<br>
}<br>
Andy
|
|
|
|
|
|
resource.h include it, but compile error...
what is IDW_PROP_BAR , where is it?
thanks!
Great C++!
|
|
|
|
|
IDW_PROP_BAR is the name of the Tab Control Identifier, and it appears in "resource.h" and CMainFrame::OnCreate.
When the Tab Control is being created, it needs to have a name that will identify it, which is what IDW_PROP_BAR is. It could have been any name, but that's the one the person writing the program chose.
William
Fortes in fide et opere!
|
|
|
|
|