Class: Win32::Screenshot

Inherits:
Object
  • Object
show all
Defined in:
lib/win32/screenshot.rb,
lib/win32/util.rb,
lib/win32/screenshot/bitmap_maker.rb

Overview

Captures screenshots with Ruby on Windows

Defined Under Namespace

Classes: BitmapMaker, Util

Class Method Summary collapse

Class Method Details

.desktop(&proc) ⇒ Object

captures visible view of the screen

to make screenshot of the real desktop, all windows must be minimized before



28
29
30
31
# File 'lib/win32/screenshot.rb', line 28

def desktop(&proc)
  hwnd = BitmapMaker.desktop_window
  BitmapMaker.capture_all(hwnd, &proc)
end

.desktop_area(x1, y1, x2, y2, &proc) ⇒ Object

captures area of the visible view of the screen where x1 and y1 are 0 in the upper left corner and x2 specifies the width and y2 the height of the area to be captured

to make screenshot of the real desktop, all windows must be minimized before



39
40
41
42
43
# File 'lib/win32/screenshot.rb', line 39

def desktop_area(x1, y1, x2, y2, &proc)
  hwnd = BitmapMaker.desktop_window
  validate_coordinates(hwnd, x1, y1, x2, y2)
  BitmapMaker.capture_area(hwnd, x1, y1, x2, y2, &proc)
end

.foreground(&proc) ⇒ Object

captures foreground



10
11
12
13
# File 'lib/win32/screenshot.rb', line 10

def foreground(&proc)
  hwnd = BitmapMaker.foreground_window
  BitmapMaker.capture_all(hwnd, &proc)
end

.foreground_area(x1, y1, x2, y2, &proc) ⇒ Object

captures area of the foreground where x1 and y1 are 0 in the upper left corner and x2 specifies the width and y2 the height of the area to be captured



18
19
20
21
22
# File 'lib/win32/screenshot.rb', line 18

def foreground_area(x1, y1, x2, y2, &proc)
  hwnd = BitmapMaker.foreground_window
  validate_coordinates(hwnd, x1, y1, x2, y2)
  BitmapMaker.capture_area(hwnd, x1, y1, x2, y2, &proc)
end

.hwnd(hwnd, pause = 0.5, &proc) ⇒ Object

captures by window handle



61
62
63
64
# File 'lib/win32/screenshot.rb', line 61

def hwnd(hwnd, pause=0.5, &proc)
  BitmapMaker.prepare_window(hwnd, pause)
  BitmapMaker.capture_all(hwnd, &proc)
end

.hwnd_area(hwnd, x1, y1, x2, y2, pause = 0.5, &proc) ⇒ Object

captures area of the window with a handle of hwnd where x1 and y1 are 0 in the upper left corner and x2 specifies the width and y2 the height of the area to be captured



69
70
71
72
73
# File 'lib/win32/screenshot.rb', line 69

def hwnd_area(hwnd, x1, y1, x2, y2, pause=0.5, &proc)
  validate_coordinates(hwnd, x1, y1, x2, y2)
  BitmapMaker.prepare_window(hwnd, pause)
  BitmapMaker.capture_area(hwnd, x1, y1, x2, y2, &proc)
end

.window(title_query, pause = 0.5, &proc) ⇒ Object

captures window with a title_query and waits pause (by default is 0.5) seconds after trying to set window to the foreground



47
48
49
50
# File 'lib/win32/screenshot.rb', line 47

def window(title_query, pause=0.5, &proc)
  hwnd = Util.window_hwnd(title_query)
  hwnd(hwnd, pause, &proc)
end

.window_area(title_query, x1, y1, x2, y2, pause = 0.5, &proc) ⇒ Object

captures area of the window with a title_query where x1 and y1 are 0 in the upper left corner and x2 specifies the width and y2 the height of the area to be captured



55
56
57
58
# File 'lib/win32/screenshot.rb', line 55

def window_area(title_query, x1, y1, x2, y2, pause=0.5, &proc)
  hwnd = Util.window_hwnd(title_query)
  hwnd_area(hwnd, x1, y1, x2, y2, pause, &proc)
end