how can I access variable in View class from my dialog member function?
-
hi I have a single document , MFC project, with a few dialog classes. In one of the dialog member functions, i have to get access to a member variable of my View class. How can I do that.. its basically a pointer to the view class what is the code Ehsan Behboudi
-
hi I have a single document , MFC project, with a few dialog classes. In one of the dialog member functions, i have to get access to a member variable of my View class. How can I do that.. its basically a pointer to the view class what is the code Ehsan Behboudi
Pass the dialog a pointer to the view class before you call DoModal(). John
-
Pass the dialog a pointer to the view class before you call DoModal(). John
-
Where do you create the dialog? From your view?? John
-
Where do you create the dialog? From your view?? John
i created the dialog class associated with my menu. say, click on File, then , Move,, the dialog (COrigin) pops up now,, in the dialog, when the user clicks on a button, IDC_BUTTON1 the function associated with this button is: void COrigin::OnButton1() { //I have to get a pointer to change a variable in the View or Doc class //which ever is easier. } Ehsan Behboudi
-
i created the dialog class associated with my menu. say, click on File, then , Move,, the dialog (COrigin) pops up now,, in the dialog, when the user clicks on a button, IDC_BUTTON1 the function associated with this button is: void COrigin::OnButton1() { //I have to get a pointer to change a variable in the View or Doc class //which ever is easier. } Ehsan Behboudi
If the data is needed in your view, you might want to keep the variable as a member of the view, and pass a pointer to the view to the dialog. or send a message ( with SendMessage ) containing the variable and handle it in the view.
Maximilien Lincourt "Never underestimate the bandwidth of a station wagon filled with backup tapes." ("Computer Networks" by Andrew S Tannenbaum )
-
i created the dialog class associated with my menu. say, click on File, then , Move,, the dialog (COrigin) pops up now,, in the dialog, when the user clicks on a button, IDC_BUTTON1 the function associated with this button is: void COrigin::OnButton1() { //I have to get a pointer to change a variable in the View or Doc class //which ever is easier. } Ehsan Behboudi
So the dialog is created in the view or the doc? I assume it is the view. Add variable to your dialog
class CMyDialog : public CDialog
{
public:
CMyView* m_pMyView;
// The rest of the dialog code goes here}
Then in our view
// I assume this is the code that you show the dialog after the correct menu button is pushed
CMyView::OnMenuButtonPushed()
{
CMyDialog dlg;dlg.m_pMyView = this;
dlg.DoModal();}
John
-
hi I have a single document , MFC project, with a few dialog classes. In one of the dialog member functions, i have to get access to a member variable of my View class. How can I do that.. its basically a pointer to the view class what is the code Ehsan Behboudi
Getting your data directly from the view in a single document application is bad design to some degree, because it breaks the SDI template. You can expect major reusability issues when you link your dialog directly to the view, since the view in turn is linked to the document. If you can help it, try declaring member variables for the data in the dialog and fill those members with the actual data from the document just before you call domodal. After the dialog returns, read the changes from the member variables back to the document. This way you’ll get a dialog class, which does not ‘directly’ depend on a particular view or document class. Concepts like this will not make your app work any different, but they will help maintenance and improve reusability. Lorenz Prem Microsoft Corporation