不选择MFC类,选择一般类,基类名可以手工填入

解决方案 »

  1.   

    to regit:
    能具体点吗?使用class wizard生成吗?
      

  2.   

    生成时随便选一个类,如CWnd。然后再把.h和.cpp的文件中的CWND替换成CDialogBar。我以前是这样做的,不知谁还有别的好办法?
      

  3.   

    HOWTO: Derive From Classes not Listed in ClassWizard 
    ID: Q99161 
    --------------------------------------------------------------------------------
    The information in this article applies to:The ClassWizard, included with:
    Microsoft Visual C++ for Windows, 16-bit edition, versions 1.0, 1.5, 1.51, 1.52 
    Microsoft Visual C++, 32-bit Editions, versions 1.0, 2.0, 2.1, 2.2, 4.0, 4.1, 4.2, 5.0, 6.0--------------------------------------------------------------------------------
    SUMMARY
    Microsoft ClassWizard supports deriving classes only from the classes listed in the Class Type field of the Add Class dialog box. To create a class derived from a previously derived class or to derive from another class based on the Microsoft Foundation Class Library CWnd class that is not listed in the Class Type field, a few extra steps are required. The text below presents these steps. MORE INFORMATION
    For example, suppose the following derivation tree is desired: 
       MyDerivedClass
             ^
             |
         MyBaseClass
             ^
             |
          CDialog 
    or, it is desirable to derive a class from a class based on CWnd that is not listed in the Class Type field in the Add Class dialog box, such as CFileDialog. There is no predefined method to create this type of class hierarchy using the ClassWizard. However, by using the parsing techniques ClassWizard uses, you can create these class hierarchies.The steps below use CDialog as the default class type. Before proceeding, determine which predefined class type is closest to the desired base class. For example, CFileDialog is similar to CDialog. If none of the classes correspond closely to your desired class, use the generic CWnd class.To create a class with multiple levels of derivation, perform the following three steps:
    Use ClassWizard to create MyDerivedClass, deriving it from CDialog (or another appropriate predefined class).
    Use ClassWizard to create MyBaseClass, deriving it from CDialog (or another appropriate predefined class).
    Edit the code generated for MyDerivedClass and replace all references to CDialog with MyBaseClass. This step is very important; many errors occur if this is not done correctly and these errors may be difficult to track down.
    To create a class based on a class based on CWnd that is not supported by ClassWizard, perform the following two steps:
    Use ClassWizard to create MyDerivedClass, deriving it from CDialog (or another appropriate predefined class based on CWnd).
    Edit the code generated for MyDerivedClass and replace all references to CDialog with the name of the class from which you are deriving this class, for example, CFileDialog. This step is very important; many errors occur if this is not done correctly and these errors may be difficult to track down.
    Then, for either type of class, perform the following three steps:
    Delete the project .CLW file.
    Start App Studio, load your project .RC file, and activate Class Wizard.
    Because the project does not have a .CLW file, ClassWizard prompts to generate a .CLW file. Choose Yes to generate the file. NOTE: You must generate this file in App Studio. If you attempt to generate the file in Visual Workbench, VWB instructs you to generate the file in App Studio.
    Once App Studio has created the .CLW file, the base class of the derived class has been changed successfully. To verify this, view the class in ClassWizard and see the data in the Class Info dialog box.For classes created using multiple levels of derivation, you can use ClassWizard to pass system messages, such as WM_INITDIALOG, to the base class as well. To do this, perform the following nine steps:
    Start ClassWizard.
    Select the MyDerivedClass class.
    Select MyDerivedClass in the Object IDs window.
    Select the WM_INITDIALOG message in the Messages window.
    Choose Add Function to add a function skeleton that calls the OnInitDialog() function in MyBaseClass.
    Select the MyBaseClass class.
    Select MyBaseClass in the Object IDs window.
    Select the WM_INITDIALOG message in the Messages window.
    Choose Add Function to add a function skeleton that calls the OnInitDialog() function in CDialog. This step is required only once. If you derive additional classes from the base class, you do not need to redo this operation.Additional query words: Keywords : kbwizard kbVC100 kbVC150 kbVC151 kbVC152 kbVC200 kbVC210 kbVC220 kbVC400 kbVC410 kbVC420 kbVC500 kbVC600 kbGrpDSTools 
    Version : WINDOWS: 1.0, 1.5, 1.51, 1.52; WINNT: 1.0, 2.0, 
    Platform : NT WINDOWS 
    Issue type : kbhowto 
    Technology : kbvc 
      

  4.   

    MORE INFORMATION
    To start out, create a CDialog class with the child controls you want to use. You can transform the CDialog class into a CDialogBar class using the following nine steps: Change the base class from CDialog to CDialogBar in the class declaration. Don't forget to also change the base class in BEGIN_MESSAGE_MAP in the .cpp file. 
    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. -->         if ( !HandleInitDialog(wParam, lParam) || !UpdateData(FALSE))
             {
                TRACE0("Warning: UpdateData failed during dialog init.\n");
                return FALSE;
             }
             ... 
    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;
          } 
      

  5.   

    先基于CDialog生成扩展类,在将CDialog改为CDialogbar,这样做的好处是支持Class Wizard,注意:CDialogBar不支持OnInitDialog,应去掉.
      

  6.   

    这么做,好象DDX,也不能用呀!!!
      

  7.   

    能自己添加到别的函数后吗?比如在Create()后面调用DoDataExchange(pdx)吗?我只是问问,其实不调用也没什么关系,呵呵。。
      

  8.   

    用wizzard生成一个基于CToolBarCtrl的对话条类,然后在生成的文件中把CToolBarCtrl替换成
    CDialogBar ,即可。试试吧,不麻烦。这样就能与类向导关联了。