Snippets ( GUI ): Difference between revisions

From AutoIt Wiki
Jump to navigation Jump to search
 
 
(28 intermediate revisions by 7 users not shown)
Line 1: Line 1:
<div class="center" style="width:auto; margin-left:auto; margin-right:auto;">'''Please always credit an author in your script if you use their code, Its only polite.'''</div>
__TOC__
===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _AlwaysOnTop() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====
 
[[category:Snippets]]
 
{{Snippet Credit Header}}
 
== _AlwaysOnTop ==
 
{{Snippet Header
| AuthorURL = 35302-guinness
| AuthorName = guinness
}}


<syntaxhighlight lang="autoit">
<syntaxhighlight lang="autoit">
Line 10: Line 20:


Func Example()
Func Example()
     Local $hGUI = GUICreate("_AlwaysOnTop()", 200, 200, -1, -1)
     Local Const $hGUI = GUICreate("_AlwaysOnTop()", 200, 200, -1, -1)
     Local $iControlID = GUICtrlCreateCheckbox("Always On Top", 5, 10, 85, 25, BitOR($BS_CHECKBOX, $BS_AUTOCHECKBOX, $BS_PUSHLIKE, $WS_TABSTOP))
 
     GUISetState(@SW_SHOW, $hGUI)
     Local Const $iControlID = GUICtrlCreateCheckbox("Always On Top", 5, 10, 85, 25, BitOR($BS_CHECKBOX, $BS_AUTOCHECKBOX, $BS_PUSHLIKE, $WS_TABSTOP))
 
     GUISetState(@SW_SHOWNORMAL, $hGUI)


     While 1
     While 1
Line 18: Line 30:
             Case $GUI_EVENT_CLOSE
             Case $GUI_EVENT_CLOSE
                 Exit
                 Exit
             Case $iControlID
             Case $iControlID
                 _AlwaysOnTop($hGUI, $iControlID)
                 _AlwaysOnTop($hGUI, $iControlID)
         EndSwitch
         EndSwitch
     WEnd
     WEnd
EndFunc  ;==>Example
EndFunc  ;==>Example


Func _AlwaysOnTop($hHandle, $iControlID)
Func _AlwaysOnTop(Const $hHandle, Const $iControlID)
     Local $iState = 0
     Local $iState = 0
     If GUICtrlRead($iControlID) = $GUI_CHECKED Then
     If GUICtrlRead($iControlID) = $GUI_CHECKED Then
         $iState = 1
         $iState = 1
     EndIf
     EndIf
     WinSetOnTop($hHandle, "", $iState)
     WinSetOnTop($hHandle, "", $iState)
     Return $iState
     Return $iState
EndFunc  ;==>_AlwaysOnTop
EndFunc  ;==>_AlwaysOnTop
</syntaxhighlight>
</syntaxhighlight>


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' Animate Display ~ Author - [http://www.autoitscript.com/forum/user/5725-raindancer/ Raindancer] '''</blockquote> =====
[[#top | ReturnToContents]]
 
== Animate Display ==
 
{{Snippet Header
| AuthorURL = 5725-raindancer
| AuthorName = Raindancer
}}


<syntaxhighlight lang="autoit">
<syntaxhighlight lang="autoit">
Line 42: Line 62:
; Author Raindancer
; Author Raindancer


Global $hwnd = GUICreate("Animate Window", 300, 300)
Global Const $hwnd = GUICreate("Animate Window", 300, 300)


DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00080000);fade-in
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00080000) ; fade-in
GUISetState()
 
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00090000);fade-out
GUISetState(@SW_SHOWNORMAL)
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00040001);slide in from left
 
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00050002);slide out to left
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00090000) ; fade-out
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00040002);slide in from right
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00040001) ; slide in from left
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00050001);slide out to right
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00050002) ; slide out to left
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00040004);slide-in from top
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00040002) ; slide in from right
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00050008);slide-out to top
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00050001) ; slide out to right
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00040008);slide-in from bottom
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00040004) ; slide-in from top
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00050004);slide-out to bottom
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00050008) ; slide-out to top
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00040005);diag slide-in from Top-left
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00040008) ; slide-in from bottom
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x0005000a);diag slide-out to Top-left
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00050004) ; slide-out to bottom
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00040006);diag slide-in from Top-Right
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00040005) ; diag slide-in from Top-left
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00050009);diag slide-out to Top-Right
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x0005000a) ; diag slide-out to Top-left
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00040009);diag slide-in from Bottom-left
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00040006) ; diag slide-in from Top-Right
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00050006);diag slide-out to Bottom-left
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00050009) ; diag slide-out to Top-Right
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x0004000a);diag slide-in from Bottom-right
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00040009) ; diag slide-in from Bottom-left
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00050005);diag slide-out to Bottom-right
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00050006) ; diag slide-out to Bottom-left
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00040010);explode
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x0004000a) ; diag slide-in from Bottom-right
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00050010);implode
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00050005) ; diag slide-out to Bottom-right
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00040010) ; explode
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00050010) ; implode


