pub fn full_bind_event_handler<F>(handle: &ControlHandle, f: F) -> EventHandler
    where F: Fn(Event, EventData, ControlHandle) -> () + 'static
{
    use winapi::um::winuser::EnumChildWindows;

    struct SetSubclassParam {
        callback_ptr: *mut *const Callback,
        subclass_id: UINT_PTR,
    }

    /**
        Function that iters over a top level window and bind the events dispatch callback
    */
    unsafe extern "system" fn set_children_subclass(h: HWND, p: LPARAM) -> i32 {
        let params_ptr = p as *mut SetSubclassParam;
        let params = &*params_ptr;
        
        let cb: Rc<Callback> = Rc::from_raw(*params.callback_ptr);

        // Simply increase the rc count because the callback
        // will also be stored into the current children window. 
        mem::forget(cb.clone());
        SetWindowSubclass(h, Some(process_events), params.subclass_id, params.callback_ptr as UINT_PTR);

        // Do not decrease the refcount
        mem::forget(cb);

        1
    }

    /**
        Push the children window handle into the EventHandler
    */
    unsafe extern "system" fn handler_children(h: HWND, p: LPARAM) -> i32 {
        let handles_ptr: *mut Vec<HWND> = p as *mut Vec<HWND>;
        let handles = &mut *handles_ptr;
        handles.push(h);
        1
    }

    let hwnd = handle.hwnd().expect("Cannot bind control with an handle of type");

    // The callback function must be passed to each children of the control
    // To do so, we must RC the callback
    let callback: Rc<Callback> = Rc::new(f);
    let callback_box: Box<*const Callback> = Box::new(Rc::into_raw(callback));
    let callback_ptr: *mut *const Callback = Box::into_raw(callback_box);
    
    let callback_fn: SUBCLASSPROC = Some(process_events);
    let subclass_id = EVENT_HANDLER_ID.fetch_add(1, Ordering::SeqCst);
    let mut handler = EventHandler {
        handles: vec![hwnd],
        id: callback_fn,
        subclass_id,
    };


    let params = Box::new(SetSubclassParam { callback_ptr, subclass_id });
    let params_ptr: *mut SetSubclassParam = Box::into_raw(params);

    unsafe {
        EnumChildWindows(hwnd, Some(handler_children), (&mut handler.handles as *mut Vec<HWND>) as LPARAM);
        EnumChildWindows(hwnd, Some(set_children_subclass), params_ptr as LPARAM);
        SetWindowSubclass(hwnd, callback_fn, subclass_id, callback_ptr as UINT_PTR);
        Box::from_raw(params_ptr);
    }

    handler
}
/**
    Hook the window subclass with the default event dispatcher.
    The hook is applied to the window and all it's children (recursively).

    Returns a `EventHandler` that can be passed to `unbind_event_handler` to remove the callbacks.

    This function will panic if `handle` is not a window handle.
*/
Hook the window subclass with the default event dispatcher.
The hook is applied to the window and all it's children (recursively).

Returns a `EventHandler` that can be passed to `unbind_event_handler` to remove the callbacks.

