wet-winobj 0.1-mswin32
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/src/wet-winobj.rb +41 -0
- data/src/wet/constants/process.rb +10 -0
- data/src/wet/constants/testconstants.rb +1 -0
- data/src/wet/constants/winconstants.rb +73 -0
- data/src/wet/constants/wincontrolconst.rb +60 -0
- data/src/wet/exceptions/CompileExceptions.rb +31 -0
- data/src/wet/exceptions/RuntimeExceptions.rb +20 -0
- data/src/wet/utils/ArrayUtils.rb +52 -0
- data/src/wet/utils/CompileUtils.rb +43 -0
- data/src/wet/utils/FileUtils.rb +75 -0
- data/src/wet/utils/TextUtils.rb +63 -0
- data/src/wet/winobjects/AppWindow.rb +144 -0
- data/src/wet/winobjects/WinButton.rb +101 -0
- data/src/wet/winobjects/WinCheckbox.rb +84 -0
- data/src/wet/winobjects/WinComboBox.rb +70 -0
- data/src/wet/winobjects/WinDialog.rb +112 -0
- data/src/wet/winobjects/WinEdit.rb +125 -0
- data/src/wet/winobjects/WinLabel.rb +112 -0
- data/src/wet/winobjects/WinObjects.rb +35 -0
- data/src/wet/winobjects/WinRadio.rb +75 -0
- data/src/wet/winobjects/WinUtils.rb +231 -0
- data/src/wet/winobjects/Window.rb +537 -0
- data/tests/README +5 -0
- data/tests/TestAppWindow.rb +96 -0
- data/tests/TestButtonsWindow.rb +71 -0
- data/tests/TestCheckbox.rb +113 -0
- data/tests/TestCombo.rb +53 -0
- data/tests/TestDialog.rb +111 -0
- data/tests/TestLabel.rb +79 -0
- data/tests/TestRadio.rb +82 -0
- data/tests/TestWebEdit.rb +100 -0
- data/tests/wet-winobj-tests.rb +325 -0
- metadata +75 -0
@@ -0,0 +1,125 @@
|
|
1
|
+
=begin license
|
2
|
+
Copyright (c) 2005, Qantom Software
|
3
|
+
All rights reserved.
|
4
|
+
|
5
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
8
|
+
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
9
|
+
Neither the name of Qantom Software nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
10
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
11
|
+
|
12
|
+
(based on BSD Open Source License)
|
13
|
+
=end
|
14
|
+
|
15
|
+
require 'wet/winobjects/Window.rb'
|
16
|
+
|
17
|
+
|
18
|
+
module Wet
|
19
|
+
module Winobjects
|
20
|
+
=begin rdoc
|
21
|
+
Class to represent a Win32 edit box.
|
22
|
+
=end
|
23
|
+
class WinEdit < Window
|
24
|
+
|
25
|
+
@@known_class_names = ["Edit"]
|
26
|
+
|
27
|
+
=begin rdoc
|
28
|
+
Constructor to create a new WinEdit. Typically not invoked
|
29
|
+
directly. WinEdits are created using helper methods.
|
30
|
+
=end
|
31
|
+
def initialize(hwnd)
|
32
|
+
super(hwnd)
|
33
|
+
if @hwnd != -1
|
34
|
+
find_styles
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
=begin rdoc
|
39
|
+
Is the Window object a possible candidate for this class?
|
40
|
+
Return true if yes. False otherwise.
|
41
|
+
=end
|
42
|
+
#Note : - in the interest of reusable design, I had first put it this as a method
|
43
|
+
#in Window. But then I realized that each class may have to make complex
|
44
|
+
#calculations - eg. A label could be a static or an edit field set to read-only
|
45
|
+
def WinEdit.candidate_match?(win_element)
|
46
|
+
is_match = false
|
47
|
+
@@known_class_names.each do |e|
|
48
|
+
if TextUtils.compare_text(win_element.win_class,e)
|
49
|
+
is_match = true
|
50
|
+
break
|
51
|
+
end
|
52
|
+
end
|
53
|
+
return is_match
|
54
|
+
end
|
55
|
+
|
56
|
+
=begin rdoc
|
57
|
+
Set the text in the textfield.
|
58
|
+
=end
|
59
|
+
def set(text)
|
60
|
+
assert_object_exists
|
61
|
+
return do_set_text(@hwnd, text)
|
62
|
+
end
|
63
|
+
|
64
|
+
=begin rdoc
|
65
|
+
Retreive the text that has been set for this
|
66
|
+
object.
|
67
|
+
=end
|
68
|
+
def text()
|
69
|
+
assert_object_exists
|
70
|
+
return do_get_text(@hwnd)
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
=begin rdoc
|
75
|
+
If the WinEdit is actually being used as a label to display text,
|
76
|
+
get that display text and return it. The display_text is only
|
77
|
+
applicable if the control's readonly is set to 'true'
|
78
|
+
=end
|
79
|
+
def display_text()
|
80
|
+
assert_object_exists
|
81
|
+
ret_text = ""
|
82
|
+
if is_readonly
|
83
|
+
ret_text = text()
|
84
|
+
end
|
85
|
+
return ret_text
|
86
|
+
end
|
87
|
+
|
88
|
+
=begin rdoc
|
89
|
+
Is this textfield supposed to be readonly. return
|
90
|
+
true or false
|
91
|
+
=end
|
92
|
+
def is_readonly()
|
93
|
+
assert_object_exists
|
94
|
+
return @is_readonly
|
95
|
+
end
|
96
|
+
|
97
|
+
=begin rdoc
|
98
|
+
Is this textfield supposed to be a password control? return
|
99
|
+
true or false
|
100
|
+
=end
|
101
|
+
def is_password()
|
102
|
+
assert_object_exists
|
103
|
+
return @is_password
|
104
|
+
end
|
105
|
+
|
106
|
+
def to_s()
|
107
|
+
str = "WinEdit(label:="
|
108
|
+
if label != nil
|
109
|
+
str = str + label()
|
110
|
+
end
|
111
|
+
str = str + ")"
|
112
|
+
return str
|
113
|
+
end
|
114
|
+
|
115
|
+
private
|
116
|
+
def find_styles()
|
117
|
+
super
|
118
|
+
|
119
|
+
@is_password = @control_style & ES_PASSWORD == ES_PASSWORD
|
120
|
+
@is_readonly = @control_style & ES_READONLY == ES_READONLY
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
=begin license
|
2
|
+
Copyright (c) 2005, Qantom Software
|
3
|
+
All rights reserved.
|
4
|
+
|
5
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
8
|
+
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
9
|
+
Neither the name of Qantom Software nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
10
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
11
|
+
|
12
|
+
(based on BSD Open Source License)
|
13
|
+
=end
|
14
|
+
|
15
|
+
module Wet
|
16
|
+
module Winobjects
|
17
|
+
|
18
|
+
=begin rdoc
|
19
|
+
Class to represent a Win32 textual label.
|
20
|
+
=end
|
21
|
+
class WinLabel < Window
|
22
|
+
@@known_class_names = ["Static"]
|
23
|
+
|
24
|
+
|
25
|
+
=begin rdoc
|
26
|
+
Constructor to create a new WinLabel. Typically not invoked
|
27
|
+
directly. WinLabels are created using helper methods.
|
28
|
+
=end
|
29
|
+
def initialize(hwnd)
|
30
|
+
super
|
31
|
+
if @hwnd != -1
|
32
|
+
found = find_labelled
|
33
|
+
if found != -1
|
34
|
+
@label_for=Window::create(found)
|
35
|
+
@label_for.set_label(self)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
=begin rdoc
|
41
|
+
Which control is this WinLabel element a 'label' for? Return
|
42
|
+
the WinObject to which the current Label element is
|
43
|
+
associated
|
44
|
+
=end
|
45
|
+
def labelled_control()
|
46
|
+
return @label_for
|
47
|
+
end
|
48
|
+
|
49
|
+
=begin rdoc
|
50
|
+
Is the Window object a possible candidate for this class?
|
51
|
+
Return true if yes. False otherwise.
|
52
|
+
=end
|
53
|
+
#Note : - in the interest of reusable design, I had first put it this as a method
|
54
|
+
#in Window. But then I realized that each class may have to make complex
|
55
|
+
#calculations - eg. A label could be a static or an edit field set to read-only
|
56
|
+
#Note : Right now only Static fields are supported
|
57
|
+
def WinLabel.candidate_match?(win_element)
|
58
|
+
is_match = false
|
59
|
+
@@known_class_names.each do |e|
|
60
|
+
if TextUtils.compare_text(win_element.win_class,e)
|
61
|
+
is_match = true
|
62
|
+
break
|
63
|
+
end
|
64
|
+
end
|
65
|
+
return is_match
|
66
|
+
end
|
67
|
+
|
68
|
+
=begin rdoc
|
69
|
+
Get the text that that is being displayed
|
70
|
+
=end
|
71
|
+
def display_text()
|
72
|
+
assert_object_exists
|
73
|
+
return text()
|
74
|
+
end
|
75
|
+
|
76
|
+
def to_s()
|
77
|
+
find_labelled()
|
78
|
+
str = "WinLabel(text:="
|
79
|
+
str = str + text()
|
80
|
+
str = str + ")"
|
81
|
+
return str
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
85
|
+
def find_labelled()
|
86
|
+
#This may start falling over - There are a few additional tests
|
87
|
+
#that you'll need to do -
|
88
|
+
#a) Does this label have '&' character - if dont consider this as
|
89
|
+
#a label.
|
90
|
+
is_label_found = false
|
91
|
+
cur_wnd = @hwnd
|
92
|
+
found_wnd = -1
|
93
|
+
while !is_label_found
|
94
|
+
cur_wnd=next_window(cur_wnd)
|
95
|
+
|
96
|
+
if cur_wnd != 0
|
97
|
+
if Window.new(cur_wnd).is_tab_stop
|
98
|
+
is_label_found = true
|
99
|
+
found_wnd = cur_wnd
|
100
|
+
break
|
101
|
+
end
|
102
|
+
else
|
103
|
+
break
|
104
|
+
end
|
105
|
+
end
|
106
|
+
return found_wnd
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
=begin license
|
2
|
+
Copyright (c) 2005, Qantom Software
|
3
|
+
All rights reserved.
|
4
|
+
|
5
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
8
|
+
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
9
|
+
Neither the name of Qantom Software nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
10
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
11
|
+
|
12
|
+
(based on BSD Open Source License)
|
13
|
+
=end
|
14
|
+
require 'wet/winobjects/WinUtils.rb'
|
15
|
+
require 'wet/winobjects/Window.rb'
|
16
|
+
require 'wet/winobjects/WinEdit.rb'
|
17
|
+
require 'wet/winobjects/WinComboBox.rb'
|
18
|
+
require 'wet/winobjects/WinButton.rb'
|
19
|
+
require 'wet/winobjects/WinCheckbox.rb'
|
20
|
+
require 'wet/winobjects/WinRadio.rb'
|
21
|
+
require 'wet/winobjects/WinLabel.rb'
|
22
|
+
require 'wet/winobjects/AppWindow.rb'
|
23
|
+
require 'wet/winobjects/WinDialog.rb'
|
24
|
+
require 'wet/utils/CompileUtils.rb'
|
25
|
+
require 'wet/exceptions/CompileExceptions.rb'
|
26
|
+
require 'wet/exceptions/RuntimeExceptions.rb'
|
27
|
+
|
28
|
+
module Wet
|
29
|
+
module Winobjects
|
30
|
+
include Wet::Utils
|
31
|
+
include WinUtils
|
32
|
+
include Wet::Exceptions
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
=begin license
|
2
|
+
Copyright (c) 2005, Qantom Software
|
3
|
+
All rights reserved.
|
4
|
+
|
5
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
8
|
+
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
9
|
+
Neither the name of Qantom Software nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
10
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
11
|
+
|
12
|
+
(based on BSD Open Source License)
|
13
|
+
=end
|
14
|
+
|
15
|
+
module Wet
|
16
|
+
module Winobjects
|
17
|
+
=begin
|
18
|
+
Class to represent a win32 button
|
19
|
+
=end
|
20
|
+
class WinRadio < WinButton
|
21
|
+
|
22
|
+
@@known_class_names = ["Button"]
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
=begin rdoc
|
27
|
+
Is the Window object a possible candidate for this class?
|
28
|
+
Return true if yes. False otherwise.
|
29
|
+
=end
|
30
|
+
#Note : - in the interest of reusable design, I had first put it this as a method
|
31
|
+
#in Window. But then I realized that each class may have to make complex
|
32
|
+
#calculations - eg. A label could be a static or an edit field set to read-only
|
33
|
+
def WinRadio.candidate_match?(win_element)
|
34
|
+
is_match = false
|
35
|
+
@@known_class_names.each do |e|
|
36
|
+
if TextUtils.compare_text(win_element.win_class,e)
|
37
|
+
tmp_button = WinButton.new(win_element.hwnd)
|
38
|
+
if tmp_button.is_radio()
|
39
|
+
is_match = true
|
40
|
+
break
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
return is_match
|
45
|
+
end
|
46
|
+
|
47
|
+
=begin rdoc
|
48
|
+
Is the radio button 'selected'?(checked)
|
49
|
+
Return true if yes. False otherwise
|
50
|
+
=end
|
51
|
+
def is_set()
|
52
|
+
assert_object_exists
|
53
|
+
return button_state()== BST_CHECKED
|
54
|
+
end
|
55
|
+
|
56
|
+
=begin rdoc
|
57
|
+
Set this radio button to 'checked' state.
|
58
|
+
=end
|
59
|
+
def set()
|
60
|
+
assert_object_exists
|
61
|
+
do_set_check_on(@hwnd)
|
62
|
+
end
|
63
|
+
|
64
|
+
def to_s()
|
65
|
+
str = "WinRadio(text:="
|
66
|
+
str = str + text()
|
67
|
+
str = str + ")"
|
68
|
+
return str
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
@@ -0,0 +1,231 @@
|
|
1
|
+
=begin license
|
2
|
+
Copyright (c) 2005, Qantom Software
|
3
|
+
All rights reserved.
|
4
|
+
|
5
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
8
|
+
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
9
|
+
Neither the name of Qantom Software nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
10
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
11
|
+
|
12
|
+
(based on BSD Open Source License)
|
13
|
+
=end
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
=begin rdoc
|
18
|
+
Win32 utils that are used to handle various Popups. Avoid using methods
|
19
|
+
from this module. This are typicall called by the various popup classes
|
20
|
+
(Like ModalDialog, FileChooser, etc.)
|
21
|
+
=end
|
22
|
+
|
23
|
+
require 'dl/import'
|
24
|
+
require 'win32ole'
|
25
|
+
require 'dl/struct'
|
26
|
+
require 'Win32API'
|
27
|
+
require 'wet/constants/winconstants'
|
28
|
+
require 'wet/utils/TextUtils'
|
29
|
+
|
30
|
+
module Wet
|
31
|
+
|
32
|
+
module WinUtils
|
33
|
+
include Wet::Utils
|
34
|
+
|
35
|
+
User32 = DL.dlopen("user32")
|
36
|
+
|
37
|
+
|
38
|
+
$continue_enum = 1
|
39
|
+
$stop_enum = 0
|
40
|
+
|
41
|
+
$get_caption_length = User32['GetWindowTextLengthA', 'LL']
|
42
|
+
$get_caption = User32['GetWindowTextA', 'LLpL']
|
43
|
+
$enum_child_windows = User32['EnumChildWindows' , 'ILPP' ]
|
44
|
+
$enum_windows = User32['EnumWindows', 'IPP']
|
45
|
+
$get_class_name = User32['GetClassName', 'ILpI']
|
46
|
+
$get_window = User32['GetWindow', 'LLI']
|
47
|
+
$get_active_popup = User32['GetLastActivePopup', 'LL']
|
48
|
+
$set_active_window = User32['SetActiveWindow', 'LL']
|
49
|
+
$get_active_window = User32['GetActiveWindow', 'L']
|
50
|
+
$show_window = User32['ShowWindow', 'ILI']
|
51
|
+
$destroy_window = User32['DestroyWindow', 'IL']
|
52
|
+
$get_window_long = User32['GetWindowLongA', 'LLL' ]
|
53
|
+
|
54
|
+
$get_parent = User32['GetParent', 'LL']
|
55
|
+
$post_message = User32['PostMessage', 'ILIPP']
|
56
|
+
$send_message = User32['SendMessage', 'ILIPP']
|
57
|
+
|
58
|
+
$send_message_for_get = User32['SendMessage', 'ILIIS']
|
59
|
+
|
60
|
+
|
61
|
+
### Call backs :- There seems to be some limitation on the number
|
62
|
+
### of dll callbacks that can be defined. Therefore all callbacks have
|
63
|
+
### to be defned as globals. I am not sure about what the limitation is
|
64
|
+
### but it seems to be around 32 at a time. If we exceed this limit - we'll
|
65
|
+
### need to find another way out.
|
66
|
+
#Call back for enumering children
|
67
|
+
|
68
|
+
$child_windows_callback = DL.callback('ILP') { |hwnd, passed_param|
|
69
|
+
eval passed_param
|
70
|
+
$continue_enum
|
71
|
+
}
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
def class_name(hwnd)
|
76
|
+
buffer = " " * 32
|
77
|
+
len, arr = $get_class_name.call(hwnd, buffer, buffer.size)
|
78
|
+
return arr[1].to_s()
|
79
|
+
end
|
80
|
+
|
81
|
+
def enabled_popup(hwnd)
|
82
|
+
res, arr = $get_window.call(hwnd, GW_ENABLEDPOPUP)
|
83
|
+
if res === hwnd || res == 0
|
84
|
+
res = -1
|
85
|
+
end
|
86
|
+
return res
|
87
|
+
end
|
88
|
+
|
89
|
+
def parent_window(hwnd)
|
90
|
+
res, arr = $get_parent.call(hwnd)
|
91
|
+
return res
|
92
|
+
end
|
93
|
+
|
94
|
+
#candidate for private class
|
95
|
+
def enum_windows()
|
96
|
+
enum_windows_callback = DL.callback('ILP') {|hwnd,lparam|
|
97
|
+
sleep 0.05
|
98
|
+
eval lparam
|
99
|
+
$continue_enum
|
100
|
+
}
|
101
|
+
reqd_objects = []
|
102
|
+
to_eval = "reqd_objects << hwnd"
|
103
|
+
$enum_windows.call(enum_windows_callback, to_eval)
|
104
|
+
return reqd_objects
|
105
|
+
end
|
106
|
+
|
107
|
+
#Technically you can use the enum_windows method and acheive this
|
108
|
+
#However since enum_windows will go ahead and find each window, this
|
109
|
+
#method is more efficient - it breaks on first find.
|
110
|
+
def find_window(title)
|
111
|
+
reqd_handle = -1
|
112
|
+
enum_windows_callback = DL.callback('ILP') {|hwnd,lparam|
|
113
|
+
sleep 0.05
|
114
|
+
win_title = window_caption(hwnd)
|
115
|
+
if TextUtils.compare_text(win_title, title)
|
116
|
+
#puts "Found window!!!#{win_title}"
|
117
|
+
reqd_handle = hwnd
|
118
|
+
$stop_enum
|
119
|
+
else
|
120
|
+
$continue_enum
|
121
|
+
end
|
122
|
+
}
|
123
|
+
|
124
|
+
$enum_windows.call(enum_windows_callback, "")
|
125
|
+
return reqd_handle
|
126
|
+
end
|
127
|
+
|
128
|
+
def set_active_window(hwnd)
|
129
|
+
res, arr = $show_window.call(hwnd, SW_MINIMIZE)
|
130
|
+
res, arr = $show_window.call(hwnd, SW_SHOWNORMAL)
|
131
|
+
return res
|
132
|
+
end
|
133
|
+
|
134
|
+
def do_maximize(hwnd)
|
135
|
+
res, arr = $show_window.call(hwnd, SW_MINIMIZE)
|
136
|
+
res, arr = $show_window.call(hwnd, SW_MAXIMIZE)
|
137
|
+
return res
|
138
|
+
end
|
139
|
+
|
140
|
+
def do_minimize(hwnd)
|
141
|
+
res, arr = $show_window.call(hwnd, SW_MINIMIZE)
|
142
|
+
return res
|
143
|
+
end
|
144
|
+
|
145
|
+
def do_destroy_window(hwnd)
|
146
|
+
do_maximize(hwnd)
|
147
|
+
res, arr = $destroy_window.call(hwnd)
|
148
|
+
return res
|
149
|
+
end
|
150
|
+
|
151
|
+
def get_window_style(hwnd)
|
152
|
+
res, arr = $get_window_long.call(hwnd, GWL_STYLE)
|
153
|
+
return res
|
154
|
+
end
|
155
|
+
|
156
|
+
|
157
|
+
def window_caption(hwnd)
|
158
|
+
len, arr = $get_caption_length.call(hwnd)
|
159
|
+
captionBuffer = " " * (len)
|
160
|
+
res, arr = $get_caption.call(hwnd, captionBuffer, len+1)
|
161
|
+
return arr[1].to_s()
|
162
|
+
end
|
163
|
+
|
164
|
+
def owner(hwnd)
|
165
|
+
res, arr = $get_window.call(hwnd, GW_OWNER)
|
166
|
+
return res
|
167
|
+
end
|
168
|
+
|
169
|
+
def next_window(hwnd)
|
170
|
+
res, arr = $get_window.call(hwnd, GW_HWNDNEXT)
|
171
|
+
return res
|
172
|
+
end
|
173
|
+
|
174
|
+
|
175
|
+
def children(hwnd, required_class = nil)
|
176
|
+
count = 0
|
177
|
+
### BAD BAD UGLY way of doing it(using the constant var)
|
178
|
+
### - There seems to be some
|
179
|
+
## limitation on the number of Dll callbacks that can be defined.
|
180
|
+
## Temporary workaround - Please clean this part of the code.
|
181
|
+
$reqd_children_objects = []
|
182
|
+
if required_class == nil
|
183
|
+
to_eval = "$reqd_children_objects << hwnd"
|
184
|
+
else
|
185
|
+
to_eval = "if class_name(hwnd) == required_class;" \
|
186
|
+
"$reqd_children_objects << hwnd;end"
|
187
|
+
end
|
188
|
+
#to_eval = "puts 'hello'"
|
189
|
+
$enum_child_windows.call(hwnd, $child_windows_callback, to_eval)
|
190
|
+
|
191
|
+
# I just hate that I have to use global variables - However given the callback count
|
192
|
+
#limitation of DL api, Iam forced to use it. Introducing atleast some gaurd - As soon
|
193
|
+
# as we are done with what we we want to do - set the global variable to nil
|
194
|
+
retn_objects = []
|
195
|
+
$reqd_children_objects.each do |r|
|
196
|
+
retn_objects << r
|
197
|
+
end
|
198
|
+
$reqd_objects = nil
|
199
|
+
return retn_objects
|
200
|
+
end
|
201
|
+
|
202
|
+
def do_button_click(hwnd)
|
203
|
+
r,rs = $post_message.call(hwnd,BM_CLICK, nil, nil)
|
204
|
+
return r
|
205
|
+
end
|
206
|
+
|
207
|
+
def do_set_text(hwnd, txt)
|
208
|
+
r,rs = $send_message.call(hwnd, WM_SETTEXT, nil, txt)
|
209
|
+
end
|
210
|
+
|
211
|
+
def do_get_text(hwnd)
|
212
|
+
buff = " " * 256
|
213
|
+
r ,rs = $send_message_for_get.call(hwnd , WM_GETTEXT , 256 , buff )
|
214
|
+
str = buff.slice(0, r)
|
215
|
+
return str
|
216
|
+
end
|
217
|
+
|
218
|
+
def do_get_button_state(hwnd)
|
219
|
+
r, arr = $send_message_for_get.call(hwnd, BM_GETSTATE, 0, 0.to_s)
|
220
|
+
return r
|
221
|
+
end
|
222
|
+
|
223
|
+
def do_set_check_on(hwnd)
|
224
|
+
r, arr = $send_message_for_get.call(hwnd, BM_SETCHECK, BST_CHECKED, 0.to_s)
|
225
|
+
end
|
226
|
+
|
227
|
+
def do_set_check_off(hwnd)
|
228
|
+
r, arr = $send_message_for_get.call(hwnd, BM_SETCHECK, BST_UNCHECKED, 0.to_s)
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|