赞 | 2 |
VIP | 1 |
好人卡 | 40 |
积分 | 1 |
经验 | 93188 |
最后登录 | 2020-7-27 |
在线时间 | 1379 小时 |
Lv1.梦旅人
- 梦石
- 0
- 星屑
- 76
- 在线时间
- 1379 小时
- 注册时间
- 2012-7-5
- 帖子
- 1698
|
本帖最后由 kuerlulu 于 2013-12-13 12:56 编辑
截图脚本我以前玩过【雾。。
夏娜大大加了个防止多个RM一起运行导致获取窗口句柄出错的方法。【这句和上面一句没有必然联系- #==============================================================================
- # ■ Kernel
- #------------------------------------------------------------------------------
- # 该模块中定义了可供所有类使用的方法。Object 类中包含了该模块。
- #==============================================================================
- module Kernel
- #--------------------------------------------------------------------------
- # ● 需要的 Windows API 函数
- #--------------------------------------------------------------------------
- GetWindowThreadProcessId = Win32API.new("user32", "GetWindowThreadProcessId", "LP", "L")
- GetWindow = Win32API.new("user32", "GetWindow", "LL", "L")
- GetClassName = Win32API.new("user32", "GetClassName", "LPL", "L")
- GetCurrentThreadId = Win32API.new("kernel32", "GetCurrentThreadId", "V", "L")
- GetForegroundWindow = Win32API.new("user32", "GetForegroundWindow", "V", "L")
- #--------------------------------------------------------------------------
- # ● 获取窗口句柄
- #--------------------------------------------------------------------------
- def get_hWnd
- # 获取调用线程(RM 的主线程)的进程标识
- threadID = GetCurrentThreadId.call
- # 获取 Z 次序中最靠前的窗口
- hWnd = GetWindow.call(GetForegroundWindow.call, 0)
- # 枚举所有窗口
- while hWnd != 0
- # 如果创建该窗口的线程标识匹配本线程标识
- if threadID == GetWindowThreadProcessId.call(hWnd, 0)
- # 分配一个 11 个字节的缓冲区
- className = " " * 11
- # 获取该窗口的类名
- GetClassName.call(hWnd, className, 12)
- # 如果匹配 RGSS Player 则跳出循环
- break if className == "RGSS Player"
- end
- # 获取下一个窗口
- hWnd = GetWindow.call(hWnd, 2)
- end
- return hWnd
- end
- end
- #===============================================================================
- #===============================================================================
- # ■设置存放截图文件夹
- DIR = "Screenshot"
- Dir.mkdir("./#{DIR}") unless FileTest.exist?(DIR + "/")
- # 主模块 Screen API ★方法:Screen::shot★
- module Screen
- @i = 1 # 又要玩迭代了
- @screen = Win32API.new 'screenshot', 'Screenshot', %w(l l l l p l l), ''
- @readini = Win32API.new 'kernel32', 'GetPrivateProfileStringA', %w(p p p p l p), 'l'
- @findwindow = Win32API.new 'user32', 'FindWindowA', %w(p p), 'l'
- module_function
- def shot(file = "shot", typ = 1) # Screen::shot("save", 1)
- if typ == 0
- typname = ".bmp"
- elsif typ == 1
- typname = ".jpg"
- elsif typ == 2
- typname = ".png"
- end
- dir = DIR + "/"
- @i += 1 while FileTest.exist?(dir + file.to_s + @i.to_s + typname.to_s)
- file_name = dir + file.to_s + @i.to_s + typname.to_s # 生成带路径的文件名
- @screen.call(0,0,640,480, file_name, get_hWnd, typ) # call出截图
- end
- # def handel
- # game_name = "\0" * 256
- # @readini.call('Game','Title','',game_name,255,".\\Game.ini")
- # game_name.delete!("\0")
- # return @findwindow.call('RGSS Player',game_name)
- # end
- end
复制代码 |
|