カテゴリー
Wiki内検索
*
最近更新したページ
最新コメント
win32/guitest by stunning seo guys
FrontPage by stunning seo guys
SWIG by awesome things!
Win32/Console by stunning seo guys
FrontPage by awesome things!
Win32SDK_ICM by stunning seo guys
Win32SDK_MM by check it out
Win32SDK_process by stunning seo guys
VisualuRuby by stunning seo guys

ruby-dl2/ウィンドウを列挙

ruby-dl2

ウィンドウを列挙


タイトルを表示してみる

require 'dl/import'
require 'dl/types'

module Win32SDK
  extend DL::Importer
  dlload "user32.dll"
  
  include DL::Win32Types
  typealias("LPARAM", "long")
  typealias("WNDENUMPROC", "void *")
  
  GW_HWNDFIRST        = 0
  GW_HWNDLAST         = 1
  GW_HWNDNEXT         = 2
  GW_HWNDPREV         = 3
  GW_OWNER            = 4
  GW_CHILD            = 5
  extern "HWND GetWindow(HWND, UINT)", :stdcall
  
  extern "BOOL EnumWindows(WNDENUMPROC, LPARAM)", :stdcall
  extern "BOOL EnumChildWindows(HWND, WNDENUMPROC, LPARAM)", :stdcall
  extern "int GetWindowTextA(HWND, LPSTR, int)", :stdcall
  extern "int GetClassNameA(HWND, LPSTR, int)", :stdcall
  extern "BOOL IsWindowVisible(HWND)", :stdcall
  WndEnumProcWithCall = bind("BOOL wnd_enum_proc_with_call(HWND, LPARAM)", :stdcall) {|hwnd, obj_id|
    ret = 0 # BOOL
    begin
      obj = ObjectSpace._id2ref(obj_id)
      if obj.respond_to?(:call) then
        r = obj.call(hwnd)
        ret = (r == 0) ? 0 : 1
      end
    rescue
    end
    
    ret
  }
end

a = []
def a.call(hwnd)
  self.push(hwnd)
  1
end

if Win32SDK.EnumWindows(Win32SDK::WndEnumProcWithCall, a.__id__) != 0 then
  a.each {|hwnd|
    if Win32SDK.IsWindowVisible(hwnd) != 0 then
      if Win32SDK.GetWindow(hwnd, Win32SDK::GW_OWNER) ==0 then
        title = "\0" * 512
        Win32SDK.GetWindowTextA(hwnd, title, title.size)
        title.strip!
        if not title.empty? then
          classname = "\0" * 512
          Win32SDK.GetClassNameA(hwnd, classname, classname.size)
          classname.strip!
          puts title if classname != 'Progman'
        end
      end
    end
  }
end
2006年09月20日(水) 17:24:43 Modified by aqualung




スマートフォン版で見る