Click here to Skip to main content
15,891,184 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Buffer Overflow's Pin
Steve S4-Mar-04 6:13
Steve S4-Mar-04 6:13 
GeneralRe: Buffer Overflow's Pin
Mike Dimmick4-Mar-04 6:29
Mike Dimmick4-Mar-04 6:29 
GeneralRe: Buffer Overflow's Pin
Frank Deo4-Mar-04 11:37
Frank Deo4-Mar-04 11:37 
GeneralAVI FIles Pin
Anonymous3-Mar-04 12:20
Anonymous3-Mar-04 12:20 
GeneralProcessing messages Pin
ffazly3-Mar-04 11:48
ffazly3-Mar-04 11:48 
GeneralRe: Processing messages Pin
rrrado4-Mar-04 6:28
rrrado4-Mar-04 6:28 
GeneralDeprecated files in \MS Visual Studio\VC98 Pin
john john mackey3-Mar-04 11:13
john john mackey3-Mar-04 11:13 
GeneralMFC dialog member sharing? (code included) Pin
Christophocles3-Mar-04 11:12
sussChristophocles3-Mar-04 11:12 
How can I use functions and member variables from one dialog's class in the message handler of another dialog (in MFC)?


For example:

I have two dialogs, with classes CDlg1 & CDlg2. CDlg1 has a tab control and some generic function. CDlg2 (modeless) has a button control.

CDlg1.h looks like:

#include "Dlg2.h"
class CDlg1 : public CDialog
{
public:
CDlg1(CWnd* pParent = NULL); // Constructor
CDlg2 m_dlg2; // To create modeless in "Dlg1.cpp"
void function(); // Generic function in "Dlg1.cpp"
// Dialog Data
//{{AFX_DATA(CDlg1)
enum { IDD = IDD_DIALOG1 };
CTabCtrl m_tab; // Tab Control member variable
//}}AFX_DATA
// Overrides
//{{AFX_VIRTUAL(CDlg1)
protected:
virtual void DoDataExchange(CDataExchange* pDX);
//}}AFX_VIRTUAL
// Implementation
protected:
HICON m_hIcon;
// Generated message map functions
//{{AFX_MSG(CDlg1)
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

CDlg2.h looks like:

class CDlg2 : public CDialog
{
public:
CDlg2(CWnd* pParent = NULL); // Constructor
// Dialog Data
//{{AFX_DATA(CDlg2)
enum { IDD = IDD_DIALOG2 };
//}}AFX_DATA
// Overrides
//{{AFX_VIRTUAL(CDlg2)
protected:
virtual void DoDataExchange(CDataExchange* pDX);
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(CDlg2)
afx_msg void OnButton();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

In the message handler for the 2nd dialog's button, I want to call the function from CDlg1 & get info from the 1st dialog's tab control (GetCurSel() or whatever).

**** From CDlg2::OnButton() in "Dlg2.cpp", how do I call function()???? ****
Just calling "function();" alone gives me the old "undeclared identifier" shiznat.

And what's the best way to control m_tab? The following seems to work, but it seems it bit messy to me:
CTabCtrl* m_tabPtr = (CTabCtrl*) GetParentOwner()->GetDlgItem(IDC_TAB);
int nCurTabSel = m_tabPtr->GetCurSel();

When I try to derive CDlg2 from CDlg1, all hell breaks loose (operator error, I'm certain) and I can't seem to make "friend" work either. Am I even barking up the right tree?

Thanks,
-Chris, the MFC newb


GeneralRe: MFC dialog member sharing? (code included) Pin
BlackDice4-Mar-04 5:10
BlackDice4-Mar-04 5:10 
GeneralRe: MFC dialog member sharing? (code included) Pin
Christophocles4-Mar-04 5:44
sussChristophocles4-Mar-04 5:44 
GeneralRe: MFC dialog member sharing? (code included) Pin
monrobot134-Mar-04 5:39
monrobot134-Mar-04 5:39 
GeneralRe: MFC dialog member sharing? (code included) Pin
Christophocles4-Mar-04 5:49
sussChristophocles4-Mar-04 5:49 
GeneralRe: MFC dialog member sharing? (code included) Pin
BlackDice4-Mar-04 6:07
BlackDice4-Mar-04 6:07 
GeneralRe: MFC dialog member sharing? (code included) Pin
Christophocles4-Mar-04 7:06
sussChristophocles4-Mar-04 7:06 
GeneralRe: MFC dialog member sharing? (code included) Pin
BlackDice4-Mar-04 8:23
BlackDice4-Mar-04 8:23 
GeneralRe: MFC dialog member sharing? (code included) Pin
Christophocles4-Mar-04 9:14
sussChristophocles4-Mar-04 9:14 
GeneralRe: MFC dialog member sharing? (code included) Pin
BlackDice4-Mar-04 9:30
BlackDice4-Mar-04 9:30 
GeneralRe: MFC dialog member sharing? (code included) Pin
Christophocles4-Mar-04 10:27
sussChristophocles4-Mar-04 10:27 
GeneralRe: MFC dialog member sharing? (code included) Pin
BlackDice5-Mar-04 3:49
BlackDice5-Mar-04 3:49 
GeneralRe: MFC dialog member sharing? (or, My Marathon Ineptitude) Pin
Christophocles5-Mar-04 4:41
sussChristophocles5-Mar-04 4:41 
GeneralRe: MFC dialog member sharing? (or My Enduring Ineptitude) Pin
Christophocles5-Mar-04 6:25
sussChristophocles5-Mar-04 6:25 
GeneralRe: MFC dialog member sharing? (or My Enduring Ineptitude) Pin
BlackDice5-Mar-04 10:43
BlackDice5-Mar-04 10:43 
GeneralRe: MFC dialog member sharing? Pin
Christophocles5-Mar-04 12:01
sussChristophocles5-Mar-04 12:01 
GeneralRe: MFC dialog member sharing? Pin
Christophocles8-Mar-04 8:01
sussChristophocles8-Mar-04 8:01 
GeneralAdvice required.... Pin
slyone3-Mar-04 10:54
slyone3-Mar-04 10:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.