我正在尝试创建一个预处理器宏函数,为我自己的GUI库注册回调函数。该库旨在通过使用上述宏功能轻松扩展第三方。
我的问题:我的宏功能包括其他我认为不允许的预处理器指令。我想以允许用户创建自己的小部件并使用主GUI库注册自己的回调函数的方式编写我的REGISTER_CUSTOM_CALLBACK_FUNCTION。有什么想法我仍然可以实现我想做的事情吗?
#define FORWARD_DECLARE_CALLBACK_FUNCTION(callbackFunctName) Integer callbackFunctName(Draw_Box& window, Integer windowIndex, Integer id, Text cmd, Text msg);
#define REGISTER_CUSTOM_CALLBACK_FUNCTION(callbackFunctName) \
#ifndef CUSTOM_CALLBACK_1 \
#define CUSTOM_CALLBACK_1 \
FORWARD_DECLARE_CALLBACK_FUNCTION(callbackFunctName) \
#elif !defined CUSTOM_CALLBACK_2 \
#define CUSTOM_CALLBACK_2 \
FORWARD_DECLARE_CALLBACK_FUNCTION(callbackFunctName) \
#endif
// Intended Usage: In a customers code they will be able to create their own
// Widgets with their own Window Callback functions like this...
REGISTER_CUSTOM_CALLBACK_FUNCTION(progressBarCallback)
... some other code
REGISTER_CUSTOM_CALLBACK_FUNCTION(hyperlinkCallback)
下面是每个时钟步骤调用的主窗口回调:
Integer main_callback(Draw_Box& window, Integer windowIndex, Integer id, Text cmd, Text msg)
{
#ifdef CUSTOM_CALLBACK_1
CUSTOM_CALLBACK_1(window, windowIndex, id, cmd, msg);
#endif
#ifdef CUSTOM_CALLBACK_2
CUSTOM_CALLBACK_2(window, windowIndex, id, cmd, msg);
#endif
}
我有什么想法可以编写我的REGISTER_CUSTOM_CALLBACK_FUNCTION以允许用户创建自己的小部件并使用主GUI库注册自己的回调函数?