Ruby win32-api GetFocus和GetWindowText
发布时间:2020-12-17 02:03:51 所属栏目:百科 来源:网络整理
导读:我正试图找到一种获取当前窗口文本的方法. 所以使用win32-api gem我使用 this page的一些帮助编写了这段代码 require 'win32/api'include Win32hWnd = GetActiveWindow = API.new('GetActiveWindow','V','L','user32').callGetWindowText = API.new('GetWind
我正试图找到一种获取当前窗口文本的方法.
所以使用win32-api gem我使用 this page的一些帮助编写了这段代码 require 'win32/api' include Win32 hWnd = GetActiveWindow = API.new('GetActiveWindow','V','L','user32').call GetWindowText = API.new('GetWindowText','LPI','I','user32') GetWindowTextLength = API.new('GetWindowTextLength','user32') buf_len = GetWindowTextLength.call(hwnd) str = ' ' * (buf_len + 1) # Retreive the text. result = GetWindowText.call(hwnd,str,str.length) puts str.strip 输出只是一个空字符串,因为由于hwnd设置为0,buf_len总是计算为0. 解决方法
如前所述,GetActiveWindow只会检索附加到调用线程的消息队列的窗口.如果您想获取用户当前窗口的句柄,而不管它在哪个进程中运行,请尝试调用
GetForegroundWindow而不是GetActiveWindow.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |