From be935cd9c8fffd405a37146af59c41a326d637e5 Mon Sep 17 00:00:00 2001 From: wallbreaker2 <784942619@qq.com> Date: Mon, 5 Aug 2019 21:11:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=99=AE=E9=80=9Adll?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/libop.h | 237 ++++++++++++++++++++++++++++++++++++++++++ op/libop.cpp | 2 +- op/op.vcxproj | 5 +- op/op.vcxproj.filters | 9 ++ 4 files changed, 251 insertions(+), 2 deletions(-) create mode 100644 include/libop.h diff --git a/include/libop.h b/include/libop.h new file mode 100644 index 0000000..80e6820 --- /dev/null +++ b/include/libop.h @@ -0,0 +1,237 @@ +// OpInterface.h: OpInterface 的声明 + +#pragma once + +#include +#include + +class WinApi; +class bkbase; +class ImageProc; + + +#if defined(OP_EXPORTS) +#define OP_API __declspec(dllexport) +#else +#define OP_API __declspec(dllimport) +#endif +// libop + +class OP_API op{ +public: + op(); + ~op(); + +private: + //一些共用变量 + + //1. Windows API + WinApi* _winapi; + // background module + bkbase* _bkproc; + //image process + ImageProc* _image_proc; + // work path + std::wstring _curr_path; + + std::map _vkmap; +public: + //---------------基本设置/属性------------------- + + //1.版本号Version + long Ver(std::wstring& ret); + //设置目录 + long SetPath(const wchar_t* path, long* ret); + //获取目录 + long GetPath(std::wstring&path); + //获取插件目录 + long GetBasePath(std::wstring& path); + //设置是否弹出错误信息,默认是打开 0为关闭,1为显示为信息框,2为保存到文件 + long SetShowErrorMsg(long show_type, long* ret); + + //sleep + long Sleep(long millseconds, long* ret); + //Process + //inject dll + long InjectDll(const wchar_t* process_name,const wchar_t* dll_name, long* ret); + //设置是否开启或者关闭插件内部的图片缓存机制 + long EnablePicCache(long enable, long* ret); + //---------------------algorithm------------------------------- + //A星算法 + long AStarFindPath(long mapWidth,long mapHeight,const wchar_t* disable_points,long beginX,long beginY, long endX,long endY,std::wstring& path); + //--------------------windows api------------------------------ + //根据指定条件,枚举系统中符合条件的窗口 + long EnumWindow(long parent, const wchar_t* title, const wchar_t* class_name, long filter, std::wstring& retstr); + //根据指定进程以及其它条件,枚举系统中符合条件的窗口 + long EnumWindowByProcess(const wchar_t* process_name, const wchar_t* title, const wchar_t* class_name, long filter, std::wstring& retstring); + //根据指定进程名,枚举系统中符合条件的进程PID + long EnumProcess(const wchar_t* name, std::wstring& retstring); + //把窗口坐标转换为屏幕坐标 + long ClientToScreen(long ClientToScreen, long* x, long* y, long* bret); + //查找符合类名或者标题名的顶层可见窗口 + long FindWindow(const wchar_t* class_name, const wchar_t* title, long* rethwnd); + //根据指定的进程名字,来查找可见窗口 + long FindWindowByProcess(const wchar_t* process_name, const wchar_t* class_name, const wchar_t* title, long* rethwnd); + //根据指定的进程Id,来查找可见窗口 + long FindWindowByProcessId(long process_id, const wchar_t* class_name, const wchar_t* title, long* rethwnd); + //查找符合类名或者标题名的顶层可见窗口,如果指定了parent,则在parent的第一层子窗口中查找 + long FindWindowEx(long parent, const wchar_t* class_name, const wchar_t* title, long* rethwnd); + //获取窗口客户区域在屏幕上的位置 + long GetClientRect(long hwnd, long* x1, long* y1, long* x2, long* y2, long* nret); + //获取窗口客户区域的宽度和高度 + long GetClientSize(long hwnd, long* width, long* height, long* nret); + //获取顶层活动窗口中具有输入焦点的窗口句柄 + long GetForegroundFocus(long* rethwnd); + //获取顶层活动窗口,可以获取到按键自带插件无法获取到的句柄 + long GetForegroundWindow(long* rethwnd); + //获取鼠标指向的可见窗口句柄 + long GetMousePointWindow(long* rethwnd); + //获取给定坐标的可见窗口句柄 + long GetPointWindow(long x, long y, long* rethwnd); + //根据指定的pid获取进程详细信息 + long GetProcessInfo(long pid, std::wstring& retstring); + //获取特殊窗口 + long GetSpecialWindow(long flag, long* rethwnd); + //获取给定窗口相关的窗口句柄 + long GetWindow(long hwnd, long flag, long* nret); + //获取窗口的类名 + long GetWindowClass(long hwnd, std::wstring& retstring); + //获取指定窗口所在的进程ID + long GetWindowProcessId(long hwnd, long* nretpid); + //获取指定窗口所在的进程的exe文件全路径 + long GetWindowProcessPath(long hwnd, std::wstring& retstring); + //获取窗口在屏幕上的位置 + long GetWindowRect(long hwnd, long* x1, long* y1, long* x2, long* y2, long* nret); + //获取指定窗口的一些属性 + long GetWindowState(long hwnd, long flag, long* rethwnd); + //获取窗口的标题 + long GetWindowTitle(long hwnd, std::wstring& rettitle); + //移动指定窗口到指定位置 + long MoveWindow(long hwnd, long x, long y, long* nret); + //把屏幕坐标转换为窗口坐标 + long ScreenToClient(long hwnd, long* x, long* y, long* nret); + //向指定窗口发送粘贴命令 + long SendPaste(long hwnd, long* nret); + //设置窗口客户区域的宽度和高度 + long SetClientSize(long hwnd, long width, long hight, long* nret); + //设置窗口的状态 + long SetWindowState(long hwnd, long flag, long* nret); + //设置窗口的大小 + long SetWindowSize(long hwnd, long width, long height, long* nret); + //设置窗口的标题 + long SetWindowText(long hwnd, const wchar_t* title, long* nret); + //设置窗口的透明度 + long SetWindowTransparent(long hwnd, long trans, long* nret); + //向指定窗口发送文本数据 + long SendString(long hwnd, const wchar_t* str, long* ret); + //向指定窗口发送文本数据-输入法 + long SendStringIme(long hwnd, const wchar_t* str, long* ret); + //运行可执行文件,可指定模式 + long RunApp(const wchar_t* cmdline, long mode, long* ret); + //运行可执行文件,可指定显示模式 + long WinExec(const wchar_t* cmdline, long cmdshow, long* ret); + + //运行命令行并返回结果 + long GetCmdStr(const wchar_t* cmd,long millseconds, std::wstring& retstr); + + //--------------------Background ----------------------- + //bind window and beign capture screen + long BindWindow(long hwnd, const wchar_t* display, const wchar_t* mouse, const wchar_t* keypad, long mode,long *ret); + // + long UnBindWindow(long* ret); + //--------------------mouse & keyboard------------------ + //获取鼠标位置. + long GetCursorPos(long* x, long* y, long* ret); + //鼠标相对于上次的位置移动rx,ry. + long MoveR(long x, long y, long* ret); + //把鼠标移动到目的点(x,y) + long MoveTo(long x, long y, long* ret); + //把鼠标移动到目的范围内的任意一点 + long MoveToEx(long x, long y,long w,long h, long* ret); + //按下鼠标左键 + long LeftClick(long* ret); + //双击鼠标左键 + long LeftDoubleClick(long* ret); + //按住鼠标左键 + long LeftDown(long* ret); + //弹起鼠标左键 + long LeftUp(long* ret); + //按下鼠标中键 + long MiddleClick(long* ret); + //按住鼠标中键 + long MiddleDown(long* ret); + //弹起鼠标中键 + long MiddleUp(long* ret); + //按下鼠标右键 + long RightClick(long* ret); + //按住鼠标右键 + long RightDown(long* ret); + //弹起鼠标右键 + long RightUp(long* ret); + //滚轮向下滚 + long WheelDown(long* ret); + //滚轮向上滚 + long WheelUp(long* ret); + //获取指定的按键状态.(前台信息,不是后台) + long GetKeyState(long vk_code, long* ret); + //按住指定的虚拟键码 + long KeyDown(long vk_code, long* ret); + //按住指定的虚拟键码 + long KeyDownChar(const wchar_t* vk_code, long* ret); + //弹起来虚拟键vk_code + long KeyUp(long vk_code, long* ret); + //弹起来虚拟键vk_code + long KeyUpChar(const wchar_t* vk_code, long* ret); + //等待指定的按键按下 (前台,不是后台) + long WaitKey(long vk_code,long time_out, long* ret); + //发送字符串 + //long SendString(long HWND) + //弹起来虚拟键vk_code + long KeyPress(long vk_code, long* ret); + long KeyPressChar(const wchar_t* vk_code, long* ret); + + //--------------------image and color----------------------- + //抓取指定区域(x1, y1, x2, y2)的图像, 保存为file + long Capture(long x1, long y1, long x2, long y2, const wchar_t* file_name, long* ret); + //比较指定坐标点(x,y)的颜色 + long CmpColor(long x, long y,const wchar_t* color,DOUBLE sim, long* ret); + //查找指定区域内的颜色 + long FindColor(long x1, long y1, long x2, long y2, const wchar_t* color,DOUBLE sim,long dir, long* x, long* y, long* ret); + //查找指定区域内的所有颜色 + long FindColorEx(long x1, long y1, long x2, long y2, const wchar_t* color, DOUBLE sim,long dir, std::wstring& retstr); + //根据指定的多点查找颜色坐标 + long 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); + //根据指定的多点查找所有颜色坐标 + long 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); + //查找指定区域内的图片 + long 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); + //查找多个图片 + long 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); + //获取(x,y)的颜色 + long GetColor(long x, long y, std::wstring& ret); + + //----------------------ocr------------------------- + //设置字库文件 + long SetDict(long idx, const wchar_t* file_name, long* ret); + //使用哪个字库文件进行识别 + long UseDict(long idx, long* ret); + //识别屏幕范围(x1,y1,x2,y2)内符合color_format的字符串,并且相似度为sim,sim取值范围(0.1-1.0), + long Ocr(long x1, long y1, long x2, long y2, const wchar_t* color, DOUBLE sim,std::wstring& ret_str); + //回识别到的字符串,以及每个字符的坐标. + long OcrEx(long x1, long y1, long x2, long y2, const wchar_t* color, DOUBLE sim, std::wstring& ret_str); + //在屏幕范围(x1,y1,x2,y2)内,查找string(可以是任意个字符串的组合),并返回符合color_format的坐标位置 + long FindStr(long x1, long y1, long x2, long y2,const wchar_t* strs, const wchar_t* color, DOUBLE sim, long* retx,long* rety,long* ret); + //返回符合color_format的所有坐标位置 + long FindStrEx(long x1, long y1, long x2, long y2, const wchar_t* strs, const wchar_t* color, DOUBLE sim,std::wstring& retstr); + //识别屏幕范围(x1,y1,x2,y2)内的字符串,自动二值化,而无需指定颜色 + long OcrAuto(long x1, long y1, long x2, long y2, DOUBLE sim, std::wstring& ret_str); + //从文件中识别图片 + long OcrFromFile(const wchar_t* file_name,const wchar_t* color_format, DOUBLE sim, std::wstring& retstr); + //从文件中识别图片,无需指定颜色 + long OcrAutoFromFile(const wchar_t* file_name, DOUBLE sim, std::wstring& retstr); + + +}; + + + diff --git a/op/libop.cpp b/op/libop.cpp index 34b1ca3..98abd96 100644 --- a/op/libop.cpp +++ b/op/libop.cpp @@ -61,7 +61,7 @@ op::~op() { long op::Ver(std::wstring& ret) { //Tool::setlog("address=%d,str=%s", ver, ver); - + ret = _T(OP_VERSION); return S_OK; } diff --git a/op/op.vcxproj b/op/op.vcxproj index c6b15dd..b34dd04 100644 --- a/op/op.vcxproj +++ b/op/op.vcxproj @@ -210,7 +210,8 @@ copy $(SolutionDir)doc\*.chm $(SolutionDir)bin\x86 /y copy $(SolutionDir)op\op_i.h $(SolutionDir)include\op.h /y -copy $(SolutionDir)op\op_i.c $(SolutionDir)include\op.c /y +copy $(SolutionDir)op\op_i.c $(SolutionDir)include\op.c /y +copy $(SolutionDir)op\libop.h $(SolutionDir)include\libop.h /y @@ -276,6 +277,7 @@ copy $(SolutionDir)op\op_i.c $(SolutionDir)include\op.c /y + @@ -323,6 +325,7 @@ copy $(SolutionDir)op\op_i.c $(SolutionDir)include\op.c /y + diff --git a/op/op.vcxproj.filters b/op/op.vcxproj.filters index 52bc738..8aa2c2a 100644 --- a/op/op.vcxproj.filters +++ b/op/op.vcxproj.filters @@ -77,6 +77,9 @@ {4b0c3175-3ca6-4736-ba45-3d277e788b5b} + + {cfd85035-dbb8-416c-9f11-e7ebb83ee607} + @@ -148,6 +151,9 @@ 3rd_party + + libop + @@ -237,6 +243,9 @@ 3rd_party + + libop +