Last active
November 26, 2015 11:08
-
-
Save smison/19815dff9470c61867df to your computer and use it in GitHub Desktop.
windowsでアクティブなウィンドウのタイトルを取得する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ gem install win32-api | |
※参考 http://stackoverflow.com/questions/14220386/ruby-win32-api-getfocus-and-getwindowtext | |
require 'win32/api' | |
include Win32 | |
while true do | |
hwnd = GetActiveWindow = API.new('GetForegroundWindow', 'V', 'L', 'user32').call | |
GetWindowText = API.new('GetWindowText', 'LPI', 'I', 'user32') | |
GetWindowTextLength = API.new('GetWindowTextLength', 'L', 'I', 'user32') | |
buf_len = GetWindowTextLength.call(hwnd) | |
str = ' ' * (buf_len + 1) | |
# Retreive the text. | |
result = GetWindowText.call(hwnd, str, str.length) | |
puts str.strip | |
sleep 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment