GUICreate: Difference between revisions

From AutoIt Wiki
Jump to navigation Jump to search
No edit summary
mNo edit summary
 
Line 1: Line 1:
<!-- Autogenerated Wiki Page. -->
<!-- Autogenerated Wiki Page. -->
<!-- Not meant to be user editable. -->
<!-- Not meant to be user editable. -->
<!-- If there is an error here then that means that there is an error in the helpfile. -->
<!-- If there is an error here then that means that there is an error in the helpfile or in my script. -->
<!-- Report it to Trac with category 'Documentation'. -->
<!-- Report it to Trac with category 'Documentation' or to my post if it is my script that is in error. -->
<!-- See this post for more info: http://www.autoitscript.com/forum/topic/153680-convert-helpfile-to-wiki-text/-->
<!-- See this post for more info: http://www.autoitscript.com/forum/topic/153680-convert-helpfile-to-wiki-text/-->
<font face='Segoe UI, Courier New, Lucida Grande, Verdana, Helvetica, sans-serif'>
<font face='Segoe UI, Courier New, Lucida Grande, Verdana, Helvetica, sans-serif'>
Line 21: Line 21:
{| class='wikitable'
{| class='wikitable'
|-
|-
| title || The title of the dialog box.
| title || The title of the dialog box.
|-
|-
| width || '''[optional]''' The width of the window.
| width || '''[optional]''' The width of the window.
|-
|-
| height || '''[optional]''' The height of the window.
| height || '''[optional]''' The height 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.
| 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
| top || '''[optional]''' The top of the dialog box. Default (-1) is centered
|-
|-
| style || '''[optional]''' defines the style of the window. See [http://www.autoitscript.com/autoit3/docs/appendix/GUIStyles.htm GUI Control Styles Appendix].
| style || '''[optional]''' defines the style of the window. See [http://www.autoitscript.com/autoit3/docs/appendix/GUIStyles.htm 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.
|-
|-
| || Use -1 for the default style which includes a combination of $WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU styles.
| exStyle || '''[optional]''' defines the extended style of the window. See the '''Extended Style Table''' below.
|-
 
| || Some styles are always included: $WS_CLIPSIBLINGS, and $WS_SYSMENU if $WS_MAXIMIZEBOX or $WS_SIZEBOX is specified.
Use -1 for the default, which is no extended styles.
|-
 
| exStyle || '''[optional]''' defines the extended style of the window. See the [GUICreate.htm#Extended Style Table Extended Style Table] below.
Forced styles: $WS_EX_WINDOWEDGE
|-
|-
| || Use -1 for the default, which is no extended styles.
| parent || '''[optional]''' The handle of another previously created window - this new window then becomes a child of that window.
|-
| || Forced styles: $WS_EX_WINDOWEDGE
|-
| parent || '''[optional]''' The handle of another previously created window - this new window then becomes a child of that window.
|}
|}


Line 111: Line 111:


===<font size=4><div id='Section' style='color:#DB7100;'>Example</div></font>===
===<font size=4><div id='Section' style='color:#DB7100;'>Example</div></font>===
<font style='color:#000080;'>'''Example 1'''
<syntaxhighlight lang='autoit'>
<syntaxhighlight lang='autoit'>
#include <GUIConstantsEx.au3>
#include <GUIConstantsEx.au3>
Line 135: Line 137:
GUIDelete($hGUI)
GUIDelete($hGUI)
EndFunc  ;==>Example
EndFunc  ;==>Example
</syntaxhighlight><syntaxhighlight lang='autoit'>
</syntaxhighlight>
<font style='color:#000080;'>'''Example 2'''
<syntaxhighlight lang='autoit'>
#include <GUIConstantsEx.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WindowsConstants.au3>

Latest revision as of 10:33, 27 August 2013

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 window.
height [optional] The height 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: Returns a windows handle.
Failure: Returns 0 if the window cannot be created and sets @error 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 included in its parent window (simulation not real MDI).
$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.


Related

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


Example

Example 1

#include <GUIConstantsEx.au3>

Example()

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

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

	While 1
		Switch GUIGetMsg()
			Case $GUI_EVENT_CLOSE, $iOK
				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\logo4.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("", 169, 68, 20, 20, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $hGUI)

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

	; Display the child GUI.
	GUISetState(@SW_SHOW)

	While 1
		Switch GUIGetMsg()
			Case $GUI_EVENT_CLOSE
				ExitLoop

		EndSwitch
	WEnd

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