CFileDialog w/ template but default button not working

I have a customized CFileDialog (e.g. CCustFileDialog) with a child dialog template. Everything is working fine except that now I want the default button change to one of the button in my child template (e.g. IDOK1).

Here is the code I tried but failed:

void CCustFileDialog::OnInitDone()
{
     // Set default button

     GetParent()->SetDefID(IDOK1);
     ((CButton*)GetParent()->GetDlgItem(IDOK))->SetButtonStyle(BS_PUSHBUTTON);
     SendDlgItemMessage(IDOK1, BM_SETSTYLE, BS_DEFPUSHBUTTON, MAKELPARAM(TRUE, 0));
}

Any one can help?
leow060498Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Amaresh080997Connect With a Mentor Commented:
Set the flag "OFN_EXPLORER" for your CFileDialog derived class..
--Amaresh
0
 
dkremerCommented:
Try sending a DM_SETDEFID message as well.

0
 
leow060498Author Commented:
Well if you look at DevStudio\VC\mfc\include\AFXWIN2.INL(570):

_AFXWIN_INLINE void CDialog::SetDefID(UINT nID)
      { ASSERT(::IsWindow(m_hWnd)); ::SendMessage(m_hWnd, DM_SETDEFID, nID, 0); }

The call of SetDefID() is sending a DM_SETDEFID....
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
leow060498Author Commented:
Try to open WinZip with an existing file and Add. You can see that it is using the CFileDialog with some buttons underneath. If you press enter on some of them, you got nothing.
0
 
chensuCommented:
Is CCustFileDialog derived from CFileDialog? Why do you use GetParent()?

It should be

void CCustFileDialog::OnInitDone()
{
     // Set default button

     this->SetDefID(IDOK1);
}

If this still does not work, try the following:

1. Define a user-defined message;
2. Post the user-defined message in CCustFileDialog::OnInitDone() by using this->PostMessage;
3. When CCustFileDialog receives this message, call this->SetDefID(IDOK1);.
0
 
leow060498Author Commented:
No luck with this->SetDefID() and the PostMessage() also.

The way to set the default button to a child dialog is not mentioned clearly in the documentation.
0
 
chensuCommented:
How about setting the Default Button style in the Dialog Editor?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.