rdp-win32screenshot 0.0.6 → 0.0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.rdoc +1 -0
- data/VERSION +1 -1
- data/lib/win32/screenshot/bitmap_maker.rb +15 -1
- data/lib/win32/screenshot.rb +3 -3
- data/spec/win32_screenshot_spec.rb +19 -11
- metadata +3 -2
data/History.rdoc
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
= 0.0.6 2010-XX-XX
|
2
2
|
* Trying to bring window to the foreground more aggressively (Roger Pack)
|
3
|
+
* Minor bug fixes with using gdi32.dll BitBlt (Roger Pack)
|
3
4
|
|
4
5
|
= 0.0.5 2010-07-07
|
5
6
|
* Added method window_area for capturing specified area of the window instead of full window (Jarmo Pertman)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.6
|
1
|
+
0.0.6.1
|
@@ -76,7 +76,7 @@ module Win32
|
|
76
76
|
true
|
77
77
|
end
|
78
78
|
end
|
79
|
-
|
79
|
+
|
80
80
|
module_function
|
81
81
|
|
82
82
|
class WindowStruct < FFI::Struct
|
@@ -91,6 +91,20 @@ module Win32
|
|
91
91
|
enum_windows(EnumWindowCallback, window.to_ptr)
|
92
92
|
window[:hwnd] == 0 ? nil : window[:hwnd]
|
93
93
|
end
|
94
|
+
|
95
|
+
def list_window_titles
|
96
|
+
out = []
|
97
|
+
out_proc = Proc.new do |hwnd, param|
|
98
|
+
title_length = window_text_length(hwnd) + 1
|
99
|
+
title = FFI::MemoryPointer.new :char, title_length
|
100
|
+
window_text(hwnd, title, title_length)
|
101
|
+
out << title.read_string
|
102
|
+
true
|
103
|
+
end
|
104
|
+
|
105
|
+
enum_windows(out_proc, nil)
|
106
|
+
out
|
107
|
+
end
|
94
108
|
|
95
109
|
def prepare_window(hwnd, pause)
|
96
110
|
restore(hwnd) if minimized(hwnd)
|
data/lib/win32/screenshot.rb
CHANGED
@@ -82,16 +82,16 @@ module Win32
|
|
82
82
|
def validate_coordinates(hwnd, *coords)
|
83
83
|
specified_coordinates = coords.join(', ')
|
84
84
|
if coords.any? {|c| c < 0}
|
85
|
-
raise "specified coordinates (#{specified_coordinates}) are invalid
|
85
|
+
raise "specified coordinates (#{specified_coordinates}) are invalid - cannot be negative!"
|
86
86
|
end
|
87
87
|
x1, y1, x2, y2 = *coords
|
88
88
|
if x1 >= x2 || y1 >= y2
|
89
|
-
raise "specified coordinates (#{specified_coordinates}) are invalid
|
89
|
+
raise "specified coordinates (#{specified_coordinates}) are invalid - cannot have x1 > x2 or y1 > y2!"
|
90
90
|
end
|
91
91
|
|
92
92
|
x1_always_zero, y1_always_zero, max_x2, max_y2 = BitmapMaker.dimensions_for(hwnd)
|
93
93
|
if x2 > max_x2 || y2 > max_y2
|
94
|
-
raise "specified coordinates (#{specified_coordinates}) are invalid
|
94
|
+
raise "specified coordinates (#{specified_coordinates}) are invalid - maximum are x2=#{max_x2} and y2=#{max_y2}!"
|
95
95
|
end
|
96
96
|
end
|
97
97
|
end
|
@@ -4,12 +4,12 @@ describe "win32-screenshot" do
|
|
4
4
|
include SpecHelper
|
5
5
|
|
6
6
|
before :all do
|
7
|
-
cleanup
|
8
7
|
PROGRAM_FILES = "c:/program files/"
|
9
8
|
@notepad = IO.popen("notepad").pid
|
10
9
|
@iexplore = IO.popen(File.join(PROGRAM_FILES, "Internet Explorer", "iexplore about:blank")).pid
|
11
10
|
@calc = IO.popen("calc").pid
|
12
11
|
wait_for_programs_to_open
|
12
|
+
cleanup
|
13
13
|
end
|
14
14
|
|
15
15
|
it "captures foreground" do
|
@@ -32,7 +32,7 @@ describe "win32-screenshot" do
|
|
32
32
|
|
33
33
|
it "doesn't allow to capture area of the foreground with invalid coordinates" do
|
34
34
|
lambda {Win32::Screenshot.foreground_area(0, 0, -1, 100) {|width, height, bmp| check_image('foreground2')}}.
|
35
|
-
should raise_exception("specified coordinates (0, 0, -1, 100) are invalid
|
35
|
+
should raise_exception("specified coordinates (0, 0, -1, 100) are invalid - cannot be negative!")
|
36
36
|
end
|
37
37
|
|
38
38
|
it "captures desktop" do
|
@@ -55,7 +55,7 @@ describe "win32-screenshot" do
|
|
55
55
|
|
56
56
|
it "doesn't allow to capture area of the desktop with invalid coordinates" do
|
57
57
|
lambda {Win32::Screenshot.desktop_area(0, 0, -1, 100) {|width, height, bmp| check_image('desktop2')}}.
|
58
|
-
should raise_exception("specified coordinates (0, 0, -1, 100) are invalid
|
58
|
+
should raise_exception("specified coordinates (0, 0, -1, 100) are invalid - cannot be negative!")
|
59
59
|
end
|
60
60
|
|
61
61
|
it "captures maximized window by window title" do
|
@@ -120,25 +120,27 @@ describe "win32-screenshot" do
|
|
120
120
|
it "doesn't allow to capture area of the window with negative coordinates" do
|
121
121
|
title = /calculator/i
|
122
122
|
lambda {Win32::Screenshot.window_area(title, 0, 0, -1, 100) {|width, height, bmp| check_image('calc2')}}.
|
123
|
-
should raise_exception("specified coordinates (0, 0, -1, 100) are invalid
|
123
|
+
should raise_exception("specified coordinates (0, 0, -1, 100) are invalid - cannot be negative!")
|
124
124
|
end
|
125
125
|
|
126
126
|
it "doesn't allow to capture area of the window if coordinates are the same" do
|
127
127
|
title = /calculator/i
|
128
128
|
lambda {Win32::Screenshot.window_area(title, 10, 0, 10, 20) {|width, height, bmp| check_image('calc4')}}.
|
129
|
-
should raise_exception("specified coordinates (10, 0, 10, 20) are invalid
|
129
|
+
should raise_exception("specified coordinates (10, 0, 10, 20) are invalid - cannot have x1 > x2 or y1 > y2!")
|
130
130
|
end
|
131
131
|
|
132
132
|
it "doesn't allow to capture area of the window if second coordinate is smaller than first one" do
|
133
133
|
title = /calculator/i
|
134
134
|
lambda {Win32::Screenshot.window_area(title, 0, 10, 10, 9) {|width, height, bmp| check_image('calc5')}}.
|
135
|
-
should raise_exception("specified coordinates (0, 10, 10, 9) are invalid
|
135
|
+
should raise_exception("specified coordinates (0, 10, 10, 9) are invalid - cannot have x1 > x2 or y1 > y2!")
|
136
136
|
end
|
137
137
|
|
138
138
|
it "doesn't allow to capture area of the window with too big coordinates" do
|
139
139
|
title = /calculator/i
|
140
|
-
|
141
|
-
|
140
|
+
hwnd = Win32::Screenshot::BitmapMaker.hwnd(title)
|
141
|
+
dimensions = Win32::Screenshot::BitmapMaker.dimensions_for(hwnd)
|
142
|
+
lambda {Win32::Screenshot.window_area(title, 0, 0, 10, 1000) {|width, height, bmp| check_image('calc3')}}.
|
143
|
+
should raise_exception("specified coordinates (0, 0, 10, 1000) are invalid - maximum are x2=#{dimensions[2]} and y2=#{dimensions[3]}!")
|
142
144
|
end
|
143
145
|
|
144
146
|
it "captures by window with handle" do
|
@@ -164,17 +166,23 @@ describe "win32-screenshot" do
|
|
164
166
|
it "doesn't allow to capture area of the window with handle with invalid coordinates" do
|
165
167
|
hwnd = Win32::Screenshot::BitmapMaker.hwnd(/calculator/i)
|
166
168
|
lambda {Win32::Screenshot.hwnd_area(hwnd, 0, 0, -1, 100) {|width, height, bmp| check_image('desktop2')}}.
|
167
|
-
should raise_exception("specified coordinates (0, 0, -1, 100) are invalid
|
169
|
+
should raise_exception("specified coordinates (0, 0, -1, 100) are invalid - cannot be negative!")
|
168
170
|
end
|
169
171
|
|
170
172
|
it "captures based on coordinates" do
|
171
173
|
hwnd = Win32::Screenshot::BitmapMaker.hwnd(/calculator/i)
|
172
174
|
bmp1 = bmp2 = nil
|
173
|
-
Win32::Screenshot.hwnd_area(hwnd, 100, 100, 170,
|
174
|
-
Win32::Screenshot.hwnd_area(hwnd, 0, 0, 70,
|
175
|
+
Win32::Screenshot.hwnd_area(hwnd, 100, 100, 170, 180) do |width, height, bmp|; bmp1 = bmp; end
|
176
|
+
Win32::Screenshot.hwnd_area(hwnd, 0, 0, 70, 80) do |width, height, bmp|; bmp2 = bmp; end
|
175
177
|
bmp1.length.should == bmp2.length
|
176
178
|
bmp1.should_not == bmp2
|
177
179
|
end
|
180
|
+
|
181
|
+
it "enumerates the available windows" do
|
182
|
+
got = Win32::Screenshot::BitmapMaker.list_window_titles
|
183
|
+
got.length.should be > 1
|
184
|
+
got[0].should be_a String
|
185
|
+
end
|
178
186
|
|
179
187
|
after :all do
|
180
188
|
Process.kill 9, @notepad
|
metadata
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rdp-win32screenshot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 85
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
9
|
- 6
|
10
|
-
|
10
|
+
- 1
|
11
|
+
version: 0.0.6.1
|
11
12
|
platform: ruby
|
12
13
|
authors:
|
13
14
|
- Jarmo Pertman
|