Solved

CFileDialog::OnTypeChange called twice?

Posted on 2002-03-07
4
428 Views
Last Modified: 2013-11-20

Why is CFileDialog::OnTypeChange called twice for every change to the current filter in the filter combo?  Is this a bug or a "feature"?

0
Comment
Question by:aaronsimmons
  • 2
4 Comments
 
LVL 49

Accepted Solution

by:
DanRollins earned 100 total points
Comment Utility
The simple answer to your question  

>>Why is CFileDialog::OnTypeChange called twice

is this:  Two CDN_TYPECHANGED notification messages appear in the message queue.  So the message map mechanism routes two calls into your OnTypeCHange handler.

Now I think you may be wondering why there are two CDN_TYPECHANGED notifications :)

I can't say for sure.  But I suspect that it is related to this:  The actual Common File dialog has a child window of type 'Dialog' that has the same ID as the 'real' one (but with a different HWND, of course) -- you can see this in Spy++).

I think this oddball nesting is related to backward compatibility with the previous Common File Dialog (the original one that didn't let you rename files and all that good stuff).  Anyway, when you use Spy++ to trace the action, you can see that one notif is sent from the inner dlg and another from the outer.  The fact that both end up on your wrapper class may be related to message reflection (again, I don't understand this well enough to say exactly what is going on.   I've looked at it a few times and decided it is not worth the time I'd spend nailing it down, conceptually).

Now finally, perhaps your REAL real question is:  
"How can I avoid processing the spurious extra call?".  
If so, here is one method:

void CMyFileDlg::OnTypeChange()
{
     static int nPrevFilterIdx= -1;

     const MSG* pMSG= GetCurrentMessage();
     ASSERT( pMSG );
     // int nCtlId= pMSG->wParam; eyeball test

     LPOFNOTIFY pNotif= (LPOFNOTIFY)pMSG->lParam;
     ASSERT( pNotif );
     ASSERT( pNotif->lpOFN );
     if ( pNotif->lpOFN->nFilterIndex == nPrevFilterIdx ) {
          return;
     }
     nPrevFilterIdx= pNotif->lpOFN->nFilterIndex;
     //-- else, take action: this is the real mccoy
     // this line will be executed ONCE per change
     MessageBox("OnTypeChange");
}

-- Dan
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
Hi aaronsimmons,
Do you have any additional questions?  Do any comments need clarification?

-- Dan
0
 
LVL 44

Expert Comment

by:AndyAinscow
Comment Utility
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Accept DanRollin's comment as answer.
Please leave any comments here within the next four days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

AndyAinscow
EE Cleanup Volunteer
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now