Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

it wants a static function as mouse callback, while you have a class member function (which would need the classe's this pointer to work properly)

it needs some indirection:

class CBeautyDlg {

    void ::realMouse(int events, int x, int y, int flag) {
         // your event handling code
    }

    static void ::onMouse(int events, int x, int y, int flag, void* me) {
        CBeautyDlg * that = (CBeautyDlg *)(me); // cast back to proper class
        that->realMouse(events, x, y, flag); // call class member
    }

    void OnBnClickedButton6() {
          ...
          setMouseCallback("myshowWnd", onMouse, (void*)this); // "this" goes into the userdata !
    }

};

it wants a static function as mouse callback, while you have a class member function (which would need the classe's this pointer to work properly)

it needs some indirection:

class CBeautyDlg {

    void ::realMouse(int events, int x, int y, int flag) {
         // your event handling code
    }

    // static wrapper (does NOT need "this")
    static void ::onMouse(int events, int x, int y, int flag, void* me) {
        CBeautyDlg * that = (CBeautyDlg *)(me); // cast back to proper class
        that->realMouse(events, x, y, flag); // call class member
    }

    void OnBnClickedButton6() {
          ...
          setMouseCallback("myshowWnd", onMouse, (void*)this); // "this" goes into the userdata !
    }

};

it wants a static function as mouse callback, while you have a class member function (which would need the classe's this pointer to work properly)

it needs some indirection:

class CBeautyDlg {

    void ::realMouse(int events, int x, int y, int flag) {
         // your event handling code
    }

    // static wrapper (does NOT need "this")
    static void ::onMouse(int events, int x, int y, int flag, void* me) {
        CBeautyDlg * that = (CBeautyDlg *)(me); // cast back to proper class
        that->realMouse(events, x, y, flag); // call class member
    }

    void OnBnClickedButton6() {
         ...
         setMouseCallback("myshowWnd", onMouse, (void*)this); // "this" goes into the userdata !
(void*)this);
    }

};

it wants a static function as mouse callback, while you have a class member function (which would need the classe's this pointer to work properly)

it needs some indirection:

class CBeautyDlg {

    void ::realMouse(int events, int x, int y, int flag) {
         // your event handling code
    }

    // static wrapper (does NOT need "this")
    static void ::onMouse(int events, int x, int y, int flag, void* me) {
        // "me" is, what we fed into setMouseCallback() below:
        CBeautyDlg * that = (CBeautyDlg *)(me); // cast back to proper class
        that->realMouse(events, x, y, flag); // call class member
    }

    void OnBnClickedButton6() {
         ...
         setMouseCallback("myshowWnd", onMouse, (void*)this);
    }

};

it wants a static function as mouse callback, while you have a class member function (which would need the classe's this pointer to work properly)

it needs some indirection:

class CBeautyDlg {

    void ::realMouse(int realMouse(int events, int x, int y, int flag) {
         // your event handling code
    }

    // static wrapper (does NOT need "this")
    static void ::onMouse(int onMouse(int events, int x, int y, int flag, void* me) {
        // "me" is, what we fed into setMouseCallback() below:
        CBeautyDlg * that = (CBeautyDlg *)(me); // cast back to proper class
        that->realMouse(events, x, y, flag); // call class member
    }

    void OnBnClickedButton6() {
         ...
         setMouseCallback("myshowWnd", onMouse, (void*)this);
    }

};