请求解决有关CControlBar的使用问题

wlzhjp 2002-11-26 01:05:37
我用CControlBar自定义一个可停靠的栏,且在此栏中,用CView视作为数据显示,
在平时工作时,可正常工作,但双击将此停靠栏转为浮动栏时,点击其上有关闭
按钮,程序即进入死状态,任何消息都不响应了,不知道怎样解决此问题。
特向各位老师请教,谢谢!
现将有关文件列于下面:
这些文件大多是从书上抄的,但将书上原程序运行时,也存在这样的问题。
//MyCtrl.H
class CMyCtrl : public CControlBar
{
DECLARE_DYNAMIC(CMyCtrl)
public:
CMyCtrl();
protected:
CSize m_sizeMin;
CSize m_sizeHorz;
CSize m_sizeVert;
CSize m_sizeFloat;
public:
//{{AFX_VIRTUAL(CMyCtrl)
public:
virtual void OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHndler);
virtual BOOL Create(CWnd* pParentWnd, UINT nID, LPCTSTR lpszWindowName = NULL, DWORD dwStyle = WS_CHILD|WS_VISIBLE|CBRS_TOP);
virtual CSize CalcFixedLayout( BOOL bStretch, BOOL bHorz );
virtual CSize CalcDynamicLayout( int nLength, DWORD dwMode );
//}}AFX_VIRTUAL

public:
virtual ~CMyCtrl();

protected:
//{{AFX_MSG(CMyCtrl)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
///////////////////////////////////////////////////////////////
// MyCtrl.cpp : implementation file
#include "stdafx.h"
#include "MyCtrl.h"
#include <afxpriv.h>

CMyCtrl::CMyCtrl()
{
m_sizeMin= CSize(200, 200);
m_sizeHorz= CSize(200, 200);
m_sizeVert= CSize(200, 200);
m_sizeFloat= CSize(200, 200);
}

CMyCtrl::~CMyCtrl()
{
}

IMPLEMENT_DYNAMIC(CMyCtrl, CControlBar)

BEGIN_MESSAGE_MAP(CMyCtrl, CControlBar)
//{{AFX_MSG_MAP(CMyCtrl)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

//////////////////////////////////////////////////////////////////////////
void CMyCtrl::OnUpdateCmdUI(CFrameWnd * pTarget, BOOL bDisableIfNoHndler)
{
UpdateDialogControls(pTarget, bDisableIfNoHndler);
}

BOOL CMyCtrl::Create(CWnd * pParentWnd, UINT nID, LPCTSTR lpszWindowName,DWORD dwStyle)
{
。。。。。。
}

CSize CMyCtrl::CalcFixedLayout(BOOL bStretch, BOOL bHorz)
{
因贴子太长省略
。。。。。。
}
CSize CMyCtrl::CalcDynamicLayout(int nLength, DWORD dwMode)
{
因贴子太长省略
。。。。。
}
/////////////////////////////////////////////////////////////////////////////
// TstCtrl.h : header file
// CTstCtrl window
#include <afxtempl.h>
#include "MyCtrl.h"

