Interaction With The Operating System >

# Windows Structure

The Windows struct provides methods to access the Windows OS' User Interface elements.

Unless noted otherwise, these methods are available in 3ds Max 2008 and higher.

They were previously available in the Avguard Extensions .

    windows.getMAXHWND()

This method returns the HWND of the main 3ds Max window as an integer (Pointer value).

    windows.getDesktopHWND()

This method returns the HWND of the MS Window's desktop as an integer (Pointer value).

    windows.sendMessage <int HWND> <int message> <int messageParameter1> <int messageParameter2>

Sends a Win32 message to the HWND specified in the first argument.

The second argument is the message ID, usually specified as hexadecimal number.

The third and fourth arguments are the message parameters. When no parameters are expected, pass 0 as a placeholder.

    windows.postMessage <int HWND> <int message> <int messageParameter1> <int messageParameter2>

Calls the Window's PostMessage function passing the argument values.

Available in 3ds Max 2011 and higher.

    windows.processPostedMessages()

Runs a message pump that retrieves any pending Window's messages and dispatches them to 3ds Max.

Calling this method will process all pending messages. It can be used inside a MAXScript loop which would otherwise cause a "white screen" in Windows 7 due to 3ds Max being unresponsive while performing long calculations.

Available in 3ds Max 2011 and higher.

    windows.getChildrenHWND {<int HWND>|#max} parent:{<int HWND>| #max}

This method returns an array of the children windows of the specified HWND, recursively.

If the specified HWND is 0, only the top level desktop windows are returned (not recursively).

If the parent HWND is specified, only windows whose immediate parent is the specified window are returned.

If #max is specified as the HWND, the HWND associated with the 3ds Max main window is used.

If the specified HWND does not exist, the value undefined is returned.

Otherwise, an array is returned.

Each element of the array corresponds to a window, and contains an 8 elements array (originally, only the first 5 elements were returned in 3ds Max 2008)

The elements of these arrays represent the window's:

1: HWND

2: the parent HWND. This does not include the owner (GetAncestor(hWnd,GA_PARENT))

3: the parent or owner HWND. If the window is a child window, the return value is a handle to the parent window. If the window is a top-level window, the return value is a handle to the owner window. (GetParent(hWnd))

4: class name as a string (GetClassName(hWnd, className, bufSize)) - limit of 255 characters

5: window text as a string (GetWindowText(hWnd, windowText, bufSize)) - limit of 255 characters

6: the owner's HWND (GetWindow(hWnd,GW_OWNER))

7: root window HWND. The root window as determined by walking the chain of parent windows (GetAncestor(hWnd,GA_ROOT))

8: owned root window HWND. The owned root window as determined by walking the chain of parent and owner windows returned by GetParent (GetAncestor(hWnd,GA_ROOTOWNER))

FOR EXAMPLE, A PARTIAL RESULT FROM THE CALL
    print (windows.getChildrenHWND #max)
looks like
    ...
    #(16990604P, 25827408P, 25827408P, "#32770", "Main Toolbar", 25827408P, 25827408P, 25827408P)
    #(2048768P, 16990604P, 16990604P, "CustToolbar", "", 0P, 25827408P, 25827408P)
    #(8794706P, 2048768P, 2048768P, "CustSeparator", "", 0P, 25827408P, 25827408P)
    #(33762226P, 2048768P, 2048768P, "CustButton", "", 0P, 25827408P, 25827408P)
    #(34615562P, 2048768P, 2048768P, "CustButton", "", 0P, 25827408P, 25827408P)
    #(999632P, 2048768P, 2048768P, "CustButton", "", 0P, 25827408P, 25827408P)
    #(5908980P, 2048768P, 2048768P, "CustSeparator", "", 0P, 25827408P, 25827408P)
    #(19083138P, 2048768P, 2048768P, "ComboBox", "All", 0P, 25827408P, 25827408P)
    ...
In this case, the Main Toolbar of 3ds Max is a docked window which has a HWND of 16990604, the 3ds Max main window's HWND is 25827408, the class name of the Main Toolbar is "#32770" and the window text of the toolbar is "Main Toolbar". It is owned by and rooted at the 3ds Max window with HWND 25827408, which explains elements 6,7 and 8. The next element is the toolbar window itself which has a HWND of 2048768 and is parented to the Main Toolbar window with HWND 16990604. The class of the toolbar is "CustToolbar" and it does not display any text. It is not owned by a window (so the HWND is 0), but it is rooted at the 3ds Max window with HWND 25827408. The next element is the first separator in the toolbar. It has a HWND of 8794706 and is parented to the custom toolbar with HWND of 2048768. Its class is "CustSeparator" and has no text associated with it. It has no owner and is rooted at the 3ds Max window. After that we get the first icon in the Main Toolbar with HWND 33762226. It is also parented to the custom toolbar with HWND of 2048768 and has the class "CustButton" and no text. It has no owner and is rooted at the 3ds Max window. After that come more buttons and separators. The one with HWND 19083138P is the Selection Filter ComboBox which displays "All" by default.

    windows.getChildHWND {<int HWND>| #max} <string> parent:{<int HWND>|#max}

The mehod returns the child window of the specified HWND with the given child window's text. Child windows are recursively searched.

If the specified HWND is 0, only the top level desktop windows are searched (not recursively).

If the parent HWND is specified, only windows whose immediate parent is the specified window are searched.

If #max is specified as the HWND, the HWND associated with 3ds Max main window is used.

If the specified HWND does not exist, the value undefined is returned.

If a child window with the specified text is not found, undefined is returned.

The text comparison is case insensitive.

If a match is found, an 8 element array is returned. See the documentation of the windows.getChildrenHWND() method above for details on their meaning.

FOR EXAMPLE, A PARTIAL RESULT FROM THE CALL
    max file xref object -- open xref object dialog
    xro_hwnd = windows.getChildHWND 0 "XRef Objects" parent:#max -- find xref object dialog
    if xro_hwnd != undefined do windows.sendMessage xro_hwnd[1] 0x0010 0 0 -- if found, send close message
    max file xref scene -- open xref sceen dialog
    xrs_hwnd = windows.getChildHWND 0 "XRef Scenes" parent:#max -- find xref scene dialog
    if xrs_hwnd != undefined do windows.sendMessage xrs_hwnd[1] 0x0010 0 0 -- if found, send close message
LISTENER OUTPUT:
    OK
    #(25961156P, 65552P, 25827408P, "#32770", "XRef Objects", 25827408P, 25961156P, 25827408P)
    1
    OK
    #(26813124P, 65552P, 25827408P, "#32770", "XRef Scenes", 25827408P, 26813124P, 25827408P)
    1

    windows.getHWNDData {<int HWND>|#max}

Returns data associated with the specified HWND.

If #max is specified as the HWND, the HWND associated with the 3ds Max main window is used.

If the specified HWND does not exist, the value undefined is returned.

If a match is found, a 8 element array is returned. See the documentation of the windows.getChildrenHWND() method above for details on their meaning.

Available in 3ds Max 2011 and higher.

Note that in 3ds Max 2011 and higher, rollouts and rollout controls expose a read-only .hwnd property.

In the case of a rollout, the property contains the Window's HWND associated with the rollout, or 0 if the rollout is not open.

In the case of a rollout User Interface control, the property contains an array of the Window's HWND of the rollout containing the rollout, or an empty array of the rollout is not open.

    windows.setWindowPos <int HWND> <int x> <int y> <int width> <int height> <bool repaint>

NEW in 3ds Max 2014: Set the position of the window specified by the HWND to the X and Y coordinates specified by the second and third arguments.

Also set the Width and Height of the window to the values passed as fourth and fifth arguments.

When the sixth argument is set to True, the window will also be repainted.

    windows.setWindowPos <int HWND> <Box2 rect> <bool repaint>

NEW in 3ds Max 2014: Set the position of the window specified by the HWND to the coordinates and size given by the second Box2 argument.

When the third argument is set to True, the window will also be repainted.

    <Box2 rect>windows.getWindowPos <int HWND>

NEW in 3ds Max 2014: Returns the position of the upper left corner and the width and height of the window specified by the HWND argument.

The position is expressed in screen coordinates relative to the upper-left corner of the screen.

FOR EXAMPLE:
    rollout test1 "Test" ( button btn "PRESS ME" ) --a test rollout
    createDialog test1 200 50 120 140 --rollout, width, height, x, y
    windows.getWindowPos test1.hwnd --get the resulting position and size
LISTENER OUTPUT:
    Rollout:test1
    true
    (Box2 120 140 206 75)
    --Note that the width and height include the borders and the title bar --and can vary depending on the Windows Theme used.
NOW LET'S MOVE AND RESIZE IT:
    windows.setWindowPos test1.hwnd 220 240 206 55 true

    <Point2>windows.clientToScreen <int HWND> <int x> <int y>

    <Point2>windows.clientToScreen <int HWND> <Point2 clientCoord>

NEW in 3ds Max 2014: Converts the coordinates from the Client space of the window specified by the first argument to coordinates relative to the upper left corner of the Screen.

    <Point2>windows.screenToClient <int HWND> <int x> <int y>

    <Point2>windows.screenToClient <int HWND> <Point2 screenCoord>

NEW in 3ds Max 2014: Converts the coordinates from Screen space relative to the upper left corner into Client space of the window specified by the first argument.

FOR EXAMPLE:
    tv = trackviews.getTrackView 1
    -><MixinInterface:TrackView>

    windows.getWindowPos tv.ui.hwnd
    ->(Box2 244 242 1200 400)

    screenPos = windows.clientToScreen tv.ui.hwnd 10 20
    ->[262,312]

    windows.screenToClient tv.ui.hwnd screenPos.x screenPos.y
    ->[10,20]

    windows.getWindowPos tv.ui.hwnd
    ->(Box2 244 242 1200 400)

    windows.setWindowPos tv.ui.hwnd 0 0 1200 400
    ->true

    windows.addChild <int_HWND> <int_HWND>

Makes an ActiveX control whose HWND is passed as first argument the child of the window with HWND passed as second argument.

The first argument cannot be a MAXScript control or rollout, it must be an ActiveX control.

Given that ActiveX controls are considered obsolete since 3ds Max 9, this method can also be considered obsolete.

#### See Also

- Interaction With The Operating System

- Sending Windows Message