This function will panic if `handle` is not a window handle.
Hook the window subclass with the default event dispatcher . The hook is applied to the window and all it ' s children ( recursively ) . Returns a ` EventHandler ` that can be passed to ` unbind_event_handler ` to remove the callbacks . This function will panic if ` handle ` is not a window handle .
pub fn full_bind_event_handler<F>(handle: &ControlHandle, f: F) -> EventHandler
    where F: Fn(Event, EventData, ControlHandle) -> () + 'static
{
    use winapi::um::winuser::EnumChildWindows;
    struct SetSubclassParam {
        callback_ptr: *mut *const Callback,
        subclass_id: UINT_PTR,
    }
    /**
        Function that iters over a top level window and bind the events dispatch callback
    */
    unsafe extern "system" fn set_children_subclass(h: HWND, p: LPARAM) -> i32 {
        let params_ptr = p as *mut SetSubclassParam;
        let params = &*params_ptr;
        let cb: Rc<Callback> = Rc::from_raw(*params.callback_ptr);
        // Simply increase the rc count because the callback
        // will also be stored into the current children window. 
        mem::forget(cb.clone());
        SetWindowSubclass(h, Some(process_events), params.subclass_id, params.callback_ptr as UINT_PTR);
        // Do not decrease the refcount
        mem::forget(cb);
        1
    }
    /**
        Push the children window handle into the EventHandler
    */
    unsafe extern "system" fn handler_children(h: HWND, p: LPARAM) -> i32 {
        let handles_ptr: *mut Vec<HWND> = p as *mut Vec<HWND>;
        let handles = &mut *handles_ptr;
        handles.push(h);
        1
    }
    let hwnd = handle.hwnd().expect("Cannot bind control with an handle of type");
    // The callback function must be passed to each children of the control
    // To do so, we must RC the callback
    let callback: Rc<Callback> = Rc::new(f);
    let callback_box: Box<*const Callback> = Box::new(Rc::into_raw(callback));
    let callback_ptr: *mut *const Callback = Box::into_raw(callback_box);
    let callback_fn: SUBCLASSPROC = Some(process_events);
    let subclass_id = EVENT_HANDLER_ID.fetch_add(1, Ordering::SeqCst);
    let mut handler = EventHandler {
        handles: vec![hwnd],
        id: callback_fn,
        subclass_id,
    };
    let params = Box::new(SetSubclassParam { callback_ptr, subclass_id });
    let params_ptr: *mut SetSubclassParam = Box::into_raw(params);
    unsafe {
        EnumChildWindows(hwnd, Some(handler_children), (&mut handler.handles as *mut Vec<HWND>) as LPARAM);
        EnumChildWindows(hwnd, Some(set_children_subclass), params_ptr as LPARAM);
        SetWindowSubclass(hwnd, callback_fn, subclass_id, callback_ptr as UINT_PTR);
        Box::from_raw(params_ptr);
    }
    handler
}
pub fn full_bind_event_handler < F > ( handle : & ControlHandle , f : F ) -> EventHandler where F : Fn ( Event , EventData , ControlHandle ) -> ( ) + ' static { use winapi :: um :: winuser :: EnumChildWindows ; struct SetSubclassParam { callback_ptr : * mut * const Callback , subclass_id : UINT_PTR , } /**
        Function that iters over a top level window and bind the events dispatch callback
    */ unsafe extern " " fn set_children_subclass ( h : HWND , p : LPARAM ) -> i32 { let params_ptr = p as * mut SetSubclassParam ; let params = & * params_ptr ; let cb : Rc < Callback > = Rc :: from_raw ( * params . callback_ptr ) ; // Simply increase the rc count because the callback // will also be stored into the current children window.  mem :: forget ( cb . clone ( ) ) ; SetWindowSubclass ( h , Some ( process_events ) , params . subclass_id , params . callback_ptr as UINT_PTR ) ; // Do not decrease the refcount mem :: forget ( cb ) ; 1 } /**
        Push the children window handle into the EventHandler
    */ unsafe extern " " fn handler_children ( h : HWND , p : LPARAM ) -> i32 { let handles_ptr : * mut Vec < HWND > = p as * mut Vec < HWND > ; let handles = & mut * handles_ptr ; handles . push ( h ) ; 1 } let hwnd = handle . hwnd ( ) . expect ( " " ) ; // The callback function must be passed to each children of the control // To do so, we must RC the callback let callback : Rc < Callback > = Rc :: new ( f ) ; let callback_box : Box < * const Callback > = Box :: new ( Rc :: into_raw ( callback ) ) ; let callback_ptr : * mut * const Callback = Box :: into_raw ( callback_box ) ; let callback_fn : SUBCLASSPROC = Some ( process_events ) ; let subclass_id = EVENT_HANDLER_ID . fetch_add ( 1 , Ordering :: SeqCst ) ; let mut handler = EventHandler { handles : vec ! [ hwnd ] , id : callback_fn , subclass_id , } ; let params = Box :: new ( SetSubclassParam { callback_ptr , subclass_id } ) ; let params_ptr : * mut SetSubclassParam = Box :: into_raw ( params ) ; unsafe { EnumChildWindows ( hwnd , Some ( handler_children ) , ( & mut handler . handles as * mut Vec < HWND > ) as LPARAM ) ; EnumChildWindows ( hwnd , Some ( set_children_subclass ) , params_ptr as LPARAM ) ; SetWindowSubclass ( hwnd , callback_fn , subclass_id , callback_ptr as UINT_PTR ) ; Box :: from_raw ( params_ptr ) ; } handler }
Hook the window subclass with the default event dispatcher.
Hook the window subclass with the default event dispatcher .
handle
&ControlHandle
f
F