[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 522
  • Last Modified:

CFileDialog::OnTypeChange called twice?


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
aaronsimmons
Asked:
aaronsimmons
  • 2
1 Solution
 
DanRollinsCommented:
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
 
DanRollinsCommented:
Hi aaronsimmons,
Do you have any additional questions?  Do any comments need clarification?

-- Dan
0
 
AndyAinscowCommented:
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now