
    ^h3                        S SK r S SK Jr  S SKJrJrJrJrJrJr  S r	Sr
SrSrSrSrS rS	rS
rS rSr " S S\ R(                  5      r\ R,                  R.                  R0                  r\ R4                  " \ R6                  \ R8                  \ R:                  " \ R8                  5      5      r\ R,                  R.                  R>                  r \ R,                  R.                  RB                  r"\ R,                  R.                  RF                  r$ " S S\ R(                  5      r%S r&S r'S r(S r)S r*S r+S r,S r-S r. " S S\5      r/S r0S r1g)    N)wintypes)PyGetWindowExceptionpointInRect
BaseWindowRectPointSize   i   i            	      c                   L    \ rS rSrS\R
                  4S\R
                  4/rSrg)POINT    xy N)__name__
__module____qualname____firstlineno__ctypesc_long_fields___static_attributes__r       N/var/www/html/env/lib/python3.13/site-packages/pygetwindow/_pygetwindow_win.pyr   r       s!    fmm$fmm$&Hr   r   c                       \ rS rSrSrS\R                  4S\R                  4S\R                  4S\R                  4/rSrg)	RECT+   zA nice wrapper of the RECT structure.

Microsoft Documentation:
https://msdn.microsoft.com/en-us/library/windows/desktop/dd162897(v=vs.85).aspx
lefttoprightbottomr   N)	r   r   r   r   __doc__r   r   r   r   r   r   r   r!   r!   +   s@    
 '&&--(6==)+Hr   r!   c                  B   ^ / mU4S jn [        [        U 5      S5        T$ )Nc                    > [        U 5      (       aO  [        U 5      n[        R                  " US-   5      n[	        XUS-   5        TR                  XR                  45        gN   T)isWindowVisiblegetWindowTextLengthr   create_unicode_buffergetWindowTextappendvalue)hWndlParamlengthbufftitless       r   foreach_window%_getAllTitles.<locals>.foreach_window;   sP    4  (.F//
;D$fqj1MM4,-r   r   enumWindowsenumWindowsProc)r7   r6   s    @r   _getAllTitlesr<   7   s%     F /3Mr   c                    [         R                  " 5       n[        R                  R                  R                  [        [        -  [        -  [        U S[        R                  " [        R                  " U5      [         R                  5      S[        5        UR                  R                  5       n[        R                  R                  R                  U5        U$ )a[  A nice wrapper for FormatMessageW(). TODO

Microsoft Documentation:
https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-formatmessagew

Additional information:
https://stackoverflow.com/questions/18905702/python-ctypes-and-mutable-buffers
https://stackoverflow.com/questions/455434/how-should-i-use-formatmessage-properly-in-c
r   )r   LPWSTRr   windllkernel32FormatMessageWFORMAT_MESSAGE_FROM_SYSTEMFORMAT_MESSAGE_ALLOCATE_BUFFERFORMAT_MESSAGE_IGNORE_INSERTSNULLcastbyrefr1   rstrip	LocalFree)	errorCodelpBuffermsgs      r   _formatMessagerM   G   s      H
MM))*DGe*e  iF  +F*.*3*+*0++fll86Lhoo*^*+*.0 ..


