MsgBox 64 - Without "pling" - is it possible?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Albireo
Posts: 1748
Joined: 16 Oct 2013, 13:53

MsgBox 64 - Without "pling" - is it possible?

21 Jan 2018, 16:10

The instruction .: MsgBox.... is a rather powerful command with quite a few possibilities.
If I use "?" as an icon, MsgBox 32... does not sound "pling".
but if I useMsgBox 64... (!) it sounds "pling".
Is it possible to control the "pling" together with MsgBox?
i.e. MsgBox 64 without "pling"?
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: MsgBox 64 - Without "pling" - is it possible?

21 Jan 2018, 16:37

"pling" = alert/notification :arrow: system sounds. You could toggle the sound on/off before&after OR create your own Gui(Msg)Box.
User avatar
Alguimist
Posts: 428
Joined: 05 Oct 2015, 16:41
Contact:

Re: MsgBox 64 - Without "pling" - is it possible?

21 Jan 2018, 16:40

Use a message box function that supports custom icon.

MsgBoxEx:

Code: Select all

Text := "No sound."

Result := MsgBoxEx(Text, "Title", "OK", [5, "user32.dll"])

MsgBoxEx(Text, Title := "", Buttons := "", Icon := "", ByRef CheckText := "", Styles := "", Owner := ""
    , Timeout := "", FontOptions := "", FontName := "", BGColor := "", Callback := "") {
    Static hWnd, y2, p, px, pw, c, cw, cy, ch, f, o, gL, hBtn, lb, DHW, ww, Off, k, v, RetVal
    Static Sound := {2: "*48", 4: "*16", 5: "*64"}

    Gui New, hWndhWnd LabelMsgBoxEx -0xA0000
    Gui % (Owner) ? "+Owner" . Owner : ""
    Gui Font
    Gui Font, % (FontOptions) ? FontOptions : "s9", % (FontName) ? FontName : "Segoe UI"
    Gui Color, % (BGColor) ? BGColor : "White"
    Gui Margin, 10, 12

    If (IsObject(Icon)) {
        Gui Add, Picture, % "x20 y24 w32 h32 Icon" . Icon[1], % (Icon[2] != "") ? Icon[2] : "shell32.dll"
    } Else If (Icon + 0) {
        Gui Add, Picture, x20 y24 Icon%Icon% w32 h32, user32.dll
        SoundPlay % Sound[Icon]
    }

    Gui Add, Link, % "x" . (Icon ? 65 : 20) . " y" . (InStr(Text, "`n") ? 24 : 32) . " vc", %Text%
    GuicontrolGet c, Pos
    GuiControl Move, c, % "w" . (cw + 30)
    y2 := (cy + ch < 52) ? 90 : cy + ch + 34

    Gui Add, Text, vf -Background ; Footer

    Gui Font
    Gui Font, s9, Segoe UI
    px := 42
    If (CheckText != "") {
        CheckText := StrReplace(CheckText, "*",, ErrorLevel)
        Gui Add, CheckBox, vCheckText x12 y%y2% h26 -Wrap -Background AltSubmit Checked%ErrorLevel%, %CheckText%
        GuicontrolGet p, Pos, CheckText
        px := px + pw + 10
    }

    o := {}
    Loop Parse, Buttons, |, *
    {
        gL := (Callback != "" && InStr(A_LoopField, "...")) ? Callback : "MsgBoxExBUTTON"
        Gui Add, Button, hWndhBtn g%gL% x%px% w90 y%y2% h26 -Wrap, %A_Loopfield%
        lb := hBtn
        o[hBtn] := px
        px += 98
    }
    GuiControl +Default, % (RegExMatch(Buttons, "([^\*\|]*)\*", Match)) ? Match1 : StrSplit(Buttons, "|")[1]

    Gui Show, Autosize Center Hide, %Title%
    DHW := A_DetectHiddenWindows
    DetectHiddenWindows On
    WinGetPos,,, ww,, ahk_id %hWnd%
    GuiControlGet p, Pos, %lb% ; Last button
    Off := ww - (((px + pw + 14) * A_ScreenDPI) // 96)
    For k, v in o {
        GuiControl Move, %k%, % "x" . (v + Off)
    }
    Guicontrol MoveDraw, f, % "x-1 y" . (y2 - 10) . " w" . ww . " h" . 48

    Gui Show
    Gui +SysMenu %Styles%
    DetectHiddenWindows %DHW%

    If (Timeout) {
        SetTimer MsgBoxExTIMEOUT, % Round(Timeout) * 1000
    }

    If (Owner) {
        WinSet Disable,, ahk_id %Owner%
    }

    GuiControl Focus, f
    Gui Font
    WinwaitClose ahk_id %hWnd%
    Return RetVal

    MsgBoxExESCAPE:
    MsgBoxExCLOSE:
    MsgBoxExTIMEOUT:
    MsgBoxExBUTTON:
        SetTimer MsgBoxExTIMEOUT, Delete

        If (A_ThisLabel == "MsgBoxExBUTTON") {
            RetVal := StrReplace(A_GuiControl, "&")
        } Else {
            RetVal := (A_ThisLabel == "MsgBoxExTIMEOUT") ? "Timeout" : "Cancel"
        }

        If (Owner) {
            WinSet Enable,, ahk_id %Owner%
        }

        Gui Submit
        Gui %hWnd%: Destroy
    Return
}
MessageBoxIndirect:

Code: Select all

Text := "No sound."

MessageBoxIndirect(Text, "Title", 0x80, "user32.dll", 104)

MessageBoxIndirect(Text, Title := "", Options := 0, IconRes := "", IconID := 1, Owner := 0) {
    If (IconRes != "") {
        hModule := DllCall("GetModuleHandle", "Str", IconRes, "Ptr")
        LoadLib := !hModule
            && hModule := DllCall("LoadLibraryEx", "Str", IconRes, "UInt", 0, "UInt", 0x2, "Ptr")
        Options |= 0x80 ; MB_USERICON
    } Else {
        hModule := 0
        LoadLib := False
    }

    ; MSGBOXPARAMS structure
    NumPut(VarSetCapacity(MBP, A_PtrSize * 7, 0), MBP, 0, "UInt")
    NumPut(Owner,   MBP, 1 * A_PtrSize, "Ptr")
    NumPut(hModule, MBP, 2 * A_PtrSize, "Ptr")
    NumPut(&Text,   MBP, 3 * A_PtrSize, "Ptr")
    NumPut(&Title,  MBP, 4 * A_PtrSize, "Ptr")
    NumPut(Options, MBP, 5 * A_PtrSize, "UInt")
    NumPut(IconID,  MBP, 6 * A_PtrSize, "Ptr")
    Ret := DllCall("MessageBoxIndirect", "Ptr", &MBP)

    If (LoadLib) {
        DllCall("FreeLibrary", "Ptr", hModule)
    }

    Return {1: "OK", 2: "Cancel", 3: "Abort", 4: "Retry", 5: "Ignore", 6: "Yes", 7: "No", 10: "Try Again", 11: "Continue"}[Ret]
}
It can also be done with the OnMessage trick:

Code: Select all

OnMessage(0x44, "OnMsgBox")
MsgBox 0x80, Title, No sound.
OnMessage(0x44, "")

OnMsgBox() {
    DetectHiddenWindows, On
    Process, Exist
    If (WinExist("ahk_class #32770 ahk_pid " . ErrorLevel)) {
        hIcon := LoadPicture("user32.dll", "w32 Icon5", _)
        SendMessage 0x172, 1, %hIcon% , Static1 ;STM_SETIMAGE
    }
}
Albireo
Posts: 1748
Joined: 16 Oct 2013, 13:53

Re: MsgBox 64 - Without "pling" - is it possible?

22 Jan 2018, 06:21

Thanks!
BoBo wrote:"pling" = alert/notification :arrow: system sounds. You could toggle the sound on/off before&after OR create your own Gui(Msg)Box.
Interesting suggestion, but I have no idea how to toggle the sound on/off before & after MsgBox with AHK.

Maybe I don't understand to use the other sugestions
MsgBoxEx .:
The AHK-program doesn't close when the button is pressed.
Is it possible to get more buttons? (Yes/No) / (Yes/No/Cancel)
It seems that it is possible to change both font and icon size - but I have not tested ...
i.e. When this code is used

Code: Select all

Text := "No sound."
Result := MsgBoxEx(Text, "Title", "OK", [5, "user32.dll"])
Result := MsgBoxEx("Test 1", "Title 1", "OK", [14, "Shell32.dll"])
Result := MsgBoxEx("Test 2", "Title 2", "Yes", [1, "Notepad.exe"])
It works! But next time the program is run, this message appear .: "An older instance of this script is already running...."
(Maybe the only solution is to use #SingleInstanse force?)

MessageBoxIndirect .:
MsgBox appears to closes, after the "OK" button is pressed.
But..
How to choose the icon from user32.dll is unclear.
It seems that you can get additional features (other buttons) - How?
What does the 0x80 or 104 mean?

OnMessage .:
Have the same problem as "MsgBoxEx" above - next time the program is run, this message appear .: "An older instance of this script is already running...."
What happens?
What does 0x80, 0x44 and 0x172 means?
It is possible to get more buttons (0x83 give "Yes" "No" and "Cancel")
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: MsgBox 64 - Without "pling" - is it possible?

22 Jan 2018, 06:39

Interesting suggestion, but I have no idea how to toggle the sound on/off before & after MsgBox with AHK.
You have > 350 posts in this forum but aren't able to check the AHK help for any command about Sound ?? :wtf:
User avatar
Alguimist
Posts: 428
Joined: 05 Oct 2015, 16:41
Contact:

Re: MsgBox 64 - Without "pling" - is it possible?

22 Jan 2018, 12:09

Albireo wrote:The AHK-program doesn't close when the button is pressed.
Exit the script with ExitApp.
Albireo wrote:Is it possible to get more buttons? (Yes/No) / (Yes/No/Cancel)
Separate each button name by a pipe character (|).
Albireo wrote:What does the 0x80, 104, 0x44 and 0x172 mean?
0x80 is MB_USERICON. A constant needed for custom icon.
104 is the resource ID of the icon. It is not the same as icon index.
0x44 is the value of an obsolete Windows message, internally used by AHK with another purpose.
0x172 is the value of the message STM_SETIMAGE.

The code I posted was generated by MagicBox, a tool included with AutoGUI.
Albireo
Posts: 1748
Joined: 16 Oct 2013, 13:53

Re: MsgBox 64 - Without "pling" - is it possible?

22 Jan 2018, 17:43

Thanks!
What is the best way to see which icons are available in, for example, User32.dll?
(Today, I right-click on a shortcut, select Properties, and choose Change Icon ... and select .: user32.dll)
Albireo
Posts: 1748
Joined: 16 Oct 2013, 13:53

Re: MsgBox 64 - Without "pling" - is it possible?

03 Feb 2018, 17:18

If I wish to create the icons to appear in MsgBoxEx(), is it possible?
(I have try to create MyIcon.ico - but but failed to make it work)

If there are other GUI windows in the same program - is that a problem? (or should the GUI window get a name: Gui, 1: ... and so on)
User avatar
Alguimist
Posts: 428
Joined: 05 Oct 2015, 16:41
Contact:

Re: MsgBox 64 - Without "pling" - is it possible?

03 Feb 2018, 18:40

Right below the predefined icons there's a button where you can select a custom icon.
Albireo wrote:If there are other GUI windows in the same program - is that a problem?
No, there will be no conflict with another GUI.
Albireo
Posts: 1748
Joined: 16 Oct 2013, 13:53

Re: MsgBox 64 - Without "pling" - is it possible?

04 Feb 2018, 10:38

Thank you!
Alguimist wrote:Right below the predefined icons there's a button where you can select a custom icon...
I'm not good at interpreting what's happening in the code...

Must the code in the function MsgBoxEx() be changed to handle e.g. ICO files?
ICO-files can not be handled in the function call?
Not sure how to do this!

If I understand correctly, is it even possible to affect both fonts and sounds.
Can it be done in the function call?
Albireo
Posts: 1748
Joined: 16 Oct 2013, 13:53

Re: MsgBox 64 - Without "pling" - is it possible?

04 Feb 2018, 12:40

In MsgBox [, Options, Title, Text, Timeout] the parameter "Timeout" exist.
Is "Timeout" possible to use in MsgBoxEx()?
User avatar
Alguimist
Posts: 428
Joined: 05 Oct 2015, 16:41
Contact:

Re: MsgBox 64 - Without "pling" - is it possible?

05 Feb 2018, 19:50

Albireo wrote:...
The answers to your questions are in the code. You should also try MagicBox that I already mentioned.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: hiahkforum, NullRefEx, ShatterCoder and 96 guests