Click to See Complete Forum and Search --> : Function calls outside class


June 2nd, 1999, 05:47 AM
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

ric
June 2nd, 1999, 06:02 AM
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;
};

David Langis
June 2nd, 1999, 06:32 AM
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.

June 2nd, 1999, 06:38 AM
Thanks very much boys great stuff