一个CDockablePane模板类,使用FeaturePack里面的CDockablePane

fietiger 2010-09-03 12:50:39
一个模板类,使用FeaturePack里面的CDockablePane会简单一些。
使用方法,在MainFrame.h里面声明:
CDockableDialogPane<CXXXDialog> m_wndXXPane ;//其中CXXXDalog派生自CDialog。欢迎指正讨论!
然后就可以像其它的CDockablePane派生类一样用了。
template<class SomeDialog>
class CDockableDialogPane : public CDockablePane
{
DECLARE_DYNAMIC(CDockableDialogPane##SomeDig)
public:
void AdjustLayout(){
if (GetSafeHwnd() == NULL)
{
return;
}
CRect rectClient;
GetClientRect(rectClient);
m_wndDialog.SetWindowPos(NULL, rectClient.left + 1, rectClient.top + 1, rectClient.Width() - 2, rectClient.Height() - 2, SWP_NOACTIVATE | SWP_NOZORDER);
};
virtual BOOL IsResizable() const { return m_bIsResizable; }
virtual void SetResizeable(bool resizeable) { m_bIsResizable = resizeable; }
CDockableDialogPane(){ m_bIsResizable = TRUE;};
virtual ~CDockableDialogPane(){};
protected:
bool m_bIsResizable;
// CViewTree m_wndFileView;
SomeDialog m_wndDialog;
protected:
virtual const AFX_MSGMAP* GetMessageMap() const
{ return GetThisMessageMap(); } ;
static const AFX_MSGMAP* PASCAL GetThisMessageMap()
{
typedef CDockableDialogPane<SomeDialog> ThisClass;
typedef CDockablePane TheBaseClass;
static const AFX_MSGMAP_ENTRY _messageEntries[] =
{ ON_WM_CREATE()
ON_WM_SETFOCUS()
ON_WM_PAINT()
ON_WM_SIZE()
{0, 0, 0, 0, AfxSig_end, (AFX_PMSG)0 }
};
static const AFX_MSGMAP messageMap =
{ &TheBaseClass::GetThisMessageMap, &_messageEntries[0] };
return &messageMap;
};
public:
virtual afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDockablePane::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
CRect rectDummy;
rectDummy.SetRectEmpty();
// 创建视图:
const DWORD dwViewStyle = WS_CHILD | WS_VISIBLE | TVS_HASLINES | TVS_LINESATROOT | TVS_HASBUTTONS;
// if (!m_wndFileView.Create(dwViewStyle, rectDummy, this, 4))
// {
// TRACE0("未能创建文件视图\n");
// return -1; // 未能创建
// }
if (!m_wndDialog.Create(SomeDialog::IDD, this))
{
TRACE("未能创建文件视图\n");
return -1; // 未能创建
}
return 0;
};
virtual afx_msg void OnSetFocus(CWnd* pOldWnd)
{
CDockablePane::OnSetFocus(pOldWnd);
// m_wndFileView.SetFocus();
m_wndDialog.SetFocus();
// TODO: Add your message handler code here
};
virtual afx_msg void OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
// Do not call CDockablePane::OnPaint() for painting messages
CRect rectTree;
// m_wndFileView.GetWindowRect(rectTree);
m_wndDialog.GetWindowRect(rectTree);
ScreenToClient(rectTree);
rectTree.InflateRect(1, 1);
dc.Draw3dRect(rectTree, ::GetSysColor(COLOR_3DSHADOW), ::GetSysColor(COLOR_3DSHADOW));
};
virtual afx_msg void OnSize(UINT nType, int cx, int cy)
{
if (!m_bIsResizable)
{
return ;
}
CDockablePane::OnSize(nType, 300, 180);
// TODO: Add your message handler code here
AdjustLayout();
m_wndDialog.SendMessage(WM_SIZE,0,0);
//m_bIsResizable = FALSE;
};
};
...全文
65 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Eleven 2010-09-29
  • 打赏
  • 举报
回复
分享帖?
向立天 2010-09-29
  • 打赏
  • 举报
回复
您好
我是本版版主
此帖已多日无人关注
请您及时结帖
如您认为问题没有解决可按无满意结帖处理
另外本版设置了疑难问题汇总帖
并已在版面置顶
相关规定其帖子中有说明
您可以根据规定提交您帖子的链接
如您目前不想结帖只需回帖说明
我们会删除此结帖通知

见此回复三日内无回应
我们将强制结帖
相关规定详见界面界面版关于版主结帖工作的具体办法
悟迟 2010-09-03
  • 打赏
  • 举报
回复
学习了,

15,979

社区成员

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

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