accessing Class members

This is a discussion on accessing Class members within the C++ Programming forums, part of the General Programming Boards category; Hi, I attached a project about my question. It is created by a class which i found in CodeGuru, a ...

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    35

    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
    Attached Files Attached Files
    Want to learn? Then try to teach...

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    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
    }

  3. #3
    Registered User
    Join Date
    Dec 2002
    Posts
    35
    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
    Want to learn? Then try to teach...

  4. #4
    Registered User
    Join Date
    Dec 2002
    Posts
    35
    hmm, like boomerang i reply to myself. I forgot to write to forum my solve. Maybe somebody needs,

    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.
    Want to learn? Then try to teach...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. returning class and struct members
    By simone.marras in forum C++ Programming
    Replies: 17
    Last Post: 03-16-2009, 12:10 PM
  2. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  3. Read-only class members
    By kidburla in forum C++ Programming
    Replies: 4
    Last Post: 10-14-2006, 01:52 PM
  4. Protected Inheritance
    By golfinguy4 in forum C++ Programming
    Replies: 8
    Last Post: 12-27-2002, 10:56 AM
  5. Accessing private data members
    By maloy in forum C++ Programming
    Replies: 11
    Last Post: 10-04-2002, 03:48 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21