简体   繁体   中英

Call function in another class from Win32 wrapper WndProc

I have a win32 wrapper class with a functioning WndProc (i use a static wndproc to forward messages to the WndProc member function).

I also have another app class which creates an instance of my win32 wrapper class.

I want the user of the app class to be able to write their own functions that represent events, such as OnMouseClick(), or OnMouseMove(), but in order for this to work, I need to call the event functions from the win32 wrapper class's Wndproc (which has no knowledge of the app class).

What's the best way to do this? Should I send a pointer to each event function to my win32 wrapper class, and call it via pointer? Or is there a better way?

The structure of your classes and their purpose is not clear. Nevertheless, the typical recommnded structure of wrapper classes is the following:

class BaseClass
{
public:
    virtual void OnMouseClick(...) { }   // Empty body
    virtual void OnMouseMove(...) { }   // Empty body
};

class AppClass : public BaseClass
{
public:
    void OnMouseClick(...) { AppCode }
    void OnMouseMove(...) { AppCode }
};

Base class is calling virtual methods when it receives Windows events in its static WndProc handler. And this triggers execution of the app code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM