Re: [Dev-C++] Subclass inside a class problem
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Richard A. <dic...@ho...> - 2001-04-07 00:26:45
|
>Hi,
>When trying to subclass an richedit control within a
>class, I ran accross a problem. When I include a
>subclass procedure in a class (the code shown below),
>I get the error (Generated by Dev-C++): "aggregate
>value used where an integer was expected", yet when I
>include the subclass procedure outside the class, it
>runs fine. How can I solve this?
>
>class akorichedit{
>private:
>//...
>WNDPROC wpOrigRichEditProc;
>LRESULT CALLBACK RichEditSubclassProc(HWND hwnd, UINT
>uMsg, WPARAM wParam, LPARAM lParam);
>//...
>public:
>void create();
>//...
>};
>
>void akorichedit::create(){
>//... ERROR BELOW
>wpOrigRichEditProc =(WNDPROC) SetWindowLong(
> (HWND)_hwnd, // handle of window
> (int)GWL_WNDPROC, // offset of value to set
> (LONG)RichEditSubclassProc
> ); // LINE 130
>//... ERROR ABOVE
>}
You can't take the address of a member function and pass it around like
this, unfortunatly, because the 'address' of the function is independent of
the object (i.e. instance) for which it's called.
This sort of situation arises most often when you're mixing C code expecting
callbacks and C++ code providing function objects... the only workaround
that I can see is to have a global function (which you give to
SetWindowLong) which is a friend of the akorichedit class, and calls various
functions of the class in response to being called itself...
of course, the function will need to know which class its being called for
each time. I usually use the window's user data to store the object's
address (use SetWindowLong with GWL_USERDATA).
hth,
richard
_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
|