Function Reference


GUICreate

Create a GUI window.

GUICreate ( "title" [, width [, height [, left = -1 [, top = -1 [, style = -1 [, exStyle = -1 [, parent = 0]]]]]]] )

Parameters

title The title of the dialog box.
width [optional] The width of the client area of the window.
height [optional] The height of the client area of the window.
left [optional] The left side of the dialog box. By default (-1), the window is centered. If defined, top must also be defined.
top [optional] The top of the dialog box. Default (-1) is centered
style [optional] defines the style of the window. See GUI Control Styles Appendix.
Use -1 for the default style which includes a combination of $WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU styles.
Some styles are always included: $WS_CLIPSIBLINGS, and $WS_SYSMENU if $WS_MAXIMIZEBOX or $WS_SIZEBOX is specified.
exStyle [optional] defines the extended style of the window. See the Extended Style Table below.
Use -1 for the default, which is no extended styles.
Forced styles: $WS_EX_WINDOWEDGE
parent [optional] The handle of another previously created window - this new window then becomes a child of that window.

Return Value

Success: a windows handle.
Failure: 0 if the window cannot be created and sets the @error flag to 1.

Remarks

By default the dialog box is non sizable and non maximizable. So WS_SIZEBOX or WS_MAXIMIZEBOX can be used in the style parameter.
As defining only one style just set this style don't forget to combine it with default ones, i.e. just defining WS_SIZEBOX will not set $WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU. So the best method to define a resizeable window is to use $WS_OVERLAPPEDWINDOW.
When using $WS_EX_MDICHILD the position is relative to client area of the parent window. With $WS_EX_LAYERED it is possible to have a transparent picture on a background picture defined in the parent window.
Adding $WS_CLIPCHILDREN style can avoid some flickering when resizing GUI containing Edit control for example.
You can enable window dragging for GUI without $WS_CAPTION by using $WS_EX_CONTROLPARENT in the exStyle parameter.

To combine styles with the default style use BitOR($GUI_SS_DEFAULT_GUI, newstyle, ...).
The size specified is the size of the client area of the window. The border and title bar will make the window slightly larger than specified. Using menu controls will also change the windows height.

Extended Style table

Extended Style result
$WS_EX_ACCEPTFILES Allow an edit or input control within the created GUI window to receive filenames via drag and drop. The control must have also the $GUI_DROPACCEPTED state set by GUICtrlSetState(). for other controls the drag&drop info can be retrieved with @GUI_DragId, @GUI_DragFile, @GUI_DropId.
$WS_EX_APPWINDOW Forces a top-level window onto the taskbar when the window is visible.
$WS_EX_CLIENTEDGE Specifies that a window has a border with a sunken edge.
$WS_EX_CONTEXTHELP Includes a question mark in the title bar of the window. Cannot be used with the $WS_MAXIMIZEBOX or $WS_MINIMIZEBOX.
$WS_EX_DLGMODALFRAME Creates a window that has a double border; the window can, optionally, be created with a title bar by specifying the WS_CAPTION style in the style parameter.
$WS_EX_MDICHILD Create a child window that will be moved with its parent (simulation of a MDI window maximize/minimize are not simulated).
$WS_EX_OVERLAPPEDWINDOW Combines the $WS_EX_CLIENTEDGE and $WS_EX_WINDOWEDGE styles.
$WS_EX_STATICEDGE Creates a window with a three-dimensional border style intended to be used for items that do not accept user input.
$WS_EX_TOPMOST Specifies that a window created with this style should be placed above all non-topmost windows and should stay above them, even when the window is deactivated.
$WS_EX_TRANSPARENT The window appears transparent because the bits of underlying sibling windows have already been painted.
$WS_EX_TOOLWINDOW Creates a tool window; that is, a window intended to be used as a floating toolbar. A tool window has a title bar that is shorter than a normal title bar, and the window title is drawn using a smaller font. A tool window does not appear in the taskbar or in the dialog box that appears when the user presses ALT+TAB. If a tool window has a system menu, its icon is not displayed on the title bar. However, you can display the system menu by typing ALT+SPACE.
$WS_EX_WINDOWEDGE Specifies that a window has a border with a raised edge.
$WS_EX_LAYERED Creates a layered window. Note that this cannot be used for child windows.

To use the values specified above you must #include <WindowsConstants.au3> in your script.

Note: The handle returned from this function is a real windows handle, which means it can be used in the same way as the result of WinGetHandle().
WinMove() use before GuiSetState() to change GUI window size will not change the position/resizing of defined Controls.

Related

GUICtrlCreate..., GUICtrlSetDefBkColor, GUICtrlSetDefColor, GUIDelete, GUIGetCursorInfo, GUIGetMsg, GUIGetStyle, GUISetParameters..., GUISetState, GUISwitch, WinGetHandle, WinMove

Example

Example 1

#include <GUIConstantsEx.au3>

Example()

Func Example()
        ; Create a GUI with various controls.
        Local $hGUI = GUICreate("Example", 400, 400)
        Local $idOK = GUICtrlCreateButton("OK", 310, 370, 85, 25)

        Local $aWindow_Size = WinGetPos($hGUI)
        ConsoleWrite('Window Width  = ' & $aWindow_Size[2] & @CRLF)
        ConsoleWrite('Window Height = ' & $aWindow_Size[3] & @CRLF)
        Local $aWindowClientArea_Size = WinGetClientSize($hGUI)
        ConsoleWrite('Window Client Area Width  = ' & $aWindowClientArea_Size[0] & @CRLF)
        ConsoleWrite('Window Client Area Height = ' & $aWindowClientArea_Size[1] & @CRLF)

        ; Display the GUI.
        GUISetState(@SW_SHOW, $hGUI)

        ; Loop until the user exits.
        While 1
                Switch GUIGetMsg()
                        Case $GUI_EVENT_CLOSE, $idOK
                                ExitLoop

                EndSwitch
        WEnd

        ; Delete the previous GUI and all controls.
        GUIDelete($hGUI)
EndFunc   ;==>Example

Example 2

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Example()

Func Example()
        Local $sFilePath = "..\GUI\logo_autoit_210x72.gif"

        ; Create a GUI with various controls.
        Local $hGUI = GUICreate("Example", 400, 100)
        GUICtrlCreatePic("..\GUI\msoobe.jpg", 0, 0, 400, 100)

        ; Display the GUI.
        GUISetState(@SW_SHOW, $hGUI)

        Local $hChild = GUICreate("", 210, 72, 20, 15, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $hGUI)

        ; Create a picture control with a transparent image.
        GUICtrlCreatePic($sFilePath, 0, 0, 210, 72)

        ; Display the child GUI.
        GUISetState(@SW_SHOW)

        ; Loop until the user exits.
        While 1
                Switch GUIGetMsg()
                        Case $GUI_EVENT_CLOSE
                                ExitLoop

                EndSwitch
        WEnd

        ; Delete the previous GUIs and all controls.
        GUIDelete($hGUI)
        GUIDelete($hChild)
EndFunc   ;==>Example