tags:

views:

41

answers:

2

i have made a file open dialog, it contains an edit control whose variable is "path" that contains the file name. what i want is to use this variable's value in other dialogs but it gives the error that "path" is an undeclard identifier. i declare path by right click on edit control, add a variable of CString type. path variable gets its value by this code

class CAboutDlg : public CDialog
{
public:    
CAboutDlg();    
static CString imgname;

in the same class, i used it like this

CString image=CAboutDlg::imgname; 
CString szFilename(image);

and passing value of path by this code

path=dlg.GetPathName();
UpdateData(FALSE);
CAboutDlg::imgname=path;

but it still gives error that CAboutDlg and imgname are undeclared identifier in the above code in which i m passing value of path. i did the same which i learned from the site now what's wrong with that? plz tell rwong

+1  A: 

Before the dialog closes, pass this "path" back to the CWinApp (by implementing Get/Set functions in the CWinApp)

Your main class, which is derived from CWinApp, is in effect the "global" class (static class, or singleton). Anything you wish to put into global variables, can be put into your CWinApp-derived class instead. Variables can be protected by mutex, and Listeners, Subscribers etc can be implemented by using this class as the central ground.

rwong
i learned the declaration of global variables from this site http://www.codeguru.com/cpp/cpp/cpp_mfc/article.php/c803. what i have done, i m showing it in my question. plz see
Sweety Khan
thanx its done :)
Sweety Khan
A: 

Try:

CFileDialog dlg(TRUE);
int result=dlg.DoModal();
if(result==IDOK)
{
    path.SetWindowText( dlg.GetPathName() );
    UpdateData(FALSE);
}

You can't assign a string to an edit ctrl. You have to set the text stored inside the edit control.

Edit:

You define this in your class.

 static CString imgname;

You also need to define statics in a single place (ie don't do it in a header). ie in the associated cpp file (and outside of the class definition) you'd add:

CString CAboutDlg::imgname;
Goz