forked from pywinauto/pywinauto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_DrawDialog_win32_1.py
425 lines (372 loc) · 9.75 KB
/
_DrawDialog_win32_1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
# GUI Application automation and testing library
# Copyright (C) 2006 Mark Mc Mahon
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public License
# as published by the Free Software Foundation; either version 2.1
# of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc.,
# 59 Temple Place,
# Suite 330,
# Boston, MA 02111-1307 USA
## import all of the wxPython GUI package
from wxPython.wx import *
from ctypes import *
import PyDlgCheckerWrapper
import sys
if len(sys.argv) < 2 :
print "Please specify the XML file to read"
sys.exit()
PyDlgCheckerWrapper.InitDialogFromFile(sys.argv[1])
dlg = PyDlgCheckerWrapper.TestInfo['Dialog']
BOOL = c_int
BYTE = c_ubyte
CHAR = c_char
DWORD = c_ulong
LONG = c_long
LPVOID = c_void_p
PVOID = c_void_p
UINT = c_uint
WCHAR = c_wchar
WORD = c_ushort
COLORREF = DWORD
HBITMAP = LONG
HINSTANCE = LONG
HMENU = LONG
HTREEITEM = LONG
HWND = LONG
LPARAM = LONG
LPCWSTR = c_wchar_p
LPWSTR = c_wchar_p #POINTER(WCHAR)
SW_ERASE = 4 # Variable c_int
SW_FORCEMINIMIZE = 11 # Variable c_int
SW_HIDE = 0 # Variable c_int
SW_INVALIDATE = 2 # Variable c_int
SW_MAX = 11 # Variable c_int
SW_MAXIMIZE = 3 # Variable c_int
SW_MINIMIZE = 6 # Variable c_int
SW_NORMAL = 1 # Variable c_int
SW_OTHERUNZOOM = 4 # Variable c_int
SW_OTHERZOOM = 2 # Variable c_int
SW_PARENTCLOSING = 1 # Variable c_int
SW_PARENTOPENING = 3 # Variable c_int
SW_RESTORE = 9 # Variable c_int
SW_SCROLLCHILDREN = 1 # Variable c_int
SW_SHOW = 5 # Variable c_int
SW_SHOWDEFAULT = 10 # Variable c_int
SW_SHOWMAXIMIZED = 3 # Variable c_int
SW_SHOWMINIMIZED = 2 # Variable c_int
SW_SHOWMINNOACTIVE = 7 # Variable c_int
SW_SHOWNA = 8 # Variable c_int
SW_SHOWNOACTIVATE = 4 # Variable c_int
SW_SHOWNORMAL = 1 # Variable c_int
# C:/PROGRA~1/MIAF9D~1/VC98/Include/winuser.h 2186
class CREATESTRUCTW(Structure):
_fields_ = [
# C:/PROGRA~1/MIAF9D~1/VC98/Include/winuser.h 2186
('lpCreateParams', LPVOID),
('hInstance', HINSTANCE),
('hMenu', HMENU),
('hwndParent', HWND),
('cy', c_int),
('cx', c_int),
('y', c_int),
('x', c_int),
('style', LONG),
('lpszName', LPCWSTR),
('lpszClass', LPCWSTR),
('dwExStyle', DWORD),
]
assert sizeof(CREATESTRUCTW) == 48, sizeof(CREATESTRUCTW)
assert alignment(CREATESTRUCTW) == 4, alignment(CREATESTRUCTW)
# C:/PROGRA~1/MIAF9D~1/VC98/Include/winuser.h 3278
class DLGTEMPLATE(Structure):
_pack_ = 2
_fields_ = [
# C:/PROGRA~1/MIAF9D~1/VC98/Include/winuser.h 3278
('style', DWORD),
('dwExtendedStyle', DWORD),
('cdit', WORD),
('x', c_short),
('y', c_short),
('cx', c_short),
('cy', c_short),
]
assert sizeof(DLGTEMPLATE) == 18, sizeof(DLGTEMPLATE)
assert alignment(DLGTEMPLATE) == 2, alignment(DLGTEMPLATE)
def Main():
import ctypes
CW = ctypes.windll.user32.CreateWindowExW
# cs = CREATESTRUCTW()
# cs.hInstance = 0 # ????
# cs.hMenu = 0
# cs.hwndParent = 0
# cs.cx = 100
# cs.cy = 200
# cs.x = 10
# cs.y = 20
# cs.style = 0 #0x80000
# cs.lpszName = u"Hi There"
# cs.lpszClass = "#32770"
# cs.dwExStyle = 0
parent = 0
for i, ctrl in enumerate(dlg.AllControls()):
if i == 0:
print "FIRST"
#klass = u"#32770"
style = ctrl.Style()
else:
klass = ctrl.Class.upper()
style = ctrl.Style()
#print klass
#style = 0
klass = ctrl.Class.upper()
if parent and ctrl.Class == "#32770":
continue
handle = CW(
ctrl.ExStyle(), # dwExStyle
klass, # class
ctrl.Title,# titles
style , #ctrl.Style(), # style
ctrl.Rectangle.left, # x
ctrl.Rectangle.top, # y
ctrl.Rectangle.right - ctrl.Rectangle.left, # cx
ctrl.Rectangle.bottom - ctrl.Rectangle.top, # cy
parent, # parent
0, # menu
ctypes.windll.kernel32.GetModuleHandleW(u"user32.dll"), # hInstance ???
0, # lparam
)
import time
time.sleep(.3)
if not parent:
parent = handle
print handle,
x = (c_wchar * 200)()
ctypes.windll.user32.GetClassNameW(handle, byref(x) ,100)
print x.value
style = ctypes.windll.user32.GetWindowLongW(handle, -16)
ctypes.windll.user32.EnableWindow(handle, 1)
if style != ctrl.Style():
print "FAILED"
ctypes.windll.user32.ShowWindow(handle, SW_SHOW)
# edit = CW(
# 0, # dwExStyle
# u"BUTTON", # class
# u"YO There",# titles
# 0, # style
# 30, # x
# 40, # y
# 40, # cx
# 20, # cy
# handle, # parent
# 0, # menu
# 0, # hInstance ???
# 0, # lparam
# )
#
# print edit
#
# ctypes.windll.user32.ShowWindow(edit, SW_SHOW)
if __name__=='__main__':
Main()
import time
time.sleep(3)
sys.exit()
##class DLGTEMPLATEEX(Structure):
### _pack_ = 1
## _fields_ = [
## ('dlgVer', WORD),
## ('signature', WORD),
## ('helpID', DWORD),
## ('exStyle', DWORD),
## ('style', DWORD),
## ('cDlgItems', WORD), #LPWSTR),
## ('x', c_short),
## ('y', c_short),
## ('cx', c_short),
## ('cy', c_short),
## ('menu', c_void_p),
## ('windowClass', c_void_p), #LPWSTR),
## ('title', c_wchar_p),
## ('pointsize', WORD),
## ('weight', WORD),
## ('italic', BYTE),
## ('charset', BYTE),
## ('typeface', c_wchar_p),
## ]
##
## def __init__(self, dlg):
## self.dlgVer = 1
## self.signature = 0xFFFF
##
## #self.helpID = dlg.helpID
## #self.exStyle = dlg.helpID
## #self.style = dlg.helpID
## #self.cdlgItems = dlg.helpID
## self.x = 10
## self.y = 10
## self.cx = 50
## self.cy = 50
## #self.menu = xx
## self.windowClass = "#32770"
## #self.title = xx
## #self.pointsize = xx
## #self.weight = xx
## #self.italic = xx
## #self.charset = xx
## #self.typeface = xx
##
##
##
##
##class DLGITEMTEMPLATEEX(Structure):
### _pack_ = 1
## _fields_ = [
## ('helpID', DWORD),
## ('exStyle', DWORD),
## ('style', DWORD),
## ('x', c_short),
## ('y', c_short),
## ('cx', c_short),
## ('cy', c_short),
## ('id', WORD),
## ('windowClass', c_void_p),
## ('title', c_void_p),
## ('extraCount', WORD),
## ]
##
## def __init__(self, ctrl):
## self.helpID = 1
## self.exStyle = 2
## self.style = 3
## self.x = 10
## self.y = 20
## self.cx = 6
## self.cy = 8
## self.id = ctrl.ControlID
## self.windowClass = 2134
## self.title = u"1234567678"
## self.extraCount = 0
##
##
##
##
##
##
##
#### Create a new frame class, derived from the wxPython Frame.
##class MyFrame(wxFrame):
##
## def __init__(self, parent, id, title):
## # First, call the base class' __init__ method to create the frame
##
##
##
## wxFrame.__init__(self,
## parent,
## id,
## dlg.Title,
## wxPoint(100, 100),
## wxSize(dlg.Rectangle.right, dlg.Rectangle.bottom))
##
## # Add a panel and some controls to display the size and position
## panel = wxPanel(self, -1)
##
##
## classes = {
## "Static": wxStaticText,
## "Button": wxButton,
## "CheckBox": wxCheckBox,
## "RadioButton": wxRadioButton,
## "Dialog": None,
## "#32770": None,
## "SysTabControl32": None,
##
### "GroupBox": None,
## "GroupBox": wxRadioBox,
##
### "Static": wxStaticText,
### "Static": wxStaticText,
### "Static": wxStaticText,
##
## }
## for ctrl in dlg.AllControls()[1:]:
## wx_class_type = classes.get(ctrl.FriendlyClassName, wxStaticText)
##
## print ctrl.FriendlyClassName, wx_class_type
##
## if wx_class_type:
## width = ctrl.Rectangle.right - ctrl.Rectangle.left
## height = ctrl.Rectangle.bottom - ctrl.Rectangle.top
##
## if wx_class_type != wxRadioBox:
## wx_class_type (
## panel,
## -1,
## ctrl.Title,
## wxPoint(ctrl.Rectangle.left -3, ctrl.Rectangle.top - 23),
## wxSize(width, height)).Raise()
## else:
##
## wx_class_type (
## panel,
## -1,
## ctrl.Title,
## wxPoint(ctrl.Rectangle.left -3, ctrl.Rectangle.top - 23),
## wxSize(width, height),
## ['']).Lower()
##
##
##
### wxStaticText(panel, -1, "Size:",
### wxDLG_PNT(panel, wxPoint(4, 4)), wxSize(30, 20))
###
### wxStaticText(panel, -1, "Pos:",
### wxDLG_PNT(panel, wxPoint(4, 14)), wxDefaultSize)
###
### self.sizeCtrl = wxTextCtrl(panel, -1, "",
### wxDLG_PNT(panel, wxPoint(24, 4)),
### wxDLG_SZE(panel, wxSize(36, -1)),
### wxTE_READONLY)
### self.posCtrl = wxTextCtrl(panel, -1, "",
### wxDLG_PNT(panel, wxPoint(24, 14)),
### wxDLG_SZE(panel, wxSize(36, -1)),
### wxTE_READONLY)
##
##
## # This method is called automatically when the CLOSE event is
## # sent to this window
## def OnCloseWindow(self, event):
## # tell the window to kill itself
## self.Destroy()
##
##
##
### Every wxWindows application must have a class derived from wxApp
##class MyApp(wxApp):
##
## # wxWindows calls this method to initialize the application
## def OnInit(self):
##
## # Create an instance of our customized Frame class
## frame = MyFrame(NULL, -1, "This is a test")
## frame.Show(true)
##
## # Tell wxWindows that this is our main window
## self.SetTopWindow(frame)
##
## # Return a success flag
## return true
##
##
##app = MyApp(0) # Create an instance of the application class
##app.MainLoop() # Tell it to start processing events