我可以使用成员函数作为 EnumWindows 的第一个参数吗 [英] Can I use member function as first argument to EnumWindows
本文介绍了我可以使用成员函数作为 EnumWindows 的第一个参数吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以使用成员函数作为 EnumWindows
的第一个参数吗?在这种情况下,即使使用 boost::bind
,我也看不到任何解决方法.
Can I use member function as first argument to EnumWindows
? I don't see any workaround in this case even with boost::bind
.
推荐答案
鉴于这个正常回调函数:
BOOL CALLBACK EnumWindowsProc(HWND wnd, LPARAM lParam);
您可以使用 lParam
调用 EnumWindows
将指针传递给您的类:
You can invoke EnumWindows
using lParam
to pass it a pointer to your class:
EnumWindows(EnumWindowsProc, reinterpret_cast<LPARAM>(this));
在 EnumWindowsProc
中,您可以简单地调用成员函数(将 lParam
转换为您的类类型).像这样:
In EnumWindowsProc
you can simply call member function (casting lParam
to your class type). Like this:
BOOL CALLBACK EnumWindowsProc(HWND wnd, LPARAM lParam)
{
return reinterpret_cast<MyClass*>(lParam)->EnumWindows(wnd);
}
如果你不想公开你的类方法,你可以:
If you don't want to make your class method public you can:
- 打包一个结构以包含类实例和指向成员的指针.
- 为代表使用一个库.
- 使用 boost
std:bind
(在这种情况下它会工作得很好,因为你在自己的类成员上这样做,它不必是__stdcall
).
- Pack a struct to contain both class instance and pointer to member.
- Use a library for delegates.
- Use boost
std:bind
(in this case it'll work well because you do it on your own class member, it has not to be__stdcall
).
无论您使用什么,您都可以在 this 中找到更多详细信息在SO上发布.
Whatever you will use you can find more details in this post here on SO.
这篇关于我可以使用成员函数作为 EnumWindows 的第一个参数吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文