freeing SetWindowLong() (windows)
After looking at the posts here: http://tinyurl.com/3nyugo
i managed to subclass various windows in order to get mousewheel messages, however i cannot work out how to free the subclassed routine when my object gets deleted or if the user just wants to stop the object running. Below are the two main functions and i have attached the full source.
Can any win32 programmers shed any light on this?
cheers,
oli
void mousewheel_start(t_mousewheel *x)
{
void *window;
if(x->oldproc == NULL)
{
window = jit_object_findregistered(x->ctxt);
if(window) jit_object_method(window, gensym("get_window_ptr"), &x->hWnd);
else x->hWnd = main_get_client(); //if no argument, get the patcher window
if(SetProp(x->hWnd,"olmousewheel", x))
x->oldproc = (WNDPROC) SetWindowLong(x->hWnd, GWL_WNDPROC,(LONG)MyOwnWndProc);
else post("Couldn't setProp()");
}
}
LRESULT CALLBACK MyOwnWndProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
{
t_mousewheel *x = (t_mousewheel*) GetProp(hwnd,"olmousewheel");
switch (umsg)
{
case WM_MOUSEWHEEL:
outlet_int(x->p_out, GET_WHEEL_DELTA_WPARAM(wParam));
return 0; // return, or can also pass to orig proc
}
if (x && x->oldproc) return CallWindowProc(x->oldproc, hwnd, umsg, wParam, lParam);
else return DefMDIChildProc(hwnd, umsg, wParam, lParam);
}
Hi Oli,
I didn't look at the source, but I think I see your problem.
In your start function you register your own message handling function for
callback, and store the old one.
x->oldproc = (WNDPROC) SetWindowLong(x->hWnd, GWL_WNDPROC,(LONG)
MyOwnWndProc);
I think what you need to do is have a stop function reverse this to reset
the original one.
if(x->oldproc){
SetWindowLong(x->hWnd, GWL_WNDPROC, x->oldproc);
x->oldproc = 0;
}
Have this available in a stop method for the user to call, and trigger the
same method in the free function of your object.
hth,
Thijs
thanks thijs!
that worked nicely.
oli