我写了个对话框类 CAdlg 是从一个公用的对话框ccommdlg继承的
这个ccommdlg是从CDialog继承过来的
请问,窗口响应函数,如何不经过CAdlg 而是直接让ccommdlg中的函数进行相应
这个ccommdlg是从CDialog继承过来的
请问,窗口响应函数,如何不经过CAdlg 而是直接让ccommdlg中的函数进行相应
解决方案 »
- 牢骚,所有分都给了
- 菜鸟问题:如何修改用MFC生成的默认工具栏的图标?
- VB转学VC请前辈指点!!!
- 在VC++中如何使用ADO来动态刷新记录集
- 救命!!! 文件编译过程中重新启动后变成二进制文件,如何恢复!3000行代码!!
- 100分求助:在CSocket中,如果设置客户端连接超时
- 我会被炒的100分,你一个人分享
- 如何从支持四通道的声卡中录音并作实时处理
- Windows IOCP模型是什么????//与WSAAsyncSelect模式什么联系?
- WIN7 任务栏(taskbar)双图标问题
- 为什么在一个工程中搜索一个文本串时,总是提示说 "Cannot find the string "?
- VC多文档中怎么获取最近打开文件的路径
比如你重载IDOK按钮的响应函数(在资源编辑处双击"确定"按钮产生)
其实他就是直接调用ccommslg的响应函数void CAdlg::OnOK()
{
ccommslg::OnOK();
}
==========
在CAdlg中转发就行了,比如处理WM_LBUTTONDOWN消息,还是让CADlg处理WM_LBUTTONDOWN消息,不过直接调用commslg::LButton..();就行了.
//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();
我理解你的意思,应该是说:
如何让子类不继承父类的某些东西
比如对某些消息的响应那么你还是要在子类重新写这些函数
比如以2楼为例:
void CAdlg::OnOK()
{
}
这样一来,子类对IDOK就相当于不响应了.
又比如8楼的
void CNewDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
//CDialog::OnLButtonDown(nFlags, point);
}
把向父类传递的代码注释掉,子类就等同于不响应数标左键了这样是你想要的结果吗?
这样应该就可以了吧
CNewDlg2* dlg = new CNewDlg2;
dlg->Create(IDD_DIALOG2, this);
dlg->ShowWindow(SW_SHOW);
-------------------------------------------------
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();