win 0.1.27 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -5
- data/.gitignore +21 -21
- data/LICENSE +20 -20
- data/README.rdoc +175 -175
- data/Rakefile +58 -58
- data/VERSION +1 -1
- data/features/support/env.rb +4 -4
- data/features/win.feature +9 -9
- data/lib/win/dde.rb +1234 -1234
- data/lib/win/error.rb +1223 -1223
- data/lib/win/extensions.rb +41 -41
- data/lib/win/gui.rb +16 -16
- data/lib/win/gui/dialog.rb +50 -50
- data/lib/win/gui/input.rb +319 -319
- data/lib/win/gui/message.rb +807 -807
- data/lib/win/gui/window.rb +679 -679
- data/lib/win/library.rb +463 -463
- data/spec/spec.opts +2 -2
- data/spec/spec_helper.rb +140 -135
- data/spec/test_apps/locknote/LockNote.exe +0 -0
- data/spec/win/dde_spec.rb +528 -528
- data/spec/win/error_spec.rb +112 -112
- data/spec/win/extensions_spec.rb +73 -73
- data/spec/win/gui/dialog_spec.rb +43 -43
- data/spec/win/gui/input_spec.rb +101 -101
- data/spec/win/gui/message_spec.rb +236 -236
- data/spec/win/gui/window_spec.rb +549 -548
- data/spec/win/library_spec.rb +341 -341
- data/win.gemspec +87 -87
- metadata +34 -17
data/.document
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
README.rdoc
|
2
|
-
lib/**/*.rb
|
3
|
-
bin/*
|
4
|
-
features/**/*.feature
|
5
|
-
LICENSE
|
1
|
+
README.rdoc
|
2
|
+
lib/**/*.rb
|
3
|
+
bin/*
|
4
|
+
features/**/*.feature
|
5
|
+
LICENSE
|
data/.gitignore
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
## MAC OS
|
2
|
-
.DS_Store
|
3
|
-
|
4
|
-
## TEXTMATE
|
5
|
-
*.tmproj
|
6
|
-
tmtags
|
7
|
-
|
8
|
-
## EMACS
|
9
|
-
*~
|
10
|
-
\#*
|
11
|
-
.\#*
|
12
|
-
|
13
|
-
## VIM
|
14
|
-
*.swp
|
15
|
-
|
16
|
-
## PROJECT::GENERAL
|
17
|
-
coverage
|
18
|
-
rdoc
|
19
|
-
pkg
|
20
|
-
|
21
|
-
## PROJECT::SPECIFIC
|
1
|
+
## MAC OS
|
2
|
+
.DS_Store
|
3
|
+
|
4
|
+
## TEXTMATE
|
5
|
+
*.tmproj
|
6
|
+
tmtags
|
7
|
+
|
8
|
+
## EMACS
|
9
|
+
*~
|
10
|
+
\#*
|
11
|
+
.\#*
|
12
|
+
|
13
|
+
## VIM
|
14
|
+
*.swp
|
15
|
+
|
16
|
+
## PROJECT::GENERAL
|
17
|
+
coverage
|
18
|
+
rdoc
|
19
|
+
pkg
|
20
|
+
|
21
|
+
## PROJECT::SPECIFIC
|
data/LICENSE
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
Copyright (c) 2009 arvicco
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
-
a copy of this software and associated documentation files (the
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
10
|
-
|
11
|
-
The above copyright notice and this permission notice shall be
|
12
|
-
included in all copies or substantial portions of the Software.
|
13
|
-
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
1
|
+
Copyright (c) 2009 arvicco
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
CHANGED
@@ -1,175 +1,175 @@
|
|
1
|
-
= win
|
2
|
-
|
3
|
-
by: Arvicco
|
4
|
-
url: http://github.com/arvicco/win
|
5
|
-
|
6
|
-
== DESCRIPTION
|
7
|
-
|
8
|
-
A collection of Windows API functions predefined for you using FFI. In addition to
|
9
|
-
straightforward (CamelCase) API wrappers, it also strives to provide more Ruby-like
|
10
|
-
snake_case methods that take a minimum of arguments with sensible defaults and have
|
11
|
-
sensible return values (false/true instead of 0/nonzero for test functions, etc).
|
12
|
-
|
13
|
-
This is still work in progress, only a small portion of Windows API wrapped so far...
|
14
|
-
|
15
|
-
== SUMMARY
|
16
|
-
|
17
|
-
So you want to write a simple program that makes some Windows API function calls.
|
18
|
-
You searched MSDN high and low and you know exactly what functions you need.
|
19
|
-
You just want to put these function calls into your Ruby code without too much pain.
|
20
|
-
You'd love this to be more or less natural extension of your Ruby code, preferably
|
21
|
-
not turning your code base into an ugly spaghetty of CamelCase calls, String/Array
|
22
|
-
pack/unpack gymnastics, buffer/pointer allocations, extracting return values
|
23
|
-
from [in/out] parameters and checking return codes for 0.
|
24
|
-
|
25
|
-
You have several options at this point. You can use 'win32-api' or 'ffi' libraries
|
26
|
-
to connect your ruby code to Windows API and manually define wrapper methods for
|
27
|
-
needed function calls. This is definitely a valid approach, even if it is a bit
|
28
|
-
low-level one: you'll have to handle (somewhat) gory details of callback announcements,
|
29
|
-
argument preparation, mimicking pointers with Strings, declaring pointers explicitly
|
30
|
-
with FFI and other stuff (like manually assigning about a gazillion obscure Windows
|
31
|
-
constants). As an example, consider the amount of code needed to complete a task as
|
32
|
-
simple as getting unicode title text for the window that you already have handle for
|
33
|
-
(using win32-api):
|
34
|
-
|
35
|
-
api = Win32::API.new( 'GetWindowTextW', ['L', 'P', 'I'], 'L', 'user32' )
|
36
|
-
buffer = "\x00" * 1024 # I just hope it will be enough...
|
37
|
-
num_chars = api.call(window_handle, buffer, buffer.size)
|
38
|
-
title = if num_chars == 0
|
39
|
-
nil
|
40
|
-
else
|
41
|
-
buffer.force_encoding('utf-16LE').encode('utf-8').rstrip
|
42
|
-
end
|
43
|
-
|
44
|
-
This is how you achieve the same result with ffi:
|
45
|
-
|
46
|
-
extend FFI::Library
|
47
|
-
ffi_lib 'user32'
|
48
|
-
ffi_convention :stdcall
|
49
|
-
attach_function :GetWindowTextW, [ :long, :buffer_out, :int ], :long
|
50
|
-
buffer = FFI::Buffer.new 1024
|
51
|
-
buffer.put_string(0, "\x00" * 1024)
|
52
|
-
num_chars = GetWindowTextW(window_handle, buffer, 1024)
|
53
|
-
title = if num_chars == 0
|
54
|
-
nil
|
55
|
-
else
|
56
|
-
buffer.get_bytes(0, num_chars).force_encoding('utf-16LE').encode('utf-8').rstrip
|
57
|
-
end
|
58
|
-
|
59
|
-
As an alternative, you can use 'windows-pr' (pure ruby) library that gives you lots of
|
60
|
-
Windows functions pre-defined and sectioned into modules, declares Windows constants and
|
61
|
-
adds some other niceties. Unfortunately this library works only with MRI (not JRuby or
|
62
|
-
other Ruby implementations), and still lacks Ruby look-and-feel for declared functions.
|
63
|
-
It helps you to cut some of the declaration slack though:
|
64
|
-
|
65
|
-
title = if GetWindowTextW(window_handle, buffer ="\x00" * 1024 , buffer.size) == 0
|
66
|
-
nil
|
67
|
-
else
|
68
|
-
buffer.force_encoding('utf-16LE').encode('utf-8').rstrip
|
69
|
-
end
|
70
|
-
|
71
|
-
But still, it seems like TOO MUCH code for something that should (ideally) look like this:
|
72
|
-
|
73
|
-
title = window_text_w(window_handle)
|
74
|
-
|
75
|
-
This is an idea behind this library - make Windows API functions easier to use and feel more
|
76
|
-
natural inside Ruby code. Following the principle of least surprise, we define wrapper methods that:
|
77
|
-
* Have meaningful Rubyesque names (iconic? and minimized? instead of IsIconic, etc)
|
78
|
-
* Require minimum arguments with sensible defaults
|
79
|
-
* Return appropriate values explicitly (several return values if necessary)
|
80
|
-
* Have sensible returns (false/true instead of 0/nonzero for test functions, nil if find function fails, etc)
|
81
|
-
* Accept blocks where callback is needed, provide default callback if no block given
|
82
|
-
* Are partitioned into appropriate namespaces, so that you can load only the modules you really need
|
83
|
-
|
84
|
-
Well, we even keep a backup solution for those diehard Win32 API longtimers who would rather
|
85
|
-
allocate their buffer strings by hand and mess with obscure return codes. If you use original
|
86
|
-
CamelCase method name instead of Rubyesque snake_case one, it will expect those standard
|
87
|
-
parameters you know and love from MSDN, return your zeroes instead of nils and support no
|
88
|
-
other enhancements.
|
89
|
-
|
90
|
-
Related Windows API functions are grouped by topic and defined in separate namespaces (modules),
|
91
|
-
that also contain related constants and convenience methods. For example, win/dde.rb file
|
92
|
-
contains only functions related to DDE protocol such as DdeInitialize() as well as constants
|
93
|
-
such as DMLERR_NO_ERROR, APPCLASS_STANDARD, etc. So if you need only DDE-related functions,
|
94
|
-
there is no need to load all the other modules, clogging your namespaces - just require 'win/dde'
|
95
|
-
and be done with it.
|
96
|
-
|
97
|
-
And if you do not see your favorite Windows API functions among those already defined, it is
|
98
|
-
quite easy to 'include Win::Library' into your module and define new ones with 'function' macro -
|
99
|
-
it does a lot of heavy lifting for you and can be customized with options and code blocks to give
|
100
|
-
you reusable API wrapper methods with the exact behavior you need.
|
101
|
-
|
102
|
-
== REQUIREMENTS:
|
103
|
-
|
104
|
-
Only works with Ruby 1.9 compatible implementations since it uses some of the most recent features
|
105
|
-
(block arguments given to block, etc...).
|
106
|
-
|
107
|
-
== FEATURES/PROBLEMS:
|
108
|
-
|
109
|
-
This project is quite new, so it may be not suitable for production-quality systems yet.
|
110
|
-
Contributors always welcome!
|
111
|
-
|
112
|
-
== INSTALLATION
|
113
|
-
|
114
|
-
$ gem install win
|
115
|
-
|
116
|
-
== SYNOPSIS
|
117
|
-
=== Using pre-defined Windows API functions:
|
118
|
-
|
119
|
-
require 'win/gui/window'
|
120
|
-
|
121
|
-
class MyClass
|
122
|
-
include Win::GUI::Window
|
123
|
-
|
124
|
-
fg_window = foreground_window
|
125
|
-
puts window_text(fg_window)
|
126
|
-
show_window(fg_window) unless minimized?(fg_window)
|
127
|
-
...
|
128
|
-
end
|
129
|
-
|
130
|
-
=== Defining your own Windows API functions:
|
131
|
-
|
132
|
-
require 'win/library'
|
133
|
-
|
134
|
-
module YourLibModule
|
135
|
-
include Win::Library
|
136
|
-
|
137
|
-
# Customizing method behavior: zeronil forces function to return nil instead of 0, rename renames method
|
138
|
-
function :FindWindow, [:pointer, :pointer], :ulong, zeronil: true, rename: :my_find
|
139
|
-
|
140
|
-
# Customizing even further: your own method extension in attached block
|
141
|
-
function :GetWindowText, [ :ulong, :pointer, :int ], :int do |api, handle|
|
142
|
-
buffer = FFI::MemoryPointer.new :char, 512
|
143
|
-
buffer.put_string(0, "\x00" * 511)
|
144
|
-
num_chars = api.call(handle, buffer, 512)
|
145
|
-
num_chars == 0 ? nil : buffer.get_bytes(0, num_chars)
|
146
|
-
end
|
147
|
-
|
148
|
-
end
|
149
|
-
|
150
|
-
include YourLibModule
|
151
|
-
|
152
|
-
handle = my_find(nil, 'cmd') # find any shell window
|
153
|
-
puts handle, window_text(handle) # print shell window handle and title
|
154
|
-
|
155
|
-
== PRIOR ART:
|
156
|
-
|
157
|
-
This library started as an extension of ideas and code described in excellent book
|
158
|
-
"Scripted GUI Testing with Ruby" by Ian Dees. 'win32-api' and 'windows-pr' gems by
|
159
|
-
Daniel J. Berger and Park Heesob provided both inspiration and an excellent source
|
160
|
-
for code borrowing. 'ffi' gem serves as a solid basis for this library, allowing to
|
161
|
-
use it for multiple Ruby implementations.
|
162
|
-
|
163
|
-
== Note on Patches/Pull Requests
|
164
|
-
|
165
|
-
* Fork the project.
|
166
|
-
* Make your feature addition or bug fix.
|
167
|
-
* Add tests for it. This is important so I don't break it in a
|
168
|
-
future version unintentionally.
|
169
|
-
* Commit, do not mess with rakefile, version, or history.
|
170
|
-
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
171
|
-
* Send me a pull request. Bonus points for topic branches.
|
172
|
-
|
173
|
-
== Copyright
|
174
|
-
|
175
|
-
Copyright (c) 2010 arvicco. See LICENSE for details.
|
1
|
+
= win
|
2
|
+
|
3
|
+
by: Arvicco
|
4
|
+
url: http://github.com/arvicco/win
|
5
|
+
|
6
|
+
== DESCRIPTION
|
7
|
+
|
8
|
+
A collection of Windows API functions predefined for you using FFI. In addition to
|
9
|
+
straightforward (CamelCase) API wrappers, it also strives to provide more Ruby-like
|
10
|
+
snake_case methods that take a minimum of arguments with sensible defaults and have
|
11
|
+
sensible return values (false/true instead of 0/nonzero for test functions, etc).
|
12
|
+
|
13
|
+
This is still work in progress, only a small portion of Windows API wrapped so far...
|
14
|
+
|
15
|
+
== SUMMARY
|
16
|
+
|
17
|
+
So you want to write a simple program that makes some Windows API function calls.
|
18
|
+
You searched MSDN high and low and you know exactly what functions you need.
|
19
|
+
You just want to put these function calls into your Ruby code without too much pain.
|
20
|
+
You'd love this to be more or less natural extension of your Ruby code, preferably
|
21
|
+
not turning your code base into an ugly spaghetty of CamelCase calls, String/Array
|
22
|
+
pack/unpack gymnastics, buffer/pointer allocations, extracting return values
|
23
|
+
from [in/out] parameters and checking return codes for 0.
|
24
|
+
|
25
|
+
You have several options at this point. You can use 'win32-api' or 'ffi' libraries
|
26
|
+
to connect your ruby code to Windows API and manually define wrapper methods for
|
27
|
+
needed function calls. This is definitely a valid approach, even if it is a bit
|
28
|
+
low-level one: you'll have to handle (somewhat) gory details of callback announcements,
|
29
|
+
argument preparation, mimicking pointers with Strings, declaring pointers explicitly
|
30
|
+
with FFI and other stuff (like manually assigning about a gazillion obscure Windows
|
31
|
+
constants). As an example, consider the amount of code needed to complete a task as
|
32
|
+
simple as getting unicode title text for the window that you already have handle for
|
33
|
+
(using win32-api):
|
34
|
+
|
35
|
+
api = Win32::API.new( 'GetWindowTextW', ['L', 'P', 'I'], 'L', 'user32' )
|
36
|
+
buffer = "\x00" * 1024 # I just hope it will be enough...
|
37
|
+
num_chars = api.call(window_handle, buffer, buffer.size)
|
38
|
+
title = if num_chars == 0
|
39
|
+
nil
|
40
|
+
else
|
41
|
+
buffer.force_encoding('utf-16LE').encode('utf-8').rstrip
|
42
|
+
end
|
43
|
+
|
44
|
+
This is how you achieve the same result with ffi:
|
45
|
+
|
46
|
+
extend FFI::Library
|
47
|
+
ffi_lib 'user32'
|
48
|
+
ffi_convention :stdcall
|
49
|
+
attach_function :GetWindowTextW, [ :long, :buffer_out, :int ], :long
|
50
|
+
buffer = FFI::Buffer.new 1024
|
51
|
+
buffer.put_string(0, "\x00" * 1024)
|
52
|
+
num_chars = GetWindowTextW(window_handle, buffer, 1024)
|
53
|
+
title = if num_chars == 0
|
54
|
+
nil
|
55
|
+
else
|
56
|
+
buffer.get_bytes(0, num_chars).force_encoding('utf-16LE').encode('utf-8').rstrip
|
57
|
+
end
|
58
|
+
|
59
|
+
As an alternative, you can use 'windows-pr' (pure ruby) library that gives you lots of
|
60
|
+
Windows functions pre-defined and sectioned into modules, declares Windows constants and
|
61
|
+
adds some other niceties. Unfortunately this library works only with MRI (not JRuby or
|
62
|
+
other Ruby implementations), and still lacks Ruby look-and-feel for declared functions.
|
63
|
+
It helps you to cut some of the declaration slack though:
|
64
|
+
|
65
|
+
title = if GetWindowTextW(window_handle, buffer ="\x00" * 1024 , buffer.size) == 0
|
66
|
+
nil
|
67
|
+
else
|
68
|
+
buffer.force_encoding('utf-16LE').encode('utf-8').rstrip
|
69
|
+
end
|
70
|
+
|
71
|
+
But still, it seems like TOO MUCH code for something that should (ideally) look like this:
|
72
|
+
|
73
|
+
title = window_text_w(window_handle)
|
74
|
+
|
75
|
+
This is an idea behind this library - make Windows API functions easier to use and feel more
|
76
|
+
natural inside Ruby code. Following the principle of least surprise, we define wrapper methods that:
|
77
|
+
* Have meaningful Rubyesque names (iconic? and minimized? instead of IsIconic, etc)
|
78
|
+
* Require minimum arguments with sensible defaults
|
79
|
+
* Return appropriate values explicitly (several return values if necessary)
|
80
|
+
* Have sensible returns (false/true instead of 0/nonzero for test functions, nil if find function fails, etc)
|
81
|
+
* Accept blocks where callback is needed, provide default callback if no block given
|
82
|
+
* Are partitioned into appropriate namespaces, so that you can load only the modules you really need
|
83
|
+
|
84
|
+
Well, we even keep a backup solution for those diehard Win32 API longtimers who would rather
|
85
|
+
allocate their buffer strings by hand and mess with obscure return codes. If you use original
|
86
|
+
CamelCase method name instead of Rubyesque snake_case one, it will expect those standard
|
87
|
+
parameters you know and love from MSDN, return your zeroes instead of nils and support no
|
88
|
+
other enhancements.
|
89
|
+
|
90
|
+
Related Windows API functions are grouped by topic and defined in separate namespaces (modules),
|
91
|
+
that also contain related constants and convenience methods. For example, win/dde.rb file
|
92
|
+
contains only functions related to DDE protocol such as DdeInitialize() as well as constants
|
93
|
+
such as DMLERR_NO_ERROR, APPCLASS_STANDARD, etc. So if you need only DDE-related functions,
|
94
|
+
there is no need to load all the other modules, clogging your namespaces - just require 'win/dde'
|
95
|
+
and be done with it.
|
96
|
+
|
97
|
+
And if you do not see your favorite Windows API functions among those already defined, it is
|
98
|
+
quite easy to 'include Win::Library' into your module and define new ones with 'function' macro -
|
99
|
+
it does a lot of heavy lifting for you and can be customized with options and code blocks to give
|
100
|
+
you reusable API wrapper methods with the exact behavior you need.
|
101
|
+
|
102
|
+
== REQUIREMENTS:
|
103
|
+
|
104
|
+
Only works with Ruby 1.9 compatible implementations since it uses some of the most recent features
|
105
|
+
(block arguments given to block, etc...).
|
106
|
+
|
107
|
+
== FEATURES/PROBLEMS:
|
108
|
+
|
109
|
+
This project is quite new, so it may be not suitable for production-quality systems yet.
|
110
|
+
Contributors always welcome!
|
111
|
+
|
112
|
+
== INSTALLATION
|
113
|
+
|
114
|
+
$ gem install win
|
115
|
+
|
116
|
+
== SYNOPSIS
|
117
|
+
=== Using pre-defined Windows API functions:
|
118
|
+
|
119
|
+
require 'win/gui/window'
|
120
|
+
|
121
|
+
class MyClass
|
122
|
+
include Win::GUI::Window
|
123
|
+
|
124
|
+
fg_window = foreground_window
|
125
|
+
puts window_text(fg_window)
|
126
|
+
show_window(fg_window) unless minimized?(fg_window)
|
127
|
+
...
|
128
|
+
end
|
129
|
+
|
130
|
+
=== Defining your own Windows API functions:
|
131
|
+
|
132
|
+
require 'win/library'
|
133
|
+
|
134
|
+
module YourLibModule
|
135
|
+
include Win::Library
|
136
|
+
|
137
|
+
# Customizing method behavior: zeronil forces function to return nil instead of 0, rename renames method
|
138
|
+
function :FindWindow, [:pointer, :pointer], :ulong, zeronil: true, rename: :my_find
|
139
|
+
|
140
|
+
# Customizing even further: your own method extension in attached block
|
141
|
+
function :GetWindowText, [ :ulong, :pointer, :int ], :int do |api, handle|
|
142
|
+
buffer = FFI::MemoryPointer.new :char, 512
|
143
|
+
buffer.put_string(0, "\x00" * 511)
|
144
|
+
num_chars = api.call(handle, buffer, 512)
|
145
|
+
num_chars == 0 ? nil : buffer.get_bytes(0, num_chars)
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
149
|
+
|
150
|
+
include YourLibModule
|
151
|
+
|
152
|
+
handle = my_find(nil, 'cmd') # find any shell window
|
153
|
+
puts handle, window_text(handle) # print shell window handle and title
|
154
|
+
|
155
|
+
== PRIOR ART:
|
156
|
+
|
157
|
+
This library started as an extension of ideas and code described in excellent book
|
158
|
+
"Scripted GUI Testing with Ruby" by Ian Dees. 'win32-api' and 'windows-pr' gems by
|
159
|
+
Daniel J. Berger and Park Heesob provided both inspiration and an excellent source
|
160
|
+
for code borrowing. 'ffi' gem serves as a solid basis for this library, allowing to
|
161
|
+
use it for multiple Ruby implementations.
|
162
|
+
|
163
|
+
== Note on Patches/Pull Requests
|
164
|
+
|
165
|
+
* Fork the project.
|
166
|
+
* Make your feature addition or bug fix.
|
167
|
+
* Add tests for it. This is important so I don't break it in a
|
168
|
+
future version unintentionally.
|
169
|
+
* Commit, do not mess with rakefile, version, or history.
|
170
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
171
|
+
* Send me a pull request. Bonus points for topic branches.
|
172
|
+
|
173
|
+
== Copyright
|
174
|
+
|
175
|
+
Copyright (c) 2010 arvicco. See LICENSE for details.
|
data/Rakefile
CHANGED
@@ -1,58 +1,58 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'rake'
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'jeweler'
|
6
|
-
Jeweler::Tasks.new do |gem|
|
7
|
-
gem.name = "win"
|
8
|
-
gem.summary = %Q{Rubyesque interfaces and wrappers for Windows API functions pre-defined using FFI }
|
9
|
-
gem.description = %Q{Rubyesque interfaces and wrappers for Windows API functions pre-defined using FFI }
|
10
|
-
gem.email = "arvitallian@gmail.com"
|
11
|
-
gem.homepage = "http://github.com/arvicco/win"
|
12
|
-
gem.authors = ["arvicco"]
|
13
|
-
gem.add_dependency "ffi", ">= 0.6.0"
|
14
|
-
gem.add_development_dependency "rspec", ">= 1.2.9"
|
15
|
-
gem.add_development_dependency "cucumber", ">= 0"
|
16
|
-
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
|
-
end
|
18
|
-
Jeweler::GemcutterTasks.new
|
19
|
-
rescue LoadError
|
20
|
-
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
21
|
-
end
|
22
|
-
|
23
|
-
require 'spec/rake/spectask'
|
24
|
-
Spec::Rake::SpecTask.new(:spec) do |spec|
|
25
|
-
spec.libs << 'lib' << 'spec'
|
26
|
-
spec.spec_files = FileList['spec/**/*_spec.rb']
|
27
|
-
end
|
28
|
-
|
29
|
-
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
30
|
-
spec.libs << 'lib' << 'spec'
|
31
|
-
spec.pattern = 'spec/**/*_spec.rb'
|
32
|
-
spec.rcov = true
|
33
|
-
end
|
34
|
-
|
35
|
-
task :spec => :check_dependencies
|
36
|
-
|
37
|
-
begin
|
38
|
-
require 'cucumber/rake/task'
|
39
|
-
Cucumber::Rake::Task.new(:features)
|
40
|
-
|
41
|
-
task :features => :check_dependencies
|
42
|
-
rescue LoadError
|
43
|
-
task :features do
|
44
|
-
abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
task :default => :spec
|
49
|
-
|
50
|
-
require 'rake/rdoctask'
|
51
|
-
Rake::RDocTask.new do |rdoc|
|
52
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
53
|
-
|
54
|
-
rdoc.rdoc_dir = 'rdoc'
|
55
|
-
rdoc.title = "win #{version}"
|
56
|
-
rdoc.rdoc_files.include('README*')
|
57
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
58
|
-
end
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "win"
|
8
|
+
gem.summary = %Q{Rubyesque interfaces and wrappers for Windows API functions pre-defined using FFI }
|
9
|
+
gem.description = %Q{Rubyesque interfaces and wrappers for Windows API functions pre-defined using FFI }
|
10
|
+
gem.email = "arvitallian@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/arvicco/win"
|
12
|
+
gem.authors = ["arvicco"]
|
13
|
+
gem.add_dependency "ffi", ">= 0.6.0"
|
14
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
15
|
+
gem.add_development_dependency "cucumber", ">= 0"
|
16
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
|
+
end
|
18
|
+
Jeweler::GemcutterTasks.new
|
19
|
+
rescue LoadError
|
20
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'spec/rake/spectask'
|
24
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
25
|
+
spec.libs << 'lib' << 'spec'
|
26
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
27
|
+
end
|
28
|
+
|
29
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
30
|
+
spec.libs << 'lib' << 'spec'
|
31
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
32
|
+
spec.rcov = true
|
33
|
+
end
|
34
|
+
|
35
|
+
task :spec => :check_dependencies
|
36
|
+
|
37
|
+
begin
|
38
|
+
require 'cucumber/rake/task'
|
39
|
+
Cucumber::Rake::Task.new(:features)
|
40
|
+
|
41
|
+
task :features => :check_dependencies
|
42
|
+
rescue LoadError
|
43
|
+
task :features do
|
44
|
+
abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
task :default => :spec
|
49
|
+
|
50
|
+
require 'rake/rdoctask'
|
51
|
+
Rake::RDocTask.new do |rdoc|
|
52
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
53
|
+
|
54
|
+
rdoc.rdoc_dir = 'rdoc'
|
55
|
+
rdoc.title = "win #{version}"
|
56
|
+
rdoc.rdoc_files.include('README*')
|
57
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
58
|
+
end
|