Solved

CFileDialog::OnTypeChange called twice?

Posted on 2002-03-07
4
477 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
function returning CString in a regular win32 DLL 8 201
ODBC Connection Logging, ADO.NET 6 71
substring method in java 1 137
unix example issues 18 106
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…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

730 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