C++ Can';t在类的成员时调用EnumWindows函数
我正在尝试使用EnumWindows()调用“enumWind”。枚举窗口来自WinAPIC++ Can';t在类的成员时调用EnumWindows函数,c++,windows,class,winapi,visual-c++,C++,Windows,Class,Winapi,Visual C++,我正在尝试使用EnumWindows()调用“enumWind”。枚举窗口来自WinAPI WINUSERAPI BOOL WINAPI EnumWindows(_In_ WNDENUMPROC lpEnumFunc, _In_ LPARAM lParam); 它工作得很好,但我想把它放在一个类中。然后它就不再工作了,说“类型的参数和类型的参数不兼容” 类型为“BOOL(\u stdcall DirectX\u Hook::*)(HWND handle,LPARAM lp)”的错误(活动)E0
WINUSERAPI BOOL WINAPI EnumWindows(_In_ WNDENUMPROC lpEnumFunc, _In_ LPARAM lParam);
它工作得很好,但我想把它放在一个类中。然后它就不再工作了,说“类型的参数和类型的参数不兼容”
类型为“BOOL(\u stdcall DirectX\u Hook::*)(HWND handle,LPARAM lp)”的错误(活动)E0167参数与类型为“WNDENUMPROC”的参数不兼容
麦可德
class DirectX_Hook
{
public:
BOOL CALLBACK enumWind(HWND handle, LPARAM lp);
HWND GetProcessWindow();
// Other functions that doesn't matter to you.
}DX_Hook;
mycode.cpp
BOOL CALLBACK DirectX_Hook::enumWind(HWND handle, LPARAM lp)
{
DWORD ProcID;
GetWindowThreadProcessId(handle, &ProcID);
if (GetCurrentProcessId() != ProcID)
return TRUE;
window = handle;
return FALSE;
}
HWND DirectX_Hook::GetProcessWindow()
{
window = NULL;
EnumWindows(enumWind, NULL); // <- The error, but not an error when i remove "DirectX_Hook::" from the function name
// Error (active) E0167 argument of type "BOOL (__stdcall DirectX_Hook::*)(HWND handle, LPARAM lp)" is incompatible with parameter of type "WNDENUMPROC"
RECT size;
GetWindowRect(window, &size);
windowSize.x = size.right - size.left;;
windowSize.y = size.bottom - size.top;
return window;
}
BOOL回调DirectX\u Hook::enumWind(HWND句柄,LPARAM lp)
{
德沃德·普罗西德;
GetWindowThreadProcessId(句柄和进程ID);
如果(GetCurrentProcessId()!=ProcID)
返回TRUE;
窗口=手柄;
返回FALSE;
}
HWND DirectX_Hook::GetProcessWindow()
{
窗口=空;
EnumWindows(enumWind,NULL);//Win32 API是为C编程语言设计的。因此,回调仅作为指向独立函数的指针实现
< C++ >中,<强>非静态< /强>类方法有一个隐藏的<代码>这个参数。这就是为什么您的<代码> DigTxxHoo::/Cux>类方法与<代码>枚举窗口()/<代码>不兼容的原因:它的签名与“代码> >枚举窗口())/代码>期望回调函数不匹配。
另一方面,静态类方法没有隐藏的此
参数。因此,可以对Win32回调函数使用静态类方法
无论您使用的是独立函数还是静态类方法,lParam
参数都可以用于将指向DirectX_Hook
对象的指针,或者至少是指向其内部窗口
成员的指针传递到回调中
例如,使用静态类方法:
class DirectX\u Hook
{
公众:
静态布尔回调(HWND句柄、LPARAM lp);
HWND GetProcessWindow();
//其他与您无关的功能。
}
外部直接X_钩DX_钩;
DirectX\u Hook DX\u Hook;
BOOL回调DirectX_Hook::enumWind(HWND句柄,LPARAM lp)
{
德沃德·普罗西德;
GetWindowThreadProcessId(句柄和进程ID);
如果(GetCurrentProcessId()!=ProcID)
返回TRUE;
重新解释铸造(lp)->窗口=手柄;
返回FALSE;
}
HWND DirectX_Hook::GetProcessWindow()
{
窗口=空;
EnumWindows(enumWind,重新解释(此));
直肠大小;
GetWindowRect(窗口和大小);
windowSize.x=size.right-size.left;
windowSize.y=size.bottom-size.top;
返回窗口;
}
或者,使用独立功能:
class DirectX\u Hook
{
公众:
HWND GetProcessWindow();
//其他与您无关的功能。
}
外部直接X_钩DX_钩;
DirectX\u Hook DX\u Hook;
静态布尔回调枚举风(HWND句柄,LPARAM lp)
{
德沃德·普罗西德;
GetWindowThreadProcessId(句柄和进程ID);
如果(GetCurrentProcessId()!=ProcID)
返回TRUE;
*重新解释铸型=手柄;
返回FALSE;
}
HWND DirectX_Hook::GetProcessWindow()
{
窗口=空;
EnumWindows(enumWind、重新解释强制转换(&window));
直肠大小;
GetWindowRect(窗口和大小);
windowSize.x=size.right-size.left;;
windowSize.y=size.bottom-size.top;
返回窗口;
}
Win32 API是为C编程语言设计的。因此,回调仅作为指向独立函数的指针实现
< C++ >中,<强>非静态< /强>类方法有一个隐藏的<代码>这个参数。这就是为什么您的<代码> DigTxxHoo::/Cux>类方法与<代码>枚举窗口()/<代码>不兼容的原因:它的签名与“代码> >枚举窗口())/代码>期望回调函数不匹配。
另一方面,静态类方法没有隐藏的此
参数。因此,可以对Win32回调函数使用静态类方法
无论您使用的是独立函数还是静态类方法,lParam
参数都可以用于将指向DirectX_Hook
对象的指针,或者至少是指向其内部窗口
成员的指针传递到回调中
例如,使用静态类方法:
class DirectX\u Hook
{
公众:
静态布尔回调(HWND句柄、LPARAM lp);
HWND GetProcessWindow();
//其他与您无关的功能。
}
外部直接X_钩DX_钩;
DirectX\u Hook DX\u Hook;
BOOL回调DirectX_Hook::enumWind(HWND句柄,LPARAM lp)
{
德沃德·普罗西德;
GetWindowThreadProcessId(句柄和进程ID);
如果(GetCurrentProcessId()!=ProcID)
返回TRUE;
重新解释铸造(lp)->窗口=手柄;
返回FALSE;
}
HWND DirectX_Hook::GetProcessWindow()
{
窗口=空;
EnumWindows(enumWind,重新解释(此));
直肠大小;
GetWindowRect(窗口和大小);
windowSize.x=size.right-size.left;
windowSize.y=size.bottom-size.top;
返回窗口;
}
或者,使用独立功能:
class DirectX\u Hook
{
公众:
HWND GetProcessWindow();
//其他与您无关的功能。
}
外部直接X_钩DX_钩;
DirectX\u Hook DX\u Hook;
静态布尔回调枚举风(HWND句柄,LPARAM lp)
{
德沃德·普罗西德;
GetWindowThreadProcessId(句柄和进程ID);
如果(GetCurrentProcessId()!=ProcID)
返回TRUE;
*重新解释铸型=手柄;
返回FALSE;
}
HWND DirectX_Hook::GetProcessWindow()
{
窗口=空;
EnumWindows(enumWind、重新解释强制转换(&window));
直肠大小;
GetWindowRect(窗口和大小);
windowSize.x=size.right-size.left;;
windowSize.y=size.bottom-size.top;
返回窗口;
}
类型的参数与类型的参数不兼容-但这是真的。这两个函数的签名不匹配。您需要使用静态函数并通过lParam@RbMm它是