Click here to Skip to main content
15,898,035 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
C#
m_pC->StartVisualGroup(1, L"Test");
m_pC->AddCheckButton(MYCHECKBOX L"Test check", isvisible);

m_pC->EndVisualGroup();
4.
C#
class CFileSaveDlg : public CFileDialog
{
    DECLARE_DYNAMIC(CFileSaveDlg)

....
....
}

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
Posted
Comments
kalyani.homkar 14-Mar-13 0:12am    
Hello,

Any update for above query?
Request you to help me. Thank you in advance

use an ID greater than 1000 and add a message handler and the macro in the message map.
 
Share this answer
 
Comments
kalyani.homkar 15-Mar-13 0:38am    
Hello Karsten,

Firstly I would like to thank you for your answer and helping me with the query.

As per your suggestion I have made the below changes:

1. #define MYCHECKBOX 1070
2. In .h file:
DECLARE_MESSAGE_MAP() and
afx_msg void OnBnClickedMYCHECKBOX ();
3. In .cpp file:
BEGIN_MESSAGE_MAP(CTMFileSaveDlg, CFileDialog)
ON_BN_CLICKED(MYCHECKBOX ,&CFileSaveDlg::OnBnClickedMYCHECKBOX )
END_MESSAGE_MAP()
and
void CFileSaveDlg::OnBnClickedMYCHECKBOX()
{
// TODO: Add your control notification handler code here
}

Kindly let me know in-case I am missing some thing else in above template code.
Also I would like to put light on the fact that none of my events are getting triggered. OnButtonClick, OnNCDestroy, etc.

I would be glad if you can give me a sample code.

Regards,
Kalyani
KarstenK 15-Mar-13 3:14am    
That is correct and complete.

And that doesnt work? Strange. :-(

Do did also consider Paul diLascias approach as mentioned in the XFolderDialog. I remembered that it worked some years ago fine for me after doing all exactly as he.

http://msdn.microsoft.com/de-de/magazine/cc301412(en-us).aspx
kalyani.homkar 19-Mar-13 1:08am    
Hello Karsten,

I have tried with above method too but I am unable to see the SaveAs Dialog box from the example I tried in msdn link (though there is a hit in its DoModal method. I am trying the full example from here now).

For the prior method we discuss, I could see the dialog-box but no event trigger.
Kindly let me know in-case you have any further ideas..

Regards,
Kalyani
After some more findings, I found the below code working for me..

.h file:
#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 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;
}


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
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900