Solved

CFileDialog::OnTypeChange called twice?

Posted on 2002-03-07
4
444 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
ID: 6855438
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
ID: 6924157
Hi aaronsimmons,
Do you have any additional questions?  Do any comments need clarification?

-- Dan
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 10371420
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
xyBalance chalenge 58 88
repeatSeparator  java  challenge 13 56
Perl Awk Need Help 3 109
difference between String.subString() and String.subSequence() 6 171
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

920 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

17 Experts available now in Live!

Get 1:1 Help Now