CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 2001
    Posts
    86

    CFileDialog cannot be subclassed in Windows 7?

    I have a class that subclasses CFileDialog. It works fine in XP but in Windows 7, it does not call the overriden functions. For example, I cannot hit my breakpoint in my class' OnCancel function. But no issue in XP.

  2. #2
    Join Date
    Oct 2009
    Posts
    577

    Smile Re: CFileDialog cannot be subclassed in Windows 7?

    Normally 'subclassing' means that you have a class derived from a control and you want to redirect messages sent to the baseclass of the control to your derived classed.

    How did you make a 'subclassing' of a CFileDlg? Do you mean you derived from it and provided 'virtual void OnCancel()' ?


    If so, it could fail if a new implementation of the control didn't call OnCancel virtually. You may try adding an own message map to your file dialog class where you try to catch the BN_CLICKED on IDCANCEL button

    Code:
    BEGIN_MESSAGE_MAP(YourFileDlg, CFileDlg)
    {
        ON_BN_CLICKED(IDCANCEL, OnBtnCancel)
    The OnBtnCancel would have signature 'afx_msg void OnBtnCancel;'

  3. #3
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,244

    Re: CFileDialog cannot be subclassed in Windows 7?

    Quote Originally Posted by itsmeandnobodyelse View Post
    Normally 'subclassing' means that you have a class derived from a control and you want to redirect messages sent to the baseclass of the control to your derived classed.
    '
    In Windows programming, normally, "subclassing" means to replace a default window procedure with another one, application-defined.
    Last edited by ovidiucucu; January 20th, 2011 at 12:59 AM.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  4. #4
    Join Date
    Aug 2001
    Posts
    86

    Re: CFileDialog cannot be subclassed in Windows 7?

    The issue has been resolved. Looks like in VS 2008, CFileDialog uses a Vista style file dialog. The constructor includes a boolean to switch back to pre-Vista.

  5. #5
    Join Date
    Oct 2009
    Posts
    577

    Smile Re: CFileDialog cannot be subclassed in Windows 7?

    Quote Originally Posted by ovidiucucu View Post
    In Windows programming, normally, "subclassing" means to replace a default window procedure with another one, application-defined.
    In MFC all member controls of a dialog or formview need to get subclassed in order to get the message map mechanism working. That was done technically by subclassing the window associated to the control by an appropriate function of the MFC framework. CWnd has member functions PreSubclassWindow, SubclassWindow, UnSubclassWindow for that purpose. See MFC sources cmdtarg.cpp, ctlcore.cpp, dlgdata.cpp, wincore.cpp and more. In first MFC versions the subclassing wasn't done automatically for your own classes derived from a standard control class but you had to do the subclassing manually. Now it is done automatically for all member controls added to the DoDataExchange member function and you need extra work only for dynamically created controls where you want to handle messages by your own derived control class.

    So the 'subclassing' has got a second meaning and what is 'normally' is dependent on whether you do Windows programming or MFC programming.

    A CFileDialog however isn't a control but a modal dialog which doesn't need to get subclassed by the calling dialog cause it has its own message pump. So, the OP apparently meant neither 'Windows subclassed' nor 'MFC subclassed' but simply 'derived'.

  6. #6
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: CFileDialog cannot be subclassed in Windows 7?

    Quote Originally Posted by Shiney Vang View Post
    The issue has been resolved. Looks like in VS 2008, CFileDialog uses a Vista style file dialog. The constructor includes a boolean to switch back to pre-Vista.
    Yes, exactly, and the flag is set to TRUE by default to use Vista style.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured