[V2-beta] Examples of Non-Standard Gui

Post your working scripts, libraries and tools.
AHK_user
Posts: 515
Joined: 04 Dec 2015, 14:52
Location: Belgium

[V2-beta] Examples of Non-Standard Gui

Post by AHK_user » 16 Oct 2021, 15:08

I translated and added some changes to the V1 gui example of @TheDewd to V2 (original can be found in this post).
It seemed a nice gui for changing the settings of scripts with a look of the Windows settings.

Features:
- Modern looking tab menu with hover functionality.
- Advanced but easy way to set control behaviour when resizing. (For example the two buttons below will move with the right bottom corner depending on just two added properties.
- Tooltips for Controls based on tooltip property
- Multiple Gui`s possible.

Updates:
- Started using text controls to create colored rectangles
- Fixed issues with nested guis
- Made menu click possible to the left corner
2021-10-16 21_58_32-Menu Interface.png
2021-10-16 21_58_32-Menu Interface.png (16.29 KiB) Viewed 4652 times

Code: Select all

; Created by:   AHK_User, 
; Date:         2021-10-20
; This Gui is based on gui example of TheDewd
; Thanks to Viv for fixing the tooltip issue and testing

#Requires AutoHotkey v2.0-beta.1
#SingleInstance Force ; Replace with new instance if script is running

; Tray definition =================================================================
Tray := A_TrayMenu
Application := { Name: "Menu Interface", Version: "0.1" }
TraySetIcon("Shell32.dll", 174)
TrayTip(Application.Name)
; Tray.Delete()
Tray.Add("Exit", (*) => ExitApp())

SettingsGui()

SettingsGui(){
    OnMessage(0x200, WM_MOUSEMOVE) ; Calling Function when moving the mouse inside the gui
    
    ; Define parameters of Gui
    Window := {Width: 600, Height: 400, Title: Application.Name}
    MenuWidth := 100
    Navigation := {Label: ["General", "Advanced", "Language", "Theme", "---", "Help", "About"]}

    myGui := Gui()
    myGui.OnEvent("Close", Gui_Escape)
    myGui.OnEvent("Escape", Gui_Escape)
    MyGui.OnEvent("Size", Gui_Size)
    myGui.Opt("+LastFound +Resize MinSize400x300")
    myGui.BackColor := "FFFFFF"

    Tab := myGui.Add("Tab2", "x-999 y-999 w0 h0 -Wrap +Theme vTabControl")
    myGui.Tabs := Tab
    Tab.UseTab() ; Exclude future controls from any tab control

    myGui.TabPicSelect := myGui.AddText("x0 y0 w4 h32 vpMenuSelect Background0x0078D7") ; Using a text control to create a colored rectangle
    myGui.TabPicHover := myGui.AddText("x0 y0 w4 h32 vpMenuHover Background0xCCE8FF Hidden") ; Using a text control to create a colored rectangle
    
    myGui.TabTitle := myGui.Add("Text", "x" MenuWidth+10 " y" 0 " w" (Window.Width-MenuWidth)-10 " h" 30 " +0x200 vPageTitle", "")
    myGui.TabTitle.SetFont("s14 ", "Segoe UI") ; Set Font Options

    Loop Navigation.Label.Length { 
        Tab.Add([Navigation.Label[A_Index]])
        If (Navigation.Label[A_Index] = "---") {
            Continue
        }
        ogcTextMenuItem := myGui.Add("Text", "x0 y" (32*A_Index)-32 " h32 w" MenuWidth " +0x200 BackgroundTrans vMenuItem" . A_Index, "     " Navigation.Label[A_Index])
        ogcTextMenuItem.SetFont("s9 c808080", "Segoe UI") ; Set Font Options
        ogcTextMenuItem.OnEvent("Click", Gui_Menu)
        ogcTextMenuItem.Index := A_Index
        if (A_Index = 1) {
            ogcTextMenuItem.SetFont("c000000")
            myGui.ActiceTab := ogcTextMenuItem
            myGui.TabTitle.Value := trim(ogcTextMenuItem.text)
        }
    }

    ogchDividerLine := myGui.AddText("x" MenuWidth+10 " y32 w" Window.Width-MenuWidth-10*2 " h1 Section BackgroundD8D8D8") ; Using a text control to create a colored rectangle
    ogchDividerLine.LeftMargin := 10
    
    ; Start of defining the custom controls

    Tab.UseTab(1) ; Future controls are owned by the specified tab

    myGui.Add("Text", "xs ys+10 BackgroundWhite", "Select your primary button")
    myGui.Add("DropDownList", "vPrimaryButton Choose1", ["Left", "Right"])
    myGui.Add("Text", "yp+40", "Cursor Speed")
    myGui.Add("Slider", "vMySlider NoTicks", 50)
    myGui.Add("Text", "yp+40 ", "Roll the mouse wheel to scroll")
    myDropDownList := myGui.Add("DropDownList", "w150 vRollMW Choose1", ["Multiple lines at a time", "On screen at a time"])
    myDropDownList.ToolTip := "test"

    myCheckbox := myGui.Add("Checkbox", "yp+40 vCheckboxExample", "Checkbox Example")
    myCheckbox.Tooltip := "This Checkbox has a tooltip"

    Tab.UseTab(2) ; Future controls are owned by the specified tab
    ogcListView := myGui.Add("ListView", "x" MenuWidth+10 " y45 w" (Window.Width-MenuWidth+10)-14, ["Col1", "Col2"])
    ogcListView.Add("", "ListView", "Example")
    ogcListView.ModifyCol()
    ogcListView.LeftMargin := "10"
    ogcListView.BottomMargin := "40"

    Tab.UseTab(3) ; Future controls are owned by the specified tab
    myGui.Add("MonthCal", "xs ys+10 ")

    Tab.UseTab(4) ; Future controls are owned by the specified tab
    myGui.Add("DateTime", "xs ys+10 ", "LongDate")

    Tab.UseTab(5) ; Future controls are owned by the specified tab

    Tab.UseTab(6) ; Future controls are owned by the specified tab
    ogcGroupbox := myGui.Add("GroupBox", "xs ys+10 " " w" (Window.Width-MenuWidth -10)-14, "GroupBox")
    ogcGroupbox.LeftMargin := "10"
    ogcGroupbox.BottomMargin := "40"

    Tab.UseTab(7) ; Future controls are owned by the specified tab
    myGui.Add("DateTime", "xs ys+10 ", "LongDate")

    Tab.UseTab("")

    ogcButtonOK := myGui.Add("Button", "x" (Window.Width - 170) - 10 " y" (Window.Height - 24) - 10 " w80 h24 vButtonOK", "OK")
    ogcButtonOK.OnEvent("Click", ButtonOK)
    ogcButtonOK.LeftDistance := "10"
    ogcButtonOK.BottomDistance := "10"
    ogcButtonCancel := myGui.Add("Button", "x" (Window.Width - 80) - 10 " y" (Window.Height - 24) - 10 " w80 h24 vButtonCancel", "Cancel")
    ogcButtonCancel.OnEvent("Click", Gui_Escape)
    ogcButtonCancel.LeftDistance := "100"
    ogcButtonCancel.BottomDistance := "10"

    myGui.Title := Window.Title
    myGui.Show(" w" Window.Width " h" Window.Height)
    
    return

    ; Nested Functions ==============================================================================
    ButtonOK(*){
        Saved := MyGui.Submit(0)
        MsgBox("CheckboxExample`t[" Saved.CheckboxExample "]`n")
        ExitApp()
    }
    
    Gui_Escape(*){ 
        ExitApp() ; Terminate the script unconditionally
    }

    Gui_Menu(guiCtrlObj, info, *){
        ; Called when clicking the menu
        thisGui := guiCtrlObj.Gui
        thisGui.ActiceTab.SetFont("c808080")
        thisGui.Tabs.Choose(trim(guiCtrlObj.text))
        thisGui.TabTitle.Value := trim(GuiCtrlObj.text)
        thisGui.ActiceTab := GuiCtrlObj
        guiCtrlObj.SetFont("c000000")
        thisGui.TabPicSelect.Move(0, (32*GuiCtrlObj.Index) - 32)
        return
    }

    Gui_Size(thisGui, MinMax, Width, Height) {
        if MinMax = -1	; The window has been minimized. No action needed.
            return
        DllCall("LockWindowUpdate", "Uint", thisGui.Hwnd)
        For Hwnd, GuiCtrlObj in thisGui{
            if GuiCtrlObj.HasProp("LeftMargin"){
                GuiCtrlObj.GetPos(&cX, &cY, &cWidth, &cHeight)
                GuiCtrlObj.Move(, , Width-cX-GuiCtrlObj.LeftMargin,)
            }
            if GuiCtrlObj.HasProp("LeftDistance") {
                GuiCtrlObj.GetPos(&cX, &cY, &cWidth, &cHeight)
                GuiCtrlObj.Move(Width -cWidth - GuiCtrlObj.LeftDistance, , , )
            }
            if GuiCtrlObj.HasProp("BottomDistance") {
                GuiCtrlObj.GetPos(&cX, &cY, &cWidth, &cHeight)
                GuiCtrlObj.Move(, Height - cHeight - GuiCtrlObj.BottomDistance, ,  )
            }
            if GuiCtrlObj.HasProp("BottomMargin") {
                GuiCtrlObj.GetPos(&cX, &cY, &cWidth, &cHeight)
                GuiCtrlObj.Move(, , , Height -cY - GuiCtrlObj.BottomMargin)
            }  
        }
        DllCall("LockWindowUpdate", "Uint", 0)
    }

    WM_MOUSEMOVE(wParam, lParam, Msg, Hwnd) {
        static PrevHwnd := 0
        static HoverControl := 0
        currControl := GuiCtrlFromHwnd(Hwnd)
        ; Setting the highlighting of the hovered menu
        if currControl {
            thisGui := currControl.Gui
            if thisGui.HasProp("TabPicHover"){
                If (InStr(currControl.Name, "MenuItem") and currControl != thisGui.ActiceTab) {
                    thisGui.TabPicHover.Visible := true
                    thisGui.TabPicHover.Move(0, (32 * currControl.Index) - 32)
                } else {
                    thisGui.TabPicHover.Visible := false
                }
            }
        } else {
            thisGui := GuiFromHwnd(Hwnd)
            if (isObject(thisGui) and thisGui.HasProp("TabPicHover")) {
                thisGui.TabPicHover.Visible := false
            }
        }
        
        ; Setting the tooltips for controls with a property tooltip
        if (Hwnd != PrevHwnd){
            Text := "", ToolTip()	; Turn off any previous tooltip.
            if CurrControl{
                if !CurrControl.HasProp("ToolTip")
                    return	; No tooltip for this control.
                SetTimer(CheckHoverControl, 50)	; Checks if hovered control is still the same
                SetTimer(DisplayToolTip, -500)
            }
            PrevHwnd := Hwnd
        }
        return

        CheckHoverControl(){
            If hwnd != prevHwnd {
                SetTimer(DisplayToolTip, 0), SetTimer(CheckHoverControl, 0)
            }
        }
        DisplayToolTip(){
            ToolTip(CurrControl.ToolTip)
            SetTimer(CheckHoverControl, 0)
        }
    }
}
Last edited by AHK_user on 19 Oct 2021, 17:39, edited 3 times in total.

viv
Posts: 217
Joined: 09 Dec 2020, 17:48

Re: [V2-beta] Examples of Non-Standard Gui

Post by viv » 17 Oct 2021, 07:14

I set MenuWidth
but the Tabhover Width dont change?
like picture
i put mouse in the red line
1.jpg
1.jpg (51.84 KiB) Viewed 4584 times

when have 2 gui
it will error when put mouse in gui2
Attachments
2.jpg
2.jpg (92.27 KiB) Viewed 4582 times

AHK_user
Posts: 515
Joined: 04 Dec 2015, 14:52
Location: Belgium

Re: [V2-beta] Examples of Non-Standard Gui

Post by AHK_user » 18 Oct 2021, 05:39

viv wrote:
17 Oct 2021, 07:14
I set MenuWidth
but the Tabhover Width dont change?
like picture
i put mouse in the red line

1.jpg


when have 2 gui
it will error when put mouse in gui2
Thanks for the testing.

The updated version should normally fix these two isssues. Can you try it?
Last edited by AHK_user on 18 Oct 2021, 12:55, edited 1 time in total.

viv
Posts: 217
Joined: 09 Dec 2020, 17:48

Re: [V2-beta] Examples of Non-Standard Gui

Post by viv » 18 Oct 2021, 06:26

@AHK_user

thx, Tabhover not fix, gui2 fixed.


like picture
my mouse is on the cursor speed
but Tabhover is active
1.jpg
1.jpg (62.43 KiB) Viewed 4523 times

AHK_user
Posts: 515
Joined: 04 Dec 2015, 14:52
Location: Belgium

Re: [V2-beta] Examples of Non-Standard Gui

Post by AHK_user » 18 Oct 2021, 12:59

I have updated my first post with some fixes and shorter code.
I also replaced the complex dllcall to create colored rectangles to simple text controls without text and a colored background.

@viv : I could not simulate your issue anymore with the hoverindication failing, is it maybe possible that you did not included all my changes?

viv
Posts: 217
Joined: 09 Dec 2020, 17:48

Re: [V2-beta] Examples of Non-Standard Gui

Post by viv » 18 Oct 2021, 15:59

@AHK_user

thx very much, all fixed!

when many items has ToolTip
it will like that
1.gif
1.gif (120.19 KiB) Viewed 4467 times




i fixed myself,but very ungly
hope it can give you a little help
in WM_MOUSEMOVE

Code: Select all

        if (Hwnd != PrevHwnd){
            ToolTip()
            if CurrControl{
                if !CurrControl.HasProp("ToolTip")
                    return
                prevClassNN := CurrControl.ClassNN
                SetTimer(ClassNNCheck, 50)	;check if move
                SetTimer(Tips, -500)
            }
            PrevHwnd := Hwnd
        }
        return

        ClassNNCheck()
        {
            If hwnd != prevHwnd || prevClassNN != CurrControl.ClassNN
                SetTimer(Tips, 0), SetTimer(ClassNNCheck, 0)
        }
        Tips()
        {
            ToolTip(CurrControl.ToolTip)
            SetTimer(ClassNNCheck, 0)
        }



Such sentences do not require inverted commas

Code: Select all

myGui.TabPicSelect := main.AddText("x0 y0 w4 h32 vpMenuSelect Background3399FF")

AHK_user
Posts: 515
Joined: 04 Dec 2015, 14:52
Location: Belgium

Re: [V2-beta] Examples of Non-Standard Gui

Post by AHK_user » 19 Oct 2021, 17:54

@viv Thanks for the testing and fixing the Tooltip. With two you see more :D

I checked other programs on their working of the tooltip, and in the most cases it stays stationary and does not moves along with the mouse. So it is nice that we have the same behaviour.
I changed it a little bit by giving the functions more meaningfull names, and removed the classnn check, because I got the impression that it was not neccesary, or am I wrong :think: ? My testing seems to be working fine so I removed it.

Maybe we could write it shorter with some kind of a () => expression, but I am not yet familiar with this. More elegant/shorter code is welcome, but it appears to be working perfectly.

(the code in the first post is updated to these changes)

Code: Select all

        if (Hwnd != PrevHwnd){
            Text := "", ToolTip()	; Turn off any previous tooltip.
            if CurrControl{
                if !CurrControl.HasProp("ToolTip")
                    return	; No tooltip for this control.
                SetTimer(CheckHoverControl, 50)	; Checks if hovered control is still the same
                SetTimer(DisplayToolTip, -500)
            }
            PrevHwnd := Hwnd
        }
        return

        CheckHoverControl(){
            If hwnd != prevHwnd {
                SetTimer(DisplayToolTip, 0), SetTimer(CheckHoverControl, 0)
            }
        }
        DisplayToolTip(){
            ToolTip(CurrControl.ToolTip)
            SetTimer(DisplayToolTip, 0)
        }

viv
Posts: 217
Joined: 09 Dec 2020, 17:48

Re: [V2-beta] Examples of Non-Standard Gui

Post by viv » 20 Oct 2021, 00:56

@AHK_user
() => is essentially a function without a function name


Let's say this sentence

Code: Select all

Tray.Add("Exit", (*) => ExitApp())
It unfolds like this

Code: Select all

Tray.Add("Exit", ExitFunc)
ExitFunc(ItemName, ItemPos, MyMenu)
{
    ExitApp()
}
There is no need to pass ItemName, ItemPos, MyMenu

Code: Select all

Tray.Add("Exit", ExitFunc)
ExitFunc(*)
{
    ExitApp()
}
No name(*) => becomes the original

SetTimer, 0
If the function name is omitted it will become the currently executing SetTimer
Since there are two basic SetTimers running at the same time and elsewhere
So you need to specify the name of the SetTimers you want to close
It is also these two

Code: Select all

SetTimer(DisplayToolTip, 0), SetTimer(CheckHoverControl, 0)
So this is not a good place to use a function that omits the name (=>)
Forcing it to look like this is fine
Since there is no if in a single statement, you can only use ? :

Code: Select all

        if (Hwnd != PrevHwnd){
            Text := "", ToolTip()	; Turn off any previous tooltip.
            if CurrControl{
                if !CurrControl.HasProp("ToolTip")
                    return	; No tooltip for this control.
                CheckHoverControl := ()=> hwnd != prevHwnd ? (SetTimer(DisplayToolTip, 0), SetTimer(CheckHoverControl, 0)) : ""
                DisplayToolTip := ()=> (ToolTip(CurrControl.ToolTip),SetTimer(CheckHoverControl, 0))
                SetTimer(CheckHoverControl, 50)	; Checks if hovered control is still the same
                SetTimer(DisplayToolTip, -500)
            }
            PrevHwnd := Hwnd

AHK_user
Posts: 515
Joined: 04 Dec 2015, 14:52
Location: Belgium

Re: [V2-beta] Examples of Non-Standard Gui

Post by AHK_user » 21 Oct 2021, 12:36

@viv Thanks for the explanation I think I am starting to understand it better, interesting method to shorten the code.

Maybe you could also help me with this issue:
I was trying to make a button with a Text control with a colored background. The Idea is that if you hover over it, the color will change. (And if you click it of course, but this is for later.)
Iniating the colorchange works, but detecting that the mouse is moved away from the button seems to be failing. Apparently it is detecting 2 hwnds?
Do you have any idea what is causing this?

Code: Select all

; Created by:   AHK_User, 
; Date:         2021-10-20
; This Gui is based on gui example of TheDewd
; Thanks to Viv for fixing the tooltip issue and testing

#Requires AutoHotkey v2.0-beta.1
#SingleInstance Force ; Replace with new instance if script is running

; Tray definition =================================================================
Tray := A_TrayMenu
Application := { Name: "Menu Interface", Version: "0.1" }
TraySetIcon("Shell32.dll", 174)
TrayTip(Application.Name)
; Tray.Delete()
Tray.Add("Exit", (*) => ExitApp())

SettingsGui()

SettingsGui(){
    OnMessage(0x200, WM_MOUSEMOVE) ; Calling Function when moving the mouse inside the gui
    
    ; Define parameters of Gui
    Window := {Width: 600, Height: 400, Title: Application.Name}
    MenuWidth := 100
    Navigation := {Label: ["General", "Advanced", "Language", "Theme", "---", "Help", "About"]}

    myGui := Gui()
    myGui.OnEvent("Close", Gui_Escape)
    myGui.OnEvent("Escape", Gui_Escape)
    MyGui.OnEvent("Size", Gui_Size)
    myGui.Opt("+LastFound +Resize MinSize400x300")
    myGui.BackColor := "FFFFFF"

    Tab := myGui.Add("Tab2", "x-999 y-999 w0 h0 -Wrap +Theme vTabControl")
    myGui.Tabs := Tab
    Tab.UseTab() ; Exclude future controls from any tab control

    myGui.TabPicSelect := myGui.AddText("x0 y0 w4 h32 vpMenuSelect Background0x0078D7") ; Using a text control to create a colored rectangle
    myGui.TabPicHover := myGui.AddText("x0 y0 w4 h32 vpMenuHover Background0xCCE8FF Hidden") ; Using a text control to create a colored rectangle
    
    myGui.TabTitle := myGui.Add("Text", "x" MenuWidth+10 " y" 0 " w" (Window.Width-MenuWidth)-10 " h" 30 " +0x200 vPageTitle", "")
    myGui.TabTitle.SetFont("s14 ", "Segoe UI") ; Set Font Options

    Loop Navigation.Label.Length { 
        Tab.Add([Navigation.Label[A_Index]])
        If (Navigation.Label[A_Index] = "---") {
            Continue
        }
        ogcTextMenuItem := myGui.Add("Text", "x0 y" (32*A_Index)-32 " h32 w" MenuWidth " +0x200 BackgroundTrans vMenuItem" . A_Index, "     " Navigation.Label[A_Index])
        ogcTextMenuItem.SetFont("s9 c808080", "Segoe UI") ; Set Font Options
        ogcTextMenuItem.OnEvent("Click", Gui_Menu)
        ogcTextMenuItem.Index := A_Index
        if (A_Index = 1) {
            ogcTextMenuItem.SetFont("c000000")
            myGui.ActiceTab := ogcTextMenuItem
            myGui.TabTitle.Value := trim(ogcTextMenuItem.text)
        }
    }

    ogchDividerLine := myGui.AddText("x" MenuWidth+10 " y32 w" Window.Width-MenuWidth-10*2 " h1 Section BackgroundD8D8D8") ; Using a text control to create a colored rectangle
    ogchDividerLine.LeftMargin := 10
    
    ; Start of defining the custom controls

    Tab.UseTab(1) ; Future controls are owned by the specified tab

    myGui.Add("Text", "xs ys+10", "Select your primary button")
    myGui.Add("DropDownList", "vPrimaryButton Choose1", ["Left", "Right"])
    myGui.Add("Text", "yp+40", "Cursor Speed")
    myGui.Add("Slider", "vMySlider NoTicks", 50)
    myGui.Add("Text", "yp+40 ", "Roll the mouse wheel to scroll")
    myDropDownList := myGui.Add("DropDownList", "w150 vRollMW Choose1", ["Multiple lines at a time", "On screen at a time"])
    myDropDownList.ToolTip := "test"

    myCheckbox := myGui.Add("Checkbox", "yp+40 vCheckboxExample", "Checkbox Example")
    myCheckbox.Tooltip := "This Checkbox has a tooltip"

    TextButton := myGui.Add("Text", "h30 w200 BackgroundBlue center cwhite", "ButtonTest")
    TextButton.HoverBGColor := "Red"

    TextButton.DefaultBGColor := "Blue"
    TextButton.OnEvent("Click", ButtonOK)

    Tab.UseTab(2) ; Future controls are owned by the specified tab
    ogcListView := myGui.Add("ListView", "x" MenuWidth+10 " y45 w" (Window.Width-MenuWidth+10)-14, ["Col1", "Col2"])
    ogcListView.Add("", "ListView", "Example")
    ogcListView.ModifyCol()
    ogcListView.LeftMargin := "10"
    ogcListView.BottomMargin := "40"

    Tab.UseTab(3) ; Future controls are owned by the specified tab
    myGui.Add("MonthCal", "xs ys+10 ")

    Tab.UseTab(4) ; Future controls are owned by the specified tab
    myGui.Add("DateTime", "xs ys+10 ", "LongDate")

    Tab.UseTab(5) ; Future controls are owned by the specified tab

    Tab.UseTab(6) ; Future controls are owned by the specified tab
    ogcGroupbox := myGui.Add("GroupBox", "xs ys+10 " " w" (Window.Width-MenuWidth -10)-14, "GroupBox")
    ogcGroupbox.LeftMargin := "10"
    ogcGroupbox.BottomMargin := "40"

    Tab.UseTab(7) ; Future controls are owned by the specified tab
    myGui.Add("DateTime", "xs ys+10 ", "LongDate")

    Tab.UseTab("")

    ogcButtonOK := myGui.Add("Button", "x" (Window.Width - 170) - 10 " y" (Window.Height - 24) - 10 " w80 h24 vButtonOK", "OK")
    ogcButtonOK.OnEvent("Click", ButtonOK)
    ogcButtonOK.LeftDistance := "10"
    ogcButtonOK.BottomDistance := "10"
    ogcButtonCancel := myGui.Add("Button", "x" (Window.Width - 80) - 10 " y" (Window.Height - 24) - 10 " w80 h24 vButtonCancel", "Cancel")
    ogcButtonCancel.OnEvent("Click", Gui_Escape)
    ogcButtonCancel.LeftDistance := "100"
    ogcButtonCancel.BottomDistance := "10"

    myGui.Title := Window.Title
    myGui.Show(" w" Window.Width " h" Window.Height)
    
    return

    ; Nested Functions ==============================================================================
    ButtonOK(*){
        Saved := MyGui.Submit(0)
        MsgBox("CheckboxExample`t[" Saved.CheckboxExample "]`n")
        ExitApp()
    }
    
    Gui_Escape(*){ 
        ExitApp() ; Terminate the script unconditionally
    }

    Gui_Menu(guiCtrlObj, info, *){
        ; Called when clicking the menu
        thisGui := guiCtrlObj.Gui
        thisGui.ActiceTab.SetFont("c808080")
        thisGui.Tabs.Choose(trim(guiCtrlObj.text))
        thisGui.TabTitle.Value := trim(GuiCtrlObj.text)
        thisGui.ActiceTab := GuiCtrlObj
        guiCtrlObj.SetFont("c000000")
        thisGui.TabPicSelect.Move(0, (32*GuiCtrlObj.Index) - 32)
        return
    }

    Gui_Size(thisGui, MinMax, Width, Height) {
        if MinMax = -1	; The window has been minimized. No action needed.
            return
        DllCall("LockWindowUpdate", "Uint", thisGui.Hwnd)
        For Hwnd, GuiCtrlObj in thisGui{
            if GuiCtrlObj.HasProp("LeftMargin"){
                GuiCtrlObj.GetPos(&cX, &cY, &cWidth, &cHeight)
                GuiCtrlObj.Move(, , Width-cX-GuiCtrlObj.LeftMargin,)
            }
            if GuiCtrlObj.HasProp("LeftDistance") {
                GuiCtrlObj.GetPos(&cX, &cY, &cWidth, &cHeight)
                GuiCtrlObj.Move(Width -cWidth - GuiCtrlObj.LeftDistance, , , )
            }
            if GuiCtrlObj.HasProp("BottomDistance") {
                GuiCtrlObj.GetPos(&cX, &cY, &cWidth, &cHeight)
                GuiCtrlObj.Move(, Height - cHeight - GuiCtrlObj.BottomDistance, ,  )
            }
            if GuiCtrlObj.HasProp("BottomMargin") {
                GuiCtrlObj.GetPos(&cX, &cY, &cWidth, &cHeight)
                GuiCtrlObj.Move(, , , Height -cY - GuiCtrlObj.BottomMargin)
            }  
        }
        DllCall("LockWindowUpdate", "Uint", 0)
    }

    WM_MOUSEMOVE(wParam, lParam, Msg, Hwnd) {
        static PrevHwnd := 0
        static HoverControl := 0
        currControl := GuiCtrlFromHwnd(Hwnd)
        ; Setting the highlighting of the hovered menu
        if currControl {
            thisGui := currControl.Gui
            if thisGui.HasProp("TabPicHover"){
                If (InStr(currControl.Name, "MenuItem") and currControl != thisGui.ActiceTab) {
                    thisGui.TabPicHover.Visible := true
                    thisGui.TabPicHover.Move(0, (32 * currControl.Index) - 32)
                } else {
                    thisGui.TabPicHover.Visible := false
                }
            }
        } else {
            thisGui := GuiFromHwnd(Hwnd)
            if (isObject(thisGui) and thisGui.HasProp("TabPicHover")) {
                thisGui.TabPicHover.Visible := false
            }
        }
        
        if (Hwnd != PrevHwnd) {
            ; Changing the color
            if CurrControl {
                if CurrControl.HasProp("HoverBGColor"){
                    HoverControl := CurrControl
                    CurrControl.Opt("+Background" CurrControl.HoverBGColor)
                    CurrControl.Redraw()
                    CheckHoverControl2 := () => hwnd != HoverControl.Hwnd ? (HoverControl.Opt("+Background" HoverControl.DefaultBGColor),HoverControl.Redraw(),SetTimer(CheckHoverControl2, 0)) : ""
                    SetTimer(CheckHoverControl2, 50)
                }
            }
        }

        ; Setting the tooltips for controls with a property tooltip
        if (Hwnd != PrevHwnd) {
            Text := "", ToolTip()	; Turn off any previous tooltip.
            if CurrControl {
                if !CurrControl.HasProp("ToolTip")
                    return	; No tooltip for this control.
                CheckHoverControl := () => hwnd != prevHwnd ? (SetTimer(DisplayToolTip, 0), SetTimer(CheckHoverControl, 0)) : ""
                DisplayToolTip := () => (ToolTip(CurrControl.ToolTip), SetTimer(CheckHoverControl, 0))
                SetTimer(CheckHoverControl, 50)	; Checks if hovered control is still the same
                SetTimer(DisplayToolTip, -500)
            }
            PrevHwnd := Hwnd
        }
        return

    }
}


Adventurer
Posts: 23
Joined: 18 Apr 2019, 06:24

Re: [V2-beta] Examples of Non-Standard Gui

Post by Adventurer » 27 Oct 2021, 18:39

I'd love to see a dark-themed version of this, even better if it detects if the system is using dark theme or not.

AHK_user
Posts: 515
Joined: 04 Dec 2015, 14:52
Location: Belgium

Re: [V2-beta] Examples of Non-Standard Gui

Post by AHK_user » 28 Oct 2021, 05:32

Adventurer wrote:
27 Oct 2021, 18:39
I'd love to see a dark-themed version of this, even better if it detects if the system is using dark theme or not.
Setting the title and menu to darkmode is possible, but not all controls support darkmode, so they do not look great. The menubar and statusbar are also not changed from color, so they do not look great, or need to be created in another way.
Example: viewtopic.php?f=83&t=78253#p421741

If you want a quick Dark mode look, I Advice to just change the title bar, the menu and the buttons and keep the background default or change it to white, like in this example:
viewtopic.php?f=83&t=95940

For the easiest implementation, I would use class GuiControl_Ex, It adds methods to the standard gui controls :D .

I think it would be wiser to create it with a html gui if you want to go in that direction. This gives the most flexibility to change the way it looks, but there are not many examples for it in V2. And handling events is a lot more difficult.

Post Reply

Return to “Scripts and Functions (v2)”