问题描述
您好,
我需要一些紧急帮助来动态添加CFileDialog(SaveAs功能)上的复选框,并获取该事件以进行检查/取消选中向用户显示SaveAs(CFileDialog)。
下面是一些代码,通过它我可以添加一个复选框,但我无法得到它的事件。 />
1. #define MYCHECKBOX 107
2. IFileDialogCustomize * m_pC;
HRESULT hr = p-> QueryInterface(
__uuidof(IFileDialogCustomize),
(LPVOID *)& m_pC);
3.
Hello,
I need some urgent help to dynamically add a checkbox on the CFileDialog (SaveAs functionality) and get the event for its check/uncheck hit when the SaveAs (CFileDialog) is shown to the user.
Below is a bit of code through which I could add a checkbox but I am unable to get its event.
1. #define MYCHECKBOX 107
2. IFileDialogCustomize *m_pC;
HRESULT hr = p->QueryInterface(
__uuidof(IFileDialogCustomize),
(LPVOID*)&m_pC);
3.
m_pC->StartVisualGroup(1, L"Test");
m_pC->AddCheckButton(MYCHECKBOX L"Test check", isvisible);
m_pC-> EndVisualGroup();
4.
m_pC->EndVisualGroup();
4.
class CFileSaveDlg : public CFileDialog
{
DECLARE_DYNAMIC(CFileSaveDlg)
....
....
}
我无法获得复选框勾选事件执行某些操作。
我尝试过使用HookProc和FileDialogControlEvents,但我想我错过了一些东西。
我也尝试过以下文章:
[ ]
和
[]
来自Vista好东西我可以运行样品但不能实施所需的活动。
如果能得到一个示例项目,我会很高兴。
开发工具包:Visual Studio 2008 IDE
平台:Windows 7 64位
问候,
Kalyani
....
....
}
I am unable to get the checkbox tick event to perform some operation.
I have tried using HookProc and also FileDialogControlEvents but I guess I am missing some things.
I also tried to follow the below articles:
XFolderDialog - a folder selection dialog based on CFileDialog[^]
and
Vista Goodies in C++: Using the New Vista File Dialogs[^]
From Vista goodies I could run the sample but could not implement the required event.
I would be glad if I can get a sample project for this.
Dev Toolkit: Visual Studio 2008 IDE
Platform: Windows 7 64bit
Regards,
Kalyani
推荐答案
#include "afxdlgs.h"
class CDlgEventHandler : public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CDlgEventHandler>,
public IFileDialogEvents,
public IFileDialogControlEvents
{
public:
CDlgEventHandler();
~CDlgEventHandler();
BEGIN_COM_MAP(CDlgEventHandler)
COM_INTERFACE_ENTRY(IFileDialogEvents)
COM_INTERFACE_ENTRY(IFileDialogControlEvents)
END_COM_MAP()
// IFileDialogEvents
STDMETHODIMP OnFileOk(IFileDialog* pfd);
STDMETHODIMP OnFolderChanging(IFileDialog* pfd, IShellItem* psiFolder);
STDMETHODIMP OnFolderChange(IFileDialog* pfd);
STDMETHODIMP OnSelectionChange(IFileDialog* pfd);
STDMETHODIMP OnShareViolation(IFileDialog* pfd, IShellItem* psi, FDE_SHAREVIOLATION_RESPONSE* pResponse);
STDMETHODIMP OnTypeChange(IFileDialog* pfd);
STDMETHODIMP OnOverwrite(IFileDialog* pfd, IShellItem* psi, FDE_OVERWRITE_RESPONSE* pResponse);
// IFileDialogControlEvents
STDMETHODIMP OnCheckButtonToggled(IFileDialogCustomize* pfdc, DWORD dwIDCtl, BOOL bChecked);
STDMETHODIMP OnItemSelected(IFileDialogCustomize* pfdc, DWORD dwIDCtl, DWORD dwIDItem);
STDMETHODIMP OnButtonClicked(IFileDialogCustomize* pfdc, DWORD dwIDCtl);
STDMETHODIMP OnControlActivating(IFileDialogCustomize* pfdc, DWORD dwIDCtl);
};
.cpp文件:
.cpp file:
// DlgEventHandler.h : interface of the CDlgEventHandler class
CDlgEventHandler::CDlgEventHandler()
{
}
CDlgEventHandler::~CDlgEventHandler()
{
}
/////////////////////////////////////////////////////////////////////////////
// IFileDialogEvents methods
STDMETHODIMP CDlgEventHandler::OnFileOk ( IFileDialog* pfd )
{
return S_OK; // allow the dialog to close
}
STDMETHODIMP CDlgEventHandler::OnFolderChanging ( IFileDialog* pfd, IShellItem* psiFolder )
{
return S_OK; // allow the change
}
STDMETHODIMP CDlgEventHandler::OnFolderChange ( IFileDialog* pfd )
{
return S_OK;
}
STDMETHODIMP CDlgEventHandler::OnSelectionChange ( IFileDialog* pfd )
{
return S_OK;
}
STDMETHODIMP CDlgEventHandler::OnShareViolation (
IFileDialog* pfd, IShellItem* psi, FDE_SHAREVIOLATION_RESPONSE* pResponse )
{
return S_OK;
}
STDMETHODIMP CDlgEventHandler::OnTypeChange ( IFileDialog* pfd )
{
ATLTRACE(">> OnTypeChange\n");
return S_OK;
}
STDMETHODIMP CDlgEventHandler::OnOverwrite (
IFileDialog* pfd, IShellItem* psi, FDE_OVERWRITE_RESPONSE* pResponse )
{
return S_OK;
}
/////////////////////////////////////////////////////////////////////////////
// IFileDialogControlEvents methods
STDMETHODIMP CDlgEventHandler::OnItemSelected (
IFileDialogCustomize* pfdc, DWORD dwIDCtl, DWORD dwIDItem )
{
return S_OK;
}
STDMETHODIMP CDlgEventHandler::OnButtonClicked (
IFileDialogCustomize* pfdc, DWORD dwIDCtl )
{
return S_OK;
}
STDMETHODIMP CDlgEventHandler::OnCheckButtonToggled (
IFileDialogCustomize* pfdc, DWORD dwIDCtl, BOOL bChecked )
{
ATLTRACE(">> OnCheckButtonToggled, button ID: %u, checked?: %d\n", dwIDCtl, bChecked);
//dwIDCtl - ID of the checkbox clicked
//Using pfdc we can control other events that we wanted to control on this click
return S_OK;
}
STDMETHODIMP CDlgEventHandler::OnControlActivating (
IFileDialogCustomize* pfdc, DWORD dwIDCtl )
{
return S_OK;
}
如何致电:
// my_dlg是派生自的类的对象CFileDialog
CComObjectStackEx< cdlgeventhandler> cbk;
CComQIPtr< ifiledialogevents> pEvents = cbk.GetUnknown();
DWORD dwCookie;
CComQIPtr< ifiledialog> pDlg = my_dlg.GetIFileDialogCustomizePointer();
HRESULT hr = pDlg->建议(pEvents,& dwCookie);
bool bAdvised =成功(小时);
if(my_dlg.DoModal()!= IDOK)
{
//调用Unadvise()停止倾听
if(bAdvised)
pDlg-> Unadvise(dwCookie);
my_dlg.DestroyWindow();
返回;
}
问候,
Kalyani
How to call:
//my_dlg is the object of class derived from CFileDialog
CComObjectStackEx<cdlgeventhandler> cbk;
CComQIPtr<ifiledialogevents> pEvents = cbk.GetUnknown();
DWORD dwCookie;
CComQIPtr<ifiledialog> pDlg = my_dlg.GetIFileDialogCustomizePointer();
HRESULT hr = pDlg->Advise ( pEvents, &dwCookie );
bool bAdvised = SUCCEEDED(hr);
if (my_dlg.DoModal() != IDOK)
{
// Call Unadvise() to stop listening
if ( bAdvised )
pDlg->Unadvise ( dwCookie );
my_dlg.DestroyWindow();
return;
}
Regards,
Kalyani
这篇关于在CFileDialog上添加一个CheckBox(MFC cpp)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!