Solved

CFileDialog::OnTypeChange called twice?

Posted on 2002-03-07
4
469 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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C++ BOOL WINAPI ReadFile fails on windows 10 when reading from USB cable 9 474
WinWaitActive parameters 12 31
format the code in java 6 101
wordappend challenge 8 201
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: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.

829 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