I don't know why I get these two errors when I run the code. error: argument of type 'BOOL (Movement::)(HWND__, LPARAM)' does not match 'BOOL ()(HWND__*, LPARAM)' error: argument of type 'BOOL (Movement::)(HWND__, LPARAM)' does not match 'BOOL ()(HWND__*, LPARAM)'
The cpp file is this:
#include "movement.h"
#include <windows.h>
#include <tchar.h>
#include <iostream>
using namespace std;
#pragma comment(lib, "user32.lib")
Movement::Movement()
{
xLoc = 10;
yLoc = 50;
while(true){
windowHandle = NULL;
EnumWindows(MyEnumProc, 0);
MoveWindow(windowHandle, getXLoc(), getYLoc(), 1220, 930, false);
Sleep(5);
}
}
BOOL CALLBACK Movement::MyEnumProc(HWND hWnd, LPARAM lParam)
{
TCHAR title[500];
ZeroMemory(title, sizeof(title));
//string strTitle;
GetWindowText(hWnd, title, sizeof(title)/sizeof(title[0]));
//_tprintf(_T("Found window: %s\n"), title);
//strTitle += title; // Convert to std::string
if(_tcsstr(title, _T("Firefox")))
{
windowHandle = hWnd;
return FALSE;
}
return TRUE;
}
int Movement::getXLoc(){
if(xLoc<70&&yLoc<=30){
xLoc += 1;
Sleep(10);
}else if(yLoc>30){
xLoc -= 1;
Sleep(10);
}
return xLoc;
}
int Movement::getYLoc(){
if(yLoc>10&&xLoc<30){
yLoc -= 1;
Sleep(10);
}else if(xLoc>=30&&yLoc<70){
yLoc += 1;
Sleep(10);
}
return yLoc;
}
This is the Header File:
#ifndef MOVEMENT_H
#define MOVEMENT_H
#include <windows.h>
#include <iostream>
using namespace std;
class Movement
{
public:
Movement();
protected:
HWND windowHandle;
BOOL CALLBACK MyEnumProc(HWND hWnd, LPARAM lParam);
int xLoc;
int yLoc;
int getXLoc();
int getYLoc();
};
#endif // MOVEMENT_H
The problem here is that EnumWindows
is expecting a WNDENUMPROC
parameter which is a typedef for
BOOL (*)(HWND, LPARAM);
In your code sample MyEnumProc
has the type
BOOL (Movement::*)(HWND, LPARAM);
The difference exists because it is an instance method on Movement
. To fix this you need to make MyEnumProc
a static method
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments