c++ - 给定一个宏,如何指定一个指向类成员函数的指针?
问题描述
我正试图围绕这个宏观结构来思考,但我的 C 技能还远远不够。我有一个必须使用的宏结构,它设置鼠标区域,以及在击中区域时调用的函数回调。如果函数是全局的,一切正常,但现在我想指定作为类成员的回调函数。
我所拥有的是:
#define FCAPI __stdcall
typedef struct MOUSECALLBACK
{
PIXPOINT relative_point;
PVOID user_data;
PMOUSERECT mouse;
PIXPOINT screen_point; // window client coordinates of the click
PVOID reserved;
} MOUSECALLBACK, *PMOUSECALLBACK, **PPMOUSECALLBACK;
// arg1 is actually pointer to MOUSECALLBACK, but for compatibility is defined here as a pointer to PIXPOINT
typedef BOOL FCAPI MOUSE_FUNCTION(PPIXPOINT arg1, FLAGS32 mouse_flags);
typedef MOUSE_FUNCTION *PMOUSE_FUNCTION;
#define OBJHDR_FOR_MOUSE_CALLBACK(PIXPOINT) ((POBJHDR)(((PMOUSECALLBACK)(PIXPOINT))->user_data))
typedef struct MOUSERECT
{
MOUSE_RECT_TYPE rect_type; // type of mouse rectangle (parent, child, eol)
PIXBOX relative_box; // relative sense rectangle (relative to parameter to register function)
CURSOR_TYPE cursor; // cursor to display when over this window
ID help_id; // pop-up help id
FLAGS mouse_flags; // types of mouse activities to look for
ID event_id; // event to generate if mouse_flags is satisfied (implies simple mouse_flags)
PMOUSE_FUNCTION mouse_function; // function to call if mouse_flag is satisfied
} MOUSERECT;
#define MOUSE_PARENT_BEGIN( x, y, w, h, helpid ) {MOUSE_RECT_PARENT, {x, y, w, h}, CURSOR_NONE, helpid, MOUSE_NONE, 0, NULL, NULL},
#define MOUSE_PARENT_END {MOUSE_RECT_END_PARENT, {0, 0, 0, 0}, CURSOR_NONE, HELP_NONE, MOUSE_NONE, 0, NULL, NULL},
#define MOUSE_PARENT( x, y, w, h, helpid ) MOUSE_PARENT_BEGIN( x, y, w, h, helpid ) \
MOUSE_PARENT_END
#define MOUSE_BEGIN( name, helpid, x, y ) MOUSERECT name[] = { \
MOUSE_PARENT_BEGIN( x, y, 0, 0, helpid )
#define MOUSE_END MOUSE_PARENT_END \
{MOUSE_RECT_EOL, {0, 0, 0, 0}, CURSOR_NONE, HELP_NONE, MOUSE_NONE, 0, NULL, NULL}};
#define MOUSE_CHILD_EVENT( x, y, w, h, cursor, mouse_flags, event_id ) {MOUSE_RECT_CHILD, {x, y, w, h}, cursor, HELP_NONE, mouse_flags, event_id, NULL, NULL},
#define MOUSE_CHILD_FUNCT( x, y, w, h, cursor, mouse_flags, function ) {MOUSE_RECT_CHILD, {x, y, w, h}, cursor, HELP_NONE, mouse_flags, 0, function, NULL},
然后,我调用宏来定义鼠标区域,以及指向函数的指针(在本例中为 MFA_B_T1)以在该区域被击中时调用:
MOUSE_BEGIN(MFA_mouse_rect, HELP_NONE, 0, 0)
MOUSE_CHILD_FUNCT(20, 20, 6, 6, CURSOR_HAND, MOUSE_LEFTSINGLE, MFA_B_T1)
```
MOUSE_END
BOOL FCAPI MFA_B_T1(PPIXPOINT relative_point, FLAGS32 mouse_flags)
{
```
return FALSE;
}
现在,我需要让 MFA_B_T1 成为一个类的成员,比如 GDIPlus_Object。所以,我需要这样的东西:
MOUSE_CHILD_FUNCT(20, 20, 6, 6, CURSOR_HAND, MOUSE_LEFTSINGLE, GDIPlus_Object::MFA_B_T1)
BOOL FCAPI GDIPlus_Object::MFD_B_T1(PPIXPOINT relative_point, FLAGS32 mouse_flags)
{
return true;
}
除了,我不确定如何从上面设置的宏中调用函数成员。我不能改变宏观结构,它的使用是项目要求。
请帮忙!
解决方案
推荐阅读
- reactjs - 如何摆脱由 set State 创建的避免无限循环?
- c - 用 C 编写大量文件后 Ubuntu 冻结
- javascript - 如何使用 Jest 在内部使用异步调用和调度测试动作减速器?
- javascript - 特定主导航链接的导航子菜单未正确显示
- python-3.x - 如何在pyspark中使用带有groupby的聚合表达式列表?
- android - 将现有的 android 应用导出为 aar(如库)
- jquery - 只有一个 div 使用 AJAX、jQuery 和 Circliful jQuery 插件填充
- xaml - UWP 中的 ItemsControl StatusChanged 等效项
- python - 如何在我的代码中实现回归模型图?
- asp.net - 在 IIS 上运行 Web 应用程序时出现 BadImageFormatException,但我的所有项目都是任何 CPU