!C
MM$$X.Jr   c                      [         R                  R                  R                  5       n [	        SU < S[        U 5      < 35      e)zwA helper function that raises PyGetWindowException using the error
information from GetLastError() and FormatMessage().zError code from Windows: z - )r   r?   r@   GetLastErrorr   rM   )rJ   s    r   _raiseWithLastErrorrP   _   s3     &&335I
YP^_hPij
kkr   c                  v    [         R                  R                  R                  5       n U S:X  a  g[	        U 5      $ )zAReturns a Window object of the currently active (focused) Window.r   N)r   r?   user32GetForegroundWindowWin32Window)r2   s    r   getActiveWindowrU   f   s/    ==335Dqy4  r   c                     ^ [         R                  R                  R                  5       mTS:X  a  gU4S jn [	        [        U 5      S5        [        $ )zLReturns a string of the title text of the currently active (focused) Window.r   Nc                    > U T:X  a?  [        U 5      n[        R                  " US-   5      n[        XUS-   5        UR                  qgr*   )r-   r   r.   r/   r1   activeWindowTitle)r2   r3   r4   r5   activeWindowHwnds       r   r7   ,getActiveWindowTitle.<locals>.foreach_windowz   sE    ##(.F//
;D$fqj1!%r   )r   r?   rR   rS   r:   r;   rX   )r7   rY   s    @r   getActiveWindowTitler[   p   sE    
 }}++??A1 /3r   c           	          / n[        5        HR  n[        XUR                  UR                  UR                  UR
                  5      (       d  MA  UR                  U5        MT     U$ )zReturns a list of Window objects whose windows contain the point ``(x, y)``.

* ``x`` (int, optional): The x position of the window(s).
* ``y`` (int, optional): The y position of the window(s).)getAllWindowsr   r#   r$   widthheightr0   )r   r   windowsAtXYwindows       r   getWindowsAtrb      sN    
 K/qV[[&**fllFMMRRv& " r   c                     [        5       n/ nU HC  u  p4U R                  5       UR                  5       ;   d  M)  UR                  [        U5      5        ME     U$ )zTReturns a list of Window objects that substring match ``title`` in their title text.)r<   upperr0   rT   )titlehWndsAndTitles
windowObjsr2   winTitles        r   getWindowsWithTitleri      sJ    "_NJ(;;=HNN,,k$/0 ) r   c                  T    [        5        V s/ s H  o R                  PM     sn $ s  sn f )zHReturns a list of strings of window titles for all visible windows.
    )r]   re   )ra   s    r   getAllTitlesrk      s      (57VLL777s   %c                  B   ^ / mU4S jn [        [        U 5      S5        T$ )z>Returns a list of Window objects for all visible windows.
    c                    > [         R                  R                  R                  U 5      S:w  a  TR	                  [        U 5      5        g)Nr   T)r   r?   rR   IsWindowVisibler0   rT   )r2   r3   rg   s     r   r7   %getAllWindows.<locals>.foreach_window   s6    ==//5:k$/0r   r   r9   )r7   rg   s    @r   r]   r]      s&     J /3r   c                       \ rS rSrS rS rS rS rS rS r	S r
S	 rS
 rS rS rS r\rS rS r\rS r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       rSrg)rT      c                 0    Xl         U R                  5         g N)_hWnd_setupRectProperties)selfr2   s     r   __init__Win32Window.__init__   s    
!!#r   c                 4   [        5       n[        R                  R                  R	                  U R
                  [        R                  " U5      5      nUS:w  a6  [        UR                  UR                  UR                  UR                  5      $ [        5         g)zA nice wrapper for GetWindowRect(). TODO

Syntax:
BOOL GetWindowRect(
  HWND   hWnd,
  LPRECT lpRect
);

Microsoft Documentation:
https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getwindowrect
r   N)r!   r   r?   rR   GetWindowRectrt   rG   r   r#   r$   r%   r&   rP   )rv   rectresults      r   _getWindowRectWin32Window._getWindowRect   sb     v%%33DJJT@RSQ;		488TZZEE!r   c                 R    U R                   R                  < SU R                  < S3$ )Nz(hWnd=))	__class__r   rt   rv   s    r   __repr__Win32Window.__repr__   s     $ 7 7DDr   c                 b    [        U[        5      =(       a    U R                  UR                  :H  $ rs   )
isinstancerT   rt   )rv   others     r   __eq__Win32Window.__eq__   s!    %-K$**2KKr   c                     [         R                  R                  R                  U R                  [
        SS5      nUS:X  a  [        5         gg)zCloses this window. This may trigger "Are you sure you want to
quit?" dialogs or other actions that prevent the window from
actually closing. This is identical to clicking the X button on the
window.r   N)r   r?   rR   PostMessageArt   WM_CLOSErP   rv   r|   s     r   closeWin32Window.close   s:    
 %%224::xANQ;! r   c                 t    [         R                  R                  R                  U R                  [
        5        g)zMinimizes this window.N)r   r?   rR   
ShowWindowrt   SW_MINIMIZEr   s    r   minimizeWin32Window.minimize        ''

K@r   c                 t    [         R                  R                  R                  U R                  [
        5        g)zMaximizes this window.N)r   r?   rR   r   rt   SW_MAXIMIZEr   s    r   maximizeWin32Window.maximize   r   r   c                 t    [         R                  R                  R                  U R                  [
        5        g)zCIf maximized or minimized, restores the window to it's normal size.N)r   r?   rR   r   rt   
SW_RESTOREr   s    r   restoreWin32Window.restore   s     ''

J?r   c                 t    [         R                  R                  R                  U R                  [
        5        g)zBIf hidden or showing, shows the window on screen and in title bar.N)r   r?   rR   r   rt   SW_SHOWr   s    r   showWin32Window.show        ''

7;r   c                 t    [         R                  R                  R                  U R                  [
        5        g)zAIf hidden or showing, hides the window from screen and title bar.N)r   r?   rR   r   rt   SW_HIDEr   s    r   hideWin32Window.hide   r   r   c                     [         R                  R                  R                  U R                  5      nUS:X  a  [        5         gg)zAActivate this window and make it the foreground (focused) window.r   N)r   r?   rR   SetForegroundWindowrt   rP   r   s     r   activateWin32Window.activate   s2    %%99$**EQ;! r   c           	          [         R                  R                  R                  U R                  [
        U R                  U R                  U R                  U-   U R                  U-   S5      nUS:X  a  [        5         gg)z0Resizes the window relative to its current size.r   Nr   r?   rR   SetWindowPosrt   HWND_TOPr#   r$   r^   r_   rP   )rv   widthOffsetheightOffsetr|   s       r   resizeWin32Window.resize   s{    %%224::xTXT\T\^b^h^hkv^vx|  yD  yD  GS  yS  UV  WQ;! r   c           	          [         R                  R                  R                  U R                  [
        U R                  U R                  XS5      nUS:X  a  [        5         gg)z-Resizes the window to a new width and height.r   N)	r   r?   rR   r   rt   r   r#   r$   rP   )rv   newWidth	newHeightr|   s       r   resizeToWin32Window.resizeTo   sI    %%224::xTXT\T\^fstuQ;! r   c           	          [         R                  R                  R                  U R                  [
        U R                  U-   U R                  U-   U R                  U R                  S5      nUS:X  a  [        5         gg)z2Moves the window relative to its current position.r   Nr   )rv   xOffsetyOffsetr|   s       r   moveWin32Window.move  sw    %%224::xU\I\^b^f^fip^prvr|r|  C  J  J  LM  NQ;! r   c           	          [         R                  R                  R                  U R                  [
        XU R                  U R                  S5      nUS:X  a  [        5         gg)z2Moves the window to new coordinates on the screen.r   N)	r   r?   rR   r   rt   r   r^   r_   rP   )rv   newLeftnewTopr|   s       r   moveToWin32Window.moveTo  sK    %%224::xZ^ZdZdfjfqfqstuQ;! r   c                 n    [         R                  R                  R                  U R                  5      S:g  $ )z6Returns ``True`` if the window is currently minimized.r   )r   r?   rR   IsIconicrt   r   s    r   isMinimizedWin32Window.isMinimized  (     }}##,,TZZ8A==r   c                 n    [         R                  R                  R                  U R                  5      S:g  $ )z6Returns ``True`` if the window is currently maximized.r   )r   r?   rR   IsZoomedrt   r   s    r   isMaximizedWin32Window.isMaximized  r   r   c                     [        5       U :H  $ )zJReturns ``True`` if the window is currently the active, foreground window.)rU   r   s    r   isActiveWin32Window.isActive  s      D((r   c                     [         R                  R                  R                  U R                  5      n[         R
                  " US-   5      n[         R                  R                  R                  U R                  X!S-   5        UR                  $ )z%Returns the window title as a string.r+   )r   r?   rR   GetWindowTextLengthWrt   r.   GetWindowTextWr1   )rv   textLenInCharactersstringBuffers      r   re   Win32Window.title$  sk     %mm22GG

