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()
Changelog:
- Jan. 18, 2023 - v0.1.1 - Merged EM_SETMARGINS SendMessage(s). Thanks iPhilip.
- Mar. 10, 2024 - v0.1.2 - Added the sOverride parameter.