import ctypes
from win32com.client import Dispatch
from comtypes.client import CreateObject
class DM:
def __init__(self, DmRegDllPath: str, dmDllPath: str):
"""
用于初始化大漠对象
:param DmRegDllPath: str,DmRegDll路径
:param dmDllPath: str,dmDll路径
"""
# print('欢迎使用Python大漠类库\n', 'Ver:1.0.0\n', 'By:奋斗吧〆少年°')
try:
dm = Dispatch('dm.dmsoft')
print('本机系统中已安装大漠插件')
except:
print('本机并未安装大漠插件,使用指定路径DLL进行初始化')
dms = ctypes.windll.LoadLibrary(DmRegDllPath)
location_dmreg = dmDllPath
dms.SetDllPathW(location_dmreg, 0)
dm = CreateObject('dm.dmsoft')
if dm:
self.dm = dm
print('初始化大漠成功,版本为:', self.Ver(), ',ID:', self.GetID())
else:
print('初始化大漠失败!')
# Foobar
if 1:
def CreateFoobarCustom(self, hwnd: int, x: int, y: int, pic_name: str, trans_color: str, sim: float):
"""
根据指定的位图创建一个自定义形状的窗口
:param hwnd: int,指定的窗口句柄,如果此值为0,那么就在桌面创建此窗口
:param x: int,左上角X坐标(相对于hwnd客户区坐标)
:param y: int,左上角Y坐标(相对于hwnd客户区坐标)
:param pic_name: str,位图名字. 如果第一个字符是@,则采用指针方式. @后面是指针地址和大小. 必须是十进制
:param trans_color: str,透明色(RRGGBB)
:param sim: float,透明色的相似值 0.1-1.0
:return: int,创建成功的窗口句柄
"""
return self.dm.CreateFoobarCustom(hwnd, x, y, pic_name, trans_color, sim)
def CreateFoobarEllipse(self, hwnd, x, y, w, h): # 创建一个椭圆窗口.
return self.dm.CreateFoobarEllipse(hwnd, x, y, w, h)
def CreateFoobarRect(self, hwnd, x, y, w, h): # 创建一个矩形窗口.
return self.dm.CreateFoobarRect(hwnd, x, y, w, h)
def CreateFoobarRoundRect(self, hwnd, x, y, w, h, rw, rh): # 创建一个圆角矩形窗口.
return self.dm.CreateFoobarRoundRect(hwnd, x, y, w, h, rw, rh)
def FoobarClearText(self, hwnd): # 清除指定的Foobar滚动文本区
return self.dm.FoobarClearText(hwnd)
def FoobarClose(self, hwnd): # 关闭一个Foobar,注意,必须调用此函数来关闭窗口,用SetWindowState也可以关闭,但会造成内存泄漏.
return self.dm.FoobarClose(hwnd)
def FoobarDrawLine(self, hwnd, x1, y1, x2, y2, color, style, width): # 在指定的Foobar窗口内部画线条.
return self.dm.FoobarDrawLine(hwnd, x1, y1, x2, y2, color, style, width)
def FoobarDrawPic(self, hwnd, x, y, pic_name, trans_color): # 在指定的Foobar窗口绘制图像
return self.dm.FoobarDrawPic(hwnd, x, y, pic_name, trans_color)
# 窗口
if 1:
def ClientToScreen(self, hwnd, x, y): # 把窗口坐标转换为屏幕坐标
return self.dm.ClientToScreen(hwnd, x, y)
def EnumProcess(self, name): # 根据指定进程名,枚举系统中符合条件的进程PID,并且按照进程打开顺序排序
return self.dm.EnumProcess(name)
def EnumWindow(self, parent, title, class_name, filter): # 根据指定条件,枚举系统中符合条件的窗口,可以枚举到按键自带的无法枚举到的窗口
return self.dm.EnumWindow(parent, title, class_name, filter)
def EnumWindowByProcess(self, process_name, title, class_name,
filter): # 根据指定进程以及其它条件,枚举系统中符合条件的窗口,可以枚举到按键自带的无法枚举到的窗口
return self.dm.EnumWindowByProcess(process_name, title, class_name, filter)
def EnumWindowByProcessId(self, pid, title, class_name,
filter): # 根据指定进程pid以及其它条件,枚举系统中符合条件的窗口,可以枚举到按键自带的无法枚举到的窗口
return self.dm.EnumWindowByProcessId(pid, title, class_name, filter)
# 基本设置
if 1:
def EnablePicCache(self, enable): # 设置是否开启或者关闭插件内部的图片缓存机制. (默认是打开).
return self.dm.EnablePicCache(enable)
def GetBasePath(self): # 获取注册在系统中的dm.dll的路径.
return self.dm.GetBasePath()
def GetDmCount(self): # 返回当前进程已经创建的dm对象个数.
return self.dm.GetDmCount()
def GetID(self): # 返回当前大漠对象的ID值,这个值对于每个对象是唯一存在的。可以用来判定两个大漠对象是否一致.
return self.dm.GetID()
def GetLastError(self): # 获取插件命令的最后错误.
return self.dm.GetLastError()
def GetPath(self): # 获取全局路径.(可用于调试)
return self.dm.GetPath()
def Reg(self, reg_code, ver_info): # 调用此函数来注册,从而使用插件的高级功能.推荐使用此函数.
return self.dm.Reg(reg_code, ver_info)
def RegEx(self, reg_code, ver_info, ip): # 调用此函数来注册,从而使用插件的高级功能. 可以根据指定的IP列表来注册. 新手不建议使用!
return self.dm.RegEx(reg_code, ver_info, ip)
def RegExNoMac(self, reg_code, ver_info,
ip): # 调用此函数来注册,从而使用插件的高级功能. 可以根据指定的IP列表来注册.新手不建议使用! 此函数同RegEx函数的不同在于,此函数用于注册的机器码是不带mac地址的.
return self.dm.RegExNoMac(reg_code, ver_info, ip)
def RegNoMac(self, reg_code,
ver_info): # 调用此函数来注册,从而使用插件的高级功能.推荐使用此函数. 新手不建议使用! 此函数同Reg函数的不同在于,此函数用于注册的机器码是不带mac地址的.
return self.dm.RegNoMac(reg_code, ver_info)
def SetDisplayInput(self, mode): # 设定图色的获取方式,默认是显示器或者后台窗口(具体参考BindWindow)
return self.dm.SetDisplayInput(mode)
def SetEnumWindowDelay(self,
delay): # 设置EnumWindow EnumWindowByProcess EnumWindowSuper FindWindow以及FindWindowEx的最长延时. 内部默认超时是10秒.
return self.dm.SetEnumWindowDelay(delay)
def SetPath(self, path): # 设置全局路径,设置了此路径后,所有接口调用中,相关的文件都相对于此路径. 比如图片,字库等.
return self.dm.SetPath(path)
def SetShowErrorMsg(self, show): # 设置是否弹出错误信息,默认是打开.
return self.dm.SetShowErrorMsg(show)
def SpeedNormalGraphic(self, enable): # 设置是否对前台图色进行加速. (默认是关闭). (对于不绑定,或者绑定图色为normal生效)( 仅对WIN8以上系统有效)
return self.dm.SpeedNormalGraphic(enable)
def Ver(self): # 返回当前插件版本号
return self.dm.Ver()
# 图色
if 1:
def CaptureJpg(self, x1: int, y1: int, x2: int, y2: int, file: str, quality: int):
"""
抓取指定区域(x1, y1, x2, y2)的图像,保存为file(JPG压缩格式)
:param x1: int,区域的左上X坐标
:param y1:
:param x2:
:param y2:
:param file:
:param quality:
:return:
"""
return self.dm.CaptureJpg(x1, y1, x2, y2, file, quality)
# 后台设置
if 1:
def BindWindowEx(self, hwnd: int, display: str, mouse: str, keypad: str, public: str, mode: int):
"""
绑定指定的窗口,并指定这个窗口的屏幕颜色获取方式,鼠标仿真模式,键盘仿真模式 高级用户使用.
:param hwnd:
:param display:
:param mouse:
:param keypad:
:param public:
:param mode:
:return:
"""
return self.dm.BindWindowEx(hwnd, display, mouse, keypad, public, mode)
def ForceUnBindWindow(self, hwnd: int):
"""
强制解除绑定窗口,并释放系统资源.
:param hwnd:
:return:
"""
return self.dm.ForceUnBindWindow(hwnd)
if __name__ == '__main__':
dm = DM(r'',
r'')
dm.Reg('', '') 版权属于:CuteKitty
本文链接:https://blog.cutekitty.cn/index.php/archives/9/
作品采用
知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议 进行许可