|
-
December 5th, 2005, 11:31 PM
#1
Subclass problem
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:
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.
-
December 6th, 2005, 01:32 AM
#2
Re: Subclass problem
I'm not an expert here...but I think you have to declare it as 'static':
Code:
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 ...they can give you the exact solution...
...???...
...don't blame me...when I smell nicc 'o' tyne...
...friends are like bras: close to your heart and there for support..
-
December 6th, 2005, 05:42 AM
#3
Re: Subclass problem
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);
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|