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 Wrapper for user32.dll in ctypes.
30 """
31
32 __revision__ = "$Id: user32.py 705 2010-07-07 22:21:08Z qvasimodo $"
33
34 from defines import *
35 from kernel32 import GetLastError, SetLastError
36 from gdi32 import POINT, PPOINT, LPPOINT, RECT, PRECT, LPRECT
41 """
42 Convert arguments to the WPARAM type.
43 Used automatically by SendMessage, PostMessage, etc.
44 You shouldn't need to call this function.
45 """
46 wParam = ctypes.cast(wParam, LPVOID).value
47 if wParam is None:
48 wParam = 0
49 return wParam
50
52 """
53 Convert arguments to the LPARAM type.
54 Used automatically by SendMessage, PostMessage, etc.
55 You shouldn't need to call this function.
56 """
57 return ctypes.cast(lParam, LPARAM)
58
60 """
61 Window enumerator class. You can pass it's instances
62 as callback functions in window enumeration APIs.
63 """
67
68 self.hwnd.append(hwnd)
69 return TRUE
70
71
72
73 WNDENUMPROC = WINFUNCTYPE(BOOL, HWND, PVOID)
74
75
76
77 HWND_DESKTOP = 0
78 HWND_TOP = 1
79 HWND_BOTTOM = 1
80 HWND_TOPMOST = -1
81 HWND_NOTOPMOST = -2
82 HWND_MESSAGE = -3
83
84
85 GWL_WNDPROC = -4
86 GWL_HINSTANCE = -6
87 GWL_HWNDPARENT = -8
88 GWL_STYLE = -16
89 GWL_EXSTYLE = -20
90 GWL_USERDATA = -21
91 GWL_ID = -12
92
93
94 SW_HIDE = 0
95 SW_SHOWNORMAL = 1
96 SW_NORMAL = 1
97 SW_SHOWMINIMIZED = 2
98 SW_SHOWMAXIMIZED = 3
99 SW_MAXIMIZE = 3
100 SW_SHOWNOACTIVATE = 4
101 SW_SHOW = 5
102 SW_MINIMIZE = 6
103 SW_SHOWMINNOACTIVE = 7
104 SW_SHOWNA = 8
105 SW_RESTORE = 9
106 SW_SHOWDEFAULT = 10
107 SW_FORCEMINIMIZE = 11
108
109
110 SMTO_NORMAL = 0
111 SMTO_BLOCK = 1
112 SMTO_ABORTIFHUNG = 2
113 SMTO_NOTIMEOUTIFNOTHUNG = 8
114 SMTO_ERRORONEXIT = 0x20
115
116
117 WPF_SETMINPOSITION = 1
118 WPF_RESTORETOMAXIMIZED = 2
119 WPF_ASYNCWINDOWPLACEMENT = 4
120
121
122
123 WM_USER = 0x400
124 WM_APP = 0x800
125
126 WM_NULL = 0
127 WM_CREATE = 1
128 WM_DESTROY = 2
129 WM_MOVE = 3
130 WM_SIZE = 5
131 WM_ACTIVATE = 6
132 WA_INACTIVE = 0
133 WA_ACTIVE = 1
134 WA_CLICKACTIVE = 2
135 WM_SETFOCUS = 7
136 WM_KILLFOCUS = 8
137 WM_ENABLE = 0x0A
138 WM_SETREDRAW = 0x0B
139 WM_SETTEXT = 0x0C
140 WM_GETTEXT = 0x0D
141 WM_GETTEXTLENGTH = 0x0E
142 WM_PAINT = 0x0F
143 WM_CLOSE = 0x10
144 WM_QUERYENDSESSION = 0x11
145 WM_QUIT = 0x12
146 WM_QUERYOPEN = 0x13
147 WM_ERASEBKGND = 0x14
148 WM_SYSCOLORCHANGE = 0x15
149 WM_ENDSESSION = 0x16
150 WM_SHOWWINDOW = 0x18
151 WM_WININICHANGE = 0x1A
152 WM_SETTINGCHANGE = WM_WININICHANGE
153 WM_DEVMODECHANGE = 0x1B
154 WM_ACTIVATEAPP = 0x1C
155 WM_FONTCHANGE = 0x1D
156 WM_TIMECHANGE = 0x1E
157 WM_CANCELMODE = 0x1F
158 WM_SETCURSOR = 0x20
159 WM_MOUSEACTIVATE = 0x21
160 WM_CHILDACTIVATE = 0x22
161 WM_QUEUESYNC = 0x23
162 WM_GETMINMAXINFO = 0x24
163 WM_PAINTICON = 0x26
164 WM_ICONERASEBKGND = 0x27
165 WM_NEXTDLGCTL = 0x28
166 WM_SPOOLERSTATUS = 0x2A
167 WM_DRAWITEM = 0x2B
168 WM_MEASUREITEM = 0x2C
169 WM_DELETEITEM = 0x2D
170 WM_VKEYTOITEM = 0x2E
171 WM_CHARTOITEM = 0x2F
172 WM_SETFONT = 0x30
173 WM_GETFONT = 0x31
174 WM_SETHOTKEY = 0x32
175 WM_GETHOTKEY = 0x33
176 WM_QUERYDRAGICON = 0x37
177 WM_COMPAREITEM = 0x39
178 WM_GETOBJECT = 0x3D
179 WM_COMPACTING = 0x41
180 WM_OTHERWINDOWCREATED = 0x42
181 WM_OTHERWINDOWDESTROYED = 0x43
182 WM_COMMNOTIFY = 0x44
183
184 CN_RECEIVE = 0x1
185 CN_TRANSMIT = 0x2
186 CN_EVENT = 0x4
187
188 WM_WINDOWPOSCHANGING = 0x46
189 WM_WINDOWPOSCHANGED = 0x47
190 WM_POWER = 0x48
191
192 PWR_OK = 1
193 PWR_FAIL = -1
194 PWR_SUSPENDREQUEST = 1
195 PWR_SUSPENDRESUME = 2
196 PWR_CRITICALRESUME = 3
197
198 WM_COPYDATA = 0x4A
199 WM_CANCELJOURNAL = 0x4B
200 WM_NOTIFY = 0x4E
201 WM_INPUTLANGCHANGEREQUEST = 0x50
202 WM_INPUTLANGCHANGE = 0x51
203 WM_TCARD = 0x52
204 WM_HELP = 0x53
205 WM_USERCHANGED = 0x54
206 WM_NOTIFYFORMAT = 0x55
207 WM_CONTEXTMENU = 0x7B
208 WM_STYLECHANGING = 0x7C
209 WM_STYLECHANGED = 0x7D
210 WM_DISPLAYCHANGE = 0x7E
211 WM_GETICON = 0x7F
212 WM_SETICON = 0x80
213 WM_NCCREATE = 0x81
214 WM_NCDESTROY = 0x82
215 WM_NCCALCSIZE = 0x83
216 WM_NCHITTEST = 0x84
217 WM_NCPAINT = 0x85
218 WM_NCACTIVATE = 0x86
219 WM_GETDLGCODE = 0x87
220 WM_SYNCPAINT = 0x88
221 WM_NCMOUSEMOVE = 0x0A0
222 WM_NCLBUTTONDOWN = 0x0A1
223 WM_NCLBUTTONUP = 0x0A2
224 WM_NCLBUTTONDBLCLK = 0x0A3
225 WM_NCRBUTTONDOWN = 0x0A4
226 WM_NCRBUTTONUP = 0x0A5
227 WM_NCRBUTTONDBLCLK = 0x0A6
228 WM_NCMBUTTONDOWN = 0x0A7
229 WM_NCMBUTTONUP = 0x0A8
230 WM_NCMBUTTONDBLCLK = 0x0A9
231 WM_KEYFIRST = 0x100
232 WM_KEYDOWN = 0x100
233 WM_KEYUP = 0x101
234 WM_CHAR = 0x102
235 WM_DEADCHAR = 0x103
236 WM_SYSKEYDOWN = 0x104
237 WM_SYSKEYUP = 0x105
238 WM_SYSCHAR = 0x106
239 WM_SYSDEADCHAR = 0x107
240 WM_KEYLAST = 0x108
241 WM_INITDIALOG = 0x110
242 WM_COMMAND = 0x111
243 WM_SYSCOMMAND = 0x112
244 WM_TIMER = 0x113
245 WM_HSCROLL = 0x114
246 WM_VSCROLL = 0x115
247 WM_INITMENU = 0x116
248 WM_INITMENUPOPUP = 0x117
249 WM_MENUSELECT = 0x11F
250 WM_MENUCHAR = 0x120
251 WM_ENTERIDLE = 0x121
252 WM_CTLCOLORMSGBOX = 0x132
253 WM_CTLCOLOREDIT = 0x133
254 WM_CTLCOLORLISTBOX = 0x134
255 WM_CTLCOLORBTN = 0x135
256 WM_CTLCOLORDLG = 0x136
257 WM_CTLCOLORSCROLLBAR = 0x137
258 WM_CTLCOLORSTATIC = 0x138
259 WM_MOUSEFIRST = 0x200
260 WM_MOUSEMOVE = 0x200
261 WM_LBUTTONDOWN = 0x201
262 WM_LBUTTONUP = 0x202
263 WM_LBUTTONDBLCLK = 0x203
264 WM_RBUTTONDOWN = 0x204
265 WM_RBUTTONUP = 0x205
266 WM_RBUTTONDBLCLK = 0x206
267 WM_MBUTTONDOWN = 0x207
268 WM_MBUTTONUP = 0x208
269 WM_MBUTTONDBLCLK = 0x209
270 WM_MOUSELAST = 0x209
271 WM_PARENTNOTIFY = 0x210
272 WM_ENTERMENULOOP = 0x211
273 WM_EXITMENULOOP = 0x212
274 WM_MDICREATE = 0x220
275 WM_MDIDESTROY = 0x221
276 WM_MDIACTIVATE = 0x222
277 WM_MDIRESTORE = 0x223
278 WM_MDINEXT = 0x224
279 WM_MDIMAXIMIZE = 0x225
280 WM_MDITILE = 0x226
281 WM_MDICASCADE = 0x227
282 WM_MDIICONARRANGE = 0x228
283 WM_MDIGETACTIVE = 0x229
284 WM_MDISETMENU = 0x230
285 WM_DROPFILES = 0x233
286 WM_MDIREFRESHMENU = 0x234
287 WM_CUT = 0x300
288 WM_COPY = 0x301
289 WM_PASTE = 0x302
290 WM_CLEAR = 0x303
291 WM_UNDO = 0x304
292 WM_RENDERFORMAT = 0x305
293 WM_RENDERALLFORMATS = 0x306
294 WM_DESTROYCLIPBOARD = 0x307
295 WM_DRAWCLIPBOARD = 0x308
296 WM_PAINTCLIPBOARD = 0x309
297 WM_VSCROLLCLIPBOARD = 0x30A
298 WM_SIZECLIPBOARD = 0x30B
299 WM_ASKCBFORMATNAME = 0x30C
300 WM_CHANGECBCHAIN = 0x30D
301 WM_HSCROLLCLIPBOARD = 0x30E
302 WM_QUERYNEWPALETTE = 0x30F
303 WM_PALETTEISCHANGING = 0x310
304 WM_PALETTECHANGED = 0x311
305 WM_HOTKEY = 0x312
306 WM_PRINT = 0x317
307 WM_PRINTCLIENT = 0x318
308 WM_PENWINFIRST = 0x380
309 WM_PENWINLAST = 0x38F
310
311
312
313
314
315
316
317
318
319
320
321 -class WINDOWPLACEMENT(Structure):
322 _fields_ = [
323 ('length', UINT),
324 ('flags', UINT),
325 ('showCmd', UINT),
326 ('ptMinPosition', POINT),
327 ('ptMaxPosition', POINT),
328 ('rcNormalPosition', RECT),
329 ]
330 PWINDOWPLACEMENT = POINTER(WINDOWPLACEMENT)
331 LPWINDOWPLACEMENT = PWINDOWPLACEMENT
332
333
334
335
336
337
338
339
340
341
342
343
344 -class GUITHREADINFO(Structure):
345 _fields_ = [
346 ('cbSize', DWORD),
347 ('flags', DWORD),
348 ('hwndActive', HWND),
349 ('hwndFocus', HWND),
350 ('hwndCapture', HWND),
351 ('hwndMenuOwner', HWND),
352 ('hwndMoveSize', HWND),
353 ('hwndCaret', HWND),
354 ('rcCaret', RECT),
355 ]
356 PGUITHREADINFO = POINTER(GUITHREADINFO)
357 LPGUITHREADINFO = PGUITHREADINFO
358
359
360
361
362
363
364 -class Point(object):
365 """
366 Python wrapper over the L{POINT} class.
367
368 @type x: int
369 @ivar x: Horizontal coordinate
370 @type y: int
371 @ivar y: Vertical coordinate
372 """
373
375 """
376 @see: L{POINT}
377 @type x: int
378 @param x: Horizontal coordinate
379 @type y: int
380 @param y: Vertical coordinate
381 """
382 self.x = x
383 self.y = y
384
387
390
392 return (self.x, self.y) [index]
393
395 if index == 0:
396 self.x = value
397 elif index == 1:
398 self.y = value
399 else:
400 raise IndexError, "index out of range"
401
402 @property
404 """
405 Compatibility with ctypes.
406 Allows passing transparently a Point object to an API call.
407 """
408 return POINT(self.x, self.y)
409
411 """
412 Translates window screen coordinates to client coordinates.
413
414 @see: L{client_to_screen}, L{translate}
415
416 @type hWnd: int or L{HWND} or L{system.Window}
417 @param hWnd: Window handle.
418
419 @rtype: L{Point}
420 @return: New object containing the translated coordinates.
421 """
422 return ScreenToClient(hWnd, self)
423
425 """
426 Translates window client coordinates to screen coordinates.
427
428 @see: L{screen_to_client}, L{translate}
429
430 @type hWnd: int or L{HWND} or L{system.Window}
431 @param hWnd: Window handle.
432
433 @rtype: L{Point}
434 @return: New object containing the translated coordinates.
435 """
436 return ClientToScreen(hWnd, self)
437
439 """
440 Translate coordinates from one window to another.
441
442 @note: To translate multiple points it's more efficient to use the
443 L{MapWindowPoints} function instead.
444
445 @see: L{client_to_screen}, L{screen_to_client}
446
447 @type hWndFrom: int or L{HWND} or L{system.Window}
448 @param hWndFrom: Window handle to translate from.
449 Use C{HWND_DESKTOP} for screen coordinates.
450
451 @type hWndTo: int or L{HWND} or L{system.Window}
452 @param hWndTo: Window handle to translate to.
453 Use C{HWND_DESKTOP} for screen coordinates.
454
455 @rtype: L{Point}
456 @return: New object containing the translated coordinates.
457 """
458 return MapWindowPoints(hWndFrom, hWndTo, [self])
459
461 """
462 Python wrapper over the L{RECT} class.
463
464 @type left: int
465 @ivar left: Horizontal coordinate for the top left corner.
466 @type top: int
467 @ivar top: Vertical coordinate for the top left corner.
468 @type right: int
469 @ivar right: Horizontal coordinate for the bottom right corner.
470 @type bottom: int
471 @ivar bottom: Vertical coordinate for the bottom right corner.
472
473 @type width: int
474 @ivar width: Width in pixels. Same as C{right - left}.
475 @type height: int
476 @ivar height: Height in pixels. Same as C{bottom - top}.
477 """
478
479 - def __init__(self, left = 0, top = 0, right = 0, bottom = 0):
480 """
481 @see: L{RECT}
482 @type left: int
483 @param left: Horizontal coordinate for the top left corner.
484 @type top: int
485 @param top: Vertical coordinate for the top left corner.
486 @type right: int
487 @param right: Horizontal coordinate for the bottom right corner.
488 @type bottom: int
489 @param bottom: Vertical coordinate for the bottom right corner.
490 """
491 self.left = left
492 self.top = top
493 self.right = right
494 self.bottom = bottom
495
498
501
504
506 if index == 0:
507 self.left = value
508 elif index == 1:
509 self.top = value
510 elif index == 2:
511 self.right = value
512 elif index == 3:
513 self.bottom = value
514 else:
515 raise IndexError, "index out of range"
516
517 @property
519 """
520 Compatibility with ctypes.
521 Allows passing transparently a Point object to an API call.
522 """
523 return RECT(self.left, self.top, self.right, self.bottom)
524
527
530
533
536
537 width = property(__get_width, __set_width)
538 height = property(__get_height, __set_height)
539
541 """
542 Translates window screen coordinates to client coordinates.
543
544 @see: L{client_to_screen}, L{translate}
545
546 @type hWnd: int or L{HWND} or L{system.Window}
547 @param hWnd: Window handle.
548
549 @rtype: L{Rect}
550 @return: New object containing the translated coordinates.
551 """
552 topleft = ScreenToClient(hWnd, (self.left, self.top))
553 bottomright = ScreenToClient(hWnd, (self.bottom, self.right))
554 return Rect( topleft.x, topleft.y, bottomright.x, bottomright.y )
555
557 """
558 Translates window client coordinates to screen coordinates.
559
560 @see: L{screen_to_client}, L{translate}
561
562 @type hWnd: int or L{HWND} or L{system.Window}
563 @param hWnd: Window handle.
564
565 @rtype: L{Rect}
566 @return: New object containing the translated coordinates.
567 """
568 topleft = ClientToScreen(hWnd, (self.left, self.top))
569 bottomright = ClientToScreen(hWnd, (self.bottom, self.right))
570 return Rect( topleft.x, topleft.y, bottomright.x, bottomright.y )
571
573 """
574 Translate coordinates from one window to another.
575
576 @see: L{client_to_screen}, L{screen_to_client}
577
578 @type hWndFrom: int or L{HWND} or L{system.Window}
579 @param hWndFrom: Window handle to translate from.
580 Use C{HWND_DESKTOP} for screen coordinates.
581
582 @type hWndTo: int or L{HWND} or L{system.Window}
583 @param hWndTo: Window handle to translate to.
584 Use C{HWND_DESKTOP} for screen coordinates.
585
586 @rtype: L{Rect}
587 @return: New object containing the translated coordinates.
588 """
589 points = [ (self.left, self.top), (self.right, self.bottom) ]
590 return MapWindowPoints(hWndFrom, hWndTo, points)
591
593 """
594 Python wrapper over the L{WINDOWPLACEMENT} class.
595 """
596
622
623 @property
642
650 _SetLastErrorEx = windll.user32.SetLastErrorEx
651 _SetLastErrorEx.argtypes = [DWORD, DWORD]
652 _SetLastErrorEx.restype = None
653 _SetLastErrorEx(dwErrCode, dwType)
654
655
656
657
658
659 -def FindWindowA(lpClassName = None, lpWindowName = None):
660 _FindWindowA = windll.user32.FindWindowA
661 _FindWindowA.argtypes = [LPSTR, LPSTR]
662 _FindWindowA.restype = HWND
663
664 hWnd = _FindWindowA(lpClassName, lpWindowName)
665 if not hWnd:
666 errcode = GetLastError()
667 if errcode != ERROR_SUCCESS:
668 raise ctypes.WinError(errcode)
669 return hWnd
670
671 -def FindWindowW(lpClassName = None, lpWindowName = None):
672 _FindWindowW = windll.user32.FindWindowW
673 _FindWindowW.argtypes = [LPWSTR, LPWSTR]
674 _FindWindowW.restype = HWND
675
676 hWnd = _FindWindowW(lpClassName, lpWindowName)
677 if not hWnd:
678 errcode = GetLastError()
679 if errcode != ERROR_SUCCESS:
680 raise ctypes.WinError(errcode)
681 return hWnd
682
683 FindWindow = GuessStringType(FindWindowA, FindWindowW)
691 _GetClassNameA = windll.user32.GetClassNameA
692 _GetClassNameA.argtypes = [HWND, LPSTR, ctypes.c_int]
693 _GetClassNameA.restype = ctypes.c_int
694
695 nMaxCount = 0x1000
696 dwCharSize = sizeof(CHAR)
697 while 1:
698 lpClassName = ctypes.create_string_buffer("", nMaxCount)
699 nCount = _GetClassNameA(hWnd, lpClassName, nMaxCount)
700 if nCount == 0:
701 raise ctypes.WinError()
702 if nCount < nMaxCount - dwCharSize:
703 break
704 nMaxCount += 0x1000
705 return lpClassName.value
706
708 _GetClassNameW = windll.user32.GetClassNameW
709 _GetClassNameW.argtypes = [HWND, LPWSTR, ctypes.c_int]
710 _GetClassNameW.restype = ctypes.c_int
711
712 nMaxCount = 0x1000
713 dwCharSize = sizeof(WCHAR)
714 while 1:
715 lpClassName = ctypes.create_unicode_buffer(u"", nMaxCount)
716 nCount = _GetClassNameW(hWnd, lpClassName, nMaxCount)
717 if nCount == 0:
718 raise ctypes.WinError()
719 if nCount < nMaxCount - dwCharSize:
720 break
721 nMaxCount += 0x1000
722 return lpClassName.value
723
724 GetClassName = GuessStringType(GetClassNameA, GetClassNameW)
731 _GetWindowLongA = windll.user32.GetWindowLongA
732 _GetWindowLongA.argtypes = [HWND, ctypes.c_int]
733 _GetWindowLongA.restype = LONG
734 return _GetWindowLongA(hWnd, nIndex)
735
737 _GetWindowLongW = windll.user32.GetWindowLongW
738 _GetWindowLongW.argtypes = [HWND, ctypes.c_int]
739 _GetWindowLongW.restype = LONG
740 return _GetWindowLongW(hWnd, nIndex)
741
742
743 GetWindowLong = GetWindowLongA
747 _GetShellWindow = windll.user32.GetShellWindow
748 _GetShellWindow.argtypes = []
749 _GetShellWindow.restype = HWND
750 _GetShellWindow.errcheck = RaiseIfZero
751 return _GetShellWindow()
752
766
771 _GetParent = windll.user32.GetParent
772 _GetParent.argtypes = [HWND]
773 _GetParent.restype = HWND
774
775 hWndParent = _GetParent(hWnd)
776 if not hWndParent:
777 winerr = GetLastError()
778 if winerr != ERROR_SUCCESS:
779 raise ctypes.WinError(winerr)
780 return hWndParent
781
787 _EnableWindow = windll.user32.EnableWindow
788 _EnableWindow.argtypes = [HWND, BOOL]
789 _EnableWindow.restype = bool
790 return _EnableWindow(hWnd, bool(bEnable))
791
797 _ShowWindow = windll.user32.ShowWindow
798 _ShowWindow.argtypes = [HWND, ctypes.c_int]
799 _ShowWindow.restype = bool
800 return _ShowWindow(hWnd, nCmdShow)
801
807 _ShowWindowAsync = windll.user32.ShowWindowAsync
808 _ShowWindowAsync.argtypes = [HWND, ctypes.c_int]
809 _ShowWindowAsync.restype = bool
810 return _ShowWindowAsync(hWnd, nCmdShow)
811
814 _GetDesktopWindow = windll.user32.GetDesktopWindow
815 _GetDesktopWindow.argtypes = []
816 _GetDesktopWindow.restype = HWND
817 _GetDesktopWindow.errcheck = RaiseIfZero
818 return _GetDesktopWindow()
819
822 _GetForegroundWindow = windll.user32.GetForegroundWindow
823 _GetForegroundWindow.argtypes = []
824 _GetForegroundWindow.restype = HWND
825 _GetForegroundWindow.errcheck = RaiseIfZero
826 return _GetForegroundWindow()
827
832 _IsWindow = windll.user32.IsWindow
833 _IsWindow.argtypes = [HWND]
834 _IsWindow.restype = bool
835 return _IsWindow(hWnd)
836
841 _IsWindowVisible = windll.user32.IsWindowVisible
842 _IsWindowVisible.argtypes = [HWND]
843 _IsWindowVisible.restype = bool
844 return _IsWindowVisible(hWnd)
845
850 _IsWindowEnabled = windll.user32.IsWindowEnabled
851 _IsWindowEnabled.argtypes = [HWND]
852 _IsWindowEnabled.restype = bool
853 return _IsWindowEnabled(hWnd)
854
859 _IsZoomed = windll.user32.IsZoomed
860 _IsZoomed.argtypes = [HWND]
861 _IsZoomed.restype = bool
862 return _IsZoomed(hWnd)
863
868 _IsIconic = windll.user32.IsIconic
869 _IsIconic.argtypes = [HWND]
870 _IsIconic.restype = bool
871 return _IsIconic(hWnd)
872
877 _IsChild = windll.user32.IsChild
878 _IsChild.argtypes = [HWND]
879 _IsChild.restype = bool
880 return _IsChild(hWnd)
881
895
900 _WindowFromPoint = windll.user32.WindowFromPoint
901 _WindowFromPoint.argtypes = [POINT]
902 _WindowFromPoint.restype = HWND
903 _WindowFromPoint.errcheck = RaiseIfZero
904 if isinstance(point, tuple):
905 point = POINT(*point)
906 return _WindowFromPoint(point)
907
913 _ChildWindowFromPoint = windll.user32.ChildWindowFromPoint
914 _ChildWindowFromPoint.argtypes = [HWND, POINT]
915 _ChildWindowFromPoint.restype = HWND
916 _ChildWindowFromPoint.errcheck = RaiseIfZero
917 if isinstance(point, tuple):
918 point = POINT(*point)
919 return _ChildWindowFromPoint(hWndParent, point)
920
926 _RealChildWindowFromPoint = windll.user32.RealChildWindowFromPoint
927 _RealChildWindowFromPoint.argtypes = [HWND, POINT]
928 _RealChildWindowFromPoint.restype = HWND
929 _RealChildWindowFromPoint.errcheck = RaiseIfZero
930 if isinstance(ptParentClientCoords, tuple):
931 ptParentClientCoords = POINT(*ptParentClientCoords)
932 return _RealChildWindowFromPoint(hWndParent, ptParentClientCoords)
933
939 _ScreenToClient = windll.user32.ScreenToClient
940 _ScreenToClient.argtypes = [HWND, LPPOINT]
941 _ScreenToClient.restype = bool
942 _ScreenToClient.errcheck = RaiseIfZero
943
944 if isinstance(lpPoint, tuple):
945 lpPoint = POINT(*lpPoint)
946 else:
947 lpPoint = POINT()
948 lpPoint.x = x
949 lpPoint.y = y
950 _ScreenToClient(hWnd, ctypes.byref(lpPoint))
951 return Point(lpPoint.x, lpPoint.y)
952
958 _ClientToScreen = windll.user32.ClientToScreen
959 _ClientToScreen.argtypes = [HWND, LPPOINT]
960 _ClientToScreen.restype = bool
961 _ClientToScreen.errcheck = RaiseIfZero
962
963 if isinstance(lpPoint, tuple):
964 lpPoint = POINT(*lpPoint)
965 else:
966 lpPoint = POINT()
967 lpPoint.x = x
968 lpPoint.y = y
969 _ClientToScreen(hWnd, ctypes.byref(lpPoint))
970 return Point(lpPoint.x, lpPoint.y)
971
979 _MapWindowPoints = windll.user32.MapWindowPoints
980 _MapWindowPoints.argtypes = [HWND, HWND, LPPOINT, UINT]
981 _MapWindowPoints.restype = ctypes.c_int
982
983 cPoints = len(lpPoints)
984 lpPoints = (POINT * cPoints)(* lpPoints)
985 SetLastError(ERROR_SUCCESS)
986 number = _MapWindowPoints(hWndFrom, hWndTo, ctypes.byref(lpPoints), cPoints)
987 if number == 0:
988 errcode = GetLastError()
989 if errcode != ERROR_SUCCESS:
990 raise ctypes.WinError(errcode)
991 x_delta = number & 0xFFFF
992 y_delta = (number >> 16) & 0xFFFF
993 return x_delta, y_delta, [ (Point.x, Point.y) for Point in lpPoints ]
994
999 _SetForegroundWindow = windll.user32.SetForegroundWindow
1000 _SetForegroundWindow.argtypes = [HWND]
1001 _SetForegroundWindow.restype = bool
1002 _SetForegroundWindow.errcheck = RaiseIfZero
1003 return _SetForegroundWindow(hWnd)
1004
1019
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042 -def MoveWindow(hWnd, X, Y, nWidth, nHeight, bRepaint = True):
1043 _MoveWindow = windll.user32.MoveWindow
1044 _MoveWindow.argtypes = [HWND, ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int, BOOL]
1045 _MoveWindow.restype = bool
1046 _MoveWindow.errcheck = RaiseIfZero
1047 _MoveWindow(hWnd, X, Y, nWidth, nHeight, bool(bRepaint))
1048
1054 _GetGUIThreadInfo = windll.user32.GetGUIThreadInfo
1055 _GetGUIThreadInfo.argtypes = [DWORD, LPGUITHREADINFO]
1056 _GetGUIThreadInfo.restype = bool
1057 _GetGUIThreadInfo.errcheck = RaiseIfZero
1058
1059 gui = GUITHREADINFO()
1060 _GetGUIThreadInfo(idThread, ctypes.byref(gui))
1061 return gui
1062
1069
1086
1093
1111
1118
1136
1137
1138
1139
1140
1141
1142
1143 -def SendMessageA(hWnd, Msg, wParam = 0, lParam = 0):
1144 _SendMessageA = windll.user32.SendMessageA
1145 _SendMessageA.argtypes = [HWND, UINT, WPARAM, LPARAM]
1146 _SendMessageA.restype = LRESULT
1147
1148 wParam = MAKE_WPARAM(wParam)
1149 lParam = MAKE_LPARAM(lParam)
1150 return _SendMessageA(hWnd, Msg, wParam, lParam)
1151
1153 _SendMessageW = windll.user32.SendMessageW
1154 _SendMessageW.argtypes = [HWND, UINT, WPARAM, LPARAM]
1155 _SendMessageW.restype = LRESULT
1156
1157 wParam = MAKE_WPARAM(wParam)
1158 lParam = MAKE_LPARAM(lParam)
1159 return _SendMessageW(hWnd, Msg, wParam, lParam)
1160
1161 SendMessage = GuessStringType(SendMessageA, SendMessageW)
1162
1163
1164
1165
1166
1167
1168
1169 -def PostMessageA(hWnd, Msg, wParam = 0, lParam = 0):
1170 _PostMessageA = windll.user32.PostMessageA
1171 _PostMessageA.argtypes = [HWND, UINT, WPARAM, LPARAM]
1172 _PostMessageA.restype = bool
1173 _PostMessageA.errcheck = RaiseIfZero
1174
1175 wParam = MAKE_WPARAM(wParam)
1176 lParam = MAKE_LPARAM(lParam)
1177 _PostMessageA(hWnd, Msg, wParam, lParam)
1178
1179 -def PostMessageW(hWnd, Msg, wParam = 0, lParam = 0):
1180 _PostMessageW = windll.user32.PostMessageW
1181 _PostMessageW.argtypes = [HWND, UINT, WPARAM, LPARAM]
1182 _PostMessageW.restype = bool
1183 _PostMessageW.errcheck = RaiseIfZero
1184
1185 wParam = MAKE_WPARAM(wParam)
1186 lParam = MAKE_LPARAM(lParam)
1187 _PostMessageW(hWnd, Msg, wParam, lParam)
1188
1189 PostMessage = GuessStringType(PostMessageA, PostMessageW)
1190
1191
1192
1193
1194
1195
1196
1197 -def PostThreadMessageA(idThread, Msg, wParam = 0, lParam = 0):
1198 _PostThreadMessageA = windll.user32.PostThreadMessageA
1199 _PostThreadMessageA.argtypes = [DWORD, UINT, WPARAM, LPARAM]
1200 _PostThreadMessageA.restype = bool
1201 _PostThreadMessageA.errcheck = RaiseIfZero
1202
1203 wParam = MAKE_WPARAM(wParam)
1204 lParam = MAKE_LPARAM(lParam)
1205 _PostThreadMessageA(idThread, Msg, wParam, lParam)
1206
1207 -def PostThreadMessageW(idThread, Msg, wParam = 0, lParam = 0):
1208 _PostThreadMessageW = windll.user32.PostThreadMessageW
1209 _PostThreadMessageW.argtypes = [DWORD, UINT, WPARAM, LPARAM]
1210 _PostThreadMessageW.restype = bool
1211 _PostThreadMessageW.errcheck = RaiseIfZero
1212
1213 wParam = MAKE_WPARAM(wParam)
1214 lParam = MAKE_LPARAM(lParam)
1215 _PostThreadMessageW(idThread, Msg, wParam, lParam)
1216
1217 PostThreadMessage = GuessStringType(PostThreadMessageA, PostThreadMessageW)
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228 -def SendMessageTimeoutA(hWnd, Msg, wParam = 0, lParam = 0, fuFlags = 0, uTimeout = 0):
1229 _SendMessageTimeoutA = windll.user32.SendMessageTimeoutA
1230 _SendMessageTimeoutA.argtypes = [HWND, UINT, WPARAM, LPARAM, UINT, UINT, PDWORD_PTR]
1231 _SendMessageTimeoutA.restype = LRESULT
1232 _SendMessageTimeoutA.errcheck = RaiseIfZero
1233
1234 wParam = MAKE_WPARAM(wParam)
1235 lParam = MAKE_LPARAM(lParam)
1236 dwResult = DWORD(0)
1237 _SendMessageTimeoutA(hWnd, Msg, wParam, lParam, fuFlags, uTimeout, ctypes.byref(dwResult))
1238 return dwResult.value
1239
1241 _SendMessageTimeoutW = windll.user32.SendMessageTimeoutW
1242 _SendMessageTimeoutW.argtypes = [HWND, UINT, WPARAM, LPARAM, UINT, UINT, PDWORD_PTR]
1243 _SendMessageTimeoutW.restype = LRESULT
1244 _SendMessageTimeoutW.errcheck = RaiseIfZero
1245
1246 wParam = MAKE_WPARAM(wParam)
1247 lParam = MAKE_LPARAM(lParam)
1248 dwResult = DWORD(0)
1249 _SendMessageTimeoutW(hWnd, Msg, wParam, lParam, fuFlags, uTimeout, ctypes.byref(dwResult))
1250 return dwResult.value
1251
1252 SendMessageTimeout = GuessStringType(SendMessageTimeoutA, SendMessageTimeoutW)
1253
1254
1255
1256
1257
1258
1259
1260 -def SendNotifyMessageA(hWnd, Msg, wParam = 0, lParam = 0):
1261 _SendNotifyMessageA = windll.user32.SendNotifyMessageA
1262 _SendNotifyMessageA.argtypes = [HWND, UINT, WPARAM, LPARAM]
1263 _SendNotifyMessageA.restype = bool
1264 _SendNotifyMessageA.errcheck = RaiseIfZero
1265
1266 wParam = MAKE_WPARAM(wParam)
1267 lParam = MAKE_LPARAM(lParam)
1268 _SendNotifyMessageA(hWnd, Msg, wParam, lParam)
1269
1271 _SendNotifyMessageW = windll.user32.SendNotifyMessageW
1272 _SendNotifyMessageW.argtypes = [HWND, UINT, WPARAM, LPARAM]
1273 _SendNotifyMessageW.restype = bool
1274 _SendNotifyMessageW.errcheck = RaiseIfZero
1275
1276 wParam = MAKE_WPARAM(wParam)
1277 lParam = MAKE_LPARAM(lParam)
1278 _SendNotifyMessageW(hWnd, Msg, wParam, lParam)
1279
1280 SendNotifyMessage = GuessStringType(SendNotifyMessageA, SendNotifyMessageW)
1281
1282
1283
1284
1285
1286
1287
1288
1289 -def SendDlgItemMessageA(hDlg, nIDDlgItem, Msg, wParam = 0, lParam = 0):
1290 _SendDlgItemMessageA = windll.user32.SendDlgItemMessageA
1291 _SendDlgItemMessageA.argtypes = [HWND, ctypes.c_int, UINT, WPARAM, LPARAM]
1292 _SendDlgItemMessageA.restype = LRESULT
1293
1294 wParam = MAKE_WPARAM(wParam)
1295 lParam = MAKE_LPARAM(lParam)
1296 return _SendDlgItemMessageA(hDlg, nIDDlgItem, Msg, wParam, lParam)
1297
1299 _SendDlgItemMessageW = windll.user32.SendDlgItemMessageW
1300 _SendDlgItemMessageW.argtypes = [HWND, ctypes.c_int, UINT, WPARAM, LPARAM]
1301 _SendDlgItemMessageW.restype = LRESULT
1302
1303 wParam = MAKE_WPARAM(wParam)
1304 lParam = MAKE_LPARAM(lParam)
1305 return _SendDlgItemMessageW(hDlg, nIDDlgItem, Msg, wParam, lParam)
1306
1307 SendDlgItemMessage = GuessStringType(SendDlgItemMessageA, SendDlgItemMessageW)
1313 _RegisterWindowMessageA = windll.user32.RegisterWindowMessageA
1314 _RegisterWindowMessageA.argtypes = [LPSTR]
1315 _RegisterWindowMessageA.restype = UINT
1316 _RegisterWindowMessageA.errcheck = RaiseIfZero
1317 return _RegisterWindowMessageA(lpString)
1318
1320 _RegisterWindowMessageW = windll.user32.RegisterWindowMessageW
1321 _RegisterWindowMessageW.argtypes = [LPWSTR]
1322 _RegisterWindowMessageW.restype = UINT
1323 _RegisterWindowMessageW.errcheck = RaiseIfZero
1324 return _RegisterWindowMessageW(lpString)
1325
1326 RegisterWindowMessage = GuessStringType(RegisterWindowMessageA, RegisterWindowMessageW)
1337
1344
1345 RegisterClipboardFormat = GuessStringType(RegisterClipboardFormatA, RegisterClipboardFormatW)
1346
1347
1348
1349
1350
1351 -def GetPropA(hWnd, lpString):
1352 _GetPropA = windll.user32.GetPropA
1353 _GetPropA.argtypes = [HWND, LPSTR]
1354 _GetPropA.restype = HANDLE
1355 return _GetPropA(lpString)
1356
1358 _GetPropW = windll.user32.GetPropW
1359 _GetPropW.argtypes = [HWND, LPWSTR]
1360 _GetPropW.restype = HANDLE
1361 return _GetPropW(lpString)
1362
1363 GetProp = GuessStringType(GetPropA, GetPropW)
1364
1365
1366
1367
1368
1369
1370 -def SetPropA(hWnd, lpString, hData):
1371 _SetPropA = windll.user32.SetPropA
1372 _SetPropA.argtypes = [HWND, LPSTR, HANDLE]
1373 _SetPropA.restype = BOOL
1374 _SetPropA.errcheck = RaiseIfZero
1375 return _SetPropA(lpString)
1376
1378 _SetPropW = windll.user32.SetPropW
1379 _SetPropW.argtypes = [HWND, LPWSTR, HANDLE]
1380 _SetPropW.restype = BOOL
1381 _SetPropW.errcheck = RaiseIfZero
1382 return _SetPropW(lpString)
1383
1384 SetProp = GuessStringType(SetPropA, SetPropW)
1385
1386
1387
1388
1389
1390 -def RemovePropA(hWnd, lpString):
1391 _RemovePropA = windll.user32.RemovePropA
1392 _RemovePropA.argtypes = [HWND, LPSTR]
1393 _RemovePropA.restype = HANDLE
1394 return _RemovePropA(lpString)
1395
1397 _RemovePropW = windll.user32.RemovePropW
1398 _RemovePropW.argtypes = [HWND, LPWSTR]
1399 _RemovePropW.restype = HANDLE
1400 return _RemovePropW(lpString)
1401
1402 RemoveProp = GuessStringType(RemovePropA, RemovePropW)
1403