Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加FindPicS,给BindWindow增加了try #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/libop/com/op_i.h")
endif()
## swig 项目
if(build_swig_py)
add_subdirectory("swig")
#add_subdirectory("swig")
endif()


36 changes: 36 additions & 0 deletions CMakeSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,42 @@
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": ""
},
{
"name": "x64-Release",
"generator": "Ninja",
"configurationType": "Release",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"inheritEnvironments": [ "msvc_x64_x64" ],
"variables": []
},
{
"name": "x86-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"inheritEnvironments": [ "msvc_x86" ],
"variables": []
},
{
"name": "x86-Release",
"generator": "Ninja",
"configurationType": "Release",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"inheritEnvironments": [ "msvc_x86" ],
"variables": []
}
]
}
4 changes: 3 additions & 1 deletion include/libop.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,10 @@ class OP_API libop{
void FindMultiColor(long x1, long y1, long x2, long y2, const wchar_t* first_color, const wchar_t* offset_color, double sim, long dir, long* x, long* y, long* ret);
//根据指定的多点查找所有颜色坐标
void FindMultiColorEx(long x1, long y1, long x2, long y2, const wchar_t* first_color, const wchar_t* offset_color, double sim, long dir,std::wstring& retstr);
//查找指定区域内的图片
//查找指定区域内的图片,返回图片索引
void FindPic(long x1,long y1,long x2,long y2,const wchar_t* files, const wchar_t* delta_color,double sim,long dir,long* x,long* y,long* ret);
//查找指定区域内的图片,返回图片名
void FindPicS(long x1, long y1, long x2, long y2, const wchar_t* files, const wchar_t* delta_color, double sim, long dir, long* x, long* y, std::wstring& retstr);
//查找多个图片
void FindPicEx(long x1, long y1, long x2, long y2, const wchar_t* files, const wchar_t* delta_color, double sim, long dir,std::wstring& retstr);
//
Expand Down
1 change: 1 addition & 0 deletions libop/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ SET(SRC_FILES
"./winapi/winapi.cpp"
"../3rd_party/src/kiero.cpp"
"libop.cpp"
"libopExport.cpp"
)

SET(COM_SRC_FILES
Expand Down
209 changes: 109 additions & 100 deletions libop/background/opBackground.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,115 +34,124 @@ opBackground::~opBackground()

long opBackground::BindWindow(long hwnd, const wstring &sdisplay, const wstring &smouse, const wstring &skeypad, long mode)
{
//step 1.避免重复绑定
UnBindWindow();

HWND hWnd = hwnd == 0 ? GetDesktopWindow() : HWND(hwnd);
//step 2.check hwnd
if (!::IsWindow(hWnd))
try
{
setlog("Invalid window handles");
return 0;
}
//step 1.避免重复绑定
UnBindWindow();

HWND hWnd = hwnd == 0 ? GetDesktopWindow() : HWND(hwnd);
//step 2.check hwnd
if (!::IsWindow(hWnd))
{
setlog("Invalid window handles");
return 0;
}

int display, mouse, keypad;
//step 3.check display... mode
if (sdisplay == L"normal")
display = RDT_NORMAL;
else if (sdisplay == L"normal.dxgi")
display = RDT_NORMAL_DXGI;
int display, mouse, keypad;
//step 3.check display... mode
if (sdisplay == L"normal")
display = RDT_NORMAL;
else if (sdisplay == L"normal.dxgi")
display = RDT_NORMAL_DXGI;
#ifdef _WIN32_WINNT_WIN11
else if (sdisplay == L"normal.wgc")
display = RDT_NORMAL_WGC;
else if (sdisplay == L"normal.wgc")
display = RDT_NORMAL_WGC;
#endif
else if (sdisplay == L"gdi")
display = RDT_GDI;
else if (sdisplay == L"gdi2")
display = RDT_GDI2;
else if (sdisplay == L"dx2")
display = RDT_GDI_DX2;
else if (sdisplay == L"dx")
display = RDT_DX_DEFAULT;
else if (sdisplay == L"dx.d3d9")
display = RDT_DX_D3D9;
else if (sdisplay == L"dx.d3d10")
display = RDT_DX_D3D10;
else if (sdisplay == L"dx.d3d11")
display = RDT_DX_D3D11;
else if (sdisplay == L"dx.d3d12")
display = RDT_DX_D3D12;
else if (sdisplay == L"opengl")
display = RDT_GL_DEFAULT;
else if (sdisplay == L"opengl.std")
display = RDT_GL_STD;
else if (sdisplay == L"opengl.nox")
display = RDT_GL_NOX;
else if (sdisplay == L"opengl.es")
display = RDT_GL_ES;
else if (sdisplay == L"opengl.fi")//glFinish
display = RDT_GL_FI;
else
{
setlog(L"error display mode: %s", sdisplay.c_str());
return 0;
}
//check mouse
if (smouse == L"normal")
mouse = INPUT_TYPE::IN_NORMAL;
else if (smouse == L"normal.hd")
mouse = INPUT_TYPE::IN_NORMAL2;
else if (smouse == L"windows")
mouse = INPUT_TYPE::IN_WINDOWS;
else if (smouse == L"dx")
mouse = INPUT_TYPE::IN_DX;
else
{
setlog(L"error mouse mode: %s", smouse.c_str());
return 0;
}
//check keypad
if (skeypad == L"normal")
keypad = INPUT_TYPE::IN_NORMAL;
else if (skeypad == L"normal.hd")
keypad = INPUT_TYPE::IN_NORMAL2;
else if (skeypad == L"windows")
keypad = INPUT_TYPE::IN_WINDOWS;
else
{
setlog(L"error keypad mode: %s", sdisplay.c_str());
return 0;
}
//step 4.init
_mode = mode;
_display = display;
_hwnd = hWnd;
set_display_method(L"screen");

//step 5. create instance
_pbkdisplay = createDisplay(display);
_bkmouse = createMouse(mouse);
_keypad = createKeypad(keypad);

if (!_pbkdisplay || !_bkmouse || !_keypad)
{
setlog("create instance error!");
UnBindWindow();
return 0;
else if (sdisplay == L"gdi")
display = RDT_GDI;
else if (sdisplay == L"gdi2")
display = RDT_GDI2;
else if (sdisplay == L"dx2")
display = RDT_GDI_DX2;
else if (sdisplay == L"dx")
display = RDT_DX_DEFAULT;
else if (sdisplay == L"dx.d3d9")
display = RDT_DX_D3D9;
else if (sdisplay == L"dx.d3d10")
display = RDT_DX_D3D10;
else if (sdisplay == L"dx.d3d11")
display = RDT_DX_D3D11;
else if (sdisplay == L"dx.d3d12")
display = RDT_DX_D3D12;
else if (sdisplay == L"opengl")
display = RDT_GL_DEFAULT;
else if (sdisplay == L"opengl.std")
display = RDT_GL_STD;
else if (sdisplay == L"opengl.nox")
display = RDT_GL_NOX;
else if (sdisplay == L"opengl.es")
display = RDT_GL_ES;
else if (sdisplay == L"opengl.fi")//glFinish
display = RDT_GL_FI;
else
{
setlog(L"error display mode: %s", sdisplay.c_str());
return 0;
}
//check mouse
if (smouse == L"normal")
mouse = INPUT_TYPE::IN_NORMAL;
else if (smouse == L"normal.hd")
mouse = INPUT_TYPE::IN_NORMAL2;
else if (smouse == L"windows")
mouse = INPUT_TYPE::IN_WINDOWS;
else if (smouse == L"dx")
mouse = INPUT_TYPE::IN_DX;
else
{
setlog(L"error mouse mode: %s", smouse.c_str());
return 0;
}
//check keypad
if (skeypad == L"normal")
keypad = INPUT_TYPE::IN_NORMAL;
else if (skeypad == L"normal.hd")
keypad = INPUT_TYPE::IN_NORMAL2;
else if (skeypad == L"windows")
keypad = INPUT_TYPE::IN_WINDOWS;
else
{
setlog(L"error keypad mode: %s", sdisplay.c_str());
return 0;
}
//step 4.init
_mode = mode;
_display = display;
_hwnd = hWnd;
set_display_method(L"screen");

//step 5. create instance
_pbkdisplay = createDisplay(display);
_bkmouse = createMouse(mouse);
_keypad = createKeypad(keypad);

if (!_pbkdisplay || !_bkmouse || !_keypad)
{
setlog("create instance error!");
UnBindWindow();
return 0;
}
//step 6.try bind
if (_pbkdisplay->Bind(hWnd, display) != 1 ||
_bkmouse->Bind(hWnd, mouse) != 1 ||
_keypad->Bind(hWnd, keypad) != 1)
{
UnBindWindow();
return 0;
}

//等待线程创建好
Sleep(200);

_is_bind = 1;
return 1;
}
//step 6.try bind
if (_pbkdisplay->Bind(hWnd, display) != 1 ||
_bkmouse->Bind(hWnd, mouse) != 1 ||
_keypad->Bind(hWnd, keypad) != 1)
catch (const std::exception& e)
{
setlog(e.what());
UnBindWindow();
return 0;
}

//等待线程创建好
Sleep(200);

_is_bind = 1;
return 1;
}

long opBackground::UnBindWindow()
Expand Down
15 changes: 15 additions & 0 deletions libop/com/OpInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,21 @@ STDMETHODIMP OpInterface::FindPic(LONG x1, LONG y1, LONG x2, LONG y2, BSTR files

return S_OK;
}

//查找指定区域内的图片
STDMETHODIMP OpInterface::FindPicS(LONG x1, LONG y1, LONG x2, LONG y2, BSTR files, BSTR delta_color, DOUBLE sim, LONG dir, VARIANT* x, VARIANT* y, BSTR* retstr)
{
wstring s;
x->vt = y->vt = VT_I4;

obj.FindPicS(x1, y1, x2, y2, files, delta_color, sim, dir, &x->lVal, &y->lVal, s);
CComBSTR newstr;
HRESULT hr;
newstr.Append(s.data());
hr = newstr.CopyTo(retstr);
return S_OK;
}

//查找多个图片
STDMETHODIMP OpInterface::FindPicEx(LONG x1, LONG y1, LONG x2, LONG y2, BSTR files, BSTR delta_color, DOUBLE sim, LONG dir, BSTR *retstr)
{
Expand Down
2 changes: 2 additions & 0 deletions libop/com/OpInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ END_COM_MAP()
STDMETHOD(FindMultiColorEx)(LONG x1, LONG y1, LONG x2, LONG y2, BSTR first_color, BSTR offset_color, DOUBLE sim, LONG dir,BSTR* retstr);
//查找指定区域内的图片
STDMETHOD(FindPic)(LONG x1,LONG y1,LONG x2,LONG y2,BSTR files, BSTR delta_color,DOUBLE sim,LONG dir,VARIANT* x,VARIANT* y,LONG* ret);
//查找指定区域内的图片,返回图片名
STDMETHOD(FindPicS)(LONG x1, LONG y1, LONG x2, LONG y2, BSTR files, BSTR delta_color, DOUBLE sim, LONG dir, VARIANT* x, VARIANT* y, BSTR* retstr);
//查找多个图片
STDMETHOD(FindPicEx)(LONG x1, LONG y1, LONG x2, LONG y2, BSTR files, BSTR delta_color, DOUBLE sim, LONG dir,BSTR* retstr);
//这个函数可以查找多个图片, 并且返回所有找到的图像的坐标.此函数同FindPicEx.只是返回值不同.(file1,x,y|file2,x,y|...)
Expand Down
Binary file added libop/com/RCa10852
Binary file not shown.
Binary file added libop/com/RCa46320
Binary file not shown.
1 change: 1 addition & 0 deletions libop/com/op.idl
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ interface IOpInterface : IDispatch
[id(176)] HRESULT Delays([in] LONG mis_min,[in] LONG mis_max, [out, retval] LONG* ret);
[id(177)] HRESULT KeyPressStr([in]BSTR key_str,[in]LONG delay,[out, retval] LONG* ret);
[id(178)] HRESULT GetColorNum([in] LONG x1, [in] LONG y1, [in] LONG x2, [in] LONG y2, [in] BSTR color, [in] DOUBLE sim, [out, retval]LONG* ret);
[id(179)] HRESULT FindPicS([in] LONG x1, [in]LONG y1, [in] LONG x2, [in] LONG y2, [in] BSTR files, [in] BSTR delta_color, [in] DOUBLE sim, [in] LONG dir, [out] VARIANT* x, [out] VARIANT* y, [out, retval] BSTR* retstr);

//ocr 200-230
[id(200)] HRESULT SetDict([in] LONG idx, [in] BSTR file_name, [out, retval] LONG* ret);
Expand Down
Binary file modified libop/com/op.rc
Binary file not shown.
4 changes: 2 additions & 2 deletions libop/core/globalVar.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
CloseHandle(h); \
h = NULL;
template <class Type>
void SAFE_DELETE(Type *&ptr)
void SAFE_DELETE(Type*& ptr)
{
delete ptr;
ptr = nullptr;
Expand Down Expand Up @@ -96,7 +96,7 @@ extern long MOUSE_DX_DELAY;

#define MAKE_OP_VERSION(a, b, c, d) _TOSTRING(a##.##b##.##c##.##d)

#define OP_VERSION MAKE_OP_VERSION(0, 4, 2, 0)
#define OP_VERSION MAKE_OP_VERSION(0, 5, 0, 7)
//模块句柄
//extern HINSTANCE gInstance;
//是否显示错误信息
Expand Down
19 changes: 19 additions & 0 deletions libop/core/helpfunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,25 @@ void split(const std::string& s, std::vector<std::string>& v, const std::string&
v.emplace_back(s.substr(pos1));
}

std::wstring SplitAndGetToken(const wchar_t* str, long index, wchar_t delimiter) {
std::wstring result;
if (str) {
std::wstring modifiableStr(str);
wchar_t* context = nullptr;
wchar_t* token = wcstok_s(const_cast<wchar_t*>(modifiableStr.c_str()), &delimiter, &context);
long currentTokenIndex = 0;
while (token != nullptr) {
if (currentTokenIndex == index) {
result = token;
break;
}
currentTokenIndex++;
token = wcstok_s(nullptr, &delimiter, &context);
}
}
return result;
}

void wstring2upper(std::wstring& s) {
std::transform(s.begin(), s.end(),s.begin(), towupper);
}
Expand Down
1 change: 1 addition & 0 deletions libop/core/helpfunc.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ long Path2GlobalPath(const std::wstring&file, const std::wstring& curr_path, std

void split(const std::wstring& s, std::vector<std::wstring>& v, const std::wstring& c);
void split(const std::string& s, std::vector<std::string>& v, const std::string& c);
std::wstring SplitAndGetToken(const wchar_t* str, long index, wchar_t delimiter);

void wstring2upper(std::wstring& s);
void string2upper(std::string& s);
Expand Down
Loading