Window Module
Contents
find
number window.find(string windowName[, string className])
Finds a window's HWND based on its title (not case-sensitive), and (optionally) its classname (case-sensitive). 'title' and 'classname' can contain wildcards * and ?.
Returns the first match found. If no match was found, returns nil.
findList
table window.findList(string windowName[, string className])
Finds a list of windows based on title (not case-sensitive), and (optionally) classname (case-sensitive). 'title' and 'classname' can contain wildcards * and ?.
Returns a table of tables containing: 'hwnd' (number; handle to window), 'name' (string; window title), and 'class' (string; identifier used by its programmer). If no match was found, returns nil.
For example, the return value might look like this:
{
{hwnd = 1234, name = "Window Name 1", class = "Window Class 1"},
{hwnd = 5678, name = "Window Name 2", class = "Window Class 2"},
{hwnd = 9012, name = "Window Name 3", class = "Window Class 3"},
}
getParent
number window.getParent(number hwnd)
Returns a window's parent, or nil on error.
getTitle
string window.getTitle(number hwnd)
Returns a window's title as a string.
setTitle
window.setTitle(number hwnd, string title)
Change a window's title.
getClassName
string window.getClassName(number hwnd)
Returns a window's class name as a string.
valid
boolean window.valid(number hwnd)
Returns true if 'hwnd' is a valid window handle, or false otherwise.
getRect
number x, number y, number w, number h window.getRect(number hwnd)
Returns the position (x,y) and size (w,h) of a window.
setRect
window.setRect(number hwnd, number x, number y, number w, number h)
Change the position and size of a window with handle 'hwnd'.
getClientRect
number x, number y, number w, number h window.getClientRect(number hwnd)
Returns the position and size of a window's client area.
setClientRect
window.setClientRect(number hwnd, number x, number y, number w, number h)
Change the position and size of a window's client area with handle 'hwnd'.
show
window.show(number hwnd, number cmd)
Show/hide/minimize/maximize/whatever with the window.
For 'cmd', you should specify one of the following constants:
SW_FORCEMINIMIZE
SW_HIDE
SW_MAXIMIZE
SW_MINIMIZE
SW_RESTORE
SW_SHOW
SW_SHOWDEFAULT
SW_SHOWMAXIMIZED
SW_SHOWMINIMIZED
SW_SHOWMINNOACTIVATE
SW_SHOWNA
SW_SHOWNOACTIVATE
SW_SHOWNORMAL
flash
window.flash(number hwnd, number flashCount)
"Flash" the window to attempt to grab the user's attention. If 'flashCount' is < 0, stop flashing If 'flashCount' is 0, flash until user focuses the window If 'flashCount' is > 0, flash this many times
getPixel
number r, number g, number b window.getPixel(number hwnd, number x, number y)
Get the color of a pixel at (x,y) inside window 'hwnd', and return the color split into red, green, and blue channels. r, g, and b results will be between 0 and 255.
pixelSearch
number x, number y window.pixelSearch(number hwnd, number r, number g, number b, number x1, number y1, number x2, number y2[, number accuracy[, number step]])
Search the given window for a pixel that matches r,g,b within the rectangle outlined by (x1,y1) -> (x2,y2) The rect may go from left-to-right, right-to-left, top-to-bottom, bottom-to-top, or any combination of those, depending on the orientation of the two points.
'accuracy' is how many units each channel must be within the given color to generate a match. ie. with an accuracy of 20, the red, green, and blue channels must be within 20 of the target color to match. Default: 1
'step' is the step size (distance between pixels to search). You generally have no need for this so long as you aren't scanning a large area, but you may experience faster scan times (with a chance of missing a match) with a higher step size. Default: 1
If the pixel is not found, this function returns nil.
saveScreenshot
window.saveScreenshot(number hwnd, string filename)
Save a screenshot of window 'hwnd' to 'filename'. If 'hwnd' is 0, this screenshots the whole desktop. NOTE: You cannot take a screenshot of a minimized window. This is a limitation in Windows.
getAppHwnd
number window.getAppHwnd()
Returns the calling process' (MicroMacro) handle to window (HWND). This is what you may use to access or modify the console's properties where an hwnd is required.
getFocusHwnd
number window.getFocusHwnd()
Returns the hwnd of whichever window is top-most as of the the start of this logic cycle. This is polled once per frame and should be fairly accurate so long as your script executes each logic cycle quickly. Be aware that as windows are being minimized, maximized, or otherwise, the focused hwnd may temporarily switch to NULL (0).
makeColor
number window.makeColor(number red, number green, number blue)
This helper function converts red-green-blue components into a long integer color value for use in other functions. All input values (red, green, and blue) should be integers between 0 and 255. (0, 0, 0) would result in black, (255, 255, 255) would result in white and (0, 255, 0) would result in green.
drawLine
boolean window.drawLine(number hwnd, number x1, number y1, number x2, number y2[, number color[, number thickness]])
Draws a line in the client region of the window specied by hwnd (note: use 0 to draw directly to screen). It is possible to draw outside of the given window with this function. A line will be drawn starting from (x1,y1) to (x2,y2) with the given color and line thickness. By default, color will be black (0, 0, 0) and thickness (in pixels) will be 1.
You should use window.makeColor() to generate the number passed as the color value if you wish to specify a color by RGB. Alternatively, you can pass the value in by hex notation (ie, 0xFF00FF).
-- Draw a red line from (0,0) to (200, 200) that is 5 pixels thick on the window.
window.drawLine(hwnd, 0, 0, 200, 200, window.makeColor(255, 0, 0), 5);
-- Draw a green line from (200, 200) to (400, 400) that is 1 pixels thick
window.drawLine(hwnd, 200, 200, 400, 400, 0x00FF00);
drawRect
boolean window.drawRect(number hwnd, number x1, number y1, number x2, number y2[, number color[, number thickness]])
This functions exactly like window.drawLine(), except that it draws a rectangle rather than a line.
Draws a line in the client region of the window specied by hwnd (note: use 0 to draw directly to screen). It is possible to draw outside of the given window with this function. A rectangle will be drawn starting from (x1,y1) to (x2,y2) with the given color and line thickness. By default, color will be black (0, 0, 0) and border thickness (in pixels) will be 1.
You should use window.makeColor() to generate the number passed as the color value if you wish to specify a color by RGB. Alternatively, you can pass the value in by hex notation (ie, 0xFF00FF).