class CTstCtrl : public CMyCtrl
{
// Construction
public:
CTstCtrl();
// Attributes
public:
CView *m_view;
// Operations
public:

// Overrides
//{{AFX_VIRTUAL(CTstCtrl)
//}}AFX_VIRTUAL

// Implementation
public:
virtual ~CTstCtrl();
BOOL AddView(LPCTSTR lpszLabel, CRuntimeClass *pViewClass, CCreateContext *pContext = NULL);

protected:
//{{AFX_MSG(CTstCtrl)
afx_msg void OnWindowPosChanged(WINDOWPOS FAR* lpwndpos);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//////////////////////////////////////////////////////////////////
// TstCtrl.cpp : implementation file
#include "stdafx.h"
#include "TST.h"
#include "TstCtrl.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

CTstCtrl::CTstCtrl()
{
}

CTstCtrl::~CTstCtrl()
{
}

BEGIN_MESSAGE_MAP(CTstCtrl, CMyCtrl)
//{{AFX_MSG_MAP(CTstCtrl)
ON_WM_WINDOWPOSCHANGED()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

BOOL CTstCtrl::AddView(LPCTSTR lpszLabel, CRuntimeClass *pViewClass, CCreateContext *pContext)
{

#ifdef _DEBUG
ASSERT_VALID(this);
ASSERT(pViewClass != NULL);
ASSERT(pViewClass->IsDerivedFrom(RUNTIME_CLASS(CWnd)));
ASSERT(AfxIsValidAddress(pViewClass, sizeof(CRuntimeClass), FALSE));
#endif

CCreateContext context;
if (pContext == NULL)
{
CView* pOldView = NULL;
if (pOldView != NULL && pOldView->IsKindOf(RUNTIME_CLASS(CView)))
{
// set info about last pane
ASSERT(context.m_pCurrentFrame == NULL);
context.m_pLastView = pOldView;
context.m_pCurrentDoc = pOldView->GetDocument();
if (context.m_pCurrentDoc != NULL)
context.m_pNewDocTemplate =
context.m_pCurrentDoc->GetDocTemplate();
}
pContext = &context;
}

CWnd* pWnd;
TRY
{
pWnd = (CWnd*)pViewClass->CreateObject();
if (pWnd == NULL)
AfxThrowMemoryException();
}
CATCH_ALL(e)
{ 。。。。
return FALSE;
}
END_CATCH_ALL

ASSERT_KINDOF(CWnd, pWnd);
ASSERT(pWnd->m_hWnd == NULL); // not yet created
DWORD dwStyle = AFX_WS_DEFAULT_VIEW;
CRect rect;
// Create with the right size and position
if (!pWnd->Create(NULL, NULL, dwStyle, rect, this, 0))
{
。。。。
return FALSE;
}
m_view = (CView*) pWnd;

((CFrameWnd *)GetParent())->SetActiveView((CView *)m_view);
return TRUE;
}


void CTstCtrl::OnWindowPosChanged(WINDOWPOS FAR* lpwndpos)
{
。。。。。。
CMyCtrl::OnWindowPosChanged(lpwndpos);
}

///////////////////////////////////////////////////////////
// TstView.h : header file
class CTstView : public CView
{
protected:
CTstView();
DECLARE_DYNCREATE(CTstView)
// Attributes
public:
CDocument *GetMyActiveDocument();
// Operations
public:

//{{AFX_VIRTUAL(CTstView)
protected:
virtual void OnDraw(CDC* pDC);
//}}AFX_VIRTUAL

// Implementation
protected:
virtual ~CTstView();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif

protected:
//{{AFX_MSG(CTstView)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
////////////////////////////////////////////////////
// TstView.cpp : implementation file
#include "stdafx.h"
#include "Tst.h"
#include "TstView.h"
#include "TstDoc.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTstView

IMPLEMENT_DYNCREATE(CTstView, CView)

CTstView::CTstView()
{
}

CTstView::~CTstView()
{
}


BEGIN_MESSAGE_MAP(CTstView, CView)
//{{AFX_MSG_MAP(CTstView)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTstView drawing

void CTstView::OnDraw(CDC* pDC)
{
CTstDoc* pDoc =(CTstDoc *)GetMyActiveDocument();
pDC->TextOut(10,20,"My Test");
}
CDocument* CTstView::GetMyActiveDocument()
{
。。。。。。
}
///////////////////////////////////////////////////////////////////
在下面的MainFrm文件中,只有在OnCreate和对ID_VIEW_CTRL的响应中对
CTstCtrl 类作了操作。
///////////////////////////////////////////////////////////////////
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
。。。。
//////////////////////////////////////////////////////////
// m_myctrl 在H文件中定义为 CTstCtrl 类
if (!m_myctrl.Create(this, ID_VIEW_CTRL,_T("MYCTRL")))
{
TRACE0("Failed to create dialog bar m_wndWorkspace\n");
return -1; // fail to create
}

m_myctrl.AddView("MYCTRL1",RUNTIME_CLASS(CTstView));
m_myctrl.SetBarStyle(m_myctrl.GetBarStyle() |
CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);

m_myctrl.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_myctrl, AFX_IDW_DOCKBAR_RIGHT);

return 0;
}
///////////////////////////////////////////////////////////////////
再次谢谢!
2002.11.26

...全文
141 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
wlzhjp 2002-12-03
  • 打赏
  • 举报
回复
robothn先生:
谢谢您的回复.但我按您的提示做了一遍,问题仍然一样。
我在使用这个控件时,如果不加入视图使用一个白控件,就不存在这样的问题,
因此我想应该不是CTstCtrl自定义控件类的问题,而是CView类的问题.可是不
知道这个类的问题究竟在哪里!
再次谢谢您的帮助。
robothn 2002-11-29
  • 打赏
  • 举报
回复
//.h
afx_msg UINT OnNcHitTest(CPoint point);

//.cpp
BEGIN_MESSAGE_MAP(CMyCtrl, CControlBar)
//{{AFX_MSG_MAP(zSkinDialog)
ON_WM_NCHITTEST()// this line
...
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

UINT zSkinDialog::OnNcHitTest(CPoint point)
{
UINT uResult = CControlBar::OnNcHitTest(point);
if(uResult == HTCLOSE)
uResult = HTCAPTION;
return uResult;
}
//大概这样就行了吧

====
wlzhjp 2002-11-26
  • 打赏
  • 举报
回复
up
wlzhjp 2002-11-26
  • 打赏
  • 举报
回复
ruihuahan先生:
这个关闭按钮是系统创建的,请问如何封掉。
谢谢。
ruihuahan 2002-11-26
  • 打赏
  • 举报
回复
封掉它的关闭按钮。
zhaolaoxin 2002-11-26
  • 打赏
  • 举报
回复
up

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