Print Page | Close Window

CFileDialog using MFC on Vista

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: General Discussion
Forum Description: Topics Related to Visual C++ MFC Development in General
URL: http://forum.codejock.com/forum_posts.asp?TID=10550
Printed Date: 27 April 2024 at 11:46am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: CFileDialog using MFC on Vista
Posted By: cpede
Subject: CFileDialog using MFC on Vista
Date Posted: 08 May 2008 at 2:59am
When using VS2008 and MFC I automatically get the Vista look on my file open dialogs. But when I have added a template this is not included :-(
 
I can then retrieve the GetIFileDialogCustomize interface and add controls. And this also works for me.
  • How can I better control the placement of the controls? E.g. if I wan to add a large edit field called Comments, I cannot control the size of it?
    My other question is about the events.
  • Is there an easy way to overwrite the control events in MFC CFileDialog? In the MFC implementation I can see the the events are implemented, but how do I get access or overwrites then. E.g. the OnButtonClicked?

Thanks, cpede




Replies:
Posted By: cpede
Date Posted: 01 December 2008 at 8:17am
I would really appreciate if someone knows answers to these problems
 
The positioning is only cosmetic, but the control events are important. Browsing the web only reveals that I should make a class derived from IFileDialogControlEvents abd use the Advise method, but since VS2008 MFC CFileDialog already does that, there must be an easier way??
 
-cpede


Posted By: znakeeye
Date Posted: 01 December 2008 at 11:30am
The new file dialog is one of the reasons why I switched back to XP


-------------
PokerMemento - http://www.pokermemento.com/


Posted By: Sven
Date Posted: 02 December 2008 at 5:40am
Set the last parameter in CFileDialogs constructor to FALSE and you will get the XP implementation on Vista too.


Posted By: cpede
Date Posted: 02 December 2008 at 7:04am
Well I was actually looking for a solution. Going back to old technology is not my style, I would rather solve the issues in front of me, - too early for me to resign.
 
Am I the only one making a custom CFileDialog? Looking in MSDN did not solve anything, and they are also terrible in answering posts at there forum.
 
-cpede


Posted By: robin_l
Date Posted: 02 December 2008 at 11:35am

Look at the IFileDialogControlEvents interface for handling button clicks etc.

I'm not sure how you change from the default control size though....



-------------
Product: Xtreme ToolkitPro 2009 (13.4.1)
Platform: Windows 7 Ultimate(64bit)
Language: Visual Studio 2010 (C++)


Posted By: cpede
Date Posted: 02 December 2008 at 2:43pm
Thanks for the reply.
I know that this is the interface to look for, and what I should do is to implement this interface and Advise the IFileDialog with this event connection point.
 
But when using CFileDialog in MFC 9 this already implements this interface, but by looking in the MFC code this implementation is empty.
 
My question is really can I redirect this interface to my own implementation?
Or is it possible to do a simple virtual inheritance?
What happens if I advice with my own, where does it leave the MFC implementation?
 
-cpede


Posted By: robin_l
Date Posted: 02 December 2008 at 3:28pm

It is a while since I did this, but what I do is the following. In a class derived from CFileDialog, I include the following in the declaration:


protected:
DECLARE_INTERFACE_MAP()
BEGIN_INTERFACE_PART(FileDialogControlEvents, IFileDialogControlEvents)
  STDMETHOD(OnItemSelected)(IFileDialogCustomize *, DWORD, DWORD);
  STDMETHOD(OnButtonClicked)(IFileDialogCustomize *, DWORD);
  STDMETHOD(OnCheckButtonToggled)(IFileDialogCustomize *, DWORD, BOOL);
  STDMETHOD(OnControlActivating)(IFileDialogCustomize *, DWORD);
END_INTERFACE_PART_OPTIONAL(FileDialogControlEvents)


Then in the source file, something like:

BEGIN_INTERFACE_MAP(CMyDialog, CFileDialog)
  INTERFACE_PART(CMyDialog, ID_IFileDialogControlEvents_MFC, FileDialogControlEvents)
END_INTERFACE_MAP()

in the constructor you need to include

USE_INTERFACE_PART_STD(FileDialogControlEvents);


you then need to implement the methods (the ones below are blank)

STDMETHODIMP CMyDialog::XFileDialogControlEvents::OnItemSelected( IFileDialogCustomize *pfdc, DWORD dwIDCtl, DWORD dwIDItem )
{
 METHOD_PROLOGUE(CMyDialog, FileDialogControlEvents)
 return S_OK;
}


STDMETHODIMP CMyDialog::XFileDialogControlEvents::OnButtonClicked( IFileDialogCustomize *pfdc, DWORD dwIDCtl )
{
 METHOD_PROLOGUE(CMyDialog, FileDialogControlEvents)
 return S_OK;
}

STDMETHODIMP CMyDialog::XFileDialogControlEvents::OnCheckButtonToggled( IFileDialogCustomize *pfdc, DWORD dwIDCtl, BOOL bChecked )
{
 METHOD_PROLOGUE(CMyDialog, FileDialogControlEvents)
 return S_OK;
}

STDMETHODIMP CMyDialog::XFileDialogControlEvents::OnControlActivating( IFileDialogCustomize *pfdc, DWORD dwIDCtl )
{
 METHOD_PROLOGUE(CMyDialog, FileDialogControlEvents)
 return S_OK;
}

STDMETHODIMP_(ULONG) CMyDialog::XFileDialogControlEvents::AddRef()
{
 METHOD_PROLOGUE(CMyDialog, FileDialogControlEvents)
 return pThis->ExternalAddRef();
}

STDMETHODIMP_(ULONG) CMyDialog::XFileDialogControlEvents::Release()
{
 METHOD_PROLOGUE(CMyDialog, FileDialogControlEvents)
 return pThis->ExternalRelease();
}

STDMETHODIMP CMyDialog::XFileDialogControlEvents::QueryInterface(
 REFIID iid, void FAR* FAR* ppvObj)
{
 METHOD_PROLOGUE(CMyDialog, FileDialogControlEvents)
 ENSURE(ppvObj != NULL);
 return (HRESULT)pThis->ExternalQueryInterface(&iid, ppvObj);
}



-------------
Product: Xtreme ToolkitPro 2009 (13.4.1)
Platform: Windows 7 Ultimate(64bit)
Language: Visual Studio 2010 (C++)


Posted By: cpede
Date Posted: 02 December 2008 at 4:52pm
Wow I really appreciate thanks
 
-cpede



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net