Click to See Complete Forum and Search --> : Subclass problem


hot_water
December 5th, 2005, 10:31 PM
I have a dialog box and there is a edit box inside. Since I want to process the wm_vscroll event, I subclassed the edit box. However, the compiler keeps giving errors of my subclass procedure:

error C2440: 'type cast' : cannot convert from 'LRESULT (__stdcall CDialogMain::* )(HWND,UINT,WPARAM,LPARAM)' to 'LONG'

I changed the return type of the subclassed proc to LONG but doesn't help.

Here is some of my code:


BOOL CALLBACK CDialogMain::staticDialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam){

if (msg == WM_INITDIALOG) {
SetWindowLong(hwnd, GWL_USERDATA, (LONG)lParam);
}

LONG self = GetWindowLong(hwnd, GWL_USERDATA);

if (!self) return FALSE;

// I do it in this way so that my dialog proc can access class members
return ((CDialogMain*)self)->dialogProc(hwnd, msg, wParam, lParam);

}

// a dialog proc which can access class members
BOOL CDialogMain::dialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam){

switch (msg)
{
case WM_INITDIALOG:
{
originalProc = (WNDPROC)SetWindowLong(GetDlgItem(hwnd, IDC_EDIT_BOX), GWL_WNDPROC, (LONG)editboxProc);
.........
}

//subclassed editbox proc in order to process scroll bar events
LRESULT CALLBACK CDialogMain::editboxProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_VSCROLL:
//do something
break;
}
return CallWindowProc(originalProc, hwnd, msg, wParam, lParam);

}


Can anyone give me some guide?

Thanks a lot.

mrRee
December 6th, 2005, 12:32 AM
I'm not an expert here...but I think you have to declare it as 'static':

static LRESULT CALLBACK CDialogMain::editboxProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)

the drawback is, it will not be able to access any of the instance variables since it's static...

I hope that'll be a quick try for you before you can get an expert to view this:D...they can give you the exact solution...

packetvb
December 6th, 2005, 04:42 AM
try this

CDialogMain* self = (CDialogMain*)GetWindowLong(hwnd, GWL_USERDATA);

if (!self) return FALSE;

// I do it in this way so that my dialog proc can access class members
return self->dialogProc(hwnd, msg, wParam, lParam);