win_gui 0.1.6 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +21 -21
- data/HISTORY +7 -0
- data/LICENSE +20 -20
- data/README.rdoc +77 -114
- data/Rakefile +24 -58
- data/VERSION +1 -1
- data/features/support/env.rb +7 -4
- data/features/win_gui.feature +9 -9
- data/lib/version.rb +8 -0
- data/lib/win_gui/window.rb +78 -69
- data/lib/win_gui.rb +25 -3
- data/spec/spec.opts +1 -1
- data/spec/spec_helper.rb +90 -118
- data/spec/win_gui/window_spec.rb +120 -123
- data/tasks/common.rake +14 -0
- data/tasks/doc.rake +14 -0
- data/tasks/gem.rake +39 -0
- data/tasks/git.rake +34 -0
- data/tasks/spec.rake +19 -0
- data/tasks/version.rake +71 -0
- metadata +68 -188
- data/.document +0 -5
- data/book_code/early_success/bundle.rb +0 -34
- data/book_code/early_success/english.txt +0 -1
- data/book_code/early_success/jruby_basics.rb +0 -47
- data/book_code/early_success/windows_basics.rb +0 -97
- data/book_code/guessing/locknote.rb +0 -379
- data/book_code/guessing/monkeyshines.rb +0 -14
- data/book_code/guessing/note.rb +0 -120
- data/book_code/guessing/note_spec.rb +0 -175
- data/book_code/guessing/replay.rb +0 -21
- data/book_code/guessing/seed.rb +0 -9
- data/book_code/guessing/spec_helper.rb +0 -69
- data/book_code/guessing/windows_gui.rb +0 -247
- data/book_code/home_stretch/junquenote.rb +0 -151
- data/book_code/home_stretch/locknote.rb +0 -180
- data/book_code/home_stretch/note.rb +0 -144
- data/book_code/home_stretch/note_spec.rb +0 -191
- data/book_code/home_stretch/spec_helper.rb +0 -55
- data/book_code/home_stretch/swing_gui.rb +0 -50
- data/book_code/home_stretch/windows_gui.rb +0 -232
- data/book_code/junquenote/exports.sh +0 -10
- data/book_code/junquenote/jruby_mac.sh +0 -10
- data/book_code/junquenote/junquenote_app.rb +0 -262
- data/book_code/novite/Rakefile +0 -10
- data/book_code/novite/app/controllers/application.rb +0 -18
- data/book_code/novite/app/controllers/guests_controller.rb +0 -28
- data/book_code/novite/app/controllers/parties_controller.rb +0 -77
- data/book_code/novite/app/helpers/application_helper.rb +0 -11
- data/book_code/novite/app/helpers/guests_helper.rb +0 -10
- data/book_code/novite/app/helpers/parties_helper.rb +0 -10
- data/book_code/novite/app/models/guest.rb +0 -11
- data/book_code/novite/app/models/party.rb +0 -32
- data/book_code/novite/app/models/party_mailer.rb +0 -19
- data/book_code/novite/app/views/layouts/application.rhtml +0 -44
- data/book_code/novite/app/views/parties/new.html.erb +0 -42
- data/book_code/novite/app/views/parties/show.html.erb +0 -43
- data/book_code/novite/app/views/party_mailer/invite.erb +0 -17
- data/book_code/novite/config/boot.rb +0 -117
- data/book_code/novite/config/database.yml +0 -19
- data/book_code/novite/config/environment.rb +0 -67
- data/book_code/novite/config/environments/development.rb +0 -29
- data/book_code/novite/config/environments/production.rb +0 -27
- data/book_code/novite/config/environments/test.rb +0 -30
- data/book_code/novite/config/initializers/inflections.rb +0 -18
- data/book_code/novite/config/initializers/mime_types.rb +0 -13
- data/book_code/novite/config/routes.rb +0 -47
- data/book_code/novite/db/migrate/001_create_parties.rb +0 -26
- data/book_code/novite/db/migrate/002_create_guests.rb +0 -23
- data/book_code/novite/db/schema.rb +0 -41
- data/book_code/novite/log/empty.txt +0 -0
- data/book_code/novite/public/.htaccess +0 -40
- data/book_code/novite/public/404.html +0 -38
- data/book_code/novite/public/422.html +0 -38
- data/book_code/novite/public/500.html +0 -38
- data/book_code/novite/public/dispatch.cgi +0 -10
- data/book_code/novite/public/dispatch.fcgi +0 -24
- data/book_code/novite/public/dispatch.rb +0 -18
- data/book_code/novite/public/favicon.ico +0 -0
- data/book_code/novite/public/images/rails.png +0 -0
- data/book_code/novite/public/index.html +0 -285
- data/book_code/novite/public/javascripts/application.js +0 -10
- data/book_code/novite/public/javascripts/controls.js +0 -971
- data/book_code/novite/public/javascripts/dragdrop.js +0 -980
- data/book_code/novite/public/javascripts/effects.js +0 -1128
- data/book_code/novite/public/javascripts/prototype.js +0 -4233
- data/book_code/novite/public/robots.txt +0 -5
- data/book_code/novite/script/about +0 -3
- data/book_code/novite/script/console +0 -3
- data/book_code/novite/script/destroy +0 -3
- data/book_code/novite/script/generate +0 -3
- data/book_code/novite/script/performance/benchmarker +0 -3
- data/book_code/novite/script/performance/profiler +0 -3
- data/book_code/novite/script/performance/request +0 -3
- data/book_code/novite/script/plugin +0 -3
- data/book_code/novite/script/process/inspector +0 -3
- data/book_code/novite/script/process/reaper +0 -3
- data/book_code/novite/script/process/spawner +0 -3
- data/book_code/novite/script/runner +0 -3
- data/book_code/novite/script/server +0 -3
- data/book_code/novite/test/test_helper.rb +0 -46
- data/book_code/one_more_thing/applescript.rb +0 -68
- data/book_code/one_more_thing/note_spec.rb +0 -50
- data/book_code/one_more_thing/spec_helper.rb +0 -17
- data/book_code/one_more_thing/textedit-pure.rb +0 -28
- data/book_code/one_more_thing/textedit.applescript +0 -26
- data/book_code/one_more_thing/textedit.rb +0 -32
- data/book_code/one_more_thing/textnote.rb +0 -87
- data/book_code/simplify/junquenote.rb +0 -48
- data/book_code/simplify/locknote.rb +0 -46
- data/book_code/simplify/note.rb +0 -35
- data/book_code/simplify/note_spec.rb +0 -28
- data/book_code/simplify/swing_gui.rb +0 -45
- data/book_code/simplify/windows_gui.rb +0 -232
- data/book_code/simplify/windows_gui_spec.rb +0 -35
- data/book_code/story/invite.story +0 -19
- data/book_code/story/journal.txt +0 -29
- data/book_code/story/novite_stories.rb +0 -156
- data/book_code/story/party.rb +0 -149
- data/book_code/story/password.rb +0 -61
- data/book_code/story/password.story +0 -26
- data/book_code/story/rsvp.story +0 -29
- data/book_code/tables/TestTime.html +0 -93
- data/book_code/tables/TestTimeSample.html +0 -63
- data/book_code/tables/calculate_time.rb +0 -39
- data/book_code/tables/calculator.rb +0 -108
- data/book_code/tables/calculator_actions.rb +0 -27
- data/book_code/tables/calculator_spec.rb +0 -47
- data/book_code/tables/fit.rb +0 -32
- data/book_code/tables/matrix.rb +0 -109
- data/book_code/tables/pseudocode.rb +0 -17
- data/book_code/tubes/book_selenium.rb +0 -67
- data/book_code/tubes/book_watir.rb +0 -60
- data/book_code/tubes/dragdrop.html +0 -81
- data/book_code/tubes/html_capture.rb +0 -33
- data/book_code/tubes/joke_list.rb +0 -67
- data/book_code/tubes/list_spec.rb +0 -41
- data/book_code/tubes/search_spec.rb +0 -32
- data/book_code/tubes/selenium_example.rb +0 -66
- data/book_code/tubes/selenium_link.rb +0 -23
- data/book_code/tubes/web_server.rb +0 -14
- data/book_code/windows/wgui.rb +0 -29
- data/book_code/windows/wobj.rb +0 -25
- data/book_code/windows/wsh.rb +0 -25
- data/book_code/with_rspec/empty_spec.rb +0 -13
- data/book_code/with_rspec/junquenote.rb +0 -60
- data/book_code/with_rspec/locknote.rb +0 -129
- data/book_code/with_rspec/note_spec.rb +0 -32
- data/book_code/with_rspec/should_examples.rb +0 -18
- data/lib/note/java/jemmy.jar +0 -0
- data/lib/note/java/jnote.rb +0 -48
- data/lib/note/java/jruby_basics.rb +0 -37
- data/lib/note/java/junquenote_app.rb +0 -262
- data/lib/note/java/note_spec.rb +0 -20
- data/lib/note/win/locknote.rb +0 -19
- data/lib/note.rb +0 -15
- data/lib/win_gui/constants.rb +0 -82
- data/lib/win_gui/def_api.rb +0 -160
- data/lib/win_gui/string_extensions.rb +0 -36
- data/lib/win_gui/win_gui.rb +0 -437
- data/old/windows_basics.rb +0 -80
- data/old/wnote.rb +0 -80
- data/old/wnote_spec.rb +0 -20
- data/spec/note/win/locknote_spec.rb +0 -7
- data/spec/test_apps/locknote/LockNote.exe +0 -0
- data/spec/win_gui/def_api_spec.rb +0 -339
- data/spec/win_gui/string_extensions_spec.rb +0 -61
- data/spec/win_gui/win_gui_spec.rb +0 -537
- data/win_gui.gemspec +0 -215
@@ -1,36 +0,0 @@
|
|
1
|
-
class String
|
2
|
-
def snake_case
|
3
|
-
gsub(/([a-z])([A-Z0-9])/, '\1_\2' ).downcase
|
4
|
-
end
|
5
|
-
|
6
|
-
def camel_case
|
7
|
-
if self.include? '_'
|
8
|
-
self.split('_').map{|e| e.capitalize}.join
|
9
|
-
else
|
10
|
-
unless self =~ (/^[A-Z]/)
|
11
|
-
self.capitalize
|
12
|
-
else
|
13
|
-
self
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def to_w
|
19
|
-
(self+"\x00").encode('utf-16LE')
|
20
|
-
end
|
21
|
-
|
22
|
-
def to_vkeys
|
23
|
-
unless size == 1
|
24
|
-
raise "Can't convert but a single character: #{self}"
|
25
|
-
end
|
26
|
-
ascii = upcase.unpack('C')[0]
|
27
|
-
case self
|
28
|
-
when 'a'..'z', '0'..'9', ' '
|
29
|
-
[ascii]
|
30
|
-
when 'A'..'Z'
|
31
|
-
[WinGui.const_get(:VK_SHIFT), ascii]
|
32
|
-
else
|
33
|
-
raise "Can't convert unknown character: #{self}"
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
data/lib/win_gui/win_gui.rb
DELETED
@@ -1,437 +0,0 @@
|
|
1
|
-
require 'string_extensions'
|
2
|
-
require 'constants'
|
3
|
-
require 'def_api'
|
4
|
-
require 'window'
|
5
|
-
|
6
|
-
#:stopdoc:
|
7
|
-
# TODO - When calling API functions, win_handle arg should default to instance var @handle of the host class
|
8
|
-
# TODO - Giving a hash of "named args" to def_api, like this:
|
9
|
-
# TODO def_api 'ShowWindow', 'LI' , 'I', :args=>{1=>:handle=>, 2=>[:cmd, :command]}
|
10
|
-
# TODO - Giving a hash of "defaults" to def_api, like this:
|
11
|
-
# TODO def_api 'ShowWindow', 'LI' , 'I', :defaults=>{1=>1234, 2=>'String2'}
|
12
|
-
# TODO - Option :class_method should define CLASS method instead of instance
|
13
|
-
#:startdoc:
|
14
|
-
|
15
|
-
module WinGui
|
16
|
-
extend DefApi
|
17
|
-
|
18
|
-
# Windows GUI API definitions:
|
19
|
-
|
20
|
-
##
|
21
|
-
# Tests whether the specified window handle identifies an existing window.
|
22
|
-
# A thread should not use IsWindow for a window that it did not create because the window
|
23
|
-
# could be destroyed after this function was called. Further, because window handles are
|
24
|
-
# recycled the handle could even point to a different window.
|
25
|
-
#
|
26
|
-
# :call-seq:
|
27
|
-
# window?( win_handle )
|
28
|
-
#
|
29
|
-
def_api 'IsWindow', 'L', 'L'
|
30
|
-
|
31
|
-
##
|
32
|
-
# Tests if the specified window, its parent window, its parent's parent window, and so forth,
|
33
|
-
# have the WS_VISIBLE style. Because the return value specifies whether the window has the
|
34
|
-
# WS_VISIBLE style, it may be true even if the window is totally obscured by other windows.
|
35
|
-
#
|
36
|
-
# :call-seq:
|
37
|
-
# visible?( win_handle ), window_visible?( win_handle )
|
38
|
-
#
|
39
|
-
def_api 'IsWindowVisible', 'L', 'L', aliases: :visible?
|
40
|
-
|
41
|
-
##
|
42
|
-
# Tests whether the specified window is maximized.
|
43
|
-
#
|
44
|
-
# :call-seq:
|
45
|
-
# zoomed?( win_handle ), maximized?( win_handle )
|
46
|
-
#
|
47
|
-
def_api 'IsZoomed', 'L', 'L', aliases: :maximized?
|
48
|
-
|
49
|
-
##
|
50
|
-
# Tests whether the specified window is maximized.
|
51
|
-
#
|
52
|
-
# :call-seq:
|
53
|
-
# iconic?( win_handle ), minimized?( win_handle )
|
54
|
-
#
|
55
|
-
def_api 'IsIconic', 'L', 'L', aliases: :minimized?
|
56
|
-
|
57
|
-
##
|
58
|
-
# Tests whether a window is a child (or descendant) window of a specified parent window.
|
59
|
-
# A child window is the direct descendant of a specified parent window if that parent window
|
60
|
-
# is in the chain of parent windows; the chain of parent windows leads from the original overlapped
|
61
|
-
# or pop-up window to the child window.
|
62
|
-
#
|
63
|
-
# :call-seq:
|
64
|
-
# child?( win_handle )
|
65
|
-
#
|
66
|
-
def_api 'IsChild', 'LL', 'L'
|
67
|
-
|
68
|
-
##
|
69
|
-
# Returns a handle to the top-level window whose class and window name match the specified strings.
|
70
|
-
# This function does not search child windows. This function does not perform a case-sensitive search.
|
71
|
-
#
|
72
|
-
# Parameters:
|
73
|
-
# class_name (P) - String that specifies (window) class name OR class atom created by a previous
|
74
|
-
# call to the RegisterClass(Ex) function. The atom must be in the low-order word of class_name;
|
75
|
-
# the high-order word must be zero. The class name can be any name registered with RegisterClass(Ex),
|
76
|
-
# or any of the predefined control-class names. If this parameter is nil, it finds any window whose
|
77
|
-
# title matches the win_title parameter.
|
78
|
-
# win_name (P) - String that specifies the window name (title). If nil, all names match.
|
79
|
-
# Return Value (L): found window handle or NIL if nothing found
|
80
|
-
#
|
81
|
-
# :call-seq:
|
82
|
-
# win_handle = find_window( class_name, win_name )
|
83
|
-
#
|
84
|
-
def_api 'FindWindow', 'PP', 'L', zeronil: true
|
85
|
-
|
86
|
-
##
|
87
|
-
# Unicode version of find_window (strings must be encoded as utf-16LE AND terminate with "\x00\x00")
|
88
|
-
#
|
89
|
-
# :call-seq:
|
90
|
-
# win_handle = find_window_w( class_name, win_name )
|
91
|
-
#
|
92
|
-
def_api 'FindWindowW', 'PP', 'L', zeronil: true
|
93
|
-
|
94
|
-
##
|
95
|
-
# Retrieves a handle to a CHILD window whose class name and window name match the specified strings.
|
96
|
-
# The function searches child windows, beginning with the one following the specified child window.
|
97
|
-
# This function does NOT perform a case-sensitive search.
|
98
|
-
#
|
99
|
-
# Parameters:
|
100
|
-
# parent (L) - Handle to the parent window whose child windows are to be searched.
|
101
|
-
# If nil, the function uses the desktop window as the parent window.
|
102
|
-
# The function searches among windows that are child windows of the desktop.
|
103
|
-
# after_child (L) - Handle to a child window. Search begins with the NEXT child window in the Z order.
|
104
|
-
# The child window must be a direct child window of parent, not just a descendant window.
|
105
|
-
# If after_child is nil, the search begins with the first child window of parent.
|
106
|
-
# win_class (P), win_title (P) - Strings that specify window class and name(title). If nil, anything matches.
|
107
|
-
# Returns (L): found child window handle or NIL if nothing found
|
108
|
-
#
|
109
|
-
# :call-seq:
|
110
|
-
# win_handle = find_window_ex( win_handle, after_child, class_name, win_name )
|
111
|
-
#
|
112
|
-
def_api 'FindWindowEx', 'LLPP', 'L', zeronil: true
|
113
|
-
|
114
|
-
##
|
115
|
-
# Returns the text of the specified window's title bar (if it has one).
|
116
|
-
# If the specified window is a control, the text of the control is copied. However, GetWindowText
|
117
|
-
# cannot retrieve the text of a control in another application.
|
118
|
-
#
|
119
|
-
# Original Parameters:
|
120
|
-
# win_handle (L) - Handle to the window and, indirectly, the class to which the window belongs.
|
121
|
-
# text (P) - Long Pointer to the buffer that is to receive the text string.
|
122
|
-
# max_count (I) - Specifies the length, in TCHAR, of the buffer pointed to by the text parameter.
|
123
|
-
# The class name string is truncated if it is longer than the buffer and is always null-terminated.
|
124
|
-
# Original Return Value (L): Length, in characters, of the copied string, not including the terminating null
|
125
|
-
# character, indicates success. Zero indicates that the window has no title bar or text, if the title bar
|
126
|
-
# is empty, or if the window or control handle is invalid. For extended error information, call GetLastError.
|
127
|
-
#
|
128
|
-
# Enhanced API requires only win_handle and returns rstripped text
|
129
|
-
#
|
130
|
-
# Enhanced Parameters:
|
131
|
-
# win_handle (L) - Handle to the window and, indirectly, the class to which the window belongs.
|
132
|
-
# Returns: Window title bar text or nil
|
133
|
-
# If the window has no title bar or text, if the title bar is empty, or if the window or control handle
|
134
|
-
# is invalid, the return value is NIL. To get extended error information, call GetLastError.
|
135
|
-
#
|
136
|
-
# Remarks: This function CANNOT retrieve the text of an edit control in ANOTHER app.
|
137
|
-
# If the target window is owned by the current process, GetWindowText causes a WM_GETTEXT message to
|
138
|
-
# be sent to the specified window or control. If the target window is owned by another process and has
|
139
|
-
# a caption, GetWindowText retrieves the window caption text. If the window does not have a caption,
|
140
|
-
# the return value is a null string. This allows to call GetWindowText without becoming unresponsive
|
141
|
-
# if the target window owner process is not responding. However, if the unresponsive target window
|
142
|
-
# belongs to the calling app, GetWindowText will cause the calling app to become unresponsive.
|
143
|
-
# To retrieve the text of a control in another process, send a WM_GETTEXT message directly instead
|
144
|
-
# of calling GetWindowText.
|
145
|
-
#
|
146
|
-
#:call-seq:
|
147
|
-
# text = get_window_text( win_handle )
|
148
|
-
#
|
149
|
-
def_api 'GetWindowText', 'LPI', 'L', &return_string
|
150
|
-
|
151
|
-
##
|
152
|
-
# Unicode version of get_window_text (returns rstripped utf-8 string)
|
153
|
-
# API improved to require only win_handle and return rstripped string
|
154
|
-
#
|
155
|
-
#:call-seq:
|
156
|
-
# text = get_window_text_w( win_handle )
|
157
|
-
#
|
158
|
-
def_api 'GetWindowTextW', 'LPI', 'L', &return_string('utf-8')
|
159
|
-
|
160
|
-
##
|
161
|
-
# Retrieves the name of the class to which the specified window belongs.
|
162
|
-
#
|
163
|
-
# Original Parameters:
|
164
|
-
# win_handle (L) - Handle to the window and, indirectly, the class to which the window belongs.
|
165
|
-
# class_name (P) - Long Pointer to the buffer that is to receive the class name string.
|
166
|
-
# max_count (I) - Specifies the length, in TCHAR, of the buffer pointed to by the class_name parameter.
|
167
|
-
# The class name string is truncated if it is longer than the buffer and is always null-terminated.
|
168
|
-
# Original Return Value (L): Length, in characters, of the copied string, not including the terminating null
|
169
|
-
# character, indicates success. Zero indicates that the window has no title bar or text, if the title bar
|
170
|
-
# is empty, or if the window or control handle is invalid. For extended error information, call GetLastError.
|
171
|
-
#
|
172
|
-
# API improved to require only win_handle and return rstripped string
|
173
|
-
#
|
174
|
-
# Enhanced Parameters:
|
175
|
-
# win_handle (L) - Handle to the window and, indirectly, the class to which the window belongs.
|
176
|
-
# Returns: Name of the class or NIL if function fails. For extended error information, call GetLastError.
|
177
|
-
#
|
178
|
-
#:call-seq:
|
179
|
-
# text = get_class_name( win_handle )
|
180
|
-
#
|
181
|
-
def_api 'GetClassName', 'LPI', 'I', &return_string
|
182
|
-
|
183
|
-
##
|
184
|
-
# Unicode version of get_class_name (returns rstripped utf-8 string)
|
185
|
-
# API improved to require only win_handle and return rstripped string
|
186
|
-
#
|
187
|
-
#:call-seq:
|
188
|
-
# text = get_class_name_w( win_handle )
|
189
|
-
#
|
190
|
-
def_api 'GetClassNameW', 'LPI', 'I', &return_string('utf-8')
|
191
|
-
|
192
|
-
##
|
193
|
-
# Shows and hides windows.
|
194
|
-
#
|
195
|
-
# Parameters:
|
196
|
-
# win_handle (L) - Handle to the window.
|
197
|
-
# cmd (I) - Specifies how the window is to be shown. This parameter is ignored the first time an
|
198
|
-
# application calls ShowWindow, if the program that launched the application provides a STARTUPINFO
|
199
|
-
# structure. Otherwise, the first time ShowWindow is called, the value should be the value obtained
|
200
|
-
# by the WinMain function in its nCmdShow parameter. In subsequent calls, cmd may be:
|
201
|
-
# SW_HIDE, SW_MAXIMIZE, SW_MINIMIZE, SW_SHOW, SW_SHOWMAXIMIZED, SW_SHOWMINIMIZED, SW_SHOWMINNOACTIVE,
|
202
|
-
# SW_SHOWNA, SW_SHOWNOACTIVATE, SW_SHOWNORMAL, SW_RESTORE, SW_SHOWDEFAULT, SW_FORCEMINIMIZE
|
203
|
-
#
|
204
|
-
# Original Return Value: - Nonzero if the window was PREVIOUSLY visible, otherwise zero
|
205
|
-
# Enhanced Returns: - True if the window was PREVIOUSLY visible, otherwise false
|
206
|
-
#
|
207
|
-
#:call-seq:
|
208
|
-
# was_visible = show_window( win_handle, cmd )
|
209
|
-
#
|
210
|
-
def_api 'ShowWindow', 'LI', 'I', boolean: true
|
211
|
-
|
212
|
-
# Hides the window and activates another window.
|
213
|
-
SW_HIDE = 0
|
214
|
-
# Same as SW_SHOWNORMAL
|
215
|
-
SW_NORMAL = 1
|
216
|
-
# Activates and displays a window. If the window is minimized or maximized, the system restores it to its
|
217
|
-
# original size and position. An application should specify this flag when displaying the window for the first time.
|
218
|
-
SW_SHOWNORMAL = 1
|
219
|
-
# Activates the window and displays it as a minimized window.
|
220
|
-
SW_SHOWMINIMIZED = 2
|
221
|
-
# Activates the window and displays it as a maximized window.
|
222
|
-
SW_SHOWMAXIMIZED = 3
|
223
|
-
# Activates the window and displays it as a maximized window.
|
224
|
-
SW_MAXIMIZE = 3
|
225
|
-
# Displays a window in its most recent size and position. Similar to SW_SHOWNORMAL, but the window is not activated.
|
226
|
-
SW_SHOWNOACTIVATE = 4
|
227
|
-
# Activates the window and displays it in its current size and position.
|
228
|
-
SW_SHOW = 5
|
229
|
-
# Minimizes the specified window, activates the next top-level window in the Z order.
|
230
|
-
SW_MINIMIZE = 6
|
231
|
-
# Displays the window as a minimized window. Similar to SW_SHOWMINIMIZED, except the window is not activated.
|
232
|
-
SW_SHOWMINNOACTIVE= 7
|
233
|
-
# Displays the window in its current size and position. Similar to SW_SHOW, except the window is not activated.
|
234
|
-
SW_SHOWNA = 8
|
235
|
-
# Activates and displays the window. If the window is minimized or maximized, the system restores it to its original
|
236
|
-
# size and position. An application should specify this flag when restoring a minimized window.
|
237
|
-
SW_RESTORE = 9
|
238
|
-
# Sets the show state based on the SW_ value specified in the STARTUPINFO structure passed to the CreateProcess
|
239
|
-
# function by the program that started the application.
|
240
|
-
SW_SHOWDEFAULT = 10
|
241
|
-
# Windows 2000/XP: Minimizes a window, even if the thread that owns the window is not responding. Only use this
|
242
|
-
# flag when minimizing windows from a different thread.
|
243
|
-
SW_FORCEMINIMIZE = 11
|
244
|
-
|
245
|
-
# Hides the window and activates another window
|
246
|
-
def hide_window(win_handle)
|
247
|
-
show_window(win_handle, SW_HIDE)
|
248
|
-
end
|
249
|
-
|
250
|
-
return_thread_process = lambda do |api, *args|
|
251
|
-
WinGui.enforce_count( args, api.prototype, -1)
|
252
|
-
thread = api.call(args.first, process = [1].pack('L'))
|
253
|
-
nonzero_array(thread, *process.unpack('L'))
|
254
|
-
end
|
255
|
-
|
256
|
-
##
|
257
|
-
# Retrieves the identifier of the thread that created the specified window
|
258
|
-
# and, optionally, the identifier of the process that created the window.
|
259
|
-
#
|
260
|
-
# Original Parameters:
|
261
|
-
# handle (L) - Handle to the window.
|
262
|
-
# process (P) - A POINTER to a (Long) variable that receives the process identifier.
|
263
|
-
# Original Return (L): Identifier of the thread that created the window.
|
264
|
-
#
|
265
|
-
# API improved to accept window handle as a single arg and return a pair of [thread, process] ids
|
266
|
-
#
|
267
|
-
# New Parameters:
|
268
|
-
# handle (L) - Handle to the window.
|
269
|
-
# Returns: Pair of identifiers of the thread and process_id that created the window.
|
270
|
-
#
|
271
|
-
#:call-seq:
|
272
|
-
# thread, process_id = get_window_tread_process_id( win_handle )
|
273
|
-
#
|
274
|
-
def_api 'GetWindowThreadProcessId', 'LP', 'L', &return_thread_process
|
275
|
-
|
276
|
-
return_rect = lambda do |api, *args|
|
277
|
-
WinGui.enforce_count( args, api.prototype, -1)
|
278
|
-
rectangle = [0, 0, 0, 0].pack('L*')
|
279
|
-
res = api.call args.first, rectangle
|
280
|
-
res == 0 ? [nil, nil, nil, nil] : rectangle.unpack('L*')
|
281
|
-
end
|
282
|
-
|
283
|
-
##
|
284
|
-
# Retrieves the dimensions of the specified window bounding rectangle.
|
285
|
-
# Dimensions are given relative to the upper-left corner of the screen.
|
286
|
-
#
|
287
|
-
# Original Parameters:
|
288
|
-
# win_handle (L) - Handle to the window.
|
289
|
-
# rect (P) - Long pointer to a RECT structure that receives the screen coordinates of the upper-left and
|
290
|
-
# lower-right corners of the window.
|
291
|
-
# Original Return Value: Nonzero indicates success. Zero indicates failure. For error info, call GetLastError.
|
292
|
-
#
|
293
|
-
# API improved to accept only window handle and return 4-member dimensions array (left, top, right, bottom)
|
294
|
-
#
|
295
|
-
# New Parameters:
|
296
|
-
# win_handle (L) - Handle to the window
|
297
|
-
# New Return: Array(left, top, right, bottom) - rectangle dimensions
|
298
|
-
#
|
299
|
-
# Remarks: As a convention for the RECT structure, the bottom-right coordinates of the returned rectangle
|
300
|
-
# are exclusive. In other words, the pixel at (right, bottom) lies immediately outside the rectangle.
|
301
|
-
#
|
302
|
-
#:call-seq:
|
303
|
-
# rect = get_window_rect( win_handle )
|
304
|
-
#
|
305
|
-
def_api 'GetWindowRect', 'LP', 'I', &return_rect
|
306
|
-
|
307
|
-
##
|
308
|
-
# The EnumWindows function enumerates all top-level windows on the screen by passing the handle to
|
309
|
-
# each window, in turn, to an application-defined callback function. EnumWindows continues until
|
310
|
-
# the last top-level window is enumerated or the callback function returns FALSE.
|
311
|
-
#
|
312
|
-
# Original Parameters:
|
313
|
-
# callback [K] - Pointer to an application-defined callback function (see EnumWindowsProc).
|
314
|
-
# message [P] - Specifies an application-defined value(message) to be passed to the callback function.
|
315
|
-
# Original Return: Nonzero if the function succeeds, zero if the function fails. GetLastError for error info.
|
316
|
-
# If callback returns zero, the return value is also zero. In this case, the callback function should
|
317
|
-
# call SetLastError to obtain a meaningful error code to be returned to the caller of EnumWindows.
|
318
|
-
#
|
319
|
-
# API improved to accept blocks (instead of callback objects) and message as a single arg
|
320
|
-
#
|
321
|
-
# New Parameters:
|
322
|
-
# message [P] - Specifies an application-defined value(message) to be passed to the callback function.
|
323
|
-
# block given to method invocation serves as an application-defined callback function (see EnumWindowsProc).
|
324
|
-
# Returns: True if the function succeeds, false if the function fails. GetLastError for error info.
|
325
|
-
# If callback returns zero, the return value is also zero. In this case, the callback function should
|
326
|
-
# call SetLastError to obtain a meaningful error code to be returned to the caller of EnumWindows.
|
327
|
-
#
|
328
|
-
# Remarks: The EnumWindows function does not enumerate child windows, with the exception of a few top-level
|
329
|
-
# windows owned by the system that have the WS_CHILD style. This function is more reliable than calling
|
330
|
-
# the GetWindow function in a loop. An application that calls GetWindow to perform this task risks being
|
331
|
-
# caught in an infinite loop or referencing a handle to a window that has been destroyed.
|
332
|
-
#
|
333
|
-
#:call-seq:
|
334
|
-
# status = enum_windows( message ) {|win_handle, message| callback procedure }
|
335
|
-
#
|
336
|
-
def_api'EnumWindows', 'KP', 'L', boolean: true, &return_enum
|
337
|
-
|
338
|
-
##
|
339
|
-
# Enumerates child windows to a given window.
|
340
|
-
#
|
341
|
-
# Original Parameters:
|
342
|
-
# parent (L) - Handle to the parent window whose child windows are to be enumerated.
|
343
|
-
# callback [K] - Pointer to an application-defined callback function (see EnumWindowsProc).
|
344
|
-
# message [P] - Specifies an application-defined value(message) to be passed to the callback function.
|
345
|
-
# Original Return: Not used (?!)
|
346
|
-
# If callback returns zero, the return value is also zero. In this case, the callback function should
|
347
|
-
# call SetLastError to obtain a meaningful error code to be returned to the caller of EnumWindows.
|
348
|
-
# If it is nil, this function is equivalent to EnumWindows. Windows 95/98/Me: parent cannot be NULL.
|
349
|
-
#
|
350
|
-
# API improved to accept blocks (instead of callback objects) and two args: parent handle and message.
|
351
|
-
# New Parameters:
|
352
|
-
# parent (L) - Handle to the parent window whose child windows are to be enumerated.
|
353
|
-
# message (P) - Specifies an application-defined value(message) to be passed to the callback function.
|
354
|
-
# block given to method invocation serves as an application-defined callback function (see EnumChildProc).
|
355
|
-
#
|
356
|
-
# Remarks:
|
357
|
-
# If a child window has created child windows of its own, EnumChildWindows enumerates those windows as well.
|
358
|
-
# A child window that is moved or repositioned in the Z order during the enumeration process will be properly enumerated.
|
359
|
-
# The function does not enumerate a child window that is destroyed before being enumerated or that is created during the enumeration process.
|
360
|
-
#
|
361
|
-
#:call-seq:
|
362
|
-
# enum_windows( parent_handle, message ) {|win_handle, message| callback procedure }
|
363
|
-
#
|
364
|
-
def_api 'EnumChildWindows', 'LKP', 'L', &return_enum
|
365
|
-
|
366
|
-
##
|
367
|
-
# GetForegroundWindow function returns a handle to the foreground window (the window with which the user
|
368
|
-
# is currently working). The system assigns a slightly higher priority to the thread that creates the
|
369
|
-
# foreground window than it does to other threads.
|
370
|
-
#
|
371
|
-
# Syntax: HWND GetForegroundWindow(VOID);
|
372
|
-
#
|
373
|
-
# Return Value: The return value is a handle to the foreground window. The foreground window can be NULL in
|
374
|
-
# certain circumstances, such as when a window is losing activation.
|
375
|
-
#
|
376
|
-
#:call-seq:
|
377
|
-
# win_handle = (get_)foreground_window()
|
378
|
-
#
|
379
|
-
def_api 'GetForegroundWindow', 'V', 'L'
|
380
|
-
|
381
|
-
def foreground?(win_handle)
|
382
|
-
win_handle == foreground_window
|
383
|
-
end
|
384
|
-
|
385
|
-
##
|
386
|
-
# The GetActiveWindow function retrieves the window handle to the active window attached to
|
387
|
-
# the calling thread's message queue.
|
388
|
-
#
|
389
|
-
# Syntax: HWND GetActiveWindow(VOID);
|
390
|
-
#
|
391
|
-
# Return Value: The return value is the handle to the active window attached to the calling
|
392
|
-
# thread's message queue. Otherwise, the return value is NULL.
|
393
|
-
#
|
394
|
-
# Remarks: To get the handle to the foreground window, you can use GetForegroundWindow.
|
395
|
-
# To get the window handle to the active window in the message queue for another thread, use GetGUIThreadInfo.
|
396
|
-
#
|
397
|
-
#:call-seq:
|
398
|
-
# win_handle = (get_)active_window()
|
399
|
-
#
|
400
|
-
def_api 'GetActiveWindow', 'V', 'L'
|
401
|
-
|
402
|
-
def_api 'keybd_event', 'IILL', 'V'
|
403
|
-
def_api 'PostMessage', 'LLLL', 'L'
|
404
|
-
def_api 'SendMessage', 'LLLP', 'L'
|
405
|
-
def_api 'GetDlgItem', 'LL', 'L'
|
406
|
-
|
407
|
-
|
408
|
-
# Convenience wrapper methods:
|
409
|
-
|
410
|
-
# emulates combinations of keys pressed (Ctrl+Alt+P+M, etc)
|
411
|
-
def keystroke(*keys)
|
412
|
-
return if keys.empty?
|
413
|
-
keybd_event keys.first, 0, KEYEVENTF_KEYDOWN, 0
|
414
|
-
sleep WG_KEY_DELAY
|
415
|
-
keystroke *keys[1..-1]
|
416
|
-
sleep WG_KEY_DELAY
|
417
|
-
keybd_event keys.first, 0, KEYEVENTF_KEYUP, 0
|
418
|
-
end
|
419
|
-
|
420
|
-
# types text message into window holding the focus
|
421
|
-
def type_in(message)
|
422
|
-
message.scan(/./m) do |char|
|
423
|
-
keystroke(*char.to_vkeys)
|
424
|
-
end
|
425
|
-
end
|
426
|
-
|
427
|
-
# finds top-level dialog window by title and yields it to given block
|
428
|
-
def dialog(title, seconds=3)
|
429
|
-
d = begin
|
430
|
-
win = Window.top_level(title, seconds)
|
431
|
-
yield(win) ? win : nil
|
432
|
-
rescue TimeoutError
|
433
|
-
end
|
434
|
-
d.wait_for_close if d
|
435
|
-
return d
|
436
|
-
end
|
437
|
-
end
|
data/old/windows_basics.rb
DELETED
@@ -1,80 +0,0 @@
|
|
1
|
-
require 'timeout'
|
2
|
-
require 'Win32API'
|
3
|
-
|
4
|
-
def user32(name, param_types, return_value) #(1)
|
5
|
-
Win32API.new 'user32', name, param_types, return_value
|
6
|
-
end
|
7
|
-
|
8
|
-
find_window = user32 'FindWindow', ['P', 'P'], 'L'
|
9
|
-
|
10
|
-
system 'start "" "C:/Dev/apps/gui_testing/win/locknote/LockNote.exe"'
|
11
|
-
|
12
|
-
sleep 0.2 while (main_window = find_window.call \
|
13
|
-
nil, 'LockNote - Steganos LockNote') <= 0 #(2)
|
14
|
-
|
15
|
-
puts "The main window's handle is #{main_window}."
|
16
|
-
|
17
|
-
keybd_event = user32 'keybd_event', ['I', 'I', 'L', 'L'], 'V'
|
18
|
-
|
19
|
-
KEYEVENTF_KEYDOWN = 0
|
20
|
-
KEYEVENTF_KEYUP = 2
|
21
|
-
|
22
|
-
"this is some text".upcase.each_byte do |b| #(3)
|
23
|
-
keybd_event.call b, 0, KEYEVENTF_KEYDOWN, 0
|
24
|
-
sleep 0.05
|
25
|
-
keybd_event.call b, 0, KEYEVENTF_KEYUP, 0
|
26
|
-
sleep 0.05
|
27
|
-
end
|
28
|
-
|
29
|
-
post_message = user32 'PostMessage', ['L', 'L', 'L', 'L'], 'L'
|
30
|
-
|
31
|
-
WM_SYSCOMMAND = 0x0112
|
32
|
-
SC_CLOSE = 0xF060
|
33
|
-
|
34
|
-
post_message.call main_window, WM_SYSCOMMAND, SC_CLOSE, 0
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
# You might need a slight delay here.
|
39
|
-
sleep 0.5
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
get_dlg_item = user32 'GetDlgItem', ['L', 'L'], 'L'
|
44
|
-
|
45
|
-
dialog = timeout(3) do #(4)
|
46
|
-
sleep 0.2 while (h = find_window.call \
|
47
|
-
nil, 'Steganos LockNote') <= 0; h #(5)
|
48
|
-
end
|
49
|
-
|
50
|
-
IDNO = 7
|
51
|
-
button = get_dlg_item.call dialog, IDNO
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
get_window_rect = user32 'GetWindowRect', ['L', 'P'], 'I'
|
57
|
-
|
58
|
-
rectangle = [0, 0, 0, 0].pack 'L*'
|
59
|
-
get_window_rect.call button, rectangle
|
60
|
-
left, top, right, bottom = rectangle.unpack 'L*'
|
61
|
-
|
62
|
-
puts "The No button is #{right - left} pixels wide." #(6)
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
set_cursor_pos = user32 'SetCursorPos', ['L', 'L'], 'I'
|
68
|
-
|
69
|
-
mouse_event = user32 'mouse_event', ['L', 'L', 'L', 'L', 'L'], 'V'
|
70
|
-
|
71
|
-
MOUSEEVENTF_LEFTDOWN = 0x0002
|
72
|
-
MOUSEEVENTF_LEFTUP = 0x0004
|
73
|
-
|
74
|
-
center = [(left + right) / 2, (top + bottom) / 2]
|
75
|
-
|
76
|
-
set_cursor_pos.call *center #(7)
|
77
|
-
|
78
|
-
mouse_event.call MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
|
79
|
-
mouse_event.call MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
|
80
|
-
|
data/old/wnote.rb
DELETED
@@ -1,80 +0,0 @@
|
|
1
|
-
require 'timeout'
|
2
|
-
require 'Win32API'
|
3
|
-
|
4
|
-
def user32(name, param_types, return_value)
|
5
|
-
Win32API.new 'user32', name, param_types, return_value
|
6
|
-
end
|
7
|
-
|
8
|
-
KEYEVENTF_KEYDOWN = 0
|
9
|
-
KEYEVENTF_KEYUP = 2
|
10
|
-
WM_GETTEXT = 0x000D
|
11
|
-
IDNO = 7
|
12
|
-
WM_SYSCOMMAND = 0x0112
|
13
|
-
SC_CLOSE = 0xF060
|
14
|
-
MOUSEEVENTF_LEFTDOWN = 0x0002
|
15
|
-
MOUSEEVENTF_LEFTUP = 0x0004
|
16
|
-
|
17
|
-
class Note
|
18
|
-
def initialize
|
19
|
-
find_window = user32 'FindWindow', ['P', 'P'], 'L'
|
20
|
-
system 'start "" "C:/Dev/apps/gui_testing/lib/win/locknote/LockNote.exe"'
|
21
|
-
sleep 0.2 while (@main_window = find_window.call nil, 'LockNote - Steganos LockNote') <= 0
|
22
|
-
#type_in 'aaaaabc'
|
23
|
-
end
|
24
|
-
|
25
|
-
def type_in(text)
|
26
|
-
keybd_event = user32 'keybd_event', ['I', 'I', 'L', 'L'], 'V'
|
27
|
-
text.upcase.each_byte do |b| # upcase needed since user32 keybd_event expects upper case chars
|
28
|
-
keybd_event.call b, 0, KEYEVENTF_KEYDOWN, 0
|
29
|
-
sleep 0.05
|
30
|
-
keybd_event.call b, 0, KEYEVENTF_KEYUP, 0
|
31
|
-
sleep 0.05
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def text
|
36
|
-
find_window_ex = user32 'FindWindowEx' , ['L' , 'L' , 'P' , 'P' ], 'L'
|
37
|
-
send_message = user32 'SendMessage' , ['L' , 'L' , 'L' , 'P' ], 'L'
|
38
|
-
edit = find_window_ex.call @main_window, 0, 'ATL:00434310' , nil
|
39
|
-
buffer = "\x0" * 2048
|
40
|
-
send_message.call edit, WM_GETTEXT, buffer.length, buffer
|
41
|
-
return buffer
|
42
|
-
end
|
43
|
-
|
44
|
-
def exit!
|
45
|
-
begin
|
46
|
-
post_message = user32 'PostMessage', ['L', 'L', 'L', 'L'], 'L'
|
47
|
-
find_window = user32 'FindWindow', ['P', 'P'], 'L'
|
48
|
-
get_dlg_item = user32 'GetDlgItem', ['L', 'L'], 'L'
|
49
|
-
get_window_rect = user32 'GetWindowRect', ['L', 'P'], 'I'
|
50
|
-
set_cursor_pos = user32 'SetCursorPos', ['L', 'L'], 'I'
|
51
|
-
mouse_event = user32 'mouse_event', ['L', 'L', 'L', 'L', 'L'], 'V'
|
52
|
-
|
53
|
-
post_message.call @main_window, WM_SYSCOMMAND, SC_CLOSE, 0
|
54
|
-
|
55
|
-
sleep 0.2 # You might need a slight delay here.
|
56
|
-
|
57
|
-
dialog = timeout(3) do #(4)
|
58
|
-
sleep 0.2 while (h = find_window.call nil, 'Steganos LockNote') <= 0; h
|
59
|
-
end
|
60
|
-
|
61
|
-
button = get_dlg_item.call dialog, IDNO
|
62
|
-
|
63
|
-
rectangle = [0, 0, 0, 0].pack 'L*'
|
64
|
-
get_window_rect.call button, rectangle
|
65
|
-
left, top, right, bottom = rectangle.unpack 'L*'
|
66
|
-
center = [(left + right) / 2, (top + bottom) / 2]
|
67
|
-
|
68
|
-
set_cursor_pos.call *center #(7)
|
69
|
-
mouse_event.call MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
|
70
|
-
mouse_event.call MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
|
71
|
-
|
72
|
-
@prompted = true
|
73
|
-
rescue
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def has_prompted?
|
78
|
-
@prompted
|
79
|
-
end
|
80
|
-
end
|
data/old/wnote_spec.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
describe 'The main window' do
|
2
|
-
it 'launches with a welcome message' do
|
3
|
-
note = Note.new
|
4
|
-
note.text.should include('Welcome' )
|
5
|
-
note.exit!
|
6
|
-
end
|
7
|
-
|
8
|
-
it 'exits without a prompt if nothing has changed' do
|
9
|
-
note = Note.new
|
10
|
-
note.exit!
|
11
|
-
note.should_not have_prompted
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'prompts before exiting if the document has changed' do
|
15
|
-
note = Note.new
|
16
|
-
note.type_in "changed"
|
17
|
-
note.exit!
|
18
|
-
note.should have_prompted
|
19
|
-
end
|
20
|
-
end
|
Binary file
|