title: Sharing variable among class instances
body: <pre><code>class MyApp : public CWinApp {
          afx_msg OnPrefrences();
      };
  </code></pre>
  
  <p>OnPrefrences() get called when user selects tools->Preference from the menubar.</p>
  
  <p>Now in one  dialog(Say DlgX) there is one button, on clicking this I need to open the  Preference dialog which has in fact many panes, but here I need to open the Preference dialog by selecting one the these pane as active. Also in that particular pane I need to hide some of the controls only when It gets open through this the dialog not through menu.</p>
  
  <p>So I have created one variable(Say m_varX) in MainFrm class.</p>
  
  <pre><code>void DlgX::OnButtonXClick()
  {
     CMainFrame* pFrame = (CMainFrame*)AfxGetMainWnd();
     if(pFrame)
     {
         pFrame-&gt;m_varX = TRUE;
        ((CMyApp*)(AfxGetApp()))-&gt;OnPrefrences();
        pFrame-&gt;m_varX = FALSE;
     }
  }
  </code></pre>
  
  <p>And in button handler of DlgX I have made this m_varX TRUE and call the OnPreference() and after closing of this preference dialog I have made m_varX FALSE.</p>
  
  <p>All this is working fine... But the problem is that things gets clutter in mainFrm. Also the project I am working on is legacy one so I cant make much changes.</p>
  
  <p><em><strong>Is there any patter available for handling such case?</em></strong></p>
  
  <p>Thanks  </p>