S334G!4KL++DJJ\]F]^ !!!r   c                 ,    [        U R                  5      $ )z3Return ``True`` if the window is currently visible.)r,   rt   r   s    r   visibleWin32Window.visible.  s     tzz**r   )rt   N)r   r   r   r   rw   r}   r   r   r   r   r   r   r   r   r   r   	resizeRelr   r   moveRelr   propertyr   r   r   re   r   r   r   r   r   rT   rT      s    $
"(EL"A
A
@<<""
 I""
 G" > > > > ) ) " " + +r   rT   c                      [        5       n [        R                  R                  R	                  [        R
                  " U 5      5        [        U R                  U R                  S9$ )zReturns the current xy coordinates of the mouse cursor as a two-integer
tuple by calling the GetCursorPos() win32 function.

Returns:
  (x, y) tuple of the current xy coordinates of the mouse cursor.
)r   r   )	r   r   r?   rR   GetCursorPosrG   r   r   r   )cursors    r   r   r   4  sA     WF
MM%%fll6&:;688vxx((r   c                      [        [        R                  R                  R	                  S5      [        R                  R                  R	                  S5      S9$ )zReturns the width and height of the screen as a two-integer tuple.

Returns:
  (width, height) tuple of the screen size, in pixels.
r   r+   )r^   r_   )r	   r   r?   rR   GetSystemMetricsr   r   r   
resolutionr   A  s<     fmm**;;A>v}}G[G[GlGlmnGoppr   )2r   r   pygetwindowr   r   r   r   r   r	   rE   rC   rB   rD   r   r   r   r   r   r   r   	Structurer   r?   rR   EnumWindowsr:   WINFUNCTYPEc_boolc_intPOINTERr;   r   r/   r   r-   rn   r,   r!   r<   rM   rP   rU   r[   rb   ri   rk   r]   rT   r   r   r   r   r   <module>r      sI     X X 	 ", '  *  


  
&F & mm""..$$V]]FLL&..QWQ]Q]B^_$$33mm**?? --&&66	+6 	+ 0l!.	8
A+* A+H
)qr   