CControlBar - derived Control not shown after - Migration from VS2008 to VS2010

  • Thread starter Thread starter dm01
  • Start date Start date
D

dm01

Guest
Hello everybody,

I have detected a breaking change in a running C++ MFC program (compiled by VS2008) after migration to VS2010 (SP1).

I use some CControlBar-derived "floatable ToolWindow" to fill it with our own controls.
In an version, compiled by Visual Studio 2008 all runs fine. The floatable CControlBar will be shown.
After compiling the same source with current Visual C++ 2010, the floatable CControlBar is not shown.

I have searched in the net for some solutions or workarounds and found a similar sample on Codeguru.

http://www.codeguru.com/Cpp/W-D/docking/article.php/c1451
SourceCode: Download demo project - 25KB



And on StackOverflow, there was an unanswered article, that describes, that this error occurs only by compiling against VS2010:

http://stackoverflow.com/questions/...ccontrolbar-not-working-in-visual-studio-2010

Im using a CControlBar derived class to implement dockable windows. The code is derived from an old codeguru example which can be found here: http://www.codeguru.com/Cpp/W-D/docking/article.php/c1451 This code worked fine but since switching from VS2008 to VS2010 the dockable window does not show up anymore. The standalone example that comes with the article mentioned above also does not work in VS2010 but behaves correctly in earlier versions of Visual Studio.

Does anybody know of any changes in MFC which could break existing code derived from CControlBar? Anyone else who used the codeguru example above as a basis for their own dockable windows.


Base Code will be ...



int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
...

CString title("CoolBar Demo");
if (!m_wndDialogBar.Create(this, &m_cDialog,title, IDD_DIALOG1))
{
TRACE0("Failed to create dialogbar\n");
return -1; // fail to create
}

> m_wndDialogBar.SetBarStyle(m_wndDialogBar.GetBarStyle() |
> CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
...
}



ControlCreation is done in this sample by code:


BOOL CCoolDialogBar::Create(CWnd* pParentWnd, CDialog *pDialog, CString &pTitle, UINT nID, DWORD dwStyle)
{
ASSERT_VALID(pParentWnd); // must have a parent
ASSERT (!((dwStyle & CBRS_SIZE_FIXED) && (dwStyle & CBRS_SIZE_DYNAMIC)));

// save the style -- AMENDED by Holger Thiele - Thankyou
m_dwStyle = dwStyle & CBRS_ALL;

// create the base window
CString wndclass = AfxRegisterWndClass(CS_DBLCLKS, LoadCursor(NULL, IDC_ARROW),
m_brushBkgd, 0);
if (!CWnd::Create(wndclass, pTitle, dwStyle, CRect(0,0,0,0),
pParentWnd, 0))
return FALSE;

// create the child dialog
m_cDialog = pDialog;
m_cDialog->Create(nID, this);

// use the dialog dimensions as default base dimensions
CRect rc;
m_cDialog->GetWindowRect(rc);
m_sizeHorz = m_sizeVert = m_sizeFloat = rc.Size();
m_sizeHorz.cy += m_cxEdge + m_cxBorder;
m_sizeVert.cx += m_cxEdge + m_cxBorder;

return TRUE;
}


The following code is the original code from my own large project:
(both code works well with VS2008 and earlier, but will not work after compiling with Visual Studio C++ 2010 SP1)



BOOL mfc_grafik_menu::Create( CMainFrame *pParent, const CRect &window_rect, BOOL dock_it )
{
UINT dockbar_id;
UINT floating_style;

ASSERT( pParent != NULL );

if( !CControlBar::Create( NULL, "",
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | CBRS_SIZE_DYNAMIC, window_rect, pParent, 0/*nID*/) )
return FALSE;

SetBarStyle( CBRS_ALIGN_TOP | CBRS_BORDER_3D | CBRS_SIZE_DYNAMIC );

WndOrgRect = window_rect;
pParent->ClientToScreen( WndOrgRect );

if( window_rect.Width() > window_rect.Height())
{
EnableDocking( CBRS_ALIGN_TOP | CBRS_ALIGN_BOTTOM );
dockbar_id = AFX_IDW_DOCKBAR_TOP;
floating_style = CBRS_ALIGN_TOP;
}
else
{
EnableDocking( CBRS_ALIGN_LEFT | CBRS_ALIGN_RIGHT );
dockbar_id = AFX_IDW_DOCKBAR_LEFT;
floating_style = CBRS_ALIGN_LEFT;
}

if( dock_it )
pParent->DockControlBar( this, dockbar_id, &WndOrgRect );
else
{
EnableDocking( 0 ); // disable docking for grafik menus if they are not created docked
pParent->FloatControlBar( this, WndOrgRect.TopLeft(), floating_style );
}
return TRUE;
}





Just take the sample from Codeguru (SourceCode: Download demo project - 25KB), load this old project from .dsw to VS2008 or VS2010 and compare the results.
Attn: In these old codeguru sample sources the only change, that is needed, is to change the signature of OnNcHitTest from UINT to LRESULT


change:
UINT CCoolDialogBar::OnNcHitTest(CPoint point)
to:
LRESULT CCoolDialogBar::OnNcHitTest(CPoint point)

After click on right most toolbar button, in the VS2008-Version you will see the floatable Toolwindow, in VS2010-Error you see nothing.
In Spy++ (by looking for all controls that match the process) you can see, that the Controls were created, but they are not shown on the sceen.
I have tried to compare the MFC-Sources from C++2008 to C++2010-Versions, but I found no point, that could have an impact on this issue.

Which CBRS_*-Flags or other Flags or Overloads or other workarounds should I use to solve this issue.

Thanks in advance.

Dietmar Mayer - dm01

Continue reading...
 
Back
Top