MFC Feature Pack for Visual C++ 2008的BUG之一
2009-08-27 09:24
441 查看
CMFCTabCtrl::EnableActiveTabCloseButton
用于在CMFCTabCtrl的Tab页显示一个关闭按钮,看看关闭按钮怎么实现:
void
CMFCBaseTabCtrl::OnLButtonDown(UINT nFlags, CPoint point)
{
m_bWindowPosChanged = FALSE;
CWnd::OnLButtonDown(nFlags, point);
if
(m_rectCloseButton.PtInRect(point))
{
m_bTabCloseButtonPressed = TRUE;
RedrawWindow(m_rectCloseButton);
return
;
}
...
void
CMFCBaseTabCtrl::OnLButtonUp(UINT nFlags, CPoint point)
{
if
(m_bTabCloseButtonPressed)
{
m_bTabCloseButtonPressed = FALSE;
m_bTabCloseButtonHighlighted = FALSE;
RedrawWindow(m_rectCloseButton);
if
(m_rectCloseButton.PtInRect(point))
{
CWnd* pWndActive = GetActiveWnd();
if
(pWndActive != NULL)
{
pWndActive->SendMessage(WM_CLOSE);
}
return
;
}
}
...
应该就这些了。
在例子TabbedView中添加这个功能:
int
CTabbedViewView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if
(CTabView::OnCreate(lpCreateStruct) == -1)
return
-1;
AddView (RUNTIME_CLASS (CView1), _T(
"Simple"
), 100);
AddView (RUNTIME_CLASS (CView2), _T(
"List"
), 101);
AddView (RUNTIME_CLASS (CView3), _T(
"Form"
), 102);
AddView (RUNTIME_CLASS (CView4), _T(
"ScrollView"
), 102);
m_wndTabs.EnableActiveTabCloseButton();
return
0;
}
然后点击一个页面上的关闭按钮,会发现这个tab页并没有消失,而切换到其他页面,程序就中断了,问题出在:
BOOL
CMFCTabCtrl::SetActiveTab(
int
iTab)
{
...
if
(m_iActiveTab != -1 && m_bHideInactiveWnd)
{
//--------------------
// Hide active window:
//--------------------
CWnd* pWndActive = GetActiveWnd();
if
(pWndActive != NULL)
{
pWndActive->ShowWindow(SW_HIDE);
}
}
由于窗口已经销毁,而该Tab页仍然存在,所以m_iActiveTab就是被销毁的窗口所在页面,pWndActive是已经被销毁的窗口,自然调用其ShowWindow方法就出错了。
用于在CMFCTabCtrl的Tab页显示一个关闭按钮,看看关闭按钮怎么实现:
void
CMFCBaseTabCtrl::OnLButtonDown(UINT nFlags, CPoint point)
{
m_bWindowPosChanged = FALSE;
CWnd::OnLButtonDown(nFlags, point);
if
(m_rectCloseButton.PtInRect(point))
{
m_bTabCloseButtonPressed = TRUE;
RedrawWindow(m_rectCloseButton);
return
;
}
...
void
CMFCBaseTabCtrl::OnLButtonUp(UINT nFlags, CPoint point)
{
if
(m_bTabCloseButtonPressed)
{
m_bTabCloseButtonPressed = FALSE;
m_bTabCloseButtonHighlighted = FALSE;
RedrawWindow(m_rectCloseButton);
if
(m_rectCloseButton.PtInRect(point))
{
CWnd* pWndActive = GetActiveWnd();
if
(pWndActive != NULL)
{
pWndActive->SendMessage(WM_CLOSE);
}
return
;
}
}
...
应该就这些了。
在例子TabbedView中添加这个功能:
int
CTabbedViewView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if
(CTabView::OnCreate(lpCreateStruct) == -1)
return
-1;
AddView (RUNTIME_CLASS (CView1), _T(
"Simple"
), 100);
AddView (RUNTIME_CLASS (CView2), _T(
"List"
), 101);
AddView (RUNTIME_CLASS (CView3), _T(
"Form"
), 102);
AddView (RUNTIME_CLASS (CView4), _T(
"ScrollView"
), 102);
m_wndTabs.EnableActiveTabCloseButton();
return
0;
}
然后点击一个页面上的关闭按钮,会发现这个tab页并没有消失,而切换到其他页面,程序就中断了,问题出在:
BOOL
CMFCTabCtrl::SetActiveTab(
int
iTab)
{
...
if
(m_iActiveTab != -1 && m_bHideInactiveWnd)
{
//--------------------
// Hide active window:
//--------------------
CWnd* pWndActive = GetActiveWnd();
if
(pWndActive != NULL)
{
pWndActive->ShowWindow(SW_HIDE);
}
}
由于窗口已经销毁,而该Tab页仍然存在,所以m_iActiveTab就是被销毁的窗口所在页面,pWndActive是已经被销毁的窗口,自然调用其ShowWindow方法就出错了。
相关文章推荐
- MFC Feature Pack for Visual C++ 2008的BUG之一
- Automating Excel 2007 and creating charts using C++ MFC application in Visual Studio 2008
- 在windows下使用 Visual Leak Detector for Visual C++ 2008的安装和配置
- 在windows下使用 Visual Leak Detector for Visual C++ 2008的安装和配置
- 使用Visual Leak Detector for Visual C++ 2008/2010輔助偵測程式中記憶體洩漏的問題
- 内存泄露检测工具 Visual Leak Detector for Visual C++ 2008/2010
- 在windows下使用 Visual Leak Detector for Visual C++ 2008的安装和配置
- 内存泄露检测工具 Visual Leak Detector for Visual C++ 2008/2010
- (搬运工)内存泄露检测工具 Visual Leak Detector for Visual C++ 2008/2010
- Visual Leak Detector for Visual C++ 2008/2010/2012
- Visual Leak Detector for Visual C++ 2008/2010/2012
- Major update for MFC in Visual Studio 2008
- "getline" bug fix for Microsoft Visual C++ 6.0 关于VC6的getline输入需要两个回车才结束的BUG修改方法
- vc2008中MFC重大变革-Visual C++ 2008 Feature Pack Beta 发布
- Visual Leak Detector for Visual C++ 2008/2010/2012
- 内存泄露检测工具 Visual Leak Detector for Visual C++ 2008/2010
- Creating a PHP Extension for Windows using Microsoft Visual C++ 2008
- MSDN Library for Visual Studio 2008 下载地址
- MSDN library for Visual Studio 2008 SP1已经提供下载
- 理解 Visual C++ Extensions for ADO