EDN Admin
Well-known member
Hello everybody,
I have detected a <span style="text-decoration:underline breaking change in a running C++ MFC program (compiled by VS2008)
<span style="text-decoration:underline after migration to VS2010 (SP1) .
I use some <span style="text-decoration:underline CControlBar-derived "floatable ToolWindow" to fill it with our own controls.<br/>
In an version, compiled by Visual Studio 2008 all runs fine. The floatable CControlBar will be shown.<br/>
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%20" target="_blank http://www.codeguru.com/Cpp/W-D/docking/article.php/c1451
<br/>
SourceCode: http://www.codeguru.com/code/legacy/docking/devstudio_like_controlbar_2_sample_src.zip 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/4149748/dockable-dialog-bar-derived-from-ccontrolbar-not-working-in-visual-studio-2010" target="_blank http://stackoverflow.com/questions/4149748/dockable-dialog-bar-derived-from-ccontrolbar-not-working-in-visual-studio-2010 <span lang="EN-US" style="font-family:"Arial","sans-serif"
<span lang="EN-US" style="font-family:"Arial","sans-serif" 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 <span lang="EN-US" style="font-family:"Arial","sans-serif" http://www.codeguru.com/Cpp/W-D/docking/article.php/c1451 <span lang="EN-US" style="font-family:"Arial","sans-serif"
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 .
<span lang="EN-US" style="font-family:"Arial","sans-serif" 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.
<span style="font-family:"Arial","sans-serif" <br/>
Base Code will be ...
<div style="color:black; background-color:white
<pre><span style="color:blue int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
...
CString title(<span style="color:#a31515 "CoolBar Demo");
<span style="color:blue if (!m_wndDialogBar.Create(<span style="color:blue this, &m_cDialog,title, IDD_DIALOG1))
{
TRACE0(<span style="color:#a31515 "Failed to create dialogbarn");
<span style="color:blue return -1; <span style="color:green // fail to create
}
> m_wndDialogBar.SetBarStyle(m_wndDialogBar.GetBarStyle() |
> CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
...
}
[/code]
<br/>
<span style="text-decoration:underline ControlCreation is done in this sample by code:
<div style="color:black; background-color:white
<pre>BOOL CCoolDialogBar::Create(CWnd* pParentWnd, CDialog *pDialog, CString &pTitle, UINT nID, DWORD dwStyle)
{
ASSERT_VALID(pParentWnd); <span style="color:green // must have a parent
ASSERT (!((dwStyle & CBRS_SIZE_FIXED) && (dwStyle & CBRS_SIZE_DYNAMIC)));
<span style="color:green // save the style -- AMENDED by Holger Thiele - Thankyou
m_dwStyle = dwStyle & CBRS_ALL;
<span style="color:green // create the base window
CString wndclass = AfxRegisterWndClass(CS_DBLCLKS, LoadCursor(NULL, IDC_ARROW),
m_brushBkgd, 0);
<span style="color:blue if (!CWnd::Create(wndclass, pTitle, dwStyle, CRect(0,0,0,0),
pParentWnd, 0))
<span style="color:blue return FALSE;
<span style="color:green // create the child dialog
m_cDialog = pDialog;
m_cDialog->Create(nID, <span style="color:blue this);
<span style="color:green // 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;
<span style="color:blue return TRUE;
}
[/code]
<span style="text-decoration:underline The following code is the original code from my own large project:<br/>
(both code works well with VS2008 and earlier, but will not work after compiling with Visual Studio C++ 2010 SP1)
<div style="color:black; background-color:white
<pre>BOOL mfc_grafik_menu::Create( CMainFrame *pParent, <span style="color:blue const CRect &window_rect, BOOL dock_it )
{
UINT dockbar_id;
UINT floating_style;
ASSERT( pParent != NULL );
<span style="color:blue if( !CControlBar::Create( NULL, <span style="color:#a31515 "",
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | CBRS_SIZE_DYNAMIC, window_rect, pParent, 0<span style="color:green /*nID*/) )
<span style="color:blue return FALSE;
SetBarStyle( CBRS_ALIGN_TOP | CBRS_BORDER_3D | CBRS_SIZE_DYNAMIC );
WndOrgRect = window_rect;
pParent->ClientToScreen( WndOrgRect );
<span style="color:blue 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;
}
<span style="color:blue else
{
EnableDocking( CBRS_ALIGN_LEFT | CBRS_ALIGN_RIGHT );
dockbar_id = AFX_IDW_DOCKBAR_LEFT;
floating_style = CBRS_ALIGN_LEFT;
}
<span style="color:blue if( dock_it )
pParent->DockControlBar( <span style="color:blue this, dockbar_id, &WndOrgRect );
<span style="color:blue else
{
EnableDocking( 0 ); <span style="color:green // disable docking for grafik menus if they are not created docked
pParent->FloatControlBar( <span style="color:blue this, WndOrgRect.TopLeft(), floating_style );
}
<span style="color:blue return TRUE;
}
[/code]
<br/>
Just take the sample from Codeguru ( SourceCode: http://www.codeguru.com/code/legacy/docking/devstudio_like_controlbar_2_sample_src.zip Download demo project - 25KB ), load this old project from .dsw to VS2008 or VS2010
and compare the results.<br/>
Attn: In these old codeguru sample sources the only change, that is needed, is to change the signature of OnNcHitTest from
<span style="text-decoration:underline UINT to <span style="text-decoration:underline
LRESULT
<div style="color:black; background-color:white
<pre> change:
UINT CCoolDialogBar::OnNcHitTest(CPoint point)
to:
LRESULT CCoolDialogBar::OnNcHitTest(CPoint point)
[/code]
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.<br/>
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.<br/>
Thanks in advance.
Didi - dm01
<br/>
<br/>
View the full article
I have detected a <span style="text-decoration:underline breaking change in a running C++ MFC program (compiled by VS2008)
<span style="text-decoration:underline after migration to VS2010 (SP1) .
I use some <span style="text-decoration:underline CControlBar-derived "floatable ToolWindow" to fill it with our own controls.<br/>
In an version, compiled by Visual Studio 2008 all runs fine. The floatable CControlBar will be shown.<br/>
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%20" target="_blank http://www.codeguru.com/Cpp/W-D/docking/article.php/c1451
<br/>
SourceCode: http://www.codeguru.com/code/legacy/docking/devstudio_like_controlbar_2_sample_src.zip 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/4149748/dockable-dialog-bar-derived-from-ccontrolbar-not-working-in-visual-studio-2010" target="_blank http://stackoverflow.com/questions/4149748/dockable-dialog-bar-derived-from-ccontrolbar-not-working-in-visual-studio-2010 <span lang="EN-US" style="font-family:"Arial","sans-serif"
<span lang="EN-US" style="font-family:"Arial","sans-serif" 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 <span lang="EN-US" style="font-family:"Arial","sans-serif" http://www.codeguru.com/Cpp/W-D/docking/article.php/c1451 <span lang="EN-US" style="font-family:"Arial","sans-serif"
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 .
<span lang="EN-US" style="font-family:"Arial","sans-serif" 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.
<span style="font-family:"Arial","sans-serif" <br/>
Base Code will be ...
<div style="color:black; background-color:white
<pre><span style="color:blue int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
...
CString title(<span style="color:#a31515 "CoolBar Demo");
<span style="color:blue if (!m_wndDialogBar.Create(<span style="color:blue this, &m_cDialog,title, IDD_DIALOG1))
{
TRACE0(<span style="color:#a31515 "Failed to create dialogbarn");
<span style="color:blue return -1; <span style="color:green // fail to create
}
> m_wndDialogBar.SetBarStyle(m_wndDialogBar.GetBarStyle() |
> CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
...
}
[/code]
<br/>
<span style="text-decoration:underline ControlCreation is done in this sample by code:
<div style="color:black; background-color:white
<pre>BOOL CCoolDialogBar::Create(CWnd* pParentWnd, CDialog *pDialog, CString &pTitle, UINT nID, DWORD dwStyle)
{
ASSERT_VALID(pParentWnd); <span style="color:green // must have a parent
ASSERT (!((dwStyle & CBRS_SIZE_FIXED) && (dwStyle & CBRS_SIZE_DYNAMIC)));
<span style="color:green // save the style -- AMENDED by Holger Thiele - Thankyou
m_dwStyle = dwStyle & CBRS_ALL;
<span style="color:green // create the base window
CString wndclass = AfxRegisterWndClass(CS_DBLCLKS, LoadCursor(NULL, IDC_ARROW),
m_brushBkgd, 0);
<span style="color:blue if (!CWnd::Create(wndclass, pTitle, dwStyle, CRect(0,0,0,0),
pParentWnd, 0))
<span style="color:blue return FALSE;
<span style="color:green // create the child dialog
m_cDialog = pDialog;
m_cDialog->Create(nID, <span style="color:blue this);
<span style="color:green // 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;
<span style="color:blue return TRUE;
}
[/code]
<span style="text-decoration:underline The following code is the original code from my own large project:<br/>
(both code works well with VS2008 and earlier, but will not work after compiling with Visual Studio C++ 2010 SP1)
<div style="color:black; background-color:white
<pre>BOOL mfc_grafik_menu::Create( CMainFrame *pParent, <span style="color:blue const CRect &window_rect, BOOL dock_it )
{
UINT dockbar_id;
UINT floating_style;
ASSERT( pParent != NULL );
<span style="color:blue if( !CControlBar::Create( NULL, <span style="color:#a31515 "",
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | CBRS_SIZE_DYNAMIC, window_rect, pParent, 0<span style="color:green /*nID*/) )
<span style="color:blue return FALSE;
SetBarStyle( CBRS_ALIGN_TOP | CBRS_BORDER_3D | CBRS_SIZE_DYNAMIC );
WndOrgRect = window_rect;
pParent->ClientToScreen( WndOrgRect );
<span style="color:blue 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;
}
<span style="color:blue else
{
EnableDocking( CBRS_ALIGN_LEFT | CBRS_ALIGN_RIGHT );
dockbar_id = AFX_IDW_DOCKBAR_LEFT;
floating_style = CBRS_ALIGN_LEFT;
}
<span style="color:blue if( dock_it )
pParent->DockControlBar( <span style="color:blue this, dockbar_id, &WndOrgRect );
<span style="color:blue else
{
EnableDocking( 0 ); <span style="color:green // disable docking for grafik menus if they are not created docked
pParent->FloatControlBar( <span style="color:blue this, WndOrgRect.TopLeft(), floating_style );
}
<span style="color:blue return TRUE;
}
[/code]
<br/>
Just take the sample from Codeguru ( SourceCode: http://www.codeguru.com/code/legacy/docking/devstudio_like_controlbar_2_sample_src.zip Download demo project - 25KB ), load this old project from .dsw to VS2008 or VS2010
and compare the results.<br/>
Attn: In these old codeguru sample sources the only change, that is needed, is to change the signature of OnNcHitTest from
<span style="text-decoration:underline UINT to <span style="text-decoration:underline
LRESULT
<div style="color:black; background-color:white
<pre> change:
UINT CCoolDialogBar::OnNcHitTest(CPoint point)
to:
LRESULT CCoolDialogBar::OnNcHitTest(CPoint point)
[/code]
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.<br/>
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.<br/>
Thanks in advance.
Didi - dm01
<br/>
<br/>
View the full article