class CFileDialogEx : public CFileDialog
{
DECLARE_DYNAMIC(CFileDialogEx)public:
CFileDialogEx(BOOL bOpenFileDialog, // 对于 FileOpen 为 TRUE,对于 FileSaveAs 为 FALSE
LPCTSTR lpszDefExt = NULL,
LPCTSTR lpszFileName = NULL,
DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
LPCTSTR lpszFilter = NULL,
CWnd* pParentWnd = NULL);
virtual ~CFileDialogEx();protected:
void OnButtonClicked(DWORD dwIDCtl);
DECLARE_MESSAGE_MAP()
};我继承了CFileDialog,然后覆写了CFileDialog的这个虚的回调函数:
void CFileDialogEx::OnButtonClicked(DWORD dwIDCtl)
{
if(_taccess(CFileDialog::GetPathName(),0)!=-1)
if(MessageBox("该文件已经存在,是否覆盖?","警告",MB_YESNO)==IDYES)
CFileDialog::OnButtonClicked(dwIDCtl);
return;
}在调用时,过程是这样的:
CFileDialogEx* fileDialog=new CFileDialogEx(FALSE,"*.txt",m_fileName,OFN_FILEMUSTEXIST |OFN_HIDEREADONLY,"文件类型(*.txt)|*.txt||",this);
fileDialog->DoModal();
结果单击窗体上的按钮时,发现始终跑不到void CFileDialogEx::OnButtonClicked(DWORD dwIDCtl)
上去虚函数回调
原来 对话框上 按钮 需要 hook 才能 响应。
virtual void OnItemSelected(DWORD dwIDCtl, DWORD dwIDItem); /// <summary>
/// Called when the button is clicked.</summary>
/// <param name="dwIDCtl">The ID of the button</param>
virtual void OnButtonClicked(DWORD dwIDCtl); /// <summary>
/// Called when the check box is checked/unchecked.</summary>
/// <param name="dwIDCtl">The ID of the check box</param>
/// <param name="bChecked">checked/unchecked</param>
virtual void OnCheckButtonToggled(DWORD dwIDCtl, BOOL bChecked); /// <summary>
/// Called when the control is being active.</summary>
/// <param name="dwIDCtl">The ID of the control</param>
为什么要这么复杂,难道MFC里面的类不符合c++标准吗?既然是虚函数,我只要覆写了就应该能产生相应的效果啊
没有
virtual void OnButtonClicked(DWORD dwIDCtl);
有一个 控件 叫commdialog 的