成员函数作回调?

x363635334 2014-04-02 03:46:14

class Assist
{
public:
Assist();
BOOL CALLBACK lpEnumFunc2(HWND hwndTurn,LPARAM lParam)
{
String sCptn=(const char*)lParam;
Sleep(1);
};
HWND GetWindowByCptn(const char* s)
{
EnumWindows(&Assist::lpEnumFunc2,(LPARAM)s);
};
};
//typedef BOOL (CALLBACK* WNDENUMPROC)(HWND, LPARAM);


EnumWindows”: 不能将参数 1 从“BOOL (__stdcall Assist::* )(HWND,LPARAM)”转换为“WNDENUMPROC”

应该怎么改
...全文
188 15 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
碼上道 2014-04-06
  • 打赏
  • 举报
回复
引用 11 楼 luotuo44 的回复:
[quote=引用 10 楼 luotuo44 的回复:] 用bind可以解决这个问题。即使lpEnumFunc2是成员函数

EnumWindows(std::tr1::bind(&Assist::lpEnumFunc2,  this,  (LPARAM)s) NULL);
写漏了一个逗号,应该为

EnumWindows(std::tr1::bind(&Assist::lpEnumFunc2, this, (LPARAM)s), NULL);
[/quote] 这里可能不这样绑定。
x363635334 2014-04-06
  • 打赏
  • 举报
回复
9楼的语法错不理解,原因是什么
luotuo44 2014-04-06
  • 打赏
  • 举报
回复
引用 10 楼 luotuo44 的回复:
用bind可以解决这个问题。即使lpEnumFunc2是成员函数

EnumWindows(std::tr1::bind(&Assist::lpEnumFunc2,  this,  (LPARAM)s) NULL);
写漏了一个逗号,应该为

EnumWindows(std::tr1::bind(&Assist::lpEnumFunc2, this, (LPARAM)s), NULL);
luotuo44 2014-04-06
  • 打赏
  • 举报
回复
用bind可以解决这个问题。即使lpEnumFunc2是成员函数

EnumWindows(std::tr1::bind(&Assist::lpEnumFunc2,  this,  (LPARAM)s) NULL);
x363635334 2014-04-06
  • 打赏
  • 举报
回复

//public声明
	static BOOL CALLBACK EW_Tt(HWND hwndTurn,LPARAM lParam);
	HWND WndByTt(const char* sTt);
//类外定义
BOOL CALLBACK EW_Tt(HWND hwndTurn,LPARAM lParam)
{
...
return true;
}
HWND Assist::WndByTt(const char* sTt)
{
	m_hwndEnum=NULL;
	EnumWindows(EW_Tt,(LPARAM)sTt);
	return m_hwndEnum;
}
error LNK2019: 无法解析的外部符号 "public: static int __stdcall Assist::EW_Tt(struct HWND__ *,long)" (?EW_Tt@Assist@@SGHPAUHWND__@@J@Z),该符号在函数 "public: struct HWND__ * __thiscall Assist::WndByTt(char const *)" (?WndByTt@Assist@@QAEPAUHWND__@@PBD@Z) 中被引用
如何改? 还有,HWND是结构体?

#if !defined(RPC_NO_WINDOWS_H)
    //
    // Notification by window message
    //
    struct {
        HWND hWnd;
        UINT Msg;
        } HWND;

#endif // RPC_NO_WINDOWS_H
#endif // _KRPCENV_
luotuo44 2014-04-06
  • 打赏
  • 举报
回复
引用 13 楼 jerry_dqh 的回复:
[quote=引用 11 楼 luotuo44 的回复:] [quote=引用 10 楼 luotuo44 的回复:] 用bind可以解决这个问题。即使lpEnumFunc2是成员函数

EnumWindows(std::tr1::bind(&Assist::lpEnumFunc2,  this,  (LPARAM)s) NULL);
写漏了一个逗号,应该为

EnumWindows(std::tr1::bind(&Assist::lpEnumFunc2, this, (LPARAM)s), NULL);
[/quote] 这里可能不这样绑定。[/quote] 嗯。需要先用function。
x363635334 2014-04-05
  • 打赏
  • 举报
回复

//类内声明
{
public:
	static BOOL CALLBACK EW_Tt(HWND hwndTurn,LPARAM lParam);
	HWND WndByTt(const char* sTt);
}
//类外定义
static BOOL CALLBACK EW_Tt(HWND hwndTurn,LPARAM lParam)
{
	return true;
}
HWND Assist::WndByTt(const char* sTt)
{
	m_hwndEnum=NULL;
	EnumWindows(EW_Tt,(LPARAM)sTt);//FindWindow(NULL,sTt)限精确匹配
	return m_hwndEnum;
}
报错无法解析的外部符号EW_Tt 
语法错误求改正
lm_whales 2014-04-04
  • 打赏
  • 举报
回复
C++ 还可以用 mem_fun,mem_fun_ref
lm_whales 2014-04-04
  • 打赏
  • 举报
回复
用静态成员函数,或者全局函数,友元函数实现 也可以组合使用(静态成员函数,或者全局函数,友元函数)和 非静态成员
movsd 2014-04-02
  • 打赏
  • 举报
回复
只能做成静态成员函数,不过从GetWindowByCptn这个函数名来看,应该是取指定标题窗口的句柄,用FindWindow会更简单。
PDD123 2014-04-02
  • 打赏
  • 举报
回复
弄成静态成员函数?
JiMoKuangXiangQu 2014-04-02
  • 打赏
  • 举报
回复
引用 3 楼 Automation_dmu 的回复:
[quote=引用 2 楼 JiMoKuangXiangQu 的回复:] [quote=引用 1 楼 max_min_ 的回复:] 不要忘记了,类的普通成员函数会有一个默认的this指针作为参数的!
++ &Assist::lpEnumFunc2 --> &(this->lpEnumFunc2) 试试。[/quote]1楼都说了原因了,这么改显然不可行啊[/quote] 对不起,我错了。LZ,当我没说好了。直接忽略我的回复,不好意思,误导您了。
AndyStevens 2014-04-02
  • 打赏
  • 举报
回复
引用 2 楼 JiMoKuangXiangQu 的回复:
[quote=引用 1 楼 max_min_ 的回复:] 不要忘记了,类的普通成员函数会有一个默认的this指针作为参数的!
++ &Assist::lpEnumFunc2 --> &(this->lpEnumFunc2) 试试。[/quote]1楼都说了原因了,这么改显然不可行啊
JiMoKuangXiangQu 2014-04-02
  • 打赏
  • 举报
回复
引用 1 楼 max_min_ 的回复:
不要忘记了,类的普通成员函数会有一个默认的this指针作为参数的!
++ &Assist::lpEnumFunc2 --> &(this->lpEnumFunc2) 试试。
max_min_ 2014-04-02
  • 打赏
  • 举报
回复
不要忘记了,类的普通成员函数会有一个默认的this指针作为参数的!

33,321

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