Windows Library:
Support for interacting with Windows.
In most applicable cases, use a HWND (windows handle) of 0 to represent the desktop window.
Find a window by title, class, and, or ID:
hWnd = win.Find([szTitle], [szClass], [HWND], [WinID], [Flags])
To ignore title, and, or class strings pass nil for them.
Only need supply HWND when using the FIND_NOT_HWND, or FIND_CHILD flags.
Only need supply WinID when using the FIND_ID flag. Use the bitwise operations to combine flags.
Optional flags:
| FIND_IGNORE_CASE | Ignore case in title and class. |
| FIND_TILE_INSIDE | Partial string match inside window title. |
| FIND_CLASS_INSIDE | Partial string match inside window class. |
| FIND_ID | Match window ID. Can be used alone or with title and class strings. |
| FIND_NOT_HWND | A window that doesn’t match the supplied HWND. |
| FIND_CHILD | Find a child window of the supplied HWND. |
Examples:
-- Find window for a Notepad.exe,. Must use FIND_TILE_INSIDE flag because of Notepad’s format.
hNotepad = win.Find(“Notepad”, “Notepad” , 0,0, win.FIND_TILE_INSIDE)
-- Find the “edit” control inside of notepad.
hNotepadEdit = win.Find(nil, “Edit”, hNotepad, 15, bit.OR(win.FIND_CHILD, win.FIND_ID))
| infotable = win.Info([HWND]) | Returns a table with various information about a window, or nil if it doesn’t exist. Pass nil or 0 for an HWND to get desktop information. |
Info table in order:
.title - Title text.
.class - Class name.
.x - X position.
.y - Y position.
.width - Width (whole area)
.height - Height
.cwidth - Width (client area)
.cheight - Height
.pid - Identifier of the process that created the window.
.id - Window ID numer.
.parent - Parent window handle (if it has one).
.hinstance - “HINSTANCE” of the window.
.winproc - Retrieves the address of the window procedure, or handle.
.style - Retrieves the window styles.
.exstyle - Retrieves the extended window style.
Window can be minimized to get proper position and size fields, except for passing 0 which gives limited desktop information (like size, etc).
Example:
winfo = win.Info(hNotepad)
print(winfo.title, winfo.class, winfo.posx, winfo.posy)
| bExists = win.Exists(HWND) | Determines whether the specified window handle identifies an existing window. |
| bInFocus = win.IsFocus(HWND) | Returns true if the specified window is the one currently in focus. |
| win.SetPos(HWND, Xpos, Ypos) | Set a window’s position. |
| win.SetSize(HWND, Width, Height) | Set a window’s size. |
| win.SetState(HWND,State) | Set various window states. |
| win.SetText(HWND, szText) | Set a window’s text. |
States:
| win.SW_SHOW | Shows window if hidden and forces it into focus. |
| win.SW_HIDE | Hide window. |
| win.SW_MINIMIZE | Minimize window. |
| win.SW_MAXIMIZE | Maximize window. |
| win.SW_RESTORE | Restore window. |
Example:
win.SetState(hNotepad, win.SW_SHOW)
Sends the specified message to specified window. It calls the window procedure for the specified window and does not return until the window procedure has processed the message.
LRESULT = win.SendMessage(hWnd, Msg, wParam, lParam)
Example:
-- Set target window text the “SendMessage()” way
WM_SETTEXT = 0x000C
win.SendMessage(hNotePad, WM_SETTEXT, 0, "Test")
Posts a message to the specified window and returns without waiting for the thread to process the message. Returns true if successful.
result = win.PostMessage(hWnd, Msg, wParam, lParam)
Note: PostMessage() , doesn’t always work where SendMessage() will. If in doubt try SendMessage().
win.Close(HWND) Attempt to close the specified window via a WM_CLOSE message.
table = win.List([HWND]) List windows into a table. Pass HWND for a list of child windows below it, or nil for all top-level windows. Note: Not all windows necessarily have a title.
For more detailed information, call win.Info() above with an HWND.
Table Format:
hwnd, title, class
win.Flash(HWND, [count], [rate]) Flash a find with optional count (default 3), and optional rate in milliseconds (200 default).
r,g,b = win.GetPixel(HWND, x, y) Read pixel from a window. Window must be at least visible on screen and not blocked or overlapped; nil returned on error.
Pass HWND as 0 to read directly from desktop.