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
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;
};
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.
Re: Function calls outside class
Thanks very much boys great stuff