#define AW_HOR_POSITIVE         0x00000001
#define AW_HOR_POSITIVE 0x00000001
#define AW_HOR_NEGATIVE         0x00000002
#define AW_HOR_NEGATIVE 0x00000002
#define AW_VER_POSITIVE         0x00000004
#define AW_VER_POSITIVE 0x00000004
#define AW_VER_NEGATIVE         0x00000008
#define AW_VER_NEGATIVE 0x00000008
#define AW_CENTER                 0x00000010
#define AW_CENTER 0x00000010
#define AW_HIDE                 0x00010000
#define AW_HIDE 0x00010000
#define AW_ACTIVATE             0x00020000
#define AW_ACTIVATE         0x00020000
#define AW_SLIDE                   0x00040000
#define AW_SLIDE           0x00040000
#define AW_BLEND                   0x00080000
#define AW_BLEND           0x00080000
</syntaxhighlight>
</syntaxhighlight>


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' Center Window on Screen ~ Authors - [http://www.autoitscript.com/forum/user/4920-valuater/ Valuater] ~ [http://www.autoitscript.com/forum/user/9669-cdkid/ cdkid] '''</blockquote> =====
[[#top | ReturnToContents]]
 
== Center Window on Screen ==
 
{{Snippet Header
| AuthorURL = 4920-valuater
| AuthorName = Valuater
| AuthorURL2 = 9669-cdkid
| AuthorName2 = cdkid
}}


<syntaxhighlight lang="autoit">
<syntaxhighlight lang="autoit">
Line 84: Line 115:
#include <GUIConstantsEx.au3>
#include <GUIConstantsEx.au3>


Global $GUI = GUICreate("Test Window",300 ,300 ,100 ,100)
Global Const $GUI = GUICreate("Test Window",300 ,300 ,100 ,100)
GUISetState(@SW_SHOW)
 
GUISetState(@SW_SHOWNORMAL)
 
Sleep(2000)
Sleep(2000)
Local $move = _Middle($GUI, "Test Window")


    While 1
_Middle($GUI, "Test Window")
        Local $msg = GUIGetMsg()
 
        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
While 1
     WEnd
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
EndSwitch
WEnd
 
Func _Middle(Const $win, Const $txt)
    Local Const $size = WinGetClientSize($win, $txt)
 
    Local Const $y = (@DesktopHeight / 2) - ($size[1] / 2)
 
     Local Const $x = (@DesktopWidth / 2) - ($size[0] / 2)


Func _Middle($win, $txt)
    Local $size = WinGetClientSize($win, $txt)
    Local $y = (@DesktopHeight / 2) - ($size[1] / 2)
    Local $x = (@DesktopWidth / 2) - ($size[0] / 2)
     Return WinMove($win, $txt, $x, $y)
     Return WinMove($win, $txt, $x, $y)
EndFunc  ;==>_Middle
EndFunc  ;==>_Middle
</syntaxhighlight>
</syntaxhighlight>


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _ChildActivate() ~ Author - [http://www.autoitscript.com/forum/user/71214-mkish/ MKISH] '''</blockquote> =====
[[#top | ReturnToContents]]
 
== _ChildActivate ==
 
{{Snippet Header
| AuthorURL = 71214-mkish
| AuthorName = MKISH
}}
 
<syntaxhighlight lang="autoit">
<syntaxhighlight lang="autoit">
#include <WinAPI.au3>
#include <WinAPI.au3>
; Set focus to Child-Window of a GUI


_ChildActivate("Main Window Title", "Child Window Title")
_ChildActivate("Main Window Title", "Child Window Title")


Func _ChildActivate($appTitle, $formName)
; Set focus to Child-Window of a GUI
     Local $hWnd = WinGetHandle($appTitle, $formName)
Func _ChildActivate(Const $appTitle, Const $formName)
     Local Const $hWnd = WinGetHandle($appTitle, $formName)
 
     Local $array = WinList($appTitle)
     Local $array = WinList($appTitle)
#forceref $array
 
#forceref $array
 
     WinActive($hWnd)
     WinActive($hWnd)
     Local $winarray = _WinAPI_EnumWindows(True, $hWnd)
 
     For $i = 1 to $winarray[0][0]
     Local Const $winarray = _WinAPI_EnumWindows(True, $hWnd)
         Local $title = _WinAPI_GetWindowText($winarray[$i][0])
 
        If ($title == $formName) or ($title == $formName & " *") Then
     Local $title
 
For $i = 1 to $winarray[0][0]
         $title = _WinAPI_GetWindowText($winarray[$i][0])
 
If ($title == $formName) or ($title == $formName & " *") Then
             _WinAPI_ShowWindow($winarray[$i][0], @SW_MAXIMIZE)
             _WinAPI_ShowWindow($winarray[$i][0], @SW_MAXIMIZE)
             _WinAPI_ShowWindow($winarray[$i][0], @SW_SHOWNORMAL)
             _WinAPI_ShowWindow($winarray[$i][0], @SW_SHOWNORMAL)
Line 124: Line 179:
EndFunc ;>>> _ChildActivate
EndFunc ;>>> _ChildActivate
</syntaxhighlight>
</syntaxhighlight>
[[#top|Return To Contents]]


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _ControlMove() ~ Author - [http://www.autoitscript.com/forum/user/38576-melba23/ Melba23] '''</blockquote> =====
[[#top | ReturnToContents]]
 
== _ControlMove ==


<syntaxhighlight lang="autoit">  
{{Snippet Header
| AuthorURL = 38576-melba23
| AuthorName = Melba23
}}
 
<syntaxhighlight lang="autoit">
#include <GuiConstantsEx.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WindowsConstants.au3>


Global Const $SC_MOVE = 0xF010
Global Const $SC_MOVE = 0xF010
$hGUI = GUICreate("Test", 300, 200)
 
$cLabel = GUICtrlCreateLabel("Move me", 100, 50, 60, 20)
Global Const $hGUI = GUICreate("Test", 300, 200)
GUICtrlSetBkColor(-1, 0x00FF00)
 
GUISetState()
Globa Const $cLabel = GUICtrlCreateLabel("Move me", 100, 50, 60, 20)
 
GUICtrlSetBkColor($cLabel, 0x00FF00)
 
GUISetState(@SW_SHOWNORMAL)


While 1
While 1
     $msg = GUIGetMsg()
     Switch GUIGetMsg()
    Switch $msg
         Case $GUI_EVENT_CLOSE
         Case $GUI_EVENT_CLOSE
             Exit
             Exit
Line 148: Line 212:
WEnd
WEnd


Func _ControlMove($cID)
Func _ControlMove(Const $cID)
     Local $aCurPos = GUIGetCursorInfo()
     Local Const $aCurPos = GUIGetCursorInfo()
 
     If @error Then Return False
     If @error Then Return False
     If $aCurPos[4] = $cID Then
     If $aCurPos[4] = $cID Then
         GUICtrlSendMsg($cID, $WM_SYSCOMMAND, BitOR($SC_MOVE, $HTCAPTION), 0)
         GUICtrlSendMsg($cID, $WM_SYSCOMMAND, BitOR($SC_MOVE, $HTCAPTION), 0)
Line 157: Line 223:
</syntaxhighlight>
</syntaxhighlight>


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' Custom Tabs ~ Authors - [http://www.autoitscript.com/forum/user/20477-mrcreator/ MrCreatoR] ~ [http://www.autoitscript.com/forum/user/14325-kickassjoe/ Kickassjoe] ~ mrRevoked '''</blockquote> =====
[[#top | ReturnToContents]]
 
== Custom Tabs ==
 
{{Snippet Header
| AuthorURL = 20477-mrcreator
| AuthorName = MrCreatoR
| AuthorURL2 = 14325-kickassjoe
| AuthorName2 = Kickassjoe
}}


<syntaxhighlight lang="autoit">
<syntaxhighlight lang="autoit">
Line 164: Line 239:
#include <GUIConstants.au3>
#include <GUIConstants.au3>


Dim $TabSwitcher[2]
GUICreate("Test")


GUICreate("Test")
Global $TabSwitcher[2]


$TabSwitcher[0] = GUICtrlCreateLabel("Tab One", 10, 10,60,20, $SS_SUNKEN +$SS_CENTER+ $SS_CENTERIMAGE)
Global Const $TabSwitcher1 = GUICtrlCreateLabel("Tab One", 10, 10,60,20, $SS_SUNKEN +$SS_CENTER+ $SS_CENTERIMAGE)
GUICtrlSetBkColor(-1, 0xf0f0f0)
GUICtrlSetBkColor(-1, 0xf0f0f0)
GUICtrlSetColor(-1, 0x000000)
GUICtrlSetColor(-1, 0x000000)


$TabSwitcher[1] = GUICtrlCreateLabel("Tab Two", 72, 10,60,20, $SS_SUNKEN +$SS_CENTER+ $SS_CENTERIMAGE)
Global Const $TabSwitcher2 = GUICtrlCreateLabel("Tab Two", 72, 10,60,20, $SS_SUNKEN +$SS_CENTER+ $SS_CENTERIMAGE)
GUICtrlSetBkColor(-1, 0xc0c0c0)
GUICtrlSetBkColor(-1, 0xc0c0c0)
GUICtrlSetColor(-1, 0x000000)
GUICtrlSetColor(-1, 0x000000)


$tab = GUICtrlCreateTab(10,40, 200, 200);can be placed anywhere, doesnt matter, not visible
Global Const $tab = GUICtrlCreateTab(10,40, 200, 200) ; can be placed anywhere, doesnt matter, not visible
GUICtrlSetState($tab, $GUI_HIDE)
 
Global Const $tab1 = GUICtrlCreateTabItem("tab1")


$tab1 = GUICtrlCreateTabItem("tab1")
GUICtrlCreateButton("button on tab 1", 10, 70)
GUICtrlCreateButton("button on tab 1", 10, 70)


$tab2 = GUICtrlCreateTabItem("tab2")
Global Const $tab2 = GUICtrlCreateTabItem("tab2")
 
GUICtrlCreateButton("button on tab 2", 10, 70)
GUICtrlCreateButton("button on tab 2", 10, 70)


GUICtrlSetState($tab, $GUI_HIDE)
GUISetState(@SW_SHOWNORMAL)
 
GUISetState()


While 1
While 1
     $msg = GUIGetMsg()
     Switch GUIGetMsg()
    Select
         Case $TabSwitcher1
         Case $msg = $TabSwitcher[0]
             If GUICtrlRead($tab, 1) = $tab1 Then ContinueLoop ; To prevent the flickering and second state set.
             If GUICtrlRead($tab, 1) = $tab1 Then ContinueLoop ;To prevent the flickering and second state set.
             GUICtrlSetState($tab1, $GUI_SHOW)
             GUICtrlSetState($tab1, $GUI_SHOW)
             GUICtrlSetBkColor($TabSwitcher[0], 0xf0f0f0)
             GUICtrlSetBkColor($TabSwitcher1, 0xf0f0f0)
             GUICtrlSetColor($TabSwitcher[0], 0x000000)
             GUICtrlSetColor($TabSwitcher1, 0x000000)
             GUICtrlSetBkColor($TabSwitcher[1], 0xc0c0c0)
             GUICtrlSetBkColor($TabSwitcher2, 0xc0c0c0)
             GUICtrlSetColor($TabSwitcher[1], 0x000000)
             GUICtrlSetColor($TabSwitcher2, 0x000000)
         Case $msg = $TabSwitcher[1]
 
             If GUICtrlRead($tab, 1) = $tab2 Then ContinueLoop ;To prevent the flickering and second state set.
         Case $TabSwitcher2
             If GUICtrlRead($tab, 1) = $tab2 Then ContinueLoop ; To prevent the flickering and second state set.
             GUICtrlSetState($tab2, $GUI_SHOW)
             GUICtrlSetState($tab2, $GUI_SHOW)
             GUICtrlSetBkColor($TabSwitcher[0], 0xc0c0c0)
             GUICtrlSetBkColor($TabSwitcher1, 0xc0c0c0)
             GUICtrlSetColor($TabSwitcher[0], 0x000000)
             GUICtrlSetColor($TabSwitcher1, 0x000000)
             GUICtrlSetBkColor($TabSwitcher[1], 0xf0f0f0)
             GUICtrlSetBkColor($TabSwitcher2, 0xf0f0f0)
             GUICtrlSetColor($TabSwitcher[1], 0x000000)
             GUICtrlSetColor($TabSwitcher2, 0x000000)
         Case $msg = -3
 
         Case $GUI_EVENT_CLOSE
             Exit
             Exit
         Case Else
         Case Else
     EndSelect
     EndSwitch
WEnd
WEnd
</syntaxhighlight>
</syntaxhighlight>


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">'''  Disable all column headers ~ Author - [http://www.autoitscript.com/forum/user/38576-melba23/ Melba23] '''</blockquote> =====
[[#top | ReturnToContents]]
 
== Disable All Column Headers ==
 
{{Snippet Header
| AuthorURL = 38576-melba23
| AuthorName = Melba23
}}


<syntaxhighlight lang="autoit">
<syntaxhighlight lang="autoit">
Line 221: Line 305:


Func _Main()
Func _Main()
     Local $hGUI = GUICreate("ListView Set Column Width", 400, 300)
     Local $hGUI = GUICreate("ListView Set Column Width", 400, 300)
     Local $hListView = GUICtrlCreateListView("Column 1|Column 2|Column 3|Column 4", 2, 2, 394, 268)
     Local $hListView = GUICtrlCreateListView("Column 1|Column 2|Column 3|Column 4", 2, 2, 394, 268)
Line 232: Line 315:
     Do
     Do
     Until GUIGetMsg() = $GUI_EVENT_CLOSE
     Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc  ;==>_Main
EndFunc  ;==>_Main
</syntaxhighlight>
</syntaxhighlight>


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">'''  Disable Specific Column Headers ~ Author - [http://www.autoitscript.com/forum/user/38576-melba23/ Melba23] '''</blockquote> =====
[[#top | ReturnToContents]]
 
== Disable Specific Column Headers ==
 
{{Snippet Header
| AuthorURL = 38576-melba23
| AuthorName = Melba23
}}


<syntaxhighlight lang="autoit">
<syntaxhighlight lang="autoit">
Line 250: Line 339:


Func _Main()
Func _Main()
    Local Const $hGUI = GUICreate("ListView Fix Column Width", 400, 300)
    Local Const $hListView = GUICtrlCreateListView("Column 0|Column 1|Column 2|Column 3", 2, 2, 394, 268)


    Local $hGUI = GUICreate("ListView Fix Column Width", 400, 300)
     GUISetState(@SW_SHOWNORMAL)
    Local $hListView = GUICtrlCreateListView("Column 0|Column 1|Column 2|Column 3", 2, 2, 394, 268)
     GUISetState()


     ; Prevent resizing of column 1
     ; Prevent resizing of column 1
Line 263: Line 353:
     Do
     Do
     Until GUIGetMsg() = $GUI_EVENT_CLOSE
     Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc  ;==>_Main
EndFunc  ;==>_Main


Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
     #forceref $hWnd, $iMsg, $wParam
     #forceref $hWnd, $iMsg, $wParam


     ; Get details of message
     ; Get details of message
     Local $tNMHEADER = DllStructCreate($tagNMHEADER, $lParam)
     Local Const $tNMHEADER = DllStructCreate($tagNMHEADER, $lParam)
 
     ; Look for header resize code
     ; Look for header resize code
     Local $iCode = DllStructGetData($tNMHEADER, "Code")
     Local Const $iCode = DllStructGetData($tNMHEADER, "Code")
 
     Switch $iCode
     Switch $iCode
         Case $HDN_BEGINTRACKW
         Case $HDN_BEGINTRACKW
             ; Now get column being resized
             ; Now get column being resized
             Local $iCol = DllStructGetData($tNMHEADER, "Item")
             Local $iCol = DllStructGetData($tNMHEADER, "Item")
             If $iCol = $iFix_Col Then
             If $iCol = $iFix_Col Then
                 ; Prevent resizing
                 ; Prevent resizing
Line 286: Line 377:
             EndIf
             EndIf
     EndSwitch
     EndSwitch
EndFunc  ;==>_WM_NOTIFY
EndFunc  ;==>_WM_NOTIFY
</syntaxhighlight>
</syntaxhighlight>


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _Flash() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====
[[#top | ReturnToContents]]
 
== _Flash ==
 
{{Snippet Header
| AuthorURL = 35302-guinness
| AuthorName = guinness
}}


<syntaxhighlight lang="autoit">
<syntaxhighlight lang="autoit">
Line 301: Line 398:


Func Example()
Func Example()
     Local $bGreen = 0x00FF00
     Local Const $bGreen = 0x00FF00
     Local $hGUI = GUICreate('')
 
     GUISetState(@SW_SHOW, $hGUI)
     Local Const $hGUI = GUICreate('')
 
     GUISetState(@SW_SHOWNORMAL, $hGUI)


     If MsgBox(4 + 4096, '', 'The following example contains flashing images, if you''re sensitive to such things then please select "No".' & @CRLF & @CRLF & _
     If MsgBox(4 + 4096, '', 'The following example contains flashing images.  If you are sensitive to such things then please select "No".' & @CRLF & @CRLF & _
             'Do you want to continue?') = 7 Then
             'Do you want to continue?') = 7 Then
         Return 0
         Return 0
     EndIf
     EndIf
     ; Change the background color of the GUI to a specified color and then back to the default grey.
     ; Change the background color of the GUI to a specified color and then back to the default grey.
     For $i = 1 To 2
     For $i = 1 To 2
Line 314: Line 414:
         Sleep(100)
         Sleep(100)
     Next
     Next
     ; Wait for 1 second to show the background color is changed to the default grey.
     ; Wait for 1 second to show the background color is changed to the default grey.
     Sleep(1000)
     Sleep(1000)
     GUIDelete($hGUI)
     GUIDelete($hGUI)
EndFunc  ;==>Example
EndFunc  ;==>Example


Func _Flash($hWnd, $bColor)
Func _Flash(Const $hWnd, Const $bColor)
     For $A = 1 To 2
     For $A = 1 To 2
         If Mod($A, 2) Then ; Odd.
         If Mod($A, 2) Then ; Odd.
Line 326: Line 428:
             GUISetBkColor(_WinAPI_GetSysColor($COLOR_MENU), $hWnd)
             GUISetBkColor(_WinAPI_GetSysColor($COLOR_MENU), $hWnd)
         EndIf
         EndIf
         Sleep(100)
         Sleep(100)
     Next
     Next
EndFunc  ;==>_Fla
EndFunc  ;==>_Flash
</syntaxhighlight>
</syntaxhighlight>


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' GUI Background Changer ~ Author - ReaperX '''</blockquote> =====
[[#top | ReturnToContents]]
 
== GUI Background Changer ==
 
{{Snippet Header
| AuthorURL = 69506-reaperx
| AuthorName = ReaperX
}}


<syntaxhighlight lang="autoit">
<syntaxhighlight lang="autoit">
#include <GUIConstants.au3>
#include <GUIConstants.au3>
#include <Misc.au3>
#include <Misc.au3>
GUICreate("Choose Color")
 
$button = GUICtrlCreateButton("Choose Color", 150, 150)
Global Const $gui_choose_color = GUICreate("Choose Color")
$iReturnType = 2
 
GUISetState()
Global Const $button = GUICtrlCreateButton("Choose Color", 150, 150)
 
GUISetState(@SW_SHOWNORMAL, $gui_choose_color)
 
Global Const $iReturnType = 2
 
Global $color
 
While 1
While 1
$msg = GUIGetMsg()
Switch GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then Exit
Case $button
Select
Case $msg = $button
$color = _ChooseColor($iReturnType)
$color = _ChooseColor($iReturnType)
GUISetBkColor($color)
GUISetBkColor($color)
EndSelect
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
WEnd


Example 2
Example 2
#include <GUIConstants.au3>
#include <GUIConstants.au3
 
MainGUI()
MainGUI()
Func MainGUI()
Func MainGUI()
GUICreate("ReaperX's Test GUI")
GUICreate("ReaperX's Test GUI")
     $file = GUICtrlCreateMenu("File")
 
    $file_notepad = GUICtrlCreateMenuItem("Open Notepad", $file)
     Local Const $file = GUICtrlCreateMenu("File")
    $file_computer = GUICtrlCreateMenuItem("Open My Computer", $file)
 
    $file_exit = GUICtrlCreateMenuItem("Exit", $file)
Local Const $file_notepad = GUICtrlCreateMenuItem("Open Notepad", $file)
    $actions = GUICtrlCreateMenu("Actions")
 
    $actions_txt_file = GUICtrlCreateMenuItem("Open Text File", $actions)
Local Const $file_computer = GUICtrlCreateMenuItem("Open My Computer", $file)
    $actions_calc = GUICtrlCreateMenuItem("Open Calculator", $actions)
 
    $help = GUICtrlCreateMenu("Help")
Local Const $file_exit = GUICtrlCreateMenuItem("Exit", $file)
    $help_about = GUICtrlCreateMenuItem("About", $help)
 
    $tab_set = GUICtrlCreateTab(110, 100, 135, 150)
Local Const $actions = GUICtrlCreateMenu("Actions")
    $tab_1 = GUICtrlCreateTabItem("Change BG")
 
    $bg_red_radio = GUICtrlCreateRadio("Red", 115, 125)
Local Const $actions_txt_file = GUICtrlCreateMenuItem("Open Text File", $actions)
    $bg_green_radio = GUICtrlCreateRadio("Green", 115, 145)
 
    $bg_yellow_radio = GUICtrlCreateRadio("Yellow", 115, 165)
Local Const $actions_calc = GUICtrlCreateMenuItem("Open Calculator", $actions)
    $tab_2 = GUICtrlCreateTabItem("AutoIt Info")
 
     GUISetState()
Local Const $help = GUICtrlCreateMenu("Help")
 
Local Const $help_about = GUICtrlCreateMenuItem("About", $help)
 
Local Const $tab_set = GUICtrlCreateTab(110, 100, 135, 150)
 
Local Const $tab_1 = GUICtrlCreateTabItem("Change BG")
 
Local Const $bg_red_radio = GUICtrlCreateRadio("Red", 115, 125)
 
Local Const $bg_green_radio = GUICtrlCreateRadio("Green", 115, 145)
 
Local Const $bg_yellow_radio = GUICtrlCreateRadio("Yellow", 115, 165)
 
Local Const $tab_2 = GUICtrlCreateTabItem("AutoIt Info")
 
     GUISetState(@SW_SHOWNORMAL)
 
     While 1
     While 1
        $msg = GUIGetMsg()
Switch GUIGetMsg()
        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Case $GUI_EVENT_CLOSE
        If $msg = $file_notepad Then
ExitLoop
            $file = Run("notepad.exe")
Case $file_notepad
        EndIf
Run("notepad.exe")
        if $msg = $file_computer Then
Case $file_computer
            $file = Run("explorer.exe")
Run("explorer.exe")
        EndIf
Case $file_exit
        If $msg = $file_exit Then
Exit
            Exit
Case $actions_txt_file
        EndIf
Local Const $txt_file_1 = FileOpenDialog("Choose a Text File to Open...", @DesktopDir, "Text Files(*.txt)")
        If $msg = $actions_txt_file Then
FileOpen($txt_file_1)
            $txt_file_1 = FileOpenDialog("Choose a Text File to Open...", @DesktopDir, "Text Files(*.txt)")
Case $actions_calc
            FileOpen($txt_file_1)
Run("calc.exe")
        EndIf
Case $help_about
        If $msg = $actions_calc Then
MsgBox(0, "About", "This Test GUI Was Created by ReaperX")
            Run("calc.exe")
Case $bg_red_radio
        EndIf
GUISetBkColor(0xED1C24)
        If $msg = $help_about Then
Case $bg_green_radio
            $help = MsgBox(0, "About", "This Test GUI Was Created by ReaperX")
GUISetBkColor(0x22B14C)
        EndIf
Case $bg_yellow_radio
        Select
GUISetBkColor(0xFFF200)
        Case $msg = $bg_red_radio
EndSwitch
            GUISetBkColor(0xED1C24)
        Case $msg = $bg_green_radio
            GUISetBkColor(0x22B14C)
        Case $msg = $bg_yellow_radio
            GUISetBkColor(0xFFF200)
            EndSelect
     WEnd
     WEnd
EndFunc
EndFunc
</syntaxhighlight>
</syntaxhighlight>


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">'''  GUICtrlGetID() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====
[[#top | ReturnToContents]]
 
== GUICtrlGetID ==
 
{{Snippet Header
| AuthorURL = 35302-guinness
| AuthorName = guinness
}}


<syntaxhighlight lang="autoit">
<syntaxhighlight lang="autoit">
Line 411: Line 548:


Func Example()
Func Example()
     Local $hGUI = GUICreate('')
     Local Const $hGUI = GUICreate('')
     Local $iLabel = GUICtrlCreateLabel('', 0, 0, 500, 500)
 
     Local $iComboBox = GUICtrlCreateCombo('', 0, 0, 500, 500)
     Local Const $iLabel = GUICtrlCreateLabel('', 0, 0, 500, 500)
     GUISetState(@SW_SHOW, $hGUI)
 
     Local Const $iComboBox = GUICtrlCreateCombo('', 0, 0, 500, 500)
 
     GUISetState(@SW_SHOWNORMAL, $hGUI)


     MsgBox(4096, '', 'AutoIt Label ID: ' & $iLabel & @CRLF & _
     MsgBox(4096, '', _
             'AutoIt Label ID From Handle: ' & GUICtrlGetID(GUICtrlGetHandle($iLabel)) & @CRLF & _
        'AutoIt Label ID: '               & $iLabel & @CRLF & _
             'AutoIt ComboBox ID: ' & $iComboBox & @CRLF & _
             'AutoIt Label ID From Handle: '   & GUICtrlGetID(GUICtrlGetHandle($iLabel)) & @CRLF & _
             'AutoIt ComboBox ID: '             & $iComboBox & @CRLF & _
             'AutoIt ComboBox ID From Handle: ' & GUICtrlGetID(GUICtrlGetHandle($iComboBox)) & @CRLF)
             'AutoIt ComboBox ID From Handle: ' & GUICtrlGetID(GUICtrlGetHandle($iComboBox)) & @CRLF)


Line 425: Line 566:


; Retrieve the control id of an AutoIt native control using the handle returned by GUICtrlGetHandle.
; Retrieve the control id of an AutoIt native control using the handle returned by GUICtrlGetHandle.
Func GUICtrlGetID($hWnd)
Func GUICtrlGetID(Const $hWnd)
     Local $aResult = DllCall('user32.dll', 'int', 'GetDlgCtrlID', 'hwnd', $hWnd) ; _WinAPI_GetDlgItem in WinAPI.au3.
     Local Const $aResult = DllCall('user32.dll', 'int', 'GetDlgCtrlID', 'hwnd', $hWnd) ; _WinAPI_GetDlgItem in WinAPI.au3.
    If @error Then
 
If @error Then
         Return SetError(@error, @extended, 0)
         Return SetError(@error, @extended, 0)
     EndIf
     EndIf
     Return $aResult[0]
     Return $aResult[0]
EndFunc  ;==>GUICtrlGetID
EndFunc  ;==>GUICtrlGetID
</syntaxhighlight>
</syntaxhighlight>


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">'''  _GUICtrlIpAddress_DisableField() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====
[[#top | ReturnToContents]]
 
== _GUICtrlIpAddress_DisableField ==
 
{{Snippet Header
| AuthorURL = 35302-guinness
| AuthorName = guinness
}}


<syntaxhighlight lang="autoit">
<syntaxhighlight lang="autoit">
Line 464: Line 614:
</syntaxhighlight>
</syntaxhighlight>


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' GUI With Scrollable TabItem ~ Author - [http://www.autoitscript.com/forum/user/46198-autobert/ AutoBert] '''</blockquote> =====
[[#top | ReturnToContents]]
 
== GUI With Scrollable TabItem ==
 
{{Snippet Header
| AuthorURL = 46198-autobert
| AuthorName = AutoBert
}}


<syntaxhighlight lang="autoit">
<syntaxhighlight lang="autoit">
Line 470: Line 627:


#include <GUIConstantsEx.au3>
#include <GUIConstantsEx.au3>
#include <GuiTab.au3>
#include <GuiScrollBars.au3>
#include <ScrollBarConstants.au3>
#include <ScrollBarConstants.au3>
#include <GuiScrollBars.au3>
#include <WindowsConstants.au3>
#include <WindowsConstants.au3>
#include <GuiTab.au3>
$hGui = GUICreate("Gui with scrollable TabItem ", 633, 350, 190, 220)
GUISetBkColor(0xFFFFFF)
$idTab = GUICtrlCreateTab(10, 10, 613, 300)
$idTab0 = GUICtrlCreateTabItem("tab0")
$hChild = GUICreate("Scrollbereich", 588, 255, 26, 45, $WS_POPUP, $WS_EX_MDICHILD, $hGui)
$x = 6 ; +22
$y = 8
Local $aInputs[15]
For $i = 0 To 14
$aInputs[$i] = GUICtrlCreateInput('', $x, $y, 21, 20)
$x += 22
$y += 21
Next
_GUIScrollBars_Init($hChild, -1)
_GUIScrollBars_ShowScrollBar($hChild, $SB_HORZ, False) ; horizontale Scrollbar verstecken
_GUIScrollBars_SetScrollRange($hChild, $SB_VERT, 3, 30)
GUISetState(@SW_HIDE, $hChild)
GUISwitch($hGui)
$idTab1 = GUICtrlCreateTabItem("tab----1")
GUICtrlCreateLabel("label1", 30, 80, 50, 20)
$idTab1combo = GUICtrlCreateCombo("", 20, 50, 60, 120)
GUICtrlSetData(-1, "Trids|CyberSlug|Larry|Jon|Tylo", "Jon"); default Jon
$idTab1OK = GUICtrlCreateButton("OK1", 80, 50, 50, 20)
$idTab2 = GUICtrlCreateTabItem("tab2")
GUICtrlSetState(-1, $Gui_SHOW); will be display first
GUICtrlCreateLabel("label2", 30, 80, 50, 20)
$idTab2OK = GUICtrlCreateButton("OK2", 140, 50, 50)
GUICtrlCreateTabItem(""); end tabitem definition
$idBtnBack = GUICtrlCreateButton("&Zurueck", 72, 320, 100, 25)
$idBtnCancel = GUICtrlCreateButton("&Beenden", 264, 320, 100, 25)
$idBtnContinue = GUICtrlCreateButton("&Weiter", 448, 320, 100, 25)
GUISetState()
GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL")


While 1
_Example()
$nMsg = GUIGetMsg()
 
Switch $nMsg
Func _Example()
Case $GUI_EVENT_CLOSE
Local $hGui = GUICreate("Gui with scrollable TabItem ", 633, 350, 190, 220)
Exit
GUISetBkColor(0xFFFFFF)
Case $idTab
Local $idTab = GUICtrlCreateTab(10, 10, 613, 300)
$iTab = _GUICtrlTab_GetCurSel($idTab)
Local $idTab0 = GUICtrlCreateTabItem("tab0")
Switch $iTab
#forceref $idTab0
Case 0
Local $hChild = GUICreate("Scroll area", 588, 255, 26, 45, $WS_POPUP, $WS_EX_MDICHILD, $hGui)
GUISetState(@SW_SHOW, $hChild)
Local $x = 6 ; +22
Case 1
Local $y = 8
GUISetState(@SW_HIDE, $hChild)
Local $aInputs[15]
EndSwitch
#forceref $aInputs
EndSwitch
For $i = 0 To 14
WEnd
$aInputs[$i] = GUICtrlCreateInput('', $x, $y, 21, 20)
$x += 22
$y += 21
Next
_GUIScrollBars_Init($hChild, -1)
_GUIScrollBars_ShowScrollBar($hChild, $SB_HORZ, False) ; horizontale Scrollbar verstecken
_GUIScrollBars_SetScrollRange($hChild, $SB_VERT, 3, 30)
GUISetState(@SW_HIDE, $hChild)
GUISwitch($hGui)
Local $idTab1 = GUICtrlCreateTabItem("tab----1")
#forceref $idTab1
GUICtrlCreateLabel("label1", 30, 80, 50, 20)
Local $idTab1combo = GUICtrlCreateCombo("", 20, 50, 60, 120)
#forceref $idTab1combo
GUICtrlSetData(-1, "Trids|CyberSlug|Larry|Jon|Tylo", "Jon") ; default Jon
Local $idTab1OK = GUICtrlCreateButton("OK1", 80, 50, 50, 20)
#forceref $idTab1OK
Local $idTab2 = GUICtrlCreateTabItem("tab2")
#forceref $idTab2
GUICtrlSetState(-1, $Gui_SHOW) ; will be display first
GUICtrlCreateLabel("label2", 30, 80, 50, 20)
Local $idTab2OK = GUICtrlCreateButton("OK2", 140, 50, 50)
#forceref $idTab2OK
GUICtrlCreateTabItem("") ; end tabitem definition
Local $idBtnBack = GUICtrlCreateButton("&Back", 72, 320, 100, 25)
#forceref $idBtnBack
Local $idBtnCancel = GUICtrlCreateButton("&Cancel", 264, 320, 100, 25)
#forceref $idBtnCancel
Local $idBtnContinue = GUICtrlCreateButton("&Continue", 448, 320, 100, 25)
#forceref $idBtnContinue
GUISetState()
GUIRegisterMsg($WM_VSCROLL, WM_VSCROLL)
 
Local $nMsg, $iTab
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $idTab
$iTab = _GUICtrlTab_GetCurSel($idTab)
Switch $iTab
Case 0
GUISetState(@SW_SHOW, $hChild)
Case 1
GUISetState(@SW_HIDE, $hChild)
EndSwitch
EndSwitch
WEnd
EndFunc  ;==>_Example
 
Func WM_VSCROLL($hWnd, $Msg, $wParam, $lParam)
Func WM_VSCROLL($hWnd, $Msg, $wParam, $lParam)
#forceref $Msg, $wParam, $lParam
#forceref $Msg, $lParam
Local $nScrollCode = BitAND($wParam, 0x0000FFFF)
Local $index = -1, $yChar
Local $index = -1, $yChar, $yPos
For $x = 0 To UBound($__g_aSB_WindowInfo) - 1 ; from GuiScrollBars.au3
Local $Min, $Max, $Page, $Pos, $TrackPos
If $__g_aSB_WindowInfo[$x][0] = $hWnd Then
For $x = 0 To UBound($aSB_WindowInfo) - 1
If $aSB_WindowInfo[$x][0] = $hWnd Then
$index = $x
$index = $x
$yChar = $aSB_WindowInfo[$index][3]
$yChar = $__g_aSB_WindowInfo[$index][3]
ExitLoop
ExitLoop
EndIf
EndIf
Line 539: Line 711:
; Get all the vertial scroll bar information
; Get all the vertial scroll bar information
Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_VERT)
Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_VERT)
$Min = DllStructGetData($tSCROLLINFO, "nMin")
Local $Min = DllStructGetData($tSCROLLINFO, "nMin")
$Max = DllStructGetData($tSCROLLINFO, "nMax")
Local $Max = DllStructGetData($tSCROLLINFO, "nMax")
$Page = DllStructGetData($tSCROLLINFO, "nPage")
Local $Page = DllStructGetData($tSCROLLINFO, "nPage")
 
; Save the position for comparison later on
; Save the position for comparison later on
$yPos = DllStructGetData($tSCROLLINFO, "nPos")
Local $yPos = DllStructGetData($tSCROLLINFO, "nPos")
$Pos = $yPos
Local $Pos = $yPos
$TrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos")
Local $TrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos")
 
Local $nScrollCode = BitAND($wParam, 0x0000FFFF)
Switch $nScrollCode
Switch $nScrollCode
Case $SB_TOP ; user clicked the HOME keyboard key
Case $SB_TOP ; user clicked the HOME keyboard key
Line 562: Line 737:
DllStructSetData($tSCROLLINFO, "nPos", $TrackPos)
DllStructSetData($tSCROLLINFO, "nPos", $TrackPos)
EndSwitch
EndSwitch
;~    // Set the position and then retrieve it.  Due to adjustments
 
;~    //  by Windows it may not be the same as the value set.
; Set the position and then retrieve it.  Due to adjustments
; by Windows it may not be the same as the value set.
DllStructSetData($tSCROLLINFO, "fMask", $SIF_POS)
DllStructSetData($tSCROLLINFO, "fMask", $SIF_POS)
_GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
_GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
_GUIScrollBars_GetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
_GUIScrollBars_GetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
;// If the position has changed, scroll the window and update it
 
; If the position has changed, scroll the window and update it
$Pos = DllStructGetData($tSCROLLINFO, "nPos")
$Pos = DllStructGetData($tSCROLLINFO, "nPos")
If ($Pos <> $yPos) Then
If ($Pos <> $yPos) Then
Line 577: Line 754:
</syntaxhighlight>
</syntaxhighlight>


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _IsAutoItGUI() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====
[[#top | ReturnToContents]]
 
== _IsAutoItGUI ==
 
{{Snippet Header
| AuthorURL = 35302-guinness
| AuthorName = guinness
}}
 
<syntaxhighlight lang="autoit">
<syntaxhighlight lang="autoit">
#include <WinAPI.au3>
#include <WinAPI.au3>
Line 585: Line 770:
Func Example()
Func Example()
     Local $hGUI = GUICreate('')
     Local $hGUI = GUICreate('')
     GUISetState(@SW_SHOW, $hGUI)
     GUISetState(@SW_SHOW, $hGUI)


Line 598: Line 784:
EndFunc  ;==>_IsAutoItGUI
EndFunc  ;==>_IsAutoItGUI
</syntaxhighlight>
</syntaxhighlight>
[[#top|Return To Contents]]


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _IsEnabled() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====
[[#top | ReturnToContents]]
 
== _IsEnabled ==
 
{{Snippet Header
| AuthorURL = 35302-guinness
| AuthorName = guinness
}}


<syntaxhighlight lang="autoit">
<syntaxhighlight lang="autoit">
Line 630: Line 822:
</syntaxhighlight>
</syntaxhighlight>


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _IsTransparent() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====
[[#top | ReturnToContents]]
 
== _IsTransparent ==
 
{{Snippet Header
| AuthorURL = 35302-guinness
| AuthorName = guinness
}}


<syntaxhighlight lang="autoit">
<syntaxhighlight lang="autoit">
Line 656: Line 855:
</syntaxhighlight>
</syntaxhighlight>


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' Limit GUI Resize ~ Author - [http://www.autoitscript.com/forum/user/38576-melba23/ Melba23] '''</blockquote> =====
[[#top | ReturnToContents]]
 
== Limit GUI Resize ==
 
{{Snippet Header
| AuthorURL = 38576-melba23
| AuthorName = Melba23
}}


<syntaxhighlight lang="autoit">
<syntaxhighlight lang="autoit">
Line 688: Line 894:
</syntaxhighlight>
</syntaxhighlight>


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' Mixed Colored List View ~ Author - [http://www.autoitscript.com/forum/user/23675-siao/ Siao] '''</blockquote> =====
[[#top | ReturnToContents]]
 
== Mixed Colored List View ==
 
{{Snippet Header
| AuthorURL = 23675-siao
| AuthorName = Siao
}}


<syntaxhighlight lang="autoit">
<syntaxhighlight lang="autoit">
Line 793: Line 1,006:
                             Else
                             Else
                                 DllStructSetData($tCustDraw, 'clrTextBk', $iColor1)
                                 DllStructSetData($tCustDraw, 'clrTextBk', $iColor1)
                             EndIf                    
                             EndIf
                     EndSwitch
                     EndSwitch
                     Return $CDRF_NEWFONT
                     Return $CDRF_NEWFONT
Line 806: Line 1,019:
</syntaxhighlight>
</syntaxhighlight>


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' Move Message Box ~ Author - [http://www.autoitscript.com/forum/user/423-herewasplato/ herewasplato] '''</blockquote> =====
[[#top | ReturnToContents]]
 
== Move Message Box ==
 
{{Snippet Header
| AuthorURL = 423-herewasplato
| AuthorName = herewasplato
}}


<syntaxhighlight lang="autoit">
<syntaxhighlight lang="autoit">
Line 833: Line 1,053:
</syntaxhighlight>
</syntaxhighlight>


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' Search In A Listview ~ Author - [http://www.autoitscript.com/forum/user/7108-xenobiologist/ Xenobiologist] '''</blockquote> =====
[[#top | ReturnToContents]]
 
== Search In A Listview ==
 
{{Snippet Header
| AuthorURL = 7108-xenobiologist
| AuthorName = Xenobiologist
}}


<syntaxhighlight lang="autoit">
<syntaxhighlight lang="autoit">
Line 879: Line 1,106:
</syntaxhighlight>
</syntaxhighlight>


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _SetWinTitle() ~ Author - [http://www.autoitscript.com/forum/user/52-geosoft/ GEOSoft] '''</blockquote> =====
[[#top | ReturnToContents]]
 
== _SetWinTitle ==
 
{{Snippet Header
| AuthorURL = 52-geosoft
| AuthorName = GEOSoft
}}


<syntaxhighlight lang="autoit">
<syntaxhighlight lang="autoit">
Line 905: Line 1,139:
</syntaxhighlight>
</syntaxhighlight>


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' Small Cue Banner ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness], Idea by - [http://www.autoitscript.com/forum/user/70983-autolaser/ Autolaser] '''</blockquote> =====
[[#top | ReturnToContents]]
 
== Small Cue Banner ==
 
{{Snippet Header
| AuthorURL = 35302-guinness
| AuthorName = guinness
| Desc = Idea by: [http://www.autoitscript.com/forum/user/70983-autolaser/ Autolaser]
}}


<syntaxhighlight lang="autoit">
<syntaxhighlight lang="autoit">
#include <GUIConstantsEx.au3>
#include <GuiEdit.au3>
#include <GuiEdit.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>


Example()
Example()
Line 928: Line 1,171:
GUISetState(@SW_SHOW, $hGUI)
GUISetState(@SW_SHOW, $hGUI)


MsgBox(4096, "", _GUICtrlEdit_GetCueBanner($iPassword))
MsgBox($MB_SYSTEMMODAL, "", _GUICtrlEdit_GetCueBanner($iPassword))


While 1
While 1
Line 937: Line 1,180:
EndSwitch
EndSwitch
WEnd
WEnd
GUIDelete($hGUI)
GUIDelete($hGUI)
EndFunc  ;==>Example
EndFunc  ;==>Example


Func _GUICtrlEdit_GetCueBanner($hWnd)
Func _GUICtrlEdit_GetCueBanner($hWnd)
If $Debug_Ed Then __UDF_ValidateClassName($hWnd, $__EDITCONSTANT_ClassName)
If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)


Line 950: Line 1,193:


Func _GUICtrlEdit_SetCueBanner($hWnd, $sText)
Func _GUICtrlEdit_SetCueBanner($hWnd, $sText)
If $Debug_Ed Then __UDF_ValidateClassName($hWnd, $__EDITCONSTANT_ClassName)
If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)


Line 957: Line 1,199:
Return _SendMessage($hWnd, $EM_SETCUEBANNER, False, $tText, 0, "wparam", "struct*") = 1
Return _SendMessage($hWnd, $EM_SETCUEBANNER, False, $tText, 0, "wparam", "struct*") = 1
EndFunc  ;==>_GUICtrlEdit_SetCueBanner
EndFunc  ;==>_GUICtrlEdit_SetCueBanner
</syntaxhighlight>


</syntaxhighlight>
[[#top | ReturnToContents]]
 
== Snapped Window ==


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _Snapped Window() ~ Author - [http://www.autoitscript.com/forum/user/126-lazycat/ Lazycat] '''</blockquote> =====
{{Snippet Header
| AuthorURL = 126-lazycat
| AuthorName = Lazycat
| AuthorURL2 = 4574-argumentum
| AuthorName2 = argumentum ( multi-monitor mod. )
}}


<syntaxhighlight lang="autoit">
<syntaxhighlight lang="autoit">
#include <AutoItConstants.au3>
#include <GUIConstants.au3>
#include <GUIConstants.au3>
#include <WinAPIMisc.au3>
#include <WinAPIGdi.au3>


Global Const $WM_WINDOWPOSCHANGING = 0x0046
Global $nGap = 30 ; 30 pixels for "dramatic effect", 10 pixels should be good for the "magnetic pull"
Global Const $SPI_GETWORKAREA = 0x30
Global $nEdge = BitOR(1, 2, 4, 8) ; Left, Top, Right, Bottom
Global $nGap = 20, $nEdge = BitOR(1, 2, 4, 8); Left, Top, Right, Bottom
Global $nEdgeBorderWidth[4] = [0, 0, 0, 0] ; Left, Top, Right, Bottom


$hGUI = GUICreate("Snapped Window", 300, 200)
Example()
GUIRegisterMsg($WM_WINDOWPOSCHANGING, "MY_WM_WINDOWPOSCHANGING")
Func Example()
GUISetState()
Local $hGUI = GUICreate("Snapped Window multi-monitor", 500, 200)
Local $bNewStyle = False, $idBtnStyle = GUICtrlCreateButton("Change Style", 50, 50, 200, 25)
GUIRegisterMsg($WM_WINDOWPOSCHANGING, "MY_WM_WINDOWPOSCHANGING")
GUISetState()
 
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
GUIDelete()
ExitLoop
 
Case $GUI_EVENT_MAXIMIZE, $GUI_EVENT_RESTORE ; should not change to this style while maximized
GUICtrlSetState($idBtnStyle, (BitAND(WinGetState($hGUI), $WIN_STATE_MAXIMIZED) ? $GUI_DISABLE : $GUI_ENABLE))
 
Case $idBtnStyle
$bNewStyle = Not $bNewStyle
If $bNewStyle Then
GUISetStyle(BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_TABSTOP))
Dim $nEdgeBorderWidth[4] = [-7, 0, 7, 7] ; adjusting for Windows 10 border scheme
Else
GUISetStyle($GUI_SS_DEFAULT_GUI)
Dim $nEdgeBorderWidth[4] = [0, 0, 0, 0]
EndIf
GUICtrlSetData($idBtnStyle, ($bNewStyle ? 'Undo Style' : 'Change Style'))
GUIStyleRefresh($hGUI)
 
EndSwitch
WEnd
EndFunc  ;==>Example
 
Func GUIStyleRefresh($hWnd)
Local $aWinPos = WinGetPos($hWnd)
If @error Then Return SetError(@error, @extended, @error)
WinMove($hWnd, "", $aWinPos[0], $aWinPos[1], $aWinPos[2] - 1, $aWinPos[3] - 1)
WinMove($hWnd, "", $aWinPos[0], $aWinPos[1], $aWinPos[2], $aWinPos[3])
EndFunc  ;==>GUIStyleRefresh
 
Func MY_WM_WINDOWPOSCHANGING($hWnd, $iMsg, $wParam, $lParam)
#forceref $hWnd, $iMsg, $wParam
; original code at https://www.autoitscript.com/forum/topic/24342-form-snap/
 
; The Static declaration speeds up the func. ( not much, nanoseconds )
Local Static $stWinPos, $tPos, $hMonitor, $aData, $nLeft, $nTop, $nRight, $nBottom, $hTimer = 0
 
If TimerDiff($hTimer) > 1000 Then
$hTimer = TimerInit()
$tPos = _WinAPI_GetMousePos()                                  ;  These func are very time consuming and
If Not @error Then $hMonitor = _WinAPI_MonitorFromPoint($tPos) ;  the user is very unlikely to move the
If Not @error Then $aData = _WinAPI_GetMonitorInfo($hMonitor)  ;  mouse into position on another monitor
If @error Then Return $GUI_RUNDEFMSG                          ;  in less than a second.
EndIf
 
; https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-windowpos?redirectedfrom=MSDN
$stWinPos = DllStructCreate("hwnd hwnd;hwnd hwndInsertAfter;int x;int y;int cx;int cy;uint flags", $lParam) ; $tagWINDOWPOS
$nLeft    = DllStructGetData($aData[1], 1)
$nTop    = DllStructGetData($aData[1], 2)
$nRight  = DllStructGetData($aData[1], 3) - $stWinPos.cx
$nBottom  = DllStructGetData($aData[1], 4) - $stWinPos.cy


While 1
If BitAND($nEdge, 1) And Abs($nLeft  - $stWinPos.x) <= $nGap Then $stWinPos.x = $nLeft  + $nEdgeBorderWidth[0]
    $GUIMsg = GUIGetMsg()
If BitAND($nEdge, 4) And Abs($nRight  - $stWinPos.x) <= $nGap Then $stWinPos.x = $nRight  + $nEdgeBorderWidth[2]
   
If BitAND($nEdge, 8) And Abs($nBottom - $stWinPos.y) <= $nGap Then $stWinPos.y = $nBottom + $nEdgeBorderWidth[3]
    Switch $GUIMsg
If BitAND($nEdge, 2) And Abs($nTop    - $stWinPos.y) <= $nGap Then $stWinPos.y = $nTop    + $nEdgeBorderWidth[1]
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd


Func MY_WM_WINDOWPOSCHANGING($hWnd, $Msg, $wParam, $lParam)
Return $GUI_RUNDEFMSG
#cs
EndFunc  ;==>MY_WM_WINDOWPOSCHANGING
    HWND hwnd;
    HWND hwndInsertAfter;
    int x;
    int y;
    int cx;
    int cy;
    UINT flags;
#ce
    Local $stRect = DllStructCreate("int;int;int;int")
    Local $stWinPos = DllStructCreate("uint;uint;int;int;int;int;uint", $lParam)
    DllCall("User32.dll", "int", "SystemParametersInfo", "int", $SPI_GETWORKAREA, "int", 0, "ptr", DllStructGetPtr($stRect), "int", 0)
    Local $nLeft  = DllStructGetData($stRect, 1)
    Local $nTop = DllStructGetData($stRect, 2)
    Local $nRight  = DllStructGetData($stRect, 3) - DllStructGetData($stWinPos, 5)
    Local $nBottom = DllStructGetData($stRect, 4) - DllStructGetData($stWinPos, 6)
    If BitAND($nEdge, 1) and Abs($nLeft  - DllStructGetData($stWinPos, 3)) <= $nGap Then DllStructSetData($stWinPos, 3, $nLeft)
    If BitAND($nEdge, 2) and Abs($nTop  - DllStructGetData($stWinPos, 4)) <= $nGap Then DllStructSetData($stWinPos, 4, $nTop)
    If BitAND($nEdge, 4) and Abs($nRight  - DllStructGetData($stWinPos, 3)) <= $nGap Then DllStructSetData($stWinPos, 3, $nRight)
    If BitAND($nEdge, 8) and Abs($nBottom - DllStructGetData($stWinPos, 4)) <= $nGap Then DllStructSetData($stWinPos, 4, $nBottom)
    Return 0
EndFunc
</syntaxhighlight>
</syntaxhighlight>


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' GUI Snap To Corners ~ Author - [http://www.autoitscript.com/forum/user/126-lazycat/ Lazycat] '''</blockquote> =====
[[#top | ReturnToContents]]
 
== GUI Snap To Corners ==
 
{{Snippet Header
| AuthorURL = 126-lazycat
| AuthorName = Lazycat
}}


<syntaxhighlight lang="autoit">
<syntaxhighlight lang="autoit">
Line 1,014: Line 1,306:
#include <GUIConstants.au3>
#include <GUIConstants.au3>


Global Const $WM_WINDOWPOSCHANGING = 0x0046
Global $nGap = 20
Global $nGap = 20
Global $ahGUI[3]
Global $ahGUI[3]
Line 1,053: Line 1,344:
</syntaxhighlight>
</syntaxhighlight>


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' TAB On TAB Resize ~ Authors - [http://www.autoitscript.com/forum/user/52-geosoft/ GEOSoft] ~ [http://www.autoitscript.com/forum/user/3602-martin/ martin] ~ [http://www.autoitscript.com/forum/user/5169-refran/ ReFran] '''</blockquote> =====
[[#top | ReturnToContents]]
 
== TAB On TAB Resize ==
 
{{Snippet Header
| AuthorURL = 52-geosoft
| AuthorName = GEOSoft
| AuthorURL2 = 3602-martin
| AuthorName2 = martin
| AuthorURL3 = 5169-refran
| AuthorName3 = ReFran
}}


<syntaxhighlight lang="autoit">
<syntaxhighlight lang="autoit">
Line 1,121: Line 1,423:
     $tabItemLast = $tabItem
     $tabItemLast = $tabItem
EndFunc  ;==>TabSwitch
EndFunc  ;==>TabSwitch


Func WM_SIZE($hWnd, $iMsg, $iWParam, $iLParam)
Func WM_SIZE($hWnd, $iMsg, $iWParam, $iLParam)
Line 1,134: Line 1,435:
</syntaxhighlight>
</syntaxhighlight>


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _Toggle_CheckOrUnCheck() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====
[[#top | ReturnToContents]]
 
== _Toggle_CheckOrUnCheck ==
 
{{Snippet Header
| AuthorURL = 35302-guinness
| AuthorName = guinness
}}


<syntaxhighlight lang="autoit">
<syntaxhighlight lang="autoit">
Line 1,171: Line 1,479:
</syntaxhighlight>
</syntaxhighlight>


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _Toggle_DropOrNoDrop() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====
[[#top | ReturnToContents]]
 
== _Toggle_DropOrNoDrop ==
 
{{Snippet Header
| AuthorURL = 35302-guinness
| AuthorName = guinness
}}


<syntaxhighlight lang="autoit">
<syntaxhighlight lang="autoit">
Line 1,209: Line 1,524:
</syntaxhighlight>
</syntaxhighlight>


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _Toggle_EnableOrDisable() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====
[[#top | ReturnToContents]]
 
== _Toggle_EnableOrDisable ==
 
{{Snippet Header
| AuthorURL = 35302-guinness
| AuthorName = guinness
}}


<syntaxhighlight lang="autoit">
<syntaxhighlight lang="autoit">
Line 1,246: Line 1,568:
</syntaxhighlight>
</syntaxhighlight>


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _Toggle_FocusOrNoFocus() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====
[[#top | ReturnToContents]]
 
== _Toggle_FocusOrNoFocus ==
 
{{Snippet Header
| AuthorURL = 35302-guinness
| AuthorName = guinness
}}


<syntaxhighlight lang="autoit">
<syntaxhighlight lang="autoit">
Line 1,283: Line 1,612:
</syntaxhighlight>
</syntaxhighlight>


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _Toggle_ShowOrHide() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====
[[#top | ReturnToContents]]
 
== _Toggle_ShowOrHide ==
 
{{Snippet Header
| AuthorURL = 35302-guinness
| AuthorName = guinness
}}


<syntaxhighlight lang="autoit">
<syntaxhighlight lang="autoit">
Line 1,320: Line 1,656:
</syntaxhighlight>
</syntaxhighlight>


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' Unmovable Window ~ Author - [http://www.autoitscript.com/forum/user/19384-wemartiansarefriendly/ WeMartiansAreFriendly] '''</blockquote> =====
[[#top | ReturnToContents]]
 
== Unmovable Window ==
 
{{Snippet Header
| AuthorURL = 19384-wemartiansarefriendly
| AuthorName = WeMartiansAreFriendly
}}


<syntaxhighlight lang="autoit">
<syntaxhighlight lang="autoit">
#include <GUIConstants.au3>
#include <GUIConstants.au3>
Global Const $WM_WINDOWPOSCHANGING = 0x0046


Global $nConstXpos = @DesktopWidth/2        ;define the constant x position
Global $nConstXpos = @DesktopWidth/2        ;define the constant x position
Line 1,354: Line 1,695:
</syntaxhighlight>
</syntaxhighlight>


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' Window Drag using GUIRegister ~ Author - [http://www.autoitscript.com/forum/user/20477-mrcreator/ MrCreatoR] '''</blockquote> =====
[[#top | ReturnToContents]]
 
== Window Drag Using GUIRegister ==
 
{{Snippet Header
| AuthorURL = 20477-mrcreator
| AuthorName = MrCreatoR
}}


<syntaxhighlight lang="autoit">
<syntaxhighlight lang="autoit">
Line 1,382: Line 1,730:
</syntaxhighlight>
</syntaxhighlight>


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' WinGetTrans() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====
[[#top | ReturnToContents]]
 
== WinGetTrans ==
 
{{Snippet Header
| AuthorURL = 35302-guinness
| AuthorName = guinness
}}


<syntaxhighlight lang="autoit">
<syntaxhighlight lang="autoit">
Line 1,408: Line 1,763:
</syntaxhighlight>
</syntaxhighlight>


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _WorkinArea() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====
[[#top | ReturnToContents]]
 
== _WorkingArea ==
 
{{Snippet Header
| AuthorURL = 35302-guinness
| AuthorName = guinness
}}
 
<syntaxhighlight lang="autoit">
<syntaxhighlight lang="autoit">
#include <APIConstants.au3>
#include <APIConstants.au3>
Line 1,466: Line 1,829:
EndFunc  ;==>_WorkingArea
EndFunc  ;==>_WorkingArea
</syntaxhighlight>
</syntaxhighlight>
[[#top|Return To Contents]]
 
== Dual Monitor + WorkingArea ==
 
{{Snippet Header
| AuthorURL = 10673-mlipok
| AuthorName = mLipok
}}
 
<syntaxhighlight lang="autoit">
#include <GUIConstants.au3>
#include <WinAPIGdi.au3>
 
_Example()
 
Func _Example()
; taken from HelpFile Example for _WinAPI_EnumDisplayMonitors()
Local $aMonitors_data = _WinAPI_EnumDisplayMonitors()
If @error Then Return SetError(@error, @extended, 0)
 
Local $hMonitor = $aMonitors_data[1][0] ; handle to first Monitor
ConsoleWrite("! " & $hMonitor & @CRLF)
 
Local Enum $MONITOR_X1 = 1, $MONITOR_Y1, $MONITOR_X2, $MONITOR_Y2
 
Local $aMonitorInfo = _WinAPI_GetMonitorInfo($hMonitor)
ConsoleWrite("! Primary=" & $aMonitorInfo[2] & '  MonitorName = ' & $aMonitorInfo[3] & @CRLF)
ConsoleWrite("- X1 = " & DllStructGetData($aMonitorInfo[1], $MONITOR_X1) & @CRLF)
ConsoleWrite("- Y1 = " & DllStructGetData($aMonitorInfo[1], $MONITOR_Y1) & @CRLF)
ConsoleWrite("- X2 = " & DllStructGetData($aMonitorInfo[1], $MONITOR_X2) & @CRLF)
ConsoleWrite("- Y2 = " & DllStructGetData($aMonitorInfo[1], $MONITOR_Y2) & @CRLF)
 
; Create a GUI_1 with various controls.
Local $hGUI_1 = GUICreate("Example 1", _
DllStructGetData($aMonitorInfo[1], $MONITOR_X2)-DllStructGetData($aMonitorInfo[1], $MONITOR_X1), _
DllStructGetData($aMonitorInfo[1], $MONITOR_Y2)-DllStructGetData($aMonitorInfo[1], $MONITOR_Y1), _
DllStructGetData($aMonitorInfo[1], $MONITOR_X1), _
DllStructGetData($aMonitorInfo[1], $MONITOR_Y1) _
)
Local $idOK_1 = GUICtrlCreateButton("OK", 310, 370, 85, 25)
; Display the GUI_1
GUISetState(@SW_SHOW, $hGUI_1)
 
; chceck if there was taken data for second monitor
If UBound($aMonitors_data) = 3 Then
$hMonitor = $aMonitors_data[2][0] ; handle to second Monitor
ConsoleWrite("! " & $hMonitor & @CRLF)
 
$aMonitorInfo = _WinAPI_GetMonitorInfo($hMonitor)
ConsoleWrite("! Primary=" & $aMonitorInfo[2] & '  MonitorName = ' & $aMonitorInfo[3] & @CRLF)
ConsoleWrite("- X1 = " & DllStructGetData($aMonitorInfo[1], $MONITOR_X1) & @CRLF)
ConsoleWrite("- Y1 = " & DllStructGetData($aMonitorInfo[1], $MONITOR_Y1) & @CRLF)
ConsoleWrite("- X2 = " & DllStructGetData($aMonitorInfo[1], $MONITOR_X2) & @CRLF)
ConsoleWrite("- Y2 = " & DllStructGetData($aMonitorInfo[1], $MONITOR_Y2) & @CRLF)
EndIf
 
; Create a GUI_2 with various controls.
Local $hGUI_2 = GUICreate("Example 2", _
DllStructGetData($aMonitorInfo[1], $MONITOR_X2)-DllStructGetData($aMonitorInfo[1], $MONITOR_X1), _
DllStructGetData($aMonitorInfo[1], $MONITOR_Y2)-DllStructGetData($aMonitorInfo[1], $MONITOR_Y1), _
DllStructGetData($aMonitorInfo[1], $MONITOR_X1), _
DllStructGetData($aMonitorInfo[1], $MONITOR_Y1) _
)
Local $idOK_2 = GUICtrlCreateButton("OK", 310, 370, 85, 25)
; Display the GUI_2
GUISetState(@SW_SHOW, $hGUI_2)
 
; Initialize a Local variable for GUIGetMsg($GUI_EVENT_ARRAY)
Local $aMsg = 0
 
; Loop until the user Close both GUI_1 and GUI_2
While IsHWnd($hGUI_1) Or IsHWnd($hGUI_2) ; check if any GUI exist
; Assign to $aMsg the advanced GUI messages.
$aMsg = GUIGetMsg($GUI_EVENT_ARRAY)
Switch $aMsg[1] ; Switch from GUIs
Case $hGUI_1 ; The event comes from the GUI1
Switch $aMsg[0] ; Switch from event ID
Case $GUI_EVENT_CLOSE
GUIDelete($hGUI_1)
Case $idOK_1
MsgBox($MB_SYSTEMMODAL, "", "Ok_1 clicked.")
EndSwitch
Case $hGUI_2  ; The event comes from the GUI2
Switch $aMsg[0] ; Switch from event ID
Case $GUI_EVENT_CLOSE
GUIDelete($hGUI_2)
Case $idOK_2
MsgBox($MB_SYSTEMMODAL, "", "Ok_2 clicked.")
EndSwitch
EndSwitch
WEnd
 
EndFunc  ;==>_Example
</syntaxhighlight>
 
[[#top | ReturnToContents]]

Latest revision as of 21:02, 19 August 2021


Please always credit an author in your script if you use their code. It is only polite.


_AlwaysOnTop

Author: guinness








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

Example()

Func Example()
    Local Const $hGUI = GUICreate("_AlwaysOnTop()", 200, 200, -1, -1)

    Local Const $iControlID = GUICtrlCreateCheckbox("Always On Top", 5, 10, 85, 25, BitOR($BS_CHECKBOX, $BS_AUTOCHECKBOX, $BS_PUSHLIKE, $WS_TABSTOP))

    GUISetState(@SW_SHOWNORMAL, $hGUI)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                Exit
            Case $iControlID
                _AlwaysOnTop($hGUI, $iControlID)
        EndSwitch
    WEnd
EndFunc   ;==>Example

Func _AlwaysOnTop(Const $hHandle, Const $iControlID)
    Local $iState = 0

    If GUICtrlRead($iControlID) = $GUI_CHECKED Then
        $iState = 1
    EndIf

    WinSetOnTop($hHandle, "", $iState)

    Return $iState
EndFunc   ;==>_AlwaysOnTop

ReturnToContents

Animate Display

Author: Raindancer








; Animate Display
; Author Raindancer

Global Const $hwnd = GUICreate("Animate Window", 300, 300)

DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00080000) ; fade-in

GUISetState(@SW_SHOWNORMAL)

DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00090000) ; fade-out
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00040001) ; slide in from left
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00050002) ; slide out to left
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00040002) ; slide in from right
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00050001) ; slide out to right
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00040004) ; slide-in from top
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00050008) ; slide-out to top
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00040008) ; slide-in from bottom
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00050004) ; slide-out to bottom
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00040005) ; diag slide-in from Top-left
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x0005000a) ; diag slide-out to Top-left
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00040006) ; diag slide-in from Top-Right
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00050009) ; diag slide-out to Top-Right
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00040009) ; diag slide-in from Bottom-left
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00050006) ; diag slide-out to Bottom-left
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x0004000a) ; diag slide-in from Bottom-right
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00050005) ; diag slide-out to Bottom-right
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00040010) ; explode
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00050010) ; implode

#define AW_HOR_POSITIVE		0x00000001
#define AW_HOR_NEGATIVE		0x00000002
#define AW_VER_POSITIVE		0x00000004
#define AW_VER_NEGATIVE		0x00000008
#define AW_CENTER			0x00000010
#define AW_HIDE				0x00010000
#define AW_ACTIVATE         0x00020000
#define AW_SLIDE            0x00040000
#define AW_BLEND            0x00080000

ReturnToContents

Center Window on Screen

Author: Valuater

Author: cdkid







; Center Window on Screen

#include <GUIConstantsEx.au3>

Global Const $GUI = GUICreate("Test Window",300 ,300 ,100 ,100)

GUISetState(@SW_SHOWNORMAL)

Sleep(2000)

_Middle($GUI, "Test Window")

While 1
	Switch GUIGetMsg()
		Case $GUI_EVENT_CLOSE
			ExitLoop
	EndSwitch
WEnd

Func _Middle(Const $win, Const $txt)
    Local Const $size = WinGetClientSize($win, $txt)

    Local Const $y = (@DesktopHeight / 2) - ($size[1] / 2)

    Local Const $x = (@DesktopWidth / 2) - ($size[0] / 2)

    Return WinMove($win, $txt, $x, $y)
EndFunc  ;==>_Middle

ReturnToContents

_ChildActivate

Author: MKISH








#include <WinAPI.au3>

_ChildActivate("Main Window Title", "Child Window Title")

; Set focus to Child-Window of a GUI
Func _ChildActivate(Const $appTitle, Const $formName)
    Local Const $hWnd = WinGetHandle($appTitle, $formName)

    Local $array = WinList($appTitle)

	#forceref $array

    WinActive($hWnd)

    Local Const $winarray = _WinAPI_EnumWindows(True, $hWnd)

    Local $title

	For $i = 1 to $winarray[0][0]
        $title = _WinAPI_GetWindowText($winarray[$i][0])

		If ($title == $formName) or ($title == $formName & " *") Then
            _WinAPI_ShowWindow($winarray[$i][0], @SW_MAXIMIZE)
            _WinAPI_ShowWindow($winarray[$i][0], @SW_SHOWNORMAL)
        EndIf
    Next
EndFunc ;>>> _ChildActivate

ReturnToContents

_ControlMove

Author: Melba23








#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>

Global Const $SC_MOVE = 0xF010

Global Const $hGUI = GUICreate("Test", 300, 200)

Globa Const $cLabel = GUICtrlCreateLabel("Move me", 100, 50, 60, 20)

GUICtrlSetBkColor($cLabel, 0x00FF00)

GUISetState(@SW_SHOWNORMAL)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_PRIMARYDOWN
            _ControlMove($cLabel)
    EndSwitch
WEnd

Func _ControlMove(Const $cID)
    Local Const $aCurPos = GUIGetCursorInfo()

    If @error Then Return False

    If $aCurPos[4] = $cID Then
        GUICtrlSendMsg($cID, $WM_SYSCOMMAND, BitOR($SC_MOVE, $HTCAPTION), 0)
    EndIf
EndFunc   ;==>_ControlMove

ReturnToContents

Custom Tabs

Author: MrCreatoR

Author: Kickassjoe







; Custom Tabs - controlled by a label, pic, etc

#include <GUIConstants.au3>

GUICreate("Test")

Global $TabSwitcher[2]

Global Const $TabSwitcher1 = GUICtrlCreateLabel("Tab One", 10, 10,60,20, $SS_SUNKEN +$SS_CENTER+ $SS_CENTERIMAGE)
GUICtrlSetBkColor(-1, 0xf0f0f0)
GUICtrlSetColor(-1, 0x000000)

Global Const $TabSwitcher2 = GUICtrlCreateLabel("Tab Two", 72, 10,60,20, $SS_SUNKEN +$SS_CENTER+ $SS_CENTERIMAGE)
GUICtrlSetBkColor(-1, 0xc0c0c0)
GUICtrlSetColor(-1, 0x000000)

Global Const $tab = GUICtrlCreateTab(10,40, 200, 200) ; can be placed anywhere, doesnt matter, not visible
GUICtrlSetState($tab, $GUI_HIDE)

Global Const $tab1 = GUICtrlCreateTabItem("tab1")

GUICtrlCreateButton("button on tab 1", 10, 70)

Global Const $tab2 = GUICtrlCreateTabItem("tab2")

GUICtrlCreateButton("button on tab 2", 10, 70)

GUISetState(@SW_SHOWNORMAL)

While 1
    Switch GUIGetMsg()
        Case $TabSwitcher1
            If GUICtrlRead($tab, 1) = $tab1 Then ContinueLoop ; To prevent the flickering and second state set.
            GUICtrlSetState($tab1, $GUI_SHOW)
            GUICtrlSetBkColor($TabSwitcher1, 0xf0f0f0)
            GUICtrlSetColor($TabSwitcher1, 0x000000)
            GUICtrlSetBkColor($TabSwitcher2, 0xc0c0c0)
            GUICtrlSetColor($TabSwitcher2, 0x000000)

        Case $TabSwitcher2
            If GUICtrlRead($tab, 1) = $tab2 Then ContinueLoop ; To prevent the flickering and second state set.
            GUICtrlSetState($tab2, $GUI_SHOW)
            GUICtrlSetBkColor($TabSwitcher1, 0xc0c0c0)
            GUICtrlSetColor($TabSwitcher1, 0x000000)
            GUICtrlSetBkColor($TabSwitcher2, 0xf0f0f0)
            GUICtrlSetColor($TabSwitcher2, 0x000000)

        Case $GUI_EVENT_CLOSE
            Exit
        Case Else
    EndSwitch
WEnd

ReturnToContents

Disable All Column Headers

Author: Melba23








#include <GuiConstantsEx.au3>
#include <GuiListView.au3>

_Main()

Func _Main()
    Local $hGUI = GUICreate("ListView Set Column Width", 400, 300)
    Local $hListView = GUICtrlCreateListView("Column 1|Column 2|Column 3|Column 4", 2, 2, 394, 268)
    GUISetState()

    ; Prevent resizing of columns
    ControlDisable($hGUI, "", HWnd(_GUICtrlListView_GetHeader($hListView)))

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc   ;==>_Main

ReturnToContents

Disable Specific Column Headers

Author: Melba23








#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <HeaderConstants.au3>

; The 0-based column to be disabled
Global $iFix_Col

_Main()

Func _Main()
    Local Const $hGUI = GUICreate("ListView Fix Column Width", 400, 300)

    Local Const $hListView = GUICtrlCreateListView("Column 0|Column 1|Column 2|Column 3", 2, 2, 394, 268)

    GUISetState(@SW_SHOWNORMAL)

    ; Prevent resizing of column 1
    $iFix_Col = 1

    GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc   ;==>_Main

Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam

    ; Get details of message
    Local Const $tNMHEADER = DllStructCreate($tagNMHEADER, $lParam)

    ; Look for header resize code
    Local Const $iCode = DllStructGetData($tNMHEADER, "Code")

    Switch $iCode
        Case $HDN_BEGINTRACKW
            ; Now get column being resized
            Local $iCol = DllStructGetData($tNMHEADER, "Item")

            If $iCol = $iFix_Col Then
                ; Prevent resizing
                Return True
            Else
                ; Allow resizing
                Return False
            EndIf
    EndSwitch
EndFunc   ;==>_WM_NOTIFY

ReturnToContents

_Flash

Author: guinness








; Change the background color of the GUI to a specified color

#include <WinAPI.au3>
#include <WindowsConstants.au3>

Example()

Func Example()
    Local Const $bGreen = 0x00FF00

    Local Const $hGUI = GUICreate('')

    GUISetState(@SW_SHOWNORMAL, $hGUI)

    If MsgBox(4 + 4096, '', 'The following example contains flashing images.  If you are sensitive to such things then please select "No".' & @CRLF & @CRLF & _
            'Do you want to continue?') = 7 Then
        Return 0
    EndIf

    ; Change the background color of the GUI to a specified color and then back to the default grey.
    For $i = 1 To 2
        _Flash($hGUI, $bGreen)
        Sleep(100)
    Next

    ; Wait for 1 second to show the background color is changed to the default grey.
    Sleep(1000)

    GUIDelete($hGUI)
EndFunc   ;==>Example

Func _Flash(Const $hWnd, Const $bColor)
    For $A = 1 To 2
        If Mod($A, 2) Then ; Odd.
            GUISetBkColor($bColor, $hWnd)
        Else ; Even.
            GUISetBkColor(_WinAPI_GetSysColor($COLOR_MENU), $hWnd)
        EndIf

        Sleep(100)
    Next
EndFunc   ;==>_Flash

ReturnToContents

GUI Background Changer

Author: ReaperX








#include <GUIConstants.au3>
#include <Misc.au3>

Global Const $gui_choose_color = GUICreate("Choose Color")

Global Const $button = GUICtrlCreateButton("Choose Color", 150, 150)

GUISetState(@SW_SHOWNORMAL, $gui_choose_color)

Global Const $iReturnType = 2

Global $color

While 1
	Switch GUIGetMsg()
		Case $button
			$color = _ChooseColor($iReturnType)
			GUISetBkColor($color)
		Case $GUI_EVENT_CLOSE
			Exit
	EndSwitch
WEnd

Example 2
#include <GUIConstants.au3

MainGUI()

Func MainGUI()
	GUICreate("ReaperX's Test GUI")

    Local Const $file = GUICtrlCreateMenu("File")

	Local Const $file_notepad = GUICtrlCreateMenuItem("Open Notepad", $file)

	Local Const $file_computer = GUICtrlCreateMenuItem("Open My Computer", $file)

	Local Const $file_exit = GUICtrlCreateMenuItem("Exit", $file)

	Local Const $actions = GUICtrlCreateMenu("Actions")

	Local Const $actions_txt_file = GUICtrlCreateMenuItem("Open Text File", $actions)

	Local Const $actions_calc = GUICtrlCreateMenuItem("Open Calculator", $actions)

	Local Const $help = GUICtrlCreateMenu("Help")

	Local Const $help_about = GUICtrlCreateMenuItem("About", $help)

	Local Const $tab_set = GUICtrlCreateTab(110, 100, 135, 150)

	Local Const $tab_1 = GUICtrlCreateTabItem("Change BG")

	Local Const $bg_red_radio = GUICtrlCreateRadio("Red", 115, 125)

	Local Const $bg_green_radio = GUICtrlCreateRadio("Green", 115, 145)

	Local Const $bg_yellow_radio = GUICtrlCreateRadio("Yellow", 115, 165)

	Local Const $tab_2 = GUICtrlCreateTabItem("AutoIt Info")

    GUISetState(@SW_SHOWNORMAL)

    While 1
		Switch GUIGetMsg()
			Case $GUI_EVENT_CLOSE
				ExitLoop
			Case $file_notepad
				Run("notepad.exe")
			Case $file_computer
				Run("explorer.exe")
			Case $file_exit
				Exit
			Case $actions_txt_file
				Local Const $txt_file_1 = FileOpenDialog("Choose a Text File to Open...", @DesktopDir, "Text Files(*.txt)")
				FileOpen($txt_file_1)
			Case $actions_calc
				Run("calc.exe")
			Case $help_about
				MsgBox(0, "About", "This Test GUI Was Created by ReaperX")
			Case $bg_red_radio
				GUISetBkColor(0xED1C24)
			Case $bg_green_radio
				GUISetBkColor(0x22B14C)
			Case $bg_yellow_radio
				GUISetBkColor(0xFFF200)
		EndSwitch
    WEnd
EndFunc

ReturnToContents

GUICtrlGetID

Author: guinness








Example()

Func Example()
    Local Const $hGUI = GUICreate('')

    Local Const $iLabel = GUICtrlCreateLabel('', 0, 0, 500, 500)

    Local Const $iComboBox = GUICtrlCreateCombo('', 0, 0, 500, 500)

    GUISetState(@SW_SHOWNORMAL, $hGUI)

    MsgBox(4096, '', _
	        'AutoIt Label ID: '                & $iLabel & @CRLF & _
            'AutoIt Label ID From Handle: '    & GUICtrlGetID(GUICtrlGetHandle($iLabel)) & @CRLF & _
            'AutoIt ComboBox ID: '             & $iComboBox & @CRLF & _
            'AutoIt ComboBox ID From Handle: ' & GUICtrlGetID(GUICtrlGetHandle($iComboBox)) & @CRLF)

    Return GUIDelete($hGUI)
EndFunc   ;==>Example

; Retrieve the control id of an AutoIt native control using the handle returned by GUICtrlGetHandle.
Func GUICtrlGetID(Const $hWnd)
    Local Const $aResult = DllCall('user32.dll', 'int', 'GetDlgCtrlID', 'hwnd', $hWnd) ; _WinAPI_GetDlgItem in WinAPI.au3.

	If @error Then
        Return SetError(@error, @extended, 0)
    EndIf

    Return $aResult[0]
EndFunc   ;==>GUICtrlGetID

ReturnToContents

_GUICtrlIpAddress_DisableField

Author: guinness








#include <GUIConstantsEx.au3>
#include <GUIIPAddress.au3>

Example()

Func Example()
    Local $hGUI, $hIPAddress
    $hGUI = GUICreate('IP Address Control Create Example', 400, 300)
    $hIPAddress = _GUICtrlIpAddress_Create($hGUI, 10, 10)
    GUISetState(@SW_SHOW, $hGUI)

    _GUICtrlIpAddress_Set($hIPAddress, '127.0.0.1')
    _GUICtrlIpAddress_DisableField($hIPAddress, 0)
    _GUICtrlIpAddress_DisableField($hIPAddress, 3)

    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    _GUICtrlIpAddress_Destroy($hIPAddress)
EndFunc   ;==>Example

; Disable an octet field. First octet field starts from index 0.
Func _GUICtrlIpAddress_DisableField($hIPAddress, $iField) ; Idea by Rover.
    Local $aField[5] = [4, 3, 2, 1]
    Return ControlDisable($hIPAddress, '', '[CLASSNN:Edit' & $aField[$iField] & ']')
EndFunc   ;==>_GUICtrlIpAddress_DisableField

ReturnToContents

GUI With Scrollable TabItem

Author: AutoBert








; GUI With Scrollable TabItem

#include <GUIConstantsEx.au3>
#include <GuiTab.au3>
#include <GuiScrollBars.au3>
#include <ScrollBarConstants.au3>
#include <WindowsConstants.au3>

_Example()

Func _Example()
	Local $hGui = GUICreate("Gui with scrollable TabItem ", 633, 350, 190, 220)
	GUISetBkColor(0xFFFFFF)
	Local $idTab = GUICtrlCreateTab(10, 10, 613, 300)
	Local $idTab0 = GUICtrlCreateTabItem("tab0")
	#forceref $idTab0
	Local $hChild = GUICreate("Scroll area", 588, 255, 26, 45, $WS_POPUP, $WS_EX_MDICHILD, $hGui)
	Local $x = 6 ; +22
	Local $y = 8
	Local $aInputs[15]
	#forceref $aInputs
	For $i = 0 To 14
		$aInputs[$i] = GUICtrlCreateInput('', $x, $y, 21, 20)
		$x += 22
		$y += 21
	Next
	_GUIScrollBars_Init($hChild, -1)
	_GUIScrollBars_ShowScrollBar($hChild, $SB_HORZ, False) ; horizontale Scrollbar verstecken
	_GUIScrollBars_SetScrollRange($hChild, $SB_VERT, 3, 30)
	GUISetState(@SW_HIDE, $hChild)
	GUISwitch($hGui)
	Local $idTab1 = GUICtrlCreateTabItem("tab----1")
	#forceref $idTab1
	GUICtrlCreateLabel("label1", 30, 80, 50, 20)
	Local $idTab1combo = GUICtrlCreateCombo("", 20, 50, 60, 120)
	#forceref $idTab1combo
	GUICtrlSetData(-1, "Trids|CyberSlug|Larry|Jon|Tylo", "Jon") ; default Jon
	Local $idTab1OK = GUICtrlCreateButton("OK1", 80, 50, 50, 20)
	#forceref $idTab1OK
	Local $idTab2 = GUICtrlCreateTabItem("tab2")
	#forceref $idTab2
	GUICtrlSetState(-1, $Gui_SHOW) ; will be display first
	GUICtrlCreateLabel("label2", 30, 80, 50, 20)
	Local $idTab2OK = GUICtrlCreateButton("OK2", 140, 50, 50)
	#forceref $idTab2OK
	GUICtrlCreateTabItem("") ; end tabitem definition
	Local $idBtnBack = GUICtrlCreateButton("&Back", 72, 320, 100, 25)
	#forceref $idBtnBack
	Local $idBtnCancel = GUICtrlCreateButton("&Cancel", 264, 320, 100, 25)
	#forceref $idBtnCancel
	Local $idBtnContinue = GUICtrlCreateButton("&Continue", 448, 320, 100, 25)
	#forceref $idBtnContinue
	GUISetState()
	GUIRegisterMsg($WM_VSCROLL, WM_VSCROLL)

	Local $nMsg, $iTab
	While 1
		$nMsg = GUIGetMsg()
		Switch $nMsg
			Case $GUI_EVENT_CLOSE
				Exit
			Case $idTab
				$iTab = _GUICtrlTab_GetCurSel($idTab)
				Switch $iTab
					Case 0
						GUISetState(@SW_SHOW, $hChild)
					Case 1
						GUISetState(@SW_HIDE, $hChild)
				EndSwitch
		EndSwitch
	WEnd
EndFunc   ;==>_Example

Func WM_VSCROLL($hWnd, $Msg, $wParam, $lParam)
	#forceref $Msg, $lParam
	Local $index = -1, $yChar
	For $x = 0 To UBound($__g_aSB_WindowInfo) - 1 ; from GuiScrollBars.au3
		If $__g_aSB_WindowInfo[$x][0] = $hWnd Then
			$index = $x
			$yChar = $__g_aSB_WindowInfo[$index][3]
			ExitLoop
		EndIf
	Next
	If $index = -1 Then Return 0

	; Get all the vertial scroll bar information
	Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_VERT)
	Local $Min = DllStructGetData($tSCROLLINFO, "nMin")
	Local $Max = DllStructGetData($tSCROLLINFO, "nMax")
	Local $Page = DllStructGetData($tSCROLLINFO, "nPage")

	; Save the position for comparison later on
	Local $yPos = DllStructGetData($tSCROLLINFO, "nPos")
	Local $Pos = $yPos
	Local $TrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos")

	Local $nScrollCode = BitAND($wParam, 0x0000FFFF)
	Switch $nScrollCode
		Case $SB_TOP ; user clicked the HOME keyboard key
			DllStructSetData($tSCROLLINFO, "nPos", $Min)
		Case $SB_BOTTOM ; user clicked the END keyboard key
			DllStructSetData($tSCROLLINFO, "nPos", $Max)
		Case $SB_LINEUP ; user clicked the top arrow
			DllStructSetData($tSCROLLINFO, "nPos", $Pos - 1)
		Case $SB_LINEDOWN ; user clicked the bottom arrow
			DllStructSetData($tSCROLLINFO, "nPos", $Pos + 1)
		Case $SB_PAGEUP ; user clicked the scroll bar shaft above the scroll box
			DllStructSetData($tSCROLLINFO, "nPos", $Pos - $Page)
		Case $SB_PAGEDOWN ; user clicked the scroll bar shaft below the scroll box
			DllStructSetData($tSCROLLINFO, "nPos", $Pos + $Page)
		Case $SB_THUMBTRACK ; user dragged the scroll box
			DllStructSetData($tSCROLLINFO, "nPos", $TrackPos)
	EndSwitch

	; Set the position and then retrieve it.  Due to adjustments
	; by Windows it may not be the same as the value set.
	DllStructSetData($tSCROLLINFO, "fMask", $SIF_POS)
	_GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
	_GUIScrollBars_GetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)

	; If the position has changed, scroll the window and update it
	$Pos = DllStructGetData($tSCROLLINFO, "nPos")
	If ($Pos <> $yPos) Then
		_GUIScrollBars_ScrollWindow($hWnd, 0, $yChar * ($yPos - $Pos))
		$yPos = $Pos
	EndIf
	Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_VSCROLL

ReturnToContents

_IsAutoItGUI

Author: guinness








#include <WinAPI.au3>

Example()

Func Example()
    Local $hGUI = GUICreate('')

    GUISetState(@SW_SHOW, $hGUI)

    ; Check if the handle is an AutoIt GUI.
    MsgBox(4096, '', 'Is the handle of the GUI an AutoIt window: ' & _IsAutoItGUI($hGUI))

    GUIDelete($hGUI)
EndFunc   ;==>Example

; Check if a handle is an AutoIt GUI.
Func _IsAutoItGUI($hWnd)
    Return _WinAPI_GetClassName($hWnd) = 'AutoIt v3 GUI'
EndFunc   ;==>_IsAutoItGUI

ReturnToContents

_IsEnabled

Author: guinness








#include <GUIConstantsEx.au3>

Example()

Func Example()
    Local $aState[2] = [$GUI_ENABLE, $GUI_DISABLE]
    GUICreate('')
    Local $iButton = GUICtrlCreateButton('Button Example', 10, 10, 120, 25)
    GUICtrlSetState($iButton, $aState[Random(0, 1, 1)]) ; Randomise whether or not the Button is enabled.
    GUISetState(@SW_SHOW)

    ; Check the state of the Button.
    MsgBox(4096, '', 'Is the Button enabled: ' & _IsEnabled($iButton))

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd
EndFunc   ;==>Example

Func _IsEnabled($iControlID)
    Return BitAND(GUICtrlGetState($iControlID), $GUI_ENABLE) = $GUI_ENABLE
EndFunc   ;==>_IsEnabled

ReturnToContents

_IsTransparent

Author: guinness








#include <WinAPI.au3>

Example()

Func Example()
    Local $hGUI = GUICreate('')
    GUISetState(@SW_SHOW, $hGUI)

    ; Set the transparency of a GUI between 0 and 255. 255 = Solid, 0 = Invisible.
    WinSetTrans($hGUI, '', Random(0, 255, 1))

    MsgBox(4096, '', 'Check if the GUI is transparent: ' & _IsTransparent($hGUI))
    GUIDelete($hGUI)
EndFunc   ;==>Example

; Check if the GUI is transparent.
Func _IsTransparent($sTitle, $sText = '')
    Local $iTransColor = 0, $iTransparency = 255
    _WinAPI_GetLayeredWindowAttributes(WinGetHandle($sTitle, $sText), $iTransColor, $iTransparency)
    Return $iTransparency = 0
EndFunc   ;==>_IsTransparent

ReturnToContents

Limit GUI Resize

Author: Melba23








; How to limit the minimum/maximum size of a resizable GUI
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
GUIRegisterMsg($WM_GETMINMAXINFO, "WM_GETMINMAXINFO")
Global $hGUI = GUICreate("Test", 500, 500, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX))
GUISetState()
Global $aPos = WinGetPos($hGUI)
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_MAXIMIZE
            WinMove($hGUI, "", $aPos[0], $aPos[1], $aPos[2], $aPos[3]) ; resets intial size
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func WM_GETMINMAXINFO($hwnd, $Msg, $wParam, $lParam)
    #forceref $hwnd, $Msg, $wParam, $lParam
    Local $GUIMINWID = 300, $GUIMINHT = 100 ; set your restrictions here
    Local $GUIMAXWID = 800, $GUIMAXHT = 500
    Local $tagMaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam)
    DllStructSetData($tagMaxinfo, 7, $GUIMINWID) ; min X
    DllStructSetData($tagMaxinfo, 8, $GUIMINHT) ; min Y
    DllStructSetData($tagMaxinfo, 9, $GUIMAXWID); max X
    DllStructSetData($tagMaxinfo, 10, $GUIMAXHT) ; max Y
    Return 0
EndFunc   ;==>WM_GETMINMAXINFO

ReturnToContents

Mixed Colored List View

Author: Siao








#Include <GuiConstantsEx.au3>
#Include <GuiListView.au3>
#include <WindowsConstants.au3>

;fonts for custom draw example
;bold
Global $aFont1 = DLLCall("gdi32.dll","int","CreateFont", "int", 14, "int", 0, "int", 0, "int", 0, "int", 700, _
                        "dword", 0, "dword", 0, "dword", 0, "dword", 0, "dword", 0, "dword", 0, "dword", 0, _
                        "dword", 0, "str", "")
;italic
Global $aFont2 = DLLCall("gdi32.dll","int","CreateFont", "int", 14, "int", 0, "int", 0, "int", 0, "int", 400, _
                        "dword", 1, "dword", 0, "dword", 0, "dword", 0, "dword", 0, "dword", 0, "dword", 0, _
                        "dword", 0, "str", "")

$GUI = GUICreate("Listview Custom Draw", 400, 300)
$cListView = GUICtrlCreateListView("", 2, 2, 394, 268)
$hListView = GUICtrlGetHandle($cListView)
;or
;~ $hListView = _GUICtrlListView_Create($GUI, "", 2, 2, 394, 268)

_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
_GUICtrlListView_InsertColumn($hListView, 0, "Column 1", 100)
_GUICtrlListView_InsertColumn($hListView, 1, "Column 2", 100)
_GUICtrlListView_InsertColumn($hListView, 2, "Column 3", 100)

; Add items
For $i = 1 To 30
    _GUICtrlListView_AddItem($hListView, "Row" & $i & ": Col 1", $i-1)
    For $j = 1 To 2
        _GUICtrlListView_AddSubItem ($hListView, $i-1, "Row" & $i & ": Col " & $j+1, $j)
    Next
Next
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
DLLCall("gdi32.dll","int","DeleteObject", "hwnd", $aFont1[0])
DLLCall("gdi32.dll","int","DeleteObject", "hwnd", $aFont2[0])
Exit

Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hListView
            Switch $iCode
                Case $NM_CUSTOMDRAW
                    If Not _GUICtrlListView_GetViewDetails($hWndFrom) Then Return $GUI_RUNDEFMSG
                     Local $tCustDraw = DllStructCreate('hwnd hwndFrom;int idFrom;int code;' & _
                                        'dword DrawStage;hwnd hdc;long rect[4];dword ItemSpec;int ItemState;dword Itemlparam;' & _
                                        'dword clrText;dword clrTextBk;int SubItem;' & _
                                        'dword ItemType;dword clrFace;int IconEffect;int IconPhase;int PartID;int StateID;long rectText[4];int Align', _ ;winxp or later
                                        $lParam), $iDrawStage, $iItem, $iSubitem, $hDC, $iColor1, $iColor2, $iColor3
                    $iDrawStage = DllStructGetData($tCustDraw, 'DrawStage')
                    If $iDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW ;request custom drawing of items
                    If $iDrawStage = $CDDS_ITEMPREPAINT Then Return $CDRF_NOTIFYSUBITEMDRAW ;request drawing each cell separately
                    If Not BitAND($iDrawStage, $CDDS_SUBITEM) Then Return $CDRF_DODEFAULT
                    $iItem = DllStructGetData($tCustDraw, 'ItemSpec')
                    $iSubitem = DllStructGetData($tCustDraw, 'SubItem')
                    Switch $iItem
                        Case 0 To 9 ;for rows 1-10 lets do this
                            $iColor1 = RGB2BGR(0xFBFFD8)
                            $iColor2 = RGB2BGR(-1)
                            $iColor3 = RGB2BGR(0xFF0000)
                            If Mod($iSubitem, 2) Then ;odd columns
                                DllStructSetData($tCustDraw, 'clrTextBk', $iColor1)
                                DllStructSetData($tCustDraw, 'clrText', 0)
                            Else ;even columns
                                DllStructSetData($tCustDraw, 'clrTextBk', $iColor2)
                                DllStructSetData($tCustDraw, 'clrText', $iColor3)
                            EndIf
                        Case 10 To 19 ;for rows 11-20 lets do this
                            $iColor1 = RGB2BGR(0xFBFFD8)
                            $iColor2 = RGB2BGR(0x3DF8FF)
                            $hDC = DllStructGetData($tCustDraw, 'hdc')
                            If Mod($iItem, 2) Then
                                If Mod($iSubitem, 2) Then
                                    DllStructSetData($tCustDraw, 'clrTextBk', $iColor1)
                                Else
                                    DllStructSetData($tCustDraw, 'clrTextBk', $iColor2)
                                EndIf
                                DLLCall("gdi32.dll","hwnd","SelectObject", "hwnd", $hDC, "hwnd", $aFont1[0]) ;select our chosen font into DC
                            Else
                                If Mod($iSubitem, 2) Then
                                    DllStructSetData($tCustDraw, 'clrTextBk', $iColor2)
                                Else
                                    DllStructSetData($tCustDraw, 'clrTextBk', $iColor1)
                                EndIf
                                DLLCall("gdi32.dll","hwnd","SelectObject", "hwnd", $hDC, "hwnd", $aFont2[0])
                            EndIf
                        Case 20 To 29 ;for rows 21-30 lets do this
                            $iColor1 = RGB2BGR(0xFBFFD8)
                            $iColor2 = RGB2BGR(-1)
                            If Mod($iItem, 2) Then ;odd rows
                                DllStructSetData($tCustDraw, 'clrTextBk', $iColor2)
                            Else
                                DllStructSetData($tCustDraw, 'clrTextBk', $iColor1)
                            EndIf
                    EndSwitch
                    Return $CDRF_NEWFONT
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func RGB2BGR($iColor)
    Return BitAND(BitShift(String(Binary($iColor)), 8), 0xFFFFFF)
EndFunc

ReturnToContents

Move Message Box

Author: herewasplato








; Move Message Box

_MoveMsgBox(0, "testTitle", "testText", 0, 10)

Func _MoveMsgBox($MBFlag, $MBTitle, $MBText, $x, $y)
    Local $file = FileOpen(EnvGet("temp") & "\MoveMB.au3", 2)
    If $file = -1 Then Return;if error, give up on the move

    Local $line1 = 'AutoItSetOption(' & '"WinWaitDelay", 0' & ')'
    Local $line2 = 'WinWait("' & $MBTitle & '", "' & $MBText & '")'
    Local $line3 = 'WinMove("' & $MBTitle & '", "' & $MBText & '"' & ', ' & $x & ', ' & $y & ')'
    FileWrite($file, $line1 & @CRLF & $line2 & @CRLF & $line3)
    FileClose($file)

    Run(@AutoItExe & " /AutoIt3ExecuteScript " & EnvGet("temp") & "\MoveMB.au3")

	Local $result = MsgBox($MBFlag, $MBTitle, $MBText)
;~     MsgBox($MBFlag, $MBTitle, $MBText)

    FileDelete(EnvGet("temp") & "\MoveMB.au3")
	Return ($result)
EndFunc;==>_MoveMsgBox

ReturnToContents

Search In A Listview

Author: Xenobiologist








; Search in a Listview and show the row with the match as the top row in the listiview.
#include <GuiListView.au3>

_main()

Func _main()
	Local $hGUI = GUICreate("Test", 500, 500)
	Local $hListView = GUICtrlCreateListView("Items", 10, 10, 480, 380)
	_GUICtrlListView_SetColumnWidth($hListView, 0, 450)
	For $i = 0 To 250
		Switch $i
			Case 50, 100, 150, 200
				GUICtrlCreateListViewItem("Item 999", $hListView)
			Case Else
				GUICtrlCreateListViewItem("Item " & StringFormat("%03i", $i), $hListView)
		EndSwitch
	Next
	Local $hButton = GUICtrlCreateButton("Search", 10, 460, 100, 30, 0x0001) ; DEFAULT_BUTTON
	Local $hInput = GUICtrlCreateInput("999", 200, 460, 100, 30)
	GUICtrlSetState($hInput, 256) ; FOCUS
	GUICtrlCreateLabel("Search for 999 - the listview will show the match as top row", 10, 410, 470, 30)
	GUISetState()
	While 1
		Switch GUIGetMsg()
			Case -3 ; EVENT_CLOSE
				Exit
			Case $hButton
				_search($hListView, GUICtrlRead($hInput))
		EndSwitch
	WEnd
EndFunc   ;==>_main
Func _search($hLV, $startPos = 0)
	_GUICtrlListView_ClickItem($hLV, _GUICtrlListView_GetTopIndex($hLV)) ;
	Local $selIndex_A = _GUICtrlListView_GetSelectedIndices($hLV, True)
	Local $iIndex = _GUICtrlListView_FindInText($hLV, $startPos, $selIndex_A[1])
	; Scroll to bottom
	_GUICtrlListView_EnsureVisible($hLV, _GUICtrlListView_GetItemCount($hLV) - 1)
	; Now click item and we get it at the top - or as close as it will go
	_GUICtrlListView_SetItemFocused($hLV, $iIndex)
	_GUICtrlListView_ClickItem($hLV, $iIndex)
EndFunc   ;==>_search

ReturnToContents

_SetWinTitle

Author: GEOSoft








Local $Frm_Main = GUICreate("")
_SetWinTitle($Frm_Main)
GUISetState()
While 1
	Local $Msg = GUIGetMsg()
	If @MIN = '00' Then _SetWinTitle($Frm_Main)
	If $Msg = -3 Then Exit
WEnd

Func _SetWinTitle($hwnd)
	Local $Greet, $Ttl
	If @HOUR >= 5 And @HOUR <= 11 Then $Greet = 'Morning  '
	If @HOUR >= 12 And @HOUR < 17 Then $Greet = 'Afternoon  '
	If @HOUR >= 17 Then $Greet = 'Evening  '
	If @HOUR < 5 Then
		$Ttl = "You're up a bit too late  " & @UserName
	Else
		$Ttl = 'Good ' & $Greet & @UserName
	EndIf
	WinSetTitle($hwnd, '', $Ttl)
EndFunc   ;==>_SetWinTitle

ReturnToContents

Small Cue Banner

Author: guinness







Idea by: Autolaser


#include <GUIConstantsEx.au3>
#include <GuiEdit.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
	Local $hGUI = GUICreate('Example', 300, 150)
	GUISetFont(9, 400, 0, 'Segoe UI')

	Local $iUsername = GUICtrlCreateInput('', 10, 10, 125, 25)
	_GUICtrlEdit_SetCueBanner($iUsername, "Search folder")

	Local $iPassword = GUICtrlCreateInput('', 10, 40, 125, 25)
	_GUICtrlEdit_SetCueBanner($iPassword, "Search...")

	Local $iClose = GUICtrlCreateButton("Close", 210, 120, 85, 25)
	ControlFocus($hGUI, "", $iClose)

	GUISetState(@SW_SHOW, $hGUI)

	MsgBox($MB_SYSTEMMODAL, "", _GUICtrlEdit_GetCueBanner($iPassword))

	While 1
		Switch GUIGetMsg()
			Case $GUI_EVENT_CLOSE, $iClose
				ExitLoop

		EndSwitch
	WEnd

	GUIDelete($hGUI)
EndFunc   ;==>Example

Func _GUICtrlEdit_GetCueBanner($hWnd)
	If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)

	Local $tText = DllStructCreate("wchar[4096]")
	If _SendMessage($hWnd, $EM_GETCUEBANNER, $tText, 4096, 0, "struct*") <> 1 Then Return SetError(-1, 0, "")
	Return _WinAPI_WideCharToMultiByte($tText)
EndFunc   ;==>_GUICtrlEdit_GetCueBanner

Func _GUICtrlEdit_SetCueBanner($hWnd, $sText)
	If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)

	Local $tText = _WinAPI_MultiByteToWideChar($sText)

	Return _SendMessage($hWnd, $EM_SETCUEBANNER, False, $tText, 0, "wparam", "struct*") = 1
EndFunc   ;==>_GUICtrlEdit_SetCueBanner

ReturnToContents

Snapped Window

Author: Lazycat

Author: argumentum ( multi-monitor mod. )







#include <AutoItConstants.au3>
#include <GUIConstants.au3>
#include <WinAPIMisc.au3>
#include <WinAPIGdi.au3>

Global $nGap = 30 ; 30 pixels for "dramatic effect", 10 pixels should be good for the "magnetic pull"
Global $nEdge = BitOR(1, 2, 4, 8) ; Left, Top, Right, Bottom
Global $nEdgeBorderWidth[4] = [0, 0, 0, 0] ; Left, Top, Right, Bottom

Example()
Func Example()
	Local $hGUI = GUICreate("Snapped Window multi-monitor", 500, 200)
	Local $bNewStyle = False, $idBtnStyle = GUICtrlCreateButton("Change Style", 50, 50, 200, 25)
	GUIRegisterMsg($WM_WINDOWPOSCHANGING, "MY_WM_WINDOWPOSCHANGING")
	GUISetState()

	While 1
		Switch GUIGetMsg()
			Case $GUI_EVENT_CLOSE
				GUIDelete()
				ExitLoop

			Case $GUI_EVENT_MAXIMIZE, $GUI_EVENT_RESTORE ; should not change to this style while maximized
				GUICtrlSetState($idBtnStyle, (BitAND(WinGetState($hGUI), $WIN_STATE_MAXIMIZED) ? $GUI_DISABLE : $GUI_ENABLE))

			Case $idBtnStyle
				$bNewStyle = Not $bNewStyle
				If $bNewStyle Then
					GUISetStyle(BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_TABSTOP))
					Dim $nEdgeBorderWidth[4] = [-7, 0, 7, 7] ; adjusting for Windows 10 border scheme
				Else
					GUISetStyle($GUI_SS_DEFAULT_GUI)
					Dim $nEdgeBorderWidth[4] = [0, 0, 0, 0]
				EndIf
				GUICtrlSetData($idBtnStyle, ($bNewStyle ? 'Undo Style' : 'Change Style'))
				GUIStyleRefresh($hGUI)

		EndSwitch
	WEnd
EndFunc   ;==>Example

Func GUIStyleRefresh($hWnd)
	Local $aWinPos = WinGetPos($hWnd)
	If @error Then Return SetError(@error, @extended, @error)
	WinMove($hWnd, "", $aWinPos[0], $aWinPos[1], $aWinPos[2] - 1, $aWinPos[3] - 1)
	WinMove($hWnd, "", $aWinPos[0], $aWinPos[1], $aWinPos[2], $aWinPos[3])
EndFunc   ;==>GUIStyleRefresh

Func MY_WM_WINDOWPOSCHANGING($hWnd, $iMsg, $wParam, $lParam)
	#forceref $hWnd, $iMsg, $wParam
	; original code at https://www.autoitscript.com/forum/topic/24342-form-snap/

	; The Static declaration speeds up the func. ( not much, nanoseconds )
	Local Static $stWinPos, $tPos, $hMonitor, $aData, $nLeft, $nTop, $nRight, $nBottom, $hTimer = 0

	If TimerDiff($hTimer) > 1000 Then
		$hTimer = TimerInit()
		$tPos = _WinAPI_GetMousePos()                                  ;  These func are very time consuming and
		If Not @error Then $hMonitor = _WinAPI_MonitorFromPoint($tPos) ;  the user is very unlikely to move the
		If Not @error Then $aData = _WinAPI_GetMonitorInfo($hMonitor)  ;  mouse into position on another monitor
		If @error Then Return $GUI_RUNDEFMSG                           ;  in less than a second.
	EndIf

	; https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-windowpos?redirectedfrom=MSDN
	$stWinPos = DllStructCreate("hwnd hwnd;hwnd hwndInsertAfter;int x;int y;int cx;int cy;uint flags", $lParam) ; $tagWINDOWPOS
	$nLeft    = DllStructGetData($aData[1], 1)
	$nTop     = DllStructGetData($aData[1], 2)
	$nRight   = DllStructGetData($aData[1], 3) - $stWinPos.cx
	$nBottom  = DllStructGetData($aData[1], 4) - $stWinPos.cy

	If BitAND($nEdge, 1) And Abs($nLeft   - $stWinPos.x) <= $nGap Then $stWinPos.x = $nLeft   + $nEdgeBorderWidth[0]
	If BitAND($nEdge, 4) And Abs($nRight  - $stWinPos.x) <= $nGap Then $stWinPos.x = $nRight  + $nEdgeBorderWidth[2]
	If BitAND($nEdge, 8) And Abs($nBottom - $stWinPos.y) <= $nGap Then $stWinPos.y = $nBottom + $nEdgeBorderWidth[3]
	If BitAND($nEdge, 2) And Abs($nTop    - $stWinPos.y) <= $nGap Then $stWinPos.y = $nTop    + $nEdgeBorderWidth[1]

	Return $GUI_RUNDEFMSG
EndFunc   ;==>MY_WM_WINDOWPOSCHANGING

ReturnToContents

GUI Snap To Corners

Author: Lazycat








; GUI snap to corners

#include <GUIConstants.au3>

Global $nGap = 20
Global $ahGUI[3]
$ahGUI[0] = GUICreate("Snapped window 1", 300, 200, 100, 100)
GUISetState()
$ahGUI[1] = GUICreate("Snapped window 2", 300, 400, 300, 400)
GUISetState()
$ahGUI[2] = GUICreate("Snapped window 3", 150, 300, 500, 100)
GUISetState()


GUIRegisterMsg($WM_WINDOWPOSCHANGING, "MY_WM_WINDOWPOSCHANGING")
While 1
    $GUIMsg = GUIGetMsg()
    Switch $GUIMsg
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

Func MY_WM_WINDOWPOSCHANGING($hWnd, $Msg, $wParam, $lParam)
    Local $stWinPos = DllStructCreate("uint;uint;int;int;int;int;uint", $lParam)
    Local $nLeft   = DllStructGetData($stWinPos, 3)
    Local $nTop    = DllStructGetData($stWinPos, 4)
    $pos_cur = WinGetPos($hWnd)
    For $i = 0 To UBound($ahGUI) - 1
        If $hWnd = $ahGUI[$i] Then ContinueLoop
        $pos_win = WinGetPos($ahGUI[$i])

        If Abs(($pos_win[0] + $pos_win[2]) - $nLeft) <= $nGap Then DllStructSetData($stWinPos, 3, $pos_win[0] + $pos_win[2])
        If Abs($nLeft + $pos_cur[2] - $pos_win[0]) <= $nGap Then DllStructSetData($stWinPos, 3, $pos_win[0] - $pos_cur[2])

        If Abs(($pos_win[1] + $pos_win[3]) - $nTop) <= $nGap Then DllStructSetData($stWinPos, 4, $pos_win[1] + $pos_win[3])
        If Abs($nTop + $pos_cur[3] - $pos_win[1]) <= $nGap Then DllStructSetData($stWinPos, 4, $pos_win[1] - $pos_cur[3])
    Next
    Return 0
EndFunc

ReturnToContents

TAB On TAB Resize

Author: GEOSoft

Author: martin

Author: ReFran






; Example of TAB On TAB Resize

#include <GUIConstants.au3>

Global $mainGUI, $ok_button, $cancel_button

; This window has 2 ok/cancel-buttons
$mainGUI = GUICreate("Tab on Tab Resize", 260, 250, 20, 10, $WS_OVERLAPPEDWINDOW + $WS_CLIPCHILDREN + $WS_CLIPSIBLINGS)
GUISetStyle(BitOR($WS_MINIMIZEBOX, $WS_MAXIMIZEBOX, $WS_CAPTION, $WS_SIZEBOX, $WS_POPUP, $WS_SYSMENU))
GUISetBkColor(0x5686A9)
$ok_button = GUICtrlCreateButton("OK", 40, 220, 70, 20)
$cancel_button = GUICtrlCreateButton("Cancel", 150, 220, 70, 20)

; Create the first child window that is implemented into the main GUI
$child1 = GUICreate("", 230, 170, 15, 35, BitOR($WS_CHILD, $WS_TABSTOP), -1, $mainGUI)

GUISetBkColor(0x46860A)
$child_tab = GUICtrlCreateTab(10, 10, 210, 150)
GUICtrlSetResizing(-1, $GUI_DOCKAUTO)
$child11tab = GUICtrlCreateTabItem("1")
$child12tab = GUICtrlCreateTabItem("2")
GUICtrlCreateTabItem("")
GUISetState()

; Create the second child window that is implemented into the main GUI
$child2 = GUICreate("", 230, 170, 15, 35, BitOR($WS_CHILD, $WS_TABSTOP), -1, $mainGUI)
GUISetBkColor(0x56869c)
$listview2 = GUICtrlCreateListView("Col1|Col2", 10, 10, 210, 150, -1, $WS_EX_CLIENTEDGE)
GUICtrlSetResizing(-1, $GUI_DOCKAUTO)
GUICtrlCreateListViewItem("ItemLong1|ItemLong12", $listview2)
GUICtrlCreateListViewItem("ItemLong2|Item22", $listview2)
;GUISetState()

; Switch back the main GUI and create the tabs
GUISwitch($mainGUI)
$main_tab = GUICtrlCreateTab(10, 10, 240, 200)
$child1tab = GUICtrlCreateTabItem("Child1")
$child2tab = GUICtrlCreateTabItem("Child2")
GUICtrlCreateTabItem("")
GUISetState()

GUIRegisterMsg($WM_SIZE, 'WM_SIZE')
Dim $tabItemLast = 0

While 1
    $msg = GUIGetMsg(1)
    Switch $msg[0]
        Case $GUI_EVENT_CLOSE, $cancel_button
            ExitLoop

        Case $main_tab
            $tabItem = GUICtrlRead($main_tab)
            If $tabItem <> $tabItemLast Then TabSwitch($tabItem)

    EndSwitch
WEnd

Func TabSwitch($tabItem)
    GUISetState(@SW_HIDE, $child1)
    GUISetState(@SW_HIDE, $child2)

    If $tabItem = 0 Then GUISetState(@SW_SHOW, $child1)
    If $tabItem = 1 Then GUISetState(@SW_SHOW, $child2)
    $tabItemLast = $tabItem
EndFunc   ;==>TabSwitch

Func WM_SIZE($hWnd, $iMsg, $iWParam, $iLParam)
    $aMGPos = WinGetClientSize($mainGUI)
    WinMove($child1, "", 15, 35, +$aMGPos[0] - 30, +$aMGPos[1] - 80)
    WinMove($child2, "", 15, 35, +$aMGPos[0] - 30, +$aMGPos[1] - 80)
    ;Guictrlsetpos($child_tab,10,10,+$aMGPos[0]-50,+$aMGPos[1]-100)
    GUICtrlSetPos($main_tab, 10, 10, +$aMGPos[0] - 20, +$aMGPos[1] - 50)
    GUICtrlSetPos($listview2, 10, 10, +$aMGPos[0] - 30 - 20, +$aMGPos[1] - 80 - 20)

EndFunc   ;==>WM_SIZE

ReturnToContents

_Toggle_CheckOrUnCheck

Author: guinness








#include <GUIConstantsEx.au3>

Example()

Func Example()
    Local $hGUI = GUICreate('')
    Local $iCheckBox = GUICtrlCreateCheckbox('Example', 5, 10, 85, 25)
    GUISetState(@SW_SHOW, $hGUI)

    ; Sleep for 2 seconds.
    Sleep(2000)

    ; The control is currently unchecked so this will toggle the state to checked.
    _Toggle_CheckOrUnCheck($iCheckBox)

    ; Sleep for 2 seconds.
    Sleep(2000)

    ; The control was changed to checked the last time _Toggle_CheckOrUnCheck was called, so now toggle the state to unchecked.
    _Toggle_CheckOrUnCheck($iCheckBox)

    ; Sleep for 2 seconds.
    Sleep(2000)

    GUIDelete($hGUI)
EndFunc   ;==>Example

; Toggle a control to either unchecked or checked, depending on it's current state.
Func _Toggle_CheckOrUnCheck($iControlID)
    Local $aState[2] = [$GUI_CHECKED, $GUI_UNCHECKED]
    GUICtrlSetState($iControlID, $aState[Number(BitAND(GUICtrlRead($iControlID), $aState[0]) = $aState[0])])
EndFunc   ;==>_Toggle_CheckOrUnCheck

ReturnToContents

_Toggle_DropOrNoDrop

Author: guinness








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

Example()

Func Example()
    Local $hGUI = GUICreate('', 500, 500, -1, -1, -1, $WS_EX_ACCEPTFILES)
    Local $iLabel = GUICtrlCreateLabel('Example', 5, 10, 85, 25)
    GUISetState(@SW_SHOW, $hGUI)

    ; Sleep for 2 seconds.
    Sleep(2000)

    ; The control is currently accepting no files to be dropped on it so this will toggle the state to allow dropped files.
    _Toggle_DropOrNoDrop($iLabel)

    ; Sleep for 2 seconds.
    Sleep(2000)

    ; The control was changed to allow dropped files the last time _Toggle_DropOrNoDrop was called, so now toggle the state to accept no dropping of files.
    _Toggle_DropOrNoDrop($iLabel)

    ; Sleep for 2 seconds.
    Sleep(2000)

    GUIDelete($hGUI)
EndFunc   ;==>Example

; Toggle a control to either accept or not accept dropped files, depending on it's current state.
Func _Toggle_DropOrNoDrop($iControlID)
    Local $aState[2] = [$GUI_DROPACCEPTED, $GUI_NODROPACCEPTED]
    GUICtrlSetState($iControlID, $aState[Number(BitAND(GUICtrlGetState($iControlID), $aState[0]) = $aState[0])])
EndFunc   ;==>_Toggle_DropOrNoDrop

ReturnToContents

_Toggle_EnableOrDisable

Author: guinness








#include <GUIConstantsEx.au3>

Example()

Func Example()
    Local $hGUI = GUICreate('')
    Local $iButton = GUICtrlCreateButton('Example', 5, 10, 85, 25)
    GUISetState(@SW_SHOW, $hGUI)

    ; Sleep for 2 seconds.
    Sleep(2000)

    ; The control is currently enabled so this will toggle the state to disabled.
    _Toggle_EnableOrDisable($iButton)

    ; Sleep for 2 seconds.
    Sleep(2000)

    ; The control was changed to disabled the last time _Toggle_EnableOrDisable was called, so now toggle the state to enabled.
    _Toggle_EnableOrDisable($iButton)

    ; Sleep for 2 seconds.
    Sleep(2000)

    GUIDelete($hGUI)
EndFunc   ;==>Example

; Toggle a control to either enabled or disabled, depending on it's current state.
Func _Toggle_EnableOrDisable($iControlID)
    Local $aState[2] = [$GUI_ENABLE, $GUI_DISABLE]
    GUICtrlSetState($iControlID, $aState[Number(BitAND(GUICtrlGetState($iControlID), $aState[0]) = $aState[0])])
EndFunc   ;==>_Toggle_EnableOrDisable

ReturnToContents

_Toggle_FocusOrNoFocus

Author: guinness








#include <GUIConstantsEx.au3>

Example()

Func Example()
    Local $hGUI = GUICreate('')
    Local $iButton = GUICtrlCreateButton('Example', 5, 10, 85, 25)
    GUISetState(@SW_SHOW, $hGUI)

    ; Sleep for 2 seconds.
    Sleep(2000)

    ; The control is currently not focused so this will toggle the state to focused.
    _Toggle_FocusOrNoFocus($iButton)

    ; Sleep for 2 seconds.
    Sleep(2000)

    ; The control was changed to focused the last time _Toggle_FocusOrNoFocus was called, so now toggle the state to not focused.
    _Toggle_FocusOrNoFocus($iButton)

    ; Sleep for 2 seconds.
    Sleep(2000)

    GUIDelete($hGUI)
EndFunc   ;==>Example

; Toggle a control to either focused or not focused, depending on it's current state.
Func _Toggle_FocusOrNoFocus($iControlID)
    Local $aState[2] = [$GUI_FOCUS, $GUI_NOFOCUS]
    GUICtrlSetState($iControlID, $aState[Number(BitAND(GUICtrlGetState($iControlID), $aState[0]) = $aState[0])])
EndFunc   ;==>_Toggle_FocusOrNoFocus

ReturnToContents

_Toggle_ShowOrHide

Author: guinness








#include <GUIConstantsEx.au3>

Example()

Func Example()
    Local $hGUI = GUICreate('')
    Local $iButton = GUICtrlCreateButton('Example', 5, 10, 85, 25)
    GUISetState(@SW_SHOW, $hGUI)

    ; Sleep for 2 seconds.
    Sleep(2000)

    ; The control is currently shown so this will toggle the state to hide.
    _Toggle_ShowOrHide($iButton)

    ; Sleep for 2 seconds.
    Sleep(2000)

    ; The control was changed to hide the last time _Toggle_ShowOrHide was called, so now toggle the state to show.
    _Toggle_ShowOrHide($iButton)

    ; Sleep for 2 seconds.
    Sleep(2000)

    GUIDelete($hGUI)
EndFunc   ;==>Example

; Toggle a control to either show or hide, depending on it's current state.
Func _Toggle_ShowOrHide($iControlID)
    Local $aState[2] = [$GUI_SHOW, $GUI_HIDE]
    GUICtrlSetState($iControlID, $aState[Number(BitAND(GUICtrlGetState($iControlID), $aState[0]) = $aState[0])])
EndFunc   ;==>_Toggle_ShowOrHide

ReturnToContents

Unmovable Window

Author: WeMartiansAreFriendly








#include <GUIConstants.au3>

Global $nConstXpos = @DesktopWidth/2        ;define the constant x position
Global $nConstYpos = @DesktopHeight/2   ;define the constant y position

$hGUI = GUICreate("Unmovable Window", 300, 200, $nConstXpos, $nConstYpos)

GUIRegisterMsg($WM_WINDOWPOSCHANGING, "MY_WM_WINDOWPOSCHANGING")

GUISetState()

While 1
    $GUIMsg = GUIGetMsg()

    Switch $GUIMsg
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

Func MY_WM_WINDOWPOSCHANGING($hWnd, $Msg, $wParam, $lParam)
    Local $stWinPos = DllStructCreate("uint hwnd;uint hwndInsertAfter;int x;int y;int cx;int cy;uint flags", $lParam)

    DllStructSetData($stWinPos, "x", $nConstXpos)
    DllStructSetData($stWinPos, "y", $nConstYpos)
    Return 0
EndFunc

ReturnToContents

Window Drag Using GUIRegister

Author: MrCreatoR








; Window Drag using GUIRegister
#include <GuiConstants.au3>

Global Const $WM_LBUTTONDOWN = 0x0201
;Global Const $WM_SYSCOMMAND = 0x0112

$Gui = GuiCreate("Test", 200, 100, -1, -1, $WS_POPUP, $WS_EX_DLGMODALFRAME)
GuiRegisterMsg($WM_LBUTTONDOWN, "_WinMove")

GUISetState()

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case -3
            Exit
    EndSwitch
WEnd

Func _WinMove($HWnd, $Command, $wParam, $lParam)
    If BitAND(WinGetState($HWnd), 32) Then Return $GUI_RUNDEFMSG
    DllCall("user32.dll", "long", "SendMessage", "hwnd", $HWnd, "int", $WM_SYSCOMMAND, "int", 0xF009, "int", 0)
EndFunc

ReturnToContents

WinGetTrans

Author: guinness








#include <WinAPI.au3>

Example()

Func Example()
    Local $hGUI = GUICreate('')
    GUISetState(@SW_SHOW, $hGUI)

    ; Set the transparency of a GUI between 0 and 255. 255 = Solid, 0 = Invisible.
    WinSetTrans($hGUI, '', 100)

    MsgBox(4096, '', 'The transparency of the GUI is: ' & WinGetTrans($hGUI) & ', this should be 100.')
    GUIDelete($hGUI)
EndFunc   ;==>Example

; Find the transparency of a GUI.
Func WinGetTrans($sTitle, $sText = '') ; By Valik - http://www.autoitscript.com/forum/topic/...gettrans/page__view__findpost_
    Local $iTransColor = 0, $iTransparency = 255
    _WinAPI_GetLayeredWindowAttributes(WinGetHandle($sTitle, $sText), $iTransColor, $iTransparency)
    Return $iTransparency
EndFunc   ;==>WinGetTrans

ReturnToContents

_WorkingArea

Author: guinness








#include <APIConstants.au3>
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>

Example()

Func Example()
    ; Set the working area of the Desktop, in this case 120px to the left and retaining the same height and width.
    Local $aWorkingArea = _WorkingArea(150, Default, Default, Default)

    ; Create the GUI.
    Local $hGUI = GUICreate('', 150, $aWorkingArea[1], $aWorkingArea[2], $aWorkingArea[3], $WS_POPUP)
    Local $iClose = GUICtrlCreateButton('Close', 5, 5, 150 - 10, 25)
    GUISetState(@SW_SHOW, $hGUI)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $iClose
                ExitLoop

        EndSwitch
    WEnd

    ; Delete the GUI.
    GUIDelete($hGUI)

    ; Reset the working area to the previous values.
    _WorkingArea()
EndFunc   ;==>Example

Func _WorkingArea($iLeft = Default, $iTop = Default, $iWidth = Default, $iHeight = Default)
    Local Static $tWorkArea = 0
    If IsDllStruct($tWorkArea) Then
        _WinAPI_SystemParametersInfo($SPI_SETWORKAREA, 0, DllStructGetPtr($tWorkArea), $SPIF_SENDCHANGE)
        $tWorkArea = 0
    Else
        $tWorkArea = DllStructCreate($tagRECT)
        _WinAPI_SystemParametersInfo($SPI_GETWORKAREA, 0, DllStructGetPtr($tWorkArea))

        Local $tCurrentArea = DllStructCreate($tagRECT)
        Local $aArray[4] = [$iLeft, $iTop, $iWidth, $iHeight]
        For $i = 0 To 3
            If $aArray[$i] = Default Or $aArray[$i] < 0 Then
                $aArray[$i] = DllStructGetData($tWorkArea, $i + 1)
            EndIf
            DllStructSetData($tCurrentArea, $i + 1, $aArray[$i])
            $aArray[$i] = DllStructGetData($tWorkArea, $i + 1)
        Next
        _WinAPI_SystemParametersInfo($SPI_SETWORKAREA, 0, DllStructGetPtr($tCurrentArea), $SPIF_SENDCHANGE)
        $aArray[2] -= $aArray[0]
        $aArray[3] -= $aArray[1]
        Local $aReturn[4] = [$aArray[2], $aArray[3], $aArray[0], $aArray[1]]
        Return $aReturn
    EndIf
EndFunc   ;==>_WorkingArea

Dual Monitor + WorkingArea

Author: mLipok








#include <GUIConstants.au3>
#include <WinAPIGdi.au3>

_Example()

Func _Example()
	; taken from HelpFile Example for _WinAPI_EnumDisplayMonitors()
	Local $aMonitors_data = _WinAPI_EnumDisplayMonitors()
	If @error Then Return SetError(@error, @extended, 0)

	Local $hMonitor = $aMonitors_data[1][0] ; handle to first Monitor
	ConsoleWrite("! " & $hMonitor & @CRLF)

	Local Enum $MONITOR_X1 = 1, $MONITOR_Y1, $MONITOR_X2, $MONITOR_Y2

	Local $aMonitorInfo = _WinAPI_GetMonitorInfo($hMonitor)
	ConsoleWrite("! Primary=" & $aMonitorInfo[2] & '  MonitorName = ' & $aMonitorInfo[3] & @CRLF)
	ConsoleWrite("- X1 = " & DllStructGetData($aMonitorInfo[1], $MONITOR_X1) & @CRLF)
	ConsoleWrite("- Y1 = " & DllStructGetData($aMonitorInfo[1], $MONITOR_Y1) & @CRLF)
	ConsoleWrite("- X2 = " & DllStructGetData($aMonitorInfo[1], $MONITOR_X2) & @CRLF)
	ConsoleWrite("- Y2 = " & DllStructGetData($aMonitorInfo[1], $MONITOR_Y2) & @CRLF)

	; Create a GUI_1 with various controls.
	Local $hGUI_1 = GUICreate("Example 1", _
			DllStructGetData($aMonitorInfo[1], $MONITOR_X2)-DllStructGetData($aMonitorInfo[1], $MONITOR_X1), _
			DllStructGetData($aMonitorInfo[1], $MONITOR_Y2)-DllStructGetData($aMonitorInfo[1], $MONITOR_Y1), _
			DllStructGetData($aMonitorInfo[1], $MONITOR_X1), _
			DllStructGetData($aMonitorInfo[1], $MONITOR_Y1) _
			)
	Local $idOK_1 = GUICtrlCreateButton("OK", 310, 370, 85, 25)
	; Display the GUI_1
	GUISetState(@SW_SHOW, $hGUI_1)

	; chceck if there was taken data for second monitor
	If UBound($aMonitors_data) = 3 Then
		$hMonitor = $aMonitors_data[2][0] ; handle to second Monitor
		ConsoleWrite("! " & $hMonitor & @CRLF)

		$aMonitorInfo = _WinAPI_GetMonitorInfo($hMonitor)
		ConsoleWrite("! Primary=" & $aMonitorInfo[2] & '  MonitorName = ' & $aMonitorInfo[3] & @CRLF)
		ConsoleWrite("- X1 = " & DllStructGetData($aMonitorInfo[1], $MONITOR_X1) & @CRLF)
		ConsoleWrite("- Y1 = " & DllStructGetData($aMonitorInfo[1], $MONITOR_Y1) & @CRLF)
		ConsoleWrite("- X2 = " & DllStructGetData($aMonitorInfo[1], $MONITOR_X2) & @CRLF)
		ConsoleWrite("- Y2 = " & DllStructGetData($aMonitorInfo[1], $MONITOR_Y2) & @CRLF)
	EndIf

	; Create a GUI_2 with various controls.
	Local $hGUI_2 = GUICreate("Example 2", _
			DllStructGetData($aMonitorInfo[1], $MONITOR_X2)-DllStructGetData($aMonitorInfo[1], $MONITOR_X1), _
			DllStructGetData($aMonitorInfo[1], $MONITOR_Y2)-DllStructGetData($aMonitorInfo[1], $MONITOR_Y1), _
			DllStructGetData($aMonitorInfo[1], $MONITOR_X1), _
			DllStructGetData($aMonitorInfo[1], $MONITOR_Y1) _
			)
	Local $idOK_2 = GUICtrlCreateButton("OK", 310, 370, 85, 25)
	; Display the GUI_2
	GUISetState(@SW_SHOW, $hGUI_2)

	; Initialize a Local variable for GUIGetMsg($GUI_EVENT_ARRAY)
	Local $aMsg = 0

	; Loop until the user Close both GUI_1 and GUI_2
	While IsHWnd($hGUI_1) Or IsHWnd($hGUI_2) ; check if any GUI exist
		; Assign to $aMsg the advanced GUI messages.
		$aMsg = GUIGetMsg($GUI_EVENT_ARRAY)
		Switch $aMsg[1] ; Switch from GUIs
			Case $hGUI_1 ; The event comes from the GUI1
				Switch $aMsg[0] ; Switch from event ID
					Case $GUI_EVENT_CLOSE
						GUIDelete($hGUI_1)
					Case $idOK_1
						MsgBox($MB_SYSTEMMODAL, "", "Ok_1 clicked.")
				EndSwitch
			Case $hGUI_2  ; The event comes from the GUI2
				Switch $aMsg[0] ; Switch from event ID
					Case $GUI_EVENT_CLOSE
						GUIDelete($hGUI_2)
					Case $idOK_2
						MsgBox($MB_SYSTEMMODAL, "", "Ok_2 clicked.")
				EndSwitch
		EndSwitch
	WEnd

EndFunc   ;==>_Example

ReturnToContents