VS2008中不能用CDialogBar,我试了好久也没弄出来,从网上查得是
class CMainFrame : public CMDIFrameWndEx父类的原因
以前VC6.0是class CMainFrame : public CFrameWnd
//
要显示的对话框和CDockablePane的派生类的头文件/
#pragma once
// CTopDlgBar 对话框
class CTopDlgBar : public CDialog
{
DECLARE_DYNAMIC(CTopDlgBar)
public:
CTopDlgBar(CWnd* pParent = NULL); // 标准构造函数
virtual ~CTopDlgBar();
// 对话框数据
enum { IDD = IDD_DIALOGBAR_TOP };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
DECLARE_MESSAGE_MAP()
public:
void OnLButtonDownOk();
};
//
//CMFCDialogBar
class CMFCDialogBar: public CDockablePane
{
public:
CMFCDialogBar();
virtual ~CMFCDialogBar();
CTopDlgBar m_dialog;
protected:
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnSize(UINT nType, int cx, int cy);
DECLARE_MESSAGE_MAP()
};
//
要显示的对话框和CDockablePane的派生类的源文件/
// TopDlgBar2.cpp : 实现文件
//
#include "stdafx.h"
#include "DBar.h"
#include "TopDlgBar.h"
// CTopDlgBar 对话框
IMPLEMENT_DYNAMIC(CTopDlgBar, CDialog)
CTopDlgBar::CTopDlgBar(CWnd* pParent /*=NULL*/)
: CDialog(CTopDlgBar::IDD, pParent)
{
}
CTopDlgBar::~CTopDlgBar()
{
}
void CTopDlgBar::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CTopDlgBar, CDialog)
ON_BN_CLICKED(IDOK, &CTopDlgBar::OnLButtonDownOk)
END_MESSAGE_MAP()
// CTopDlgBar 消息处理程序
void CTopDlgBar::OnLButtonDownOk()
{
MessageBox(_T("点下了按钮"));
}
//
//CMFCDialogBar
BEGIN_MESSAGE_MAP(CMFCDialogBar, CDockablePane)
ON_WM_CREATE()
ON_WM_SIZE()
END_MESSAGE_MAP()
CMFCDialogBar::CMFCDialogBar()
{
}
CMFCDialogBar::~CMFCDialogBar()
{
}
int CMFCDialogBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDockablePane::OnCreate(lpCreateStruct) == -1)
return -1;
CRect rectDummy;
rectDummy.SetRectEmpty();
// 创建选项卡窗口:
if (!m_dialog.Create(IDD_DIALOGBAR_TOP,this))
{
TRACE0("未能创建输出选项卡窗口/n");
return -1; // 未能创建
}
m_dialog.ShowWindow(SW_SHOW);
return 0;
}
void CMFCDialogBar::OnSize(UINT nType, int cx, int cy)
{
CDockablePane::OnSize(nType, cx, cy);
// 选项卡控件应覆盖整个工作区:
m_dialog.SetWindowPos (this, -1, -1, cx, cy, SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
m_dialog.ShowWindow(SW_SHOW);
}
/MainFrm.h//
#include "TopDlgBar.h"
class CMainFrame : public CMDIFrameWndEx
{
....
CMFCDialogBar m_DialogBar; // 定义自己写的那个类的变量
....
}
/
/MainFrm.cpp/
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (!m_DialogBar.Create(_T("修改"), this, CRect(0, 0, 100, 100),
TRUE, IDD_DIALOGBAR_TOP, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_RIGHT | CBRS_FLOAT_MULTI))
{
TRACE0("未能创建输出窗口/n");
return FALSE; // 未能创建
}
m_DialogBar.EnableDocking(CBRS_ALIGN_ANY);
DockPane(&m_DialogBar); // 调整m_DialogBar的大小使之适合父窗口
}