Snippets ( GUI ): Difference between revisions
Argumentum (talk | contribs) m (→Snapped Window) |
|||
(7 intermediate revisions by 2 users not shown) | |||
Line 627: | Line 627: | ||
#include <GUIConstantsEx.au3> | #include <GUIConstantsEx.au3> | ||
#include <GuiTab.au3> | |||
#include <GuiScrollBars.au3> | |||
#include <ScrollBarConstants.au3> | #include <ScrollBarConstants.au3> | ||
#include <WindowsConstants.au3> | #include <WindowsConstants.au3> | ||
While 1 | _Example() | ||
$nMsg = | |||
Switch $nMsg | 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 | |||
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, $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 | EndFunc ;==>WM_VSCROLL | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 1,199: | Line 1,219: | ||
Global $nGap = 30 ; 30 pixels for "dramatic effect", 10 pixels should be good for the "magnetic pull" | 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 $nEdge = BitOR(1, 2, 4, 8) ; Left, Top, Right, Bottom | ||
Global $nEdgeBorderWidth[4] = [0, 0, 0, 0] ; Left, Top, Right, Bottom | Global $nEdgeBorderWidth[4] = [0, 0, 0, 0] ; Left, Top, Right, Bottom | ||
Example() | |||
Func Example() | |||
GUIRegisterMsg($WM_WINDOWPOSCHANGING, "MY_WM_WINDOWPOSCHANGING") | Local $hGUI = GUICreate("Snapped Window multi-monitor", 500, 200) | ||
GUISetState() | Local $bNewStyle = False, $idBtnStyle = GUICtrlCreateButton("Change Style", 50, 50, 200, 25) | ||
GUIRegisterMsg($WM_WINDOWPOSCHANGING, "MY_WM_WINDOWPOSCHANGING") | |||
GUISetState() | |||
While 1 | 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 | WEnd | ||
EndFunc ;==>Example | |||
Func GUIStyleRefresh($hWnd) | Func GUIStyleRefresh($hWnd) | ||
Line 1,236: | Line 1,259: | ||
WinMove($hWnd, "", $aWinPos[0], $aWinPos[1], $aWinPos[2] - 1, $aWinPos[3] - 1) | WinMove($hWnd, "", $aWinPos[0], $aWinPos[1], $aWinPos[2] - 1, $aWinPos[3] - 1) | ||
WinMove($hWnd, "", $aWinPos[0], $aWinPos[1], $aWinPos[2], $aWinPos[3]) | WinMove($hWnd, "", $aWinPos[0], $aWinPos[1], $aWinPos[2], $aWinPos[3]) | ||
EndFunc | EndFunc ;==>GUIStyleRefresh | ||
Func MY_WM_WINDOWPOSCHANGING($hWnd, $iMsg, $wParam, $lParam) | Func MY_WM_WINDOWPOSCHANGING($hWnd, $iMsg, $wParam, $lParam) | ||
Line 1,244: | Line 1,267: | ||
; The Static declaration speeds up the func. ( not much, nanoseconds ) | ; The Static declaration speeds up the func. ( not much, nanoseconds ) | ||
Local Static $stWinPos, $tPos, $hMonitor, $aData, $nLeft, $nTop, $nRight, $nBottom, $hTimer = 0 | Local Static $stWinPos, $tPos, $hMonitor, $aData, $nLeft, $nTop, $nRight, $nBottom, $hTimer = 0 | ||
If TimerDiff($hTimer) > 1000 Then | If TimerDiff($hTimer) > 1000 Then | ||
$hTimer = TimerInit() | $hTimer = TimerInit() | ||
$tPos = _WinAPI_GetMousePos() ; | $tPos = _WinAPI_GetMousePos() ; These func are very time consuming and | ||
If Not @error Then $hMonitor = _WinAPI_MonitorFromPoint($tPos); | 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 | If Not @error Then $aData = _WinAPI_GetMonitorInfo($hMonitor) ; mouse into position on another monitor | ||
If @error Then Return $GUI_RUNDEFMSG ; | If @error Then Return $GUI_RUNDEFMSG ; in less than a second. | ||
EndIf | EndIf | ||
$stWinPos = DllStructCreate( | ; 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) | $nLeft = DllStructGetData($aData[1], 1) | ||
$nTop = DllStructGetData($aData[1], 2) | $nTop = DllStructGetData($aData[1], 2) | ||
$nRight = DllStructGetData($aData[1], 3) - | $nRight = DllStructGetData($aData[1], 3) - $stWinPos.cx | ||
$nBottom = DllStructGetData($aData[1], 4) - | $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 | EndFunc ;==>MY_WM_WINDOWPOSCHANGING | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Latest revision as of 21:02, 19 August 2021
_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
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
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
_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
_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
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
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
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
_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
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
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
_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
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
_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
_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
_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
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
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
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
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
_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
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
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
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
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
_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
_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
_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
_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
_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
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
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
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
_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