winappdbg.window

Window instrumentation.

class winappdbg.window.Window(hWnd=None, process=None, thread=None)

Interface to an open window in the current desktop.

Variables:
  • hWnd – Window handle.

  • dwProcessId – Global ID of the process that owns this window.

  • dwThreadId – Global ID of the thread that owns this window.

  • process – Process that owns this window. Use the get_process() method instead.

  • thread – Thread that owns this window. Use the get_thread() method instead.

  • classname – Window class name.

  • text – Window text (caption).

  • placement – Window placement in the desktop.

client_to_screen(x, y)

Translates window client coordinates to screen coordinates.

Note

This is a simplified interface to some of the functionality of the win32.Point class.

See:

win32.Point.client_to_screen()

Parameters:
  • x (int) – Horizontal coordinate.

  • y (int) – Vertical coordinate.

Return type:

tuple( int, int )

Returns:

Translated coordinates in a tuple (x, y).

Raises:

WindowsError – An error occured while processing this request.

disable()

Disable the user input for the window.

See:

enable()

Raises:

WindowsError – An error occured while processing this request.

enable()

Enable the user input for the window.

See:

disable()

Raises:

WindowsError – An error occured while processing this request.

get_child_at(x, y, bAllowTransparency=True)

Get the child window located at the given coordinates. If no such window exists an exception is raised.

See:

get_children()

Parameters:
  • x (int) – Horizontal coordinate.

  • y (int) – Vertical coordinate.

  • bAllowTransparency (bool) – If True transparent areas in windows are ignored, returning the window behind them. If False transparent areas are treated just like any other area.

Return type:

Window

Returns:

Child window at the requested position, or None if there is no window at those coordinates.

get_children()
See:

get_parent()

Return type:

list( Window )

Returns:

List of child windows.

Raises:

WindowsError – An error occured while processing this request.

get_classname()
Return type:

str

Returns:

Window class name.

Raises:

WindowsError – An error occured while processing this request.

get_client_rect()

Get the window’s client area coordinates in the desktop.

Return type:

win32.Rect

Returns:

Rectangle occupied by the window’s client area in the desktop.

Raises:

WindowsError – An error occured while processing this request.

get_extended_style()
Return type:

int

Returns:

Window extended style mask.

Raises:

WindowsError – An error occured while processing this request.

get_handle()
Return type:

int

Returns:

Window handle.

Raises:

ValueError – No window handle set.

get_parent()
See:

get_children()

Return type:

Window or None

Returns:

Parent window. Returns None if the window has no parent.

Raises:

WindowsError – An error occured while processing this request.

get_pid()
Return type:

int

Returns:

Global ID of the process that owns this window.

get_placement()

Retrieve the window placement in the desktop.

See:

set_placement()

Return type:

win32.WindowPlacement

Returns:

Window placement in the desktop.

Raises:

WindowsError – An error occured while processing this request.

get_process()
Return type:

Process

Returns:

Parent Process object.

get_root()
See:

get_tree()

Return type:

Window

Returns:

If this is a child window, return the top-level window it belongs to. If this window is already a top-level window, returns itself.

Raises:

WindowsError – An error occured while processing this request.

get_screen_rect()

Get the window coordinates in the desktop.

Return type:

win32.Rect

Returns:

Rectangle occupied by the window in the desktop.

Raises:

WindowsError – An error occured while processing this request.

get_style()
Return type:

int

Returns:

Window style mask.

Raises:

WindowsError – An error occured while processing this request.

get_text()
See:

set_text()

Return type:

str

Returns:

Window text (caption) on success, None on error.

get_thread()
Return type:

Thread

Returns:

Parent Thread object.

get_tid()
Return type:

int

Returns:

Global ID of the thread that owns this window.

get_tree()
See:

get_root()

Return type:

dict( Window -> dict( … ) )

Returns:

Dictionary of dictionaries forming a tree of child windows.

Raises:

WindowsError – An error occured while processing this request.

hide(bAsync=True)

Make the window invisible.

See:

show()

Parameters:

bAsync (bool) – Perform the request asynchronously.

Raises:

WindowsError – An error occured while processing this request.

is_child()
See:

get_parent()

Return type:

bool

Returns:

True if the window is a child window.

is_enabled()
See:

enable(), disable()

Return type:

bool

Returns:

True if the window is in an enabled state.

is_iconic()
See:

minimize()

Return type:

bool

Returns:

True if the window is minimized.

is_maximized()
See:

maximize()

Return type:

bool

Returns:

True if the window is maximized.

is_minimized()
See:

minimize()

Return type:

bool

Returns:

True if the window is minimized.

is_valid()
Return type:

bool

Returns:

True if the window handle is still valid.

is_visible()
See:

show(), hide()

Return type:

bool

Returns:

True if the window is in a visible state.

is_zoomed()
See:

maximize()

Return type:

bool

Returns:

True if the window is maximized.

kill()

Signals the program to quit.

Note

This is an asyncronous request.

Raises:

WindowsError – An error occured while processing this request.

maximize(bAsync=True)

Maximize the window.

See:

minimize(), restore()

Parameters:

bAsync (bool) – Perform the request asynchronously.

Raises:

WindowsError – An error occured while processing this request.

minimize(bAsync=True)

Minimize the window.

See:

maximize(), restore()

Parameters:

bAsync (bool) – Perform the request asynchronously.

Raises:

WindowsError – An error occured while processing this request.

move(x=None, y=None, width=None, height=None, bRepaint=True)

Moves and/or resizes the window.

Note

This is request is performed syncronously.

Parameters:
  • x (int) – (Optional) New horizontal coordinate.

  • y (int) – (Optional) New vertical coordinate.

  • width (int) – (Optional) Desired window width.

  • height (int) – (Optional) Desired window height.

  • bRepaint (bool) – (Optional) True if the window should be redrawn afterwards.

Raises:

WindowsError – An error occured while processing this request.

post(uMsg, wParam=None, lParam=None)

Post a low-level window message asyncronically.

Parameters:
  • uMsg (int) – Message code.

  • wParam – The type and meaning of this parameter depends on the message.

  • lParam – The type and meaning of this parameter depends on the message.

Raises:

WindowsError – An error occured while sending the message.

restore(bAsync=True)

Unmaximize and unminimize the window.

See:

maximize(), minimize()

Parameters:

bAsync (bool) – Perform the request asynchronously.

Raises:

WindowsError – An error occured while processing this request.

screen_to_client(x, y)

Translates window screen coordinates to client coordinates.

Note

This is a simplified interface to some of the functionality of the win32.Point class.

See:

win32.Point.screen_to_client()

Parameters:
  • x (int) – Horizontal coordinate.

  • y (int) – Vertical coordinate.

Return type:

tuple( int, int )

Returns:

Translated coordinates in a tuple (x, y).

Raises:

WindowsError – An error occured while processing this request.

send(uMsg, wParam=None, lParam=None, dwTimeout=None)

Send a low-level window message syncronically.

Parameters:
  • uMsg (int) – Message code.

  • wParam – The type and meaning of this parameter depends on the message.

  • lParam – The type and meaning of this parameter depends on the message.

  • dwTimeout – Optional timeout for the operation. Use None to wait indefinitely.

Return type:

int

Returns:

The meaning of the return value depends on the window message. Typically a value of 0 means an error occured. You can get the error code by calling win32.GetLastError().

set_placement(placement)

Set the window placement in the desktop.

See:

get_placement()

Parameters:

placement (win32.WindowPlacement) – Window placement in the desktop.

Raises:

WindowsError – An error occured while processing this request.

set_process(process=None)

Manually set the parent process. Use with care!

Parameters:

process (Process) – (Optional) Process object. Use None to autodetect.

set_text(text)

Set the window text (caption).

See:

get_text()

Parameters:

text (str) – New window text.

Raises:

WindowsError – An error occured while processing this request.

set_thread(thread=None)

Manually set the thread process. Use with care!

Parameters:

thread (Thread) – (Optional) Thread object. Use None to autodetect.

show(bAsync=True)

Make the window visible.

See:

hide()

Parameters:

bAsync (bool) – Perform the request asynchronously.

Raises:

WindowsError – An error occured while processing this request.