I have a very basic question. I am building a user interface with MFC. In one of my buttonClicks methods I create a temporary object (folderDlg), and I want the to get this object back in other buttonClicks (somewhat like saving the handles in matlab gui). Currently I create a member object (pathFolder) in my dlg class (GUI_FORM) and set its reference to the temp object. Obviously the temp object is destructed at the end of the buttoClick, and the reference of the member is lost... What is the easiest way to keep the object created for further use?
relevant code part:
class GUI_FORM : public CDialog
{
public:
GUI_FORM(CWnd* pParent = NULL) : CDialog(GUI_FORM::IDD, pParent) // wizard code
{ }
CFolderPickerDialog * pathFolder;
public:
DECLARE_MESSAGE_MAP()
afx_msg void OnBnClickSaveAs();
...
}
void GUI_FORM::OnBnClickSaveAs()
{
CFolderPickerDialog folderDlg;
if (folderDlg.DoModal() == IDOK)
AfxMessageBox(folderDlg.GetFolderPath());
GUI_FORM::pathFolder = &folderDlg;
}