[a136] Gui ONE LINERS With Dot Notation

Post your working scripts, libraries and tools.
xroot
Posts: 40
Joined: 21 Jun 2019, 08:45

[a136] Gui ONE LINERS With Dot Notation

Post by xroot » 14 Jun 2021, 12:13

I am Working on a class to make ONE LINE Guies with dot notation.

Here is I_Gui Class, in the zip.

Code: Select all

Class I_Gui{
    __New(p*){
        this.win  := Gui(p*)
        this.cntl := []
        this.X    := 0
        this.Y    := 0
    }
    Margin(x:=0,y:=0){
        this.win.MarginX := x
        this.win.MarginY := y
        return this
    }
    Left(inum){
        this.X := inum
        return this
    }
    Top(inum){
        this.Y := inum
        return this
    }
    BackColor(icolor){
        this.win.BackColor := icolor
        return this
    }
    Add(p*){
        If(p.length>3){
            If(type(p[3])="Array"){
                local arr := p[3]
                Loop p[4]{
                    this.cntl.Push this.win.Add(p[1],p[2],arr[A_Index])
                    If(this.X)
                        p[2] := StrReplace(p[2],SubStr(p[2],InStr(p[2],"x")+1,3),SubStr(p[2],InStr(p[2],"x")+1,3)+this.X)
                    If(this.Y)
                        p[2] := StrReplace(p[2],SubStr(p[2],InStr(p[2],"y")+1,3),SubStr(p[2],InStr(p[2],"y")+1,3)+this.Y)
                    If(p.length>4)
                        this.%p[5]%(p[6],p[7])
                }
            }Else
                Loop p[4]
                    this.cntl.Push this.win.Add(p[1],p[2],p[3])
        }Else
            this.cntl.Push this.win.Add(p*)
        return this
    }
    OnEvent(p*){
        Switch this.cntl.Length{
            Case 0:this.win.OnEvent(p*)
            Case this.cntl.Length:this.cntl[this.cntl.Length].OnEvent(p*)
        }
        return this
    }
    SetFont(p*){
        Switch this.cntl.Length{
           Case 0:this.win.SetFont(p*)
           Case this.cntl.Length:this.cntl[this.cntl.Length].SetFont(p*)
        }
        return this
    }
    SetGuiFont(p*){
        this.win.SetFont(p*)
        return this
    }
    SetTransParent(inum){
        WinSetTransParent inum,this.win.hWnd
        return this
    }
    SetTransColor(icolor){
        WinSetTransColor icolor,this.win.hWnd
        return this
    }
    SetRegion(iopt){
        WinSetRegion iopt,this.win.hWnd
        return this
    }
    OnMessage(p*){
        OnMessage(p*)
        return this
    }
    SetCursor(icursor){
        static GCL_HCURSOR := -12,IMAGE_CURSOR := 2
        Switch this.cntl.Length{
            Case 0:iptr := this.win.hWnd
            Case this.cntl.Length:iptr := this.cntl[this.cntl.Length].hWnd
        }
        DllCall (a_ptrsize=8)?"SetClassLongPtr":"SetClassLong","ptr",iptr,"int",GCL_HCURSOR,"ptr",LoadPicture(icursor,,&IMAGE_CURSOR)
        return this
    }
    SetTimer(p*){
        SetTimer(p*)
        return this
    }
    SetWinDelay(p){
        SetWinDelay p
        return this
    }
    Move(p*){
        this.win.Move(p*)
        return this
    }
    Sleep(itime){
        Sleep itime
        return this
    }
    Close(){
        Winclose this.win
        return this
    }
    Show(p*){
        this.win.Show(p*)
        return this
    }
}
Here is a simple 2 ONE LINER Guies, making a full crosshair cursor.

Code: Select all

#SingleInstance
#Include I_Gui.ahk

CoordMode "Mouse"
SetWinDelay 0

MouseGetPos &x,&y

LineColor := "Blue"
LineSize  := 4

xwin := I_Gui("-caption +AlwaysOnTop +E32").BackColor(LineColor).SetTransParent(255).Show("x0 y" y " w" A_ScreenWidth " h" LineSize)
ywin := I_Gui("-caption +AlwaysOnTop +E32 +owner").BackColor(LineColor).SetTransParent(255).Show("x" x " y0 w" LineSize " h" A_ScreenHeight)

Loop{
    MouseGetPos &x,&y
    xwin.Move ,y
    ywin.Move x
    Sleep 0
}

Esc::ExitApp
The I_Gui class, can be changed or added too, because each example has it's own uniqueness.
Methods work in one scripts, but not in an other, all depends on the order of the methods.
Play with the class, studying the Add method and have some fun.

More Examples.
I_Gui.zip
(156.31 KiB) Downloaded 50 times
Example 1: Array of Text controls with mouse functions, THE BEATLES, idea from a forum post.
Example 2: One Main Gui, and 3 Sub Guies, all ONE LINERS to show a shaped Gui window.
Example 3: Array of Picture controls to show a LED clock.

Return to “Scripts and Functions (v2)”