On Sep 17, 8:47 am, Neviton <nevito...@gmail.comwrote:
Thanks for the quickly response Barry.
Last resort, there must be something wrong with your design, refactor.
Yes probably. :) I'm starting.
Perhaps you can give me some tip.
I'm subclassing a Button control.
I create a class for this and I define my subclassing procedure as
static.
But I have a non-static HBITMAP variable that I want to use inner
subclassing static procedure.
Presumably you are doing this because there is some
library code (the operating system, etc.) that looks
after the mundane parts of doing the button operations.
And that other code wants a static function so it can
be used as a callback. This is an evergreen question
that gets asked repeatedly. Read through the FAQ for
what to do about callbacks.
But basically: A static member function does not know
about specific instances of the class. You've got to
tell it somehow. It isn't really possible for me to
solve your problem without actually doing all the work.
You need to have some scheme for keeping track of which
button-class instance is being invoked. Some callback
systems allow the setting of a parameter that can be
a pointer. Some allow the storage of some kind of ID
number that your prog could keep track of buttons.
Or possibly there is some ID number the system keeps
track of automatically and you can use that. In window
systems there is usually a window ID or a frame number
or some such.
So, when you are setting up the button, you'd store
something in the system. When the callback happens,
it passes you some extra parameter. And you use that
extra parameter to sort out which button instance
you need to call. Your static function looks up this
stuff in a static table, then calls it. That table
is something you have to maintain as buttons are
created, destroyed, modified, etc.
If at all possible, it's way better to have the
callback system get a pointer to an instance. Then
if you can persuade it to call a member function
to do the job you can shorten this entire problem.
But that assumes you have the ability to modify
the system so that works. If you don't, then you
have to do something like the static table.
Socks