我写了个对话框类  CAdlg 是从一个公用的对话框ccommdlg继承的
  这个ccommdlg是从CDialog继承过来的
请问,窗口响应函数,如何不经过CAdlg 而是直接让ccommdlg中的函数进行相应

解决方案 »

  1.   

    ccommdlg::窗口响应函数名
    比如你重载IDOK按钮的响应函数(在资源编辑处双击"确定"按钮产生)
    其实他就是直接调用ccommslg的响应函数void CAdlg::OnOK()
    {
        ccommslg::OnOK();
    }
      

  2.   

    请问,窗口响应函数,如何不经过CAdlg 而是直接让ccommdlg中的函数进行相应
    ==========
    在CAdlg中转发就行了,比如处理WM_LBUTTONDOWN消息,还是让CADlg处理WM_LBUTTONDOWN消息,不过直接调用commslg::LButton..();就行了.
      

  3.   

    你说的是这个意思吗?例如下面的
    //CNewDlg类 ,处理WM_LBUTTONDOWN消息// CNewDlg的H文件
    class CNewDlg : public CDialog
    {
    // Construction
    public:
    CNewDlg(CWnd* pParent = NULL);   // standard constructor// Dialog Data
    //{{AFX_DATA(CNewDlg)
    enum { IDD = IDD_DIALOG1 };
    // NOTE: the ClassWizard will add data members here
    //}}AFX_DATA
    // Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CNewDlg)
    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    //}}AFX_VIRTUAL// Implementation
    protected: // Generated message map functions
    //{{AFX_MSG(CNewDlg)
    afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    };
    // CNewDlg的CPP文件
    CNewDlg::CNewDlg(CWnd* pParent /*=NULL*/)
    : CDialog(CNewDlg::IDD, pParent)
    {
    //{{AFX_DATA_INIT(CNewDlg)
    // NOTE: the ClassWizard will add member initialization here
    //}}AFX_DATA_INIT
    }
    void CNewDlg::DoDataExchange(CDataExchange* pDX)
    {
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CNewDlg)
    // NOTE: the ClassWizard will add DDX and DDV calls here
    //}}AFX_DATA_MAP
    }
    BEGIN_MESSAGE_MAP(CNewDlg, CDialog)
    //{{AFX_MSG_MAP(CNewDlg)
    ON_WM_LBUTTONDOWN()
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CNewDlg message handlersvoid CNewDlg::OnLButtonDown(UINT nFlags, CPoint point) 
    {
    // TODO: Add your message handler code here and/or call default
    AfxMessageBox(_T("Hello"));
    CDialog::OnLButtonDown(nFlags, point);
    }
    ------------------------------------------------------------------
    // CNewDlg2继承了CNewDlg类
    #include "NewDlg.h"// CNewDlg2的H文件
    class CNewDlg2 : public CNewDlg
    {
    // Construction
    public:
    CNewDlg2(CWnd* pParent = NULL);   // standard constructor// Dialog Data
    //{{AFX_DATA(CNewDlg2)
    enum { IDD = IDD_DIALOG1 };
    // NOTE: the ClassWizard will add data members here
    //}}AFX_DATA
    // Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CNewDlg2)
    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    //}}AFX_VIRTUAL// Implementation
    protected: // Generated message map functions
    //{{AFX_MSG(CNewDlg2)
    // NOTE: the ClassWizard will add member functions here
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    };// CNewDlg2的CPP文件CNewDlg2::CNewDlg2(CWnd* pParent /*=NULL*/)
    : CNewDlg(pParent)
    {
    //{{AFX_DATA_INIT(CNewDlg2)
    // NOTE: the ClassWizard will add member initialization here
    //}}AFX_DATA_INIT
    }
    void CNewDlg2::DoDataExchange(CDataExchange* pDX)
    {
    CNewDlg::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CNewDlg2)
    // NOTE: the ClassWizard will add DDX and DDV calls here
    //}}AFX_DATA_MAP
    }
    BEGIN_MESSAGE_MAP(CNewDlg2, CNewDlg)
    //{{AFX_MSG_MAP(CNewDlg2)
    // NOTE: the ClassWizard will add message map macros here
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CNewDlg2 message handlers
    --------------------------------------------------------------------------------
    //调用:
    CNewDlg2 dlg;
    dlg.DoModal();
      

  4.   

    你想要的恐怕不能实现。根据继承的概念,假设你对ccommdlg添加了消息WM_LBUTTONDOWN,那么它的子类CAdlg也同样会继承该消息。因此你说的让父类的消息子类不响应应该不行。不知道我的理解对不对,请高手继续解答!
      

  5.   

    试了一下部长的代码,好像弹出来的并不是子类对话框,而是CNewDlg类
      

  6.   


    我理解你的意思,应该是说:
    如何让子类不继承父类的某些东西
    比如对某些消息的响应那么你还是要在子类重新写这些函数
    比如以2楼为例:
    void CAdlg::OnOK()
    {
    }
    这样一来,子类对IDOK就相当于不响应了.
    又比如8楼的
    void CNewDlg::OnLButtonDown(UINT nFlags, CPoint point) 
    {
       //CDialog::OnLButtonDown(nFlags, point);
    }
    把向父类传递的代码注释掉,子类就等同于不响应数标左键了这样是你想要的结果吗?
      

  7.   

    因为子类中的ID和父类的一样
    这样应该就可以了吧
    CNewDlg2* dlg = new CNewDlg2;
    dlg->Create(IDD_DIALOG2, this);
    dlg->ShowWindow(SW_SHOW);
      

  8.   

    或者这样,你修改分别修改CNewDlg和CNewDlg2的构造函数
    -------------------------------------------------
    class CNewDlg : public CDialog
    {
    // Construction
    public:
    CNewDlg(UINT nID, CWnd* pParent = NULL);   // standard constructor// Dialog Data
    //{{AFX_DATA(CNewDlg)
    // enum { IDD = IDD_DIALOG1 };
    // NOTE: the ClassWizard will add data members here
    //}}AFX_DATA
    // Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CNewDlg)
    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    //}}AFX_VIRTUAL// Implementation
    protected: // Generated message map functions
    //{{AFX_MSG(CNewDlg)
    afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    };
    ---------------------------------------------------------------CNewDlg::CNewDlg(UINT nID, CWnd* pParent /*=NULL*/)
    : CDialog(nID, pParent)
    {
    //{{AFX_DATA_INIT(CNewDlg)
    // NOTE: the ClassWizard will add member initialization here
    //}}AFX_DATA_INIT
    }
    void CNewDlg::DoDataExchange(CDataExchange* pDX)
    {
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CNewDlg)
    // NOTE: the ClassWizard will add DDX and DDV calls here
    //}}AFX_DATA_MAP
    }
    BEGIN_MESSAGE_MAP(CNewDlg, CDialog)
    //{{AFX_MSG_MAP(CNewDlg)
    ON_WM_LBUTTONDOWN()
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CNewDlg message handlersvoid CNewDlg::OnLButtonDown(UINT nFlags, CPoint point) 
    {
    // TODO: Add your message handler code here and/or call default
    AfxMessageBox(_T("new1"));
    CDialog::OnLButtonDown(nFlags, point);
    }
    --------------------------------------------------------------------
    ----------------------------------------------------------------------
    #include "NewDlg.h"class CNewDlg2 : public CNewDlg
    {
    // Construction
    public:
    CNewDlg2(CWnd* pParent = NULL);   // standard constructor// Dialog Data
    //{{AFX_DATA(CNewDlg2)
    enum { IDD = IDD_DIALOG2 };
    // NOTE: the ClassWizard will add data members here
    //}}AFX_DATA
    // Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CNewDlg2)
    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    //}}AFX_VIRTUAL// Implementation
    protected: // Generated message map functions
    //{{AFX_MSG(CNewDlg2)
    // NOTE: the ClassWizard will add member functions here
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    };
    ------------------------------------------------------------------------
    CNewDlg2::CNewDlg2(CWnd* pParent /*=NULL*/)
    : CNewDlg(CNewDlg2::IDD,pParent)
    {
    //{{AFX_DATA_INIT(CNewDlg2)
    // NOTE: the ClassWizard will add member initialization here
    //}}AFX_DATA_INIT
    }
    void CNewDlg2::DoDataExchange(CDataExchange* pDX)
    {
    CNewDlg::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CNewDlg2)
    // NOTE: the ClassWizard will add DDX and DDV calls here
    //}}AFX_DATA_MAP
    }
    BEGIN_MESSAGE_MAP(CNewDlg2, CNewDlg)
    //{{AFX_MSG_MAP(CNewDlg2)
    // NOTE: the ClassWizard will add message map macros here
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CNewDlg2 message handlers-------------------------------------------------
    ----------------------------------------------
    //调用
    CNewDlg2 dlg;
    dlg.DoModal();
      

  9.   

    注意一下CNewDlg和CNewDlg2的构造函数的不同
      

  10.   

    发个例子到我邮箱行吗,拜托了[email protected]