文档视图结构的工程
在视图左侧添加一个CDialogBar的控制面板
用来控制视图中的图形这个CDialogBar是这样添加的
MainFrm.h中:
//DialogBar变量
CDialogBar m_myDialogBarLeft;MainFrm.cpp的CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)中:
//生成DialogBar
m_myDialogBarLeft.Create(this,IDD_DIALOG_CONRTOL_PANEL,
CBRS_LEFT,IDD_DIALOG_CONRTOL_PANEL);但是发现在ID为IDD_DIALOG_CONRTOL_PANEL的CDialogBar对话框上添加控件后,控件是无响应的
比如说添加一个按钮,按钮是灰色的特别是我想在IDD_DIALOG_CONRTOL_PANEL的对话框上使用属性页控件,我是这样做的:
IDD_DIALOG_CONRTOL_PANEL的对话框生成一个对话框类CDlgControlPanel
打算在这个类中处理属性页控件以及上面的3个页(由3个对话框组成)
但是程序调试时,发现根本没有经过
BOOL CDlgControlPanel::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_sheet.AddPage("tab1", &m_PagePart, IDD_DIALOG_PART);
m_sheet.AddPage("tab2", &m_PageRoomEnterAuto, IDD_DIALOG_ROOM_ENTER_AUTO);
m_sheet.AddPage("tab3", &m_PageRoomEnterArtificially, IDD_DIALOG_ROOM_ENTER_ARTIFICIALLY);
m_sheet.Show();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}因此属性页也就没有生成请问怎样处理呢
谢谢
在视图左侧添加一个CDialogBar的控制面板
用来控制视图中的图形这个CDialogBar是这样添加的
MainFrm.h中:
//DialogBar变量
CDialogBar m_myDialogBarLeft;MainFrm.cpp的CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)中:
//生成DialogBar
m_myDialogBarLeft.Create(this,IDD_DIALOG_CONRTOL_PANEL,
CBRS_LEFT,IDD_DIALOG_CONRTOL_PANEL);但是发现在ID为IDD_DIALOG_CONRTOL_PANEL的CDialogBar对话框上添加控件后,控件是无响应的
比如说添加一个按钮,按钮是灰色的特别是我想在IDD_DIALOG_CONRTOL_PANEL的对话框上使用属性页控件,我是这样做的:
IDD_DIALOG_CONRTOL_PANEL的对话框生成一个对话框类CDlgControlPanel
打算在这个类中处理属性页控件以及上面的3个页(由3个对话框组成)
但是程序调试时,发现根本没有经过
BOOL CDlgControlPanel::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_sheet.AddPage("tab1", &m_PagePart, IDD_DIALOG_PART);
m_sheet.AddPage("tab2", &m_PageRoomEnterAuto, IDD_DIALOG_ROOM_ENTER_AUTO);
m_sheet.AddPage("tab3", &m_PageRoomEnterArtificially, IDD_DIALOG_ROOM_ENTER_ARTIFICIALLY);
m_sheet.Show();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}因此属性页也就没有生成请问怎样处理呢
谢谢
Change the constructor in both the .h and the .cpp files. Also make the change to the DoDataExchange(). Below are three items to change. Change the following from
CMyDlgBar (CWnd* pParent = NULL); // standard constructor CMyDlgBar:: CMyDlgBar (CWnd* pParent /*=NULL*/)
: CDialog(CMyDlgBar::IDD, pParent)
{
... void CMyDlgBar::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
...
to the following:
CMyDlgBar (); // standard constructor CMyDlgBar:: CMyDlgBar ()
{
... void CMyDlgBar::DoDataExchange(CDataExchange* pDX)
{
CDialogBar::DoDataExchange(pDX);
...
The key to the transformation is the conversion of the virtual OnInitDialog() member function to the WM_INITDIALOG message mapped method by changing the OnInitDialog method and by adding the ON_MESSAGE() handler. You may not have an override of OnInitDialog(). If not, add one before proceeding.
Remove "virtual BOOL OnInitDialog();" from the class header and add "afx_msg LONG OnInitDialog ( UINT, LONG );" in its place. For example:
class CMyDlgBar : public CDialogBar
{
...
// Implementation
protected: // Generated message map functions
//{{AFX_MSG(CMyDlgBar)
virtual BOOL OnInitDialog(); // <-Remove this line.
//}}AFX_MSG afx_msg LONG OnInitDialog ( UINT, LONG ); // <-Add this line.
DECLARE_MESSAGE_MAP()
};
Now, in the class implementation section, make the corresponding changes.
Add "ON_MESSAGE(WM_INITDIALOG, OnInitDialog );" to the message map in the .CPP implementation file. For example:
BEGIN_MESSAGE_MAP(CMyDlgBar, CDialogBar) //{{AFX_MSG_MAP(CMyDlgBar)
...
//}}AFX_MSG_MAP
ON_MESSAGE(WM_INITDIALOG, OnInitDialog ) // <-- Add this line.
END_MESSAGE_MAP()
Now, convert the virtual OnInitDialog() to the message-mapped OnInitDialog().
Make the OnInitDialog() conversion as follows:
Change the following: BOOL CMyDlgBar::OnInitDialog()
{
CDialog::OnInitDialog(); // <-- Replace this line:
...
to the following:
LONG CMyDlgBar::OnInitDialog ( UINT wParam, LONG lParam)
{
// <-- with these lines. --> BOOL bRet = HandleInitDialog(wParam, lParam); if (!UpdateData(FALSE))
{
TRACE0("Warning: UpdateData failed during dialog init.\n");
}
... return bRet;
The CDialogBar class doesn't have a virtual OnInitDialog(), and therefore calling one does not work. UpdateData is called to subclass or initialize any child controls.
Make sure the dialog box resource styles to the following:
Style: Child
Boarder: None
Visible: Unchecked
At this point, everything has been reconnected to make the transformation from a CDialog class to a CDialogBar class work correctly. Now, create and use it.
Add an instance of the derived CDialogBar to the CframeWnd-derived class (normally called CMainFrame). For example:
class CMainFrame : public CFrameWnd
{
...
CMyDlgBar m_myDlgBar;
...
};
Call the create method for the m_myDlgBar variable in the CFrameWnd::OnCreate() method similar to the following:
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
...
if (!m_myDlgBar.Create(this, IDD_DLGBAR1, CBRS_LEFT,
IDD_DLGBAR1))
{
TRACE0("Failed to create dialog bar\n");
return -1; // fail to create
}
...
}
Finally, if you want to support dynamic docking and resizing of the CDialogBar, add the following lines to the end of CMainFrame::OnCreate():
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
...
m_myDlgBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
m_myDlgBar.EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_myDlgBar); return 0;
}