Language: Visual C++, MFC
Environment: Visual Studio 2005
I have a dialog that requires the user to set file paths for six different settings. Each text box has a browse button which launches a file browser.
How can I set it up so that all of the browse buttons all call the same function to launch the chooser, then use a switch to determine which button invoked the file chooser so that I can set the text of the appropriate CEdit box with the path? // run-on sentence, hah
I’m sure I’ll have to use GetDlgCtrlID, I’m just not sure how.
Thank you for your help in advance!
~ Jon
EDIT: Here’s the code I have now…very simple because I’m just getting it to work for now.
BEGIN_MESSAGE_MAP(FSC_3DPersp, CSAPrefsSubDlg)
//{{AFX_MSG_MAP(FSC_3DPersp)
// NOTE: the ClassWizard will add message map macros here
//}}AFX_MSG_MAP
ON_COMMAND(BN_CLICKED, &FSC_3DPersp::Browse)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// FSC_3DPersp message handlers
void FSC_3DPersp::Browse(UINT uiID)
{
// TODO: Add your control notification handler code here
switch(uiID)
{
case IDC_BUTTON1:
MessageBox("1");
break;
case IDC_BUTTON2:
MessageBox("2");
break;
case IDC_BUTTON3:
MessageBox("3");
break;
case IDC_BUTTON4:
MessageBox("4");
break;
case IDC_BUTTON5:
MessageBox("5");
break;
case IDC_BUTTON6:
MessageBox("6");
break;
case IDC_BUTTON7:
MessageBox("7");
break;
}
}
BOOL FSC_3DPersp::OnCommand(WPARAM wParam, LPARAM lParam)
{
if (HIWORD(wParam) == BN_CLICKED)
{
Browse(LOWORD(wParam));
return TRUE;
}
return CWnd::OnCommand(wParam, lParam);
}
If you’re responding to the
BN_CLICKEDmessage, the button ID will be contained in theLOWORDof thewparamof the message.Edit: MFC normally discards the
wparamof the message. To access it you must override theOnCommandhandler in your dialog.