Another Custom MsgBox for AHK_L v1
Posted: 18 Feb 2019, 00:29
Hi,
So many people have contributed to helping me here with Autohotkey.
You all are amazing when you share code, reply to questions, post tutorials. This is great.
My way of saying thank you for now is to in turn share this function that can be handy when designing Custom Guis all scripted in Autohotkey.
This function will generate a MsgBox and provide basic fonctionnality to do an action with the user selection.
Please let me know what you think and if you know how to do a genuine FrameShadow without affecting other windows of the same class, please post
Version Changes:
2019-02-19 v0.2 - Basic support for bigger titlebar size and text size. Uses Ternary checks and picture stretching (pics stretch not ideal)
You will also need the 3 .png images included in the .zip file here to show correctly
https://1drv.ms/u/s!AnxboyZ6ZdpRg_0Y43MhN54UpvK2hw
Thank you for this great community
Alex
So many people have contributed to helping me here with Autohotkey.
You all are amazing when you share code, reply to questions, post tutorials. This is great.
My way of saying thank you for now is to in turn share this function that can be handy when designing Custom Guis all scripted in Autohotkey.
This function will generate a MsgBox and provide basic fonctionnality to do an action with the user selection.
Please let me know what you think and if you know how to do a genuine FrameShadow without affecting other windows of the same class, please post
Version Changes:
2019-02-19 v0.2 - Basic support for bigger titlebar size and text size. Uses Ternary checks and picture stretching (pics stretch not ideal)
Code: Select all
;--------------------------------------------------------------------------------
; D Rocks Custom MsgBox v0.2 - 2019-02-19
;
;
; Inspired and motivated by: Hellbent aka CivReborn
; - https://www.autohotkey.com/boards/viewtopic.php?f=76&t=62081
;
; Model by: TheDewd and kczx3 - 2016 post
; - https://www.autohotkey.com/boards/viewtopic.php?t=18271
;
;
; KNOWN ISSUE:
; - Using FrameShadow affects all windows of same class which is most of the times unwanted
; > Disabled until I find how to solve this
; > If you know how please post here
;
; - Pictures must scale for bigger font sizes
; > Basic modification implemented to stretch pictures, not ideal. It is better to modify source image size non-destructively
;--------------------------------------------------------------------------------
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance, Force ; Prevent double execution of this script
;--------------------------------------------------------------------------------
; ExampleA including 2 buttons: YES and NO
CustomMsgBox_Func(350, 150, "Another Custom MsgBox will pop-up`nif you choose YES.`n`nDo you want to continue ?", "CONFIRMATION", "gCustomMsgBox", "YES", "NO")
WinWaitClose, % "ahk_id " hMsgBox ; Waits until you select something and by selecting something the window should close
;--------------------------------------------------------------------------------
; ExampleB including 1 button: YEP
If (MsgBoxChoice = "YES") {
CustomMsgBox_Func(250, 100, "You have pressed the YES button.", "SUCCESS", "gCustomMsgBox", "YEP !")
WinWaitClose, % "ahk_id " hMsgBox ; Waits until you select something and by selecting something the window should close
} ;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; ExampleC including 2 buttons: HmK too bad
If (MsgBoxChoice = "YEP !") {
CustomMsgBox_Func(500, 150, "You just experienced amazing stuff.", "THANK YOU", "gCustomMsgBox", "Hmm K", "Too bad")
WinWaitClose, % "ahk_id " hMsgBox ; Waits until you select something and by selecting something the window should close
} ;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; ExampleD including 2 buttons: BIG BROTHER
If (MsgBoxChoice = "Hmm K") {
CustomMsgBox_Func(800, 270, "This example uses monster font size and image scaling.`n`nIs it looking good on 4k display?", "BIGGER EVERYTHING", "gCustomMsgBox", "BIG...", "GUY", , 26, 18)
} ;--------------------------------------------------------------------------------
return
;-----------------------------------------------------------------------------------------------------------------------------------------
CustomMsgBox_Func(GuiW, GuiH, DisplayText, GuiWinTitle, gLabel, Button1text, Button2text:="", Owner:="", TitleSize:="", TextSize:="") {
;-----------------------------------------------------------------------------------------------------------------------------------------
Global hMsgBox, hButton1text, hButton2text, HasOwner
;=== Gui pop-up options
Gui, CustomMsgBox: New, +hWndhMsgBox -Caption -SysMenu -MinimizeBox +AlwaysOnTop
Gui, Color, White
;=== Gui Variables
TitlebarColor:= "000" ; black
,TitlebarHeight:= (TitleSize>18? (TitleSize>24? 60:45):30)
,ButtonW:=(TextSize>12? 250:140)
,BorderThickness:= 4
,InnerMargin:= 15, Margin:= InnerMargin + BorderThickness
,Padding:= 12
,CenterHorizontal:= "Center", CenterVertical:= 0x200
,Height:= GuiH+30 + BorderThickness + (Padding-4)
,TextPos:= "x" Margin " y+"((GuiH)//7) " w" (GuiW - (Margin * 2))
;=== Use a Progress Meter to fake a title bar.
Gui, Font, % (TitleSize>11? "s" . TitleSize : "s11") " bold cWhite"
Gui, Add, Progress , % "x0 y0 w" GuiW " h" TitlebarHeight " Background" TitlebarColor
Gui, Add, Text , % "x0 y0 w" GuiW " h" TitlebarHeight " BackgroundTrans " CenterHorizontal " " CenterVertical,% GuiWinTitle
;=== Place the MsgBox controls
Gui, Font
Gui, Font, % (TextSize>10? "s"TextSize:"s10") " cBlack"
; text displayed in center ----------------------------------------------------------------------
Gui, Add, Text, % TextPos " center", % DisplayText
;--------------------------------------------------------------------------------
;== CUSTOM BUTTONS ==============================================================================
if (Button2text) {
;-- Button1------------------------------------------------------------------------------
Gui, Add, Picture, % "x"Margin+2 " y"GuiH-(Margin) " SECTION" , % ImageFolder "ConfirmerMsgBoxIcon.png" ; Check icon
Gui, Add, Picture, % "xp yp w" ButtonW " +BackgroundTrans", % ImageFolder "CustomMsgBoxButtonShadow.png" ; Shadow button
Gui, Add, Text, % "g" gLabel " hWndhButton1text xp yp-2 w" ButtonW-11 " h45 +BackgroundTrans center " CenterVertical, % " " Button1text ; Texte sur bouton
;--------------------------------------------------------------------------------
;-- Button2--------------------------------------------------------------------------------
Gui, Add, Picture, % "x" GuiW-(30+(Margin+Padding)) " ys+3",% ImageFolder "AnnulerMsgBoxIcon.png" ; X icon
Gui, Add, Picture, % "xp-"(ButtonW-50) " yp-3 w"ButtonW " +BackgroundTrans", % ImageFolder "CustomMsgBoxButtonShadow.png" ; Shadow button
Gui, Add, Text, % "g" gLabel " hWndhButton2text xp yp-2 w"ButtonW-11 " hp +BackgroundTrans center " CenterVertical, % Button2text " " ; Texte sur bouton
} ;--------------------------------------------------------------------------------
else {
;-- Button1------------------------------------------------------------------------------
Gui, Add, Picture, % "x"(GuiW/2)-(140/2) " y"GuiH-(Margin), % ImageFolder "ConfirmerMsgBoxIcon.png" ; Check icon
Gui, Add, Picture, % "xp yp +BackgroundTrans", % ImageFolder "CustomMsgBoxButtonShadow.png" ; Shadow button
Gui, Add, Text, % "g" gLabel " hWndhButton1text xp yp w" ButtonW " h45 +BackgroundTrans center " CenterVertical, % " " Button1text ; Texte sur bouton
;--------------------------------------------------------------------------------
}
;==============================================================================================
;=== Add the border.
Gui, Add, Progress, % "x" 0 " y" (Height - BorderThickness) " w" GuiW " h" BorderThickness " Background" TitlebarColor ; Border Bottom
Gui, Add, Progress, % "x" 0 " y" TitlebarHeight " w" BorderThickness " h" Height-34 " Background" TitlebarColor ; Border Left
Gui, Add, Progress, % "x" (GuiW - BorderThickness) " y" TitlebarHeight " w" BorderThickness " h" Height-34 " Background" TitlebarColor ; Border Right
;=== Shadow - Added by kczx3
;FrameShadow(hMsgBox)
;DllCall("SetClassLong","UInt",hMsgBox,"Int",-26,"Int",DllCall("GetClassLong","UInt",hMsgBox,"Int",-26)|0x20000)
; Disabled until I find how to not affect other window shadows of the same class
;=== Show MsgBox and disable owner Gui
Gui, %hMsgBox%:Show, % "w" GuiW " h" Height, % GuiWinTitle ; At last show the Custom MsgBox
if (Owner) {
HasOwner:=Owner
Gui, %Owner%:+Disabled ; Owner(hWnd) will be disabled
}
}
/*
;--------------------------------------------------------------------------------
FrameShadow(HGui) {
;--------------------------------------------------------------------------------
; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=29117&p=264035#p264035
DllCall("dwmapi\DwmIsCompositionEnabled","IntP",_ISENABLED) ; Get if DWM Manager is Enabled
if _ISENABLED ; if DWM is not enabled, Make Basic Shadow
DllCall("SetClassLong","UInt",HGui,"Int",-26,"Int",DllCall("GetClassLong","UInt",HGui,"Int",-26)|0x20000)
else {
VarSetCapacity(_MARGINS,16)
NumPut(1,&_MARGINS,0,"UInt")
NumPut(1,&_MARGINS,4,"UInt")
NumPut(1,&_MARGINS,8,"UInt")
NumPut(1,&_MARGINS,12,"UInt")
DllCall("dwmapi\DwmSetWindowAttribute", "Ptr", HGui, "UInt", 2, "Int*", 2, "UInt", 4)
DllCall("dwmapi\DwmExtendFrameIntoClientArea", "Ptr", HGui, "Ptr", &_MARGINS)
}
}
*/
;-- On MsgBox Exit ------------------------------------------------------------------------------
gCustomMsgBox:
CustomMsgBoxGuiEscape:
CustomMsgBoxGuiClose:
if (A_GuiControl) ; vrai quand on clic sur un bouton
MsgBoxChoice:= Trim(A_GuiControl)
if (HasOwner)
Gui, %hGuiMain%:-Disabled ; hGuiMain owner will be re-enabled
HasOwner:=""
Gui, %hMsgBox%:Destroy ; msgbox pop-up will be destroyed
return
;--------------------------------------------------------------------------------
https://1drv.ms/u/s!AnxboyZ6ZdpRg_0Y43MhN54UpvK2hw
Thank you for this great community
Alex