CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Guest

    Function calls outside class

    I'll be gratefull of any help....

    I have a dialog and a list, a button on the dialog deletes list items, I have a subclassed CListbox which gets keyboard input, and when delete is pressed I wish to call my delete func on the dialog. I have tried several ways, what am I doing wrong...the delete function is a class wizard generated button click ie protected.... I tried to pass a pointer to my dialog to the list in OnInitDialog, but I had errors as I needed to include the dialog.h in the list for the pointer and the list.h in the dialog for the control. I tried calling MyDialog::OnBtDelete but cannot access protected member, if I create a public function and call in the same way I get invalid call to non static member. I thought perhaps I need a friend function, if so how...please help, and thanks

    Stewart


  2. #2
    Join Date
    Apr 1999
    Posts
    306

    Re: Function calls outside class

    I do not clearly understand the matter, but here is how I grasped it:

    if you want to access a protected function of CMyDialog:: in CMyList:: you should declare your dialog class friend in your listbox class, something like:

    #include "mydialog.h"

    class CMyList : public CListBox
    {
    friend class CMyDialog;
    };


  3. #3
    Join Date
    May 1999
    Posts
    44

    Re: Function calls outside class

    Instead of calling your dialog function from your list box class, you could send a message to the dialog.

    Something like

    CWnd* pDlg = GetParent();
    ASSERT_VALID(pDlg);

    pDlg->SendMessage(WM_COMMAND, IDC_BUTTON_DELETE);

    This way, the button click handler of your dialog will be called.



  4. #4
    Guest

    Re: Function calls outside class

    Thanks very much boys great stuff


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured