-
accessing Class members
Hi,
I attached a project about my question. It is created by a class which i found in CodeGuru, a TabControl. From the main dialog file(MyTabExampleDlg.cpp) i want to get the handle of the button but i couldnt.
In fact i can get the handle in "CTabOne" class and store it in same class, then storing it in class as a member.
Code:
class CTabOne : public CDialog
{
// Construction
public:
CTabOne(CWnd* pParent = NULL); // standard constructor
[...]
HWND hbutton;
[...]
};
/////////////////////////////////////////////////////////////////////////////
// CTab1 message handlers
BOOL CTabOne::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
hbutton = ::GetDlgItem(m_hWnd, IDC_BUTTON1);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
Then in the main dialog (MyTabExampleDlg.cpp),
Code:
BOOL CMyTabExampleDlg::OnInitDialog()
{
CDialog::OnInitDialog();
[...]
CTabOne tab1;
HWND buttonHandTest = tab1.hbutton; // << Here!
[...]
return TRUE; // return TRUE unless you set the focus to a control
}
The place which i show in second peace of code, this is not returning the handle. I know i am doing wrong, obviously, but what is the correct one?
Thanks
-
Code:
BOOL CMyTabExampleDlg::OnInitDialog()
{
CDialog::OnInitDialog();
[...]
CTabOne tab1;
HWND buttonHandTest = tab1.hbutton; // << Here!
[...]
return TRUE; // return TRUE unless you set the focus to a control
}
Just a guess:
Code:
BOOL CMyTabExampleDlg::OnInitDialog()
{
[...]
CTabOne tab1;
tab1.OnInitDialog();
HWND buttonHandTest = tab1.hbutton; // << Here!
[...]
return TRUE; // return TRUE unless you set the focus to a control
}
-
Thank you swoopy,
error C2248: 'OnInitDialog' : cannot access protected member declared in class 'CTabOne'
this is the error i get. I suppose maybe can use accessors, not sure but, in fact i am not sure how to do this.
Any idea? How can be access to a control over a child dialog from main dialog?
I reall will be a crazy, couldnt find any example do this, please help, or give me an example.
Thanks
-
hmm, like boomerang i reply to myself. I forgot to write to forum my solve. Maybe somebody needs,:p
1. in .cpp of child dialog;
CWnd *CWndTab1; // global
for a control over, in WM_INITDIALOG,
CWndTab1 = m_edit1.GetParent();
2. in main .cpp (where will be use),
extern CWnd *CWndTab1; // global
and when using,
CWndTab1->IsDlgButtonChecked(...);
and also for other controls over target child dialog.
If i didnt forget anything, this was my solution.