[Win32utils-devel] [ win32utils-Support Requests-23395 ] EnumChildWindows and EnumWindowsProc with win32-api-1.2.2

noreply at rubyforge.org noreply at rubyforge.org
Wed Dec 31 05:15:00 EST 2008


Support Requests item #23395, was opened at 2008-12-31 05:15
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=412&aid=23395&group_id=85

Category: win32-api
Group: None
Status: Open
Resolution: None
Priority: 3
Submitted By: Nobody (None)
Assigned to: Nobody (None)
Summary: EnumChildWindows and EnumWindowsProc with win32-api-1.2.2

Initial Comment:
My program doesn't work normally with win32-api-1.2.2.
There was no problem with win32-api-1.2.0.

At EnumChildWindows.call(), lparam in EnumWindowsProc is not correct.


# my program

require 'win32/api'

class SimpleWindow
  GetWindowText = Win32::API.new('GetWindowText', 'LPI', 'I', 'user32')
  GetClassName = Win32::API.new('GetClassName', 'LPI', 'I', 'user32')

  EnumWindows = Win32::API.new('EnumWindows', 'KL', 'L', 'user32')
  EnumChildWindows = Win32::API.new('EnumChildWindows', 'LKL', 'L', 'user32')

  EnumWindowsProc = Win32::API::Callback.new('LL', 'I') {|hwnd, lparam|
    begin
      block = ObjectSpace._id2ref(lparam)
      if block.respond_to? :call
        block.call(SimpleWindow.new(hwnd)) == :break ? 0 : 1
      else
        0
      end
    rescue
      warn $!
      0
    end
  }
  
  TMP = ("\0" * 256).freeze
  
  def self.each(&block)
    EnumWindows.call(EnumWindowsProc, block.__id__)
  end
  
  def initialize(hwnd)
    @hwnd = hwnd
  end
  
  def each(&block)
    EnumChildWindows.call(@hwnd, EnumWindowsProc, block.__id__)
  end
  
  def caption
    tmp = TMP.dup
    GetWindowText.call(@hwnd, tmp, tmp.size-1)
    tmp.rstrip
  end
  
  def class_name
    tmp = TMP.dup
    len = GetClassName.call(@hwnd, tmp, tmp.size-1)
    tmp.rstrip
  end
end

p Win32::API::VERSION
SimpleWindow.each {|win|
  if win.class_name == 'Shell_TrayWnd'
    win.each {|cwin|
      p [cwin.caption, cwin.class_name]
    }
    next :break
  end
}


----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=412&aid=23395&group_id=85


More information about the win32utils-devel mailing list