[FUNCTION] Gui_QuickAbout - Quick and dirty about/help gui

Post your working scripts, libraries and tools.
User avatar
cyruz
Posts: 348
Joined: 30 Sep 2013, 13:31

[FUNCTION] Gui_QuickAbout - Quick and dirty about/help gui

Post by cyruz » 31 Dec 2022, 21:34

Hi guys,

I was tired to rewrite the same about function for every little project I come up with, so I wrote this short function:

Code: Select all

; ----------------------------------------------------------------------------------------------------------------------
; Function .....: Gui_QuickAbout
; Description ..: Just a quick about GUI.
; Parameters ...: sTitle    - GUI title.
; ..............: sBody     - Content of the Edit control, a.k.a. the About field.
; ..............: sGuiOpts  - GUI options.
; ..............: sEditOpts - Edit control options.
; ..............: sOverride - Override the static variables. Format must be "xxx:=N xxx:=`"xxx`" xxx:=N".
; AHK Version ..: AHK v2
; Author .......: Cyruz  (http://ciroprincipe.info)
; License ......: WTFPL - http://www.wtfpl.net/txt/copying/
; Changelog ....: Dec. 31, 2022 - v0.1.0 - First version.
; ..............: Jan. 18, 2023 - v0.1.1 - Merged EM_SETMARGINS SendMessage(s). Thanks iPhilip.
; ..............: Mar. 10, 2024 - v0.1.2 - Added the sOverride parameter.
; ----------------------------------------------------------------------------------------------------------------------

Gui_QuickAbout(sTitle, sBody, sGuiOpts:="", sEditOpts:="", sOverride:="")
{
    Static oGuiAbout
         , nPosX  := 0
         , nPosY  := 0
         , nMarX  := 15
         , nMarY  := 15
         , nPadSx := 1
         , nPadRx := 1
         , nBtnSz := 100
         , nIcoId := 24
         , nIcoSz := 48
         , sIcoFi := "C:\Windows\System32\shell32.dll"
    
    Try WinExist("ahk_id " oGuiAbout.Hwnd)
    Catch
    {
        If sOverride != ""
        && RegExMatch(sOverride, "([^\s]+):=([\d]+|`"[^`"]+`")", &oMatch:=0)
        && !Mod(oMatch.Count, 2)
            Loop oMatch.Count//2
                %oMatch[2*A_Index-1]% := oMatch[2*A_Index]
        
        oGuiAbout := Gui(sGuiOpts, sTitle)
        oGuiAbout.OnEvent( "Close", (*) => (WinGetPos(&nPosX, &nPosY), oGuiAbout.Destroy()) )
        oGuiAbout.MarginX := nMarX, oGuiAbout.MarginY := nMarY
        
        oGuiAbout.Add("Picture", "w" nIcoSz " h-1 Icon" nIcoId, sIcoFi)
        
        ; *** We create a readonly Edit control without borders (-E0x200), we deselect its content and we
        ; *** hide the caret on creation. The caret must be hidden anytime the control gets keyboard focus.
        ; *** We use SendMessage to set left and right margin for the control.
        
        oEditCtrl := oGuiAbout.Add("Edit", sEditOpts " x+" nMarX " +Multi +ReadOnly -E0x200", sBody)
        ControlSend("{Up}", oEditCtrl.Hwnd), DllCall("HideCaret", "Ptr",oEditCtrl.Hwnd)
        oEditCtrl.OnEvent( "Focus", (*) => DllCall("HideCaret", "Ptr",oEditCtrl.Hwnd) )
        SendMessage(0xD3, 1 | 2, nPadSx | nPadRx << 16,, "ahk_id " oEditCtrl.Hwnd) ; EM_SETMARGINS = 0xD3
        
        (oGuiAbout.Add("Button", "w" nBtnSz " x+-" nBtnSz " y+" nMarY, "OK" ))
        .OnEvent( "Click", (*) => (WinGetPos(&nPosX, &nPosY), oGuiAbout.Destroy()) )
        
        oGuiAbout.Show(nPosX != 0 && nPosY != 0 ? "X" nPosX " Y" nPosY : "")
        Return
    }
    
    ; Activate/Flash if gui is visible. WS_VISIBLE = 0x10000000.
    (WinGetStyle("ahk_id " oGuiAbout.Hwnd) & 0x10000000 ) && WinActivate("ahk_id " oGuiAbout.Hwnd), oGuiAbout.Flash()
}

Example:

Code: Select all

#Include <Gui_QuickAbout>

a := "
(
Shittyproj v.1.0.1
> Super shitty useless little project that does absolutely nothing.
> (C)2022 Gino Pilotino
> https://en.wikipedia.org/wiki/Loopin%27_Louie

Lorem ipsum dolor sit amet, consectetur 
adipiscing elit, sed do eiusmod tempor incididunt 
ut labore et dolore magna aliqua.

Ut enim ad minim veniam, quis nostrud exercitation 
ullamco laboris nisi ut aliquip ex ea commodo consequat.

Duis aute irure dolor in reprehenderit in voluptate 
velit esse cillum dolore eu fugiat nulla pariatur.

Excepteur sint occaecat cupidatat non proident, sunt in 
culpa qui officia deserunt mollit anim id est laborum."
)"

g := gui()
b := g.Add("Button", "w200", "About")
b.OnEvent("Click", (*) => Gui_QuickAbout("My About", a, "", "w320 h200"))
g.Show()
MyAbout.png
MyAbout.png (18.42 KiB) Viewed 1315 times

Changelog:
  • Jan. 18, 2023 - v0.1.1 - Merged EM_SETMARGINS SendMessage(s). Thanks iPhilip.
  • Mar. 10, 2024 - v0.1.2 - Added the sOverride parameter.
Cheers and Happy New Year :beer:
Last edited by cyruz on 10 Mar 2024, 06:43, edited 7 times in total.
ABCza on the old forum.
My GitHub.

User avatar
kczx3
Posts: 1649
Joined: 06 Oct 2015, 21:39

Re: [FUNCTION] Gui_QuickAbout - Quick and dirty about/help gui

Post by kczx3 » 31 Dec 2022, 23:38

Why pass an object to the OnEvent callback what a fat arrow function itself should suffice?

User avatar
cyruz
Posts: 348
Joined: 30 Sep 2013, 13:31

Re: [FUNCTION] Gui_QuickAbout - Quick and dirty about/help gui

Post by cyruz » 01 Jan 2023, 02:04

kczx3 wrote:
31 Dec 2022, 23:38
Why pass an object to the OnEvent callback what a fat arrow function itself should suffice?
I’m basically doing trial and error with v2 and I started reading about gui events only recently. I guess I missed that part, thanks for pointing it out. I’ll fix it as soon possible.

EDIT: Fixed.
ABCza on the old forum.
My GitHub.

william_ahk
Posts: 506
Joined: 03 Dec 2018, 20:02

Re: [FUNCTION] Gui_QuickAbout - Quick and dirty about/help gui

Post by william_ahk » 01 Jan 2023, 21:44

Nice! Will use this in my next shit.

User avatar
cyruz
Posts: 348
Joined: 30 Sep 2013, 13:31

Re: [FUNCTION] Gui_QuickAbout - Quick and dirty about/help gui

Post by cyruz » 02 Jan 2023, 18:51

william_ahk wrote:
01 Jan 2023, 21:44
Nice! Will use this in my next shit.
Great! :bravo:
ABCza on the old forum.
My GitHub.

User avatar
andymbody
Posts: 967
Joined: 02 Jul 2017, 23:47

Re: [FUNCTION] Gui_QuickAbout - Quick and dirty about/help gui

Post by andymbody » 02 Jan 2023, 18:59

I will hold out for a cleaner version... ;)

User avatar
cyruz
Posts: 348
Joined: 30 Sep 2013, 13:31

Re: [FUNCTION] Gui_QuickAbout - Quick and dirty about/help gui

Post by cyruz » 02 Jan 2023, 22:55

andymbody wrote:
02 Jan 2023, 18:59
I will hold out for a cleaner version... ;)
I guess it’s a bit too dirty? :mrgreen:

My self-imposed restrictions were short code and avoiding hidden GUIs. Anyway, please feel free to modify it or talk about any possible improvement.
ABCza on the old forum.
My GitHub.

iPhilip
Posts: 832
Joined: 02 Oct 2013, 12:21

Re: [FUNCTION] Gui_QuickAbout - Quick and dirty about/help gui

Post by iPhilip » 18 Jan 2023, 12:24

Nice function!
cyruz wrote:
02 Jan 2023, 22:55
Anyway, please feel free to modify it or talk about any possible improvement.
You can combine the two SendMessage's

Code: Select all

SendMessage(0xD3, 1, nPadSx,,       "ahk_id " oEditCtrl.Hwnd) ; EM_SETMARGINS = 0xD3
SendMessage(0xD3, 2, nPadRx << 16,, "ahk_id " oEditCtrl.Hwnd) ; EM_SETMARGINS = 0xD3
into one.

Code: Select all

SendMessage(0xD3, 1 | 2, nPadSx | nPadRx << 16,, "ahk_id " oEditCtrl.Hwnd) ; EM_SETMARGINS = 0xD3
Windows 10 Pro (64 bit) - AutoHotkey v2.0+ (Unicode 64-bit)

User avatar
cyruz
Posts: 348
Joined: 30 Sep 2013, 13:31

Re: [FUNCTION] Gui_QuickAbout - Quick and dirty about/help gui

Post by cyruz » 18 Jan 2023, 15:16

iPhilip wrote:
18 Jan 2023, 12:24
Nice function!
cyruz wrote:
02 Jan 2023, 22:55
Anyway, please feel free to modify it or talk about any possible improvement.
You can combine the two SendMessage's

Code: Select all

SendMessage(0xD3, 1, nPadSx,,       "ahk_id " oEditCtrl.Hwnd) ; EM_SETMARGINS = 0xD3
SendMessage(0xD3, 2, nPadRx << 16,, "ahk_id " oEditCtrl.Hwnd) ; EM_SETMARGINS = 0xD3
into one.

Code: Select all

SendMessage(0xD3, 1 | 2, nPadSx | nPadRx << 16,, "ahk_id " oEditCtrl.Hwnd) ; EM_SETMARGINS = 0xD3
Yeah makes a lot of sense :D

Merged, thank you!
ABCza on the old forum.
My GitHub.

iPhilip
Posts: 832
Joined: 02 Oct 2013, 12:21

Re: [FUNCTION] Gui_QuickAbout - Quick and dirty about/help gui

Post by iPhilip » 18 Jan 2023, 18:57

You are welcome. :)
Windows 10 Pro (64 bit) - AutoHotkey v2.0+ (Unicode 64-bit)

Post Reply

Return to “Scripts and Functions (v2)”