Skip to content

Commit

Permalink
cleanup Struct code
Browse files Browse the repository at this point in the history
  • Loading branch information
rdp committed Jul 2, 2010
1 parent ffecdb8 commit 1aadb5e
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions lib/win32/screenshot/bitmap_maker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,13 @@ module BitmapMaker #:nodoc:all


EnumWindowCallback = Proc.new do |hwnd, param|
got = SimpleStruct.new param
got = NameAndHwndStruct.new param

print 'in enum', param, 'searching for',got[:window_title_pointer].read_string, got, 'name is', got[:window_title_pointer].read_string, "\n"
title_length = window_text_length(hwnd) + 1
title = FFI::MemoryPointer.new :char, title_length
window_text(hwnd, title, title_length)
title = title.read_string
if title =~ Regexp.new(got[:window_title_pointer].read_string) && window_visible(hwnd)
puts 'match, writing', hwnd, 'to', param
got[:hwnd] = hwnd
false
else
Expand All @@ -83,7 +81,7 @@ module BitmapMaker #:nodoc:all

module_function

class SimpleStruct < FFI::Struct
class NameAndHwndStruct < FFI::Struct
layout :window_title_pointer, :pointer,
:hwnd, :long
end
Expand All @@ -92,17 +90,12 @@ def hwnd(window_title)
original_title=window_title
window_title = window_title.to_s
window_params = FFI::MemoryPointer.from_string(window_title)
window_struct = SimpleStruct.new
window_struct = NameAndHwndStruct.new
window_struct[:window_title_pointer] = window_params
p 'passing params as ', window_struct, window_struct.to_ptr
enum_windows(EnumWindowCallback, window_struct.to_ptr)
p 'got', window_struct[:hwnd]
if window_struct[:hwnd] != 0
# hwnd found
puts 'success...'
hwnd = window_struct[:hwnd] # reads a long
puts 'success!', hwnd, 'now is', window_title, 'was', original_title
hwnd
window_struct[:hwnd] # reads a long
else
nil
end
Expand Down

0 comments on commit 1aadb5e

Please sign in to comment.