Jump to content

_MsgBoxCustom


wraithdu
 Share

Recommended Posts

I had a need for a fully customizable MessageBox function that went beyond changing the text on the standard three buttons. Here's what I came up with. It should be documented well enough.

Thanks to Yashied and his Icons UDF. Parts are included (and attributed) in this UDF. Also thanks to trancexxx for her _StringSize function.

_MsgBoxCustom

#include-once
#include <WinAPI.au3>
#include <GuiMenu.au3>
#include <Constants.au3>
;~ #include <WindowsConstants.au3>

; #FUNCTION# ====================================================================================================
; Name...........:  _MsgBoxCustom
; Description....:  Create a custom message box.
; Syntax.........:  _MsgBoxCustom($sTitle, $sText, $aBut, $iIcon = 0, $sIcon = "", $iIndex = 0, $iOpt = 0, $iTimeout = 0, $hParent = 0, $ibWidth = 88, $ibHeight = 26)
; Parameters.....:  $sTitle     - Title of the message box
;                   $sText      - Text of the message box
;                   $aBut       - A string array of buttons
;                   $iIcon      - [Optional] Icon to display (Default = 0):
;                               | 1 - Stop Sign
;                               | 2 - Question Mark
;                               | 3 - Exclamation Point
;                               | 4 - Information
;                   $sIcon      - [Optional] If $iIcon is set to 0, optional path to icon file (ico or dll, Default = "")
;                   $iIndex     - [Optional] If $sIcon is a dll, the index of the icon to use (Default = 0)
;                   $iOpt       - [Optional] BitOR'd combination of display options (Default = 0):
;                               | 1 - Always on top
;                               | 2 - Message box will have a default button.  In this case, prepend the desired button text with a single * (asterisk).
;                                     Only the last button designated with a * will be the default.
;                               | 4 - Enable the close button (X) in the dialog
;                   $iTimeout   - [Optional] Timeout in seconds before dismissing the message box (Default = 0, returns -1)
;                   $hParent    - [Optional] Handle to a parent window (Default = 0)
;                   $ibWidth            - [Optional] Width of each button (Default = 88)
;                   $ibHeight           - [Optional] Height of each button (Default = 26)
;
; Return values..:  Success - 1-based index of button pressed, -1 if timed out, 0 if closed from close button (X)
;                   Failure - 0 and sets @error
; Author.........:  Erik Pilsits
; Modified.......:
; Remarks........:
; Related........:
; Link...........:
; Example........:
; ===============================================================================================================
Func _MsgBoxCustom($sTitle, $sText, $aBut, $iIcon = 0, $sIcon = "", $iIndex = 0, $iOpt = 0, $iTimeout = 0, $hParent = 0, $ibWidth = 88, $ibHeight = 26)
    Local $oldOpt = Opt("GUIOnEventMode", 0)
    ; styles
    Local $iStyle = 0x80C80000, $iExStyle = 1 ; default styles:  WS_POPUP|WS_CAPTION|WS_SYSMENU / WS_EX_DLGMODALFRAME
    ; display options
    Local $fDefBtn = False
    If BitAND($iOpt, 1) Then $iExStyle = BitOR($iExStyle, 8) ; WS_EX_TOPMOST
    If BitAND($iOpt, 2) Then $fDefBtn = True
    ; font
    Local $fSize = 9, $sFont = _GetSysFontInfo("lfFaceName5")
    Local $laHeight = _StringSize("ONE", $fSize, 400, 0, $sFont) ; get standard label height
    $laHeight = $laHeight[1]
    Local $size = _StringSize($sText, $fSize, 400, 0, $sFont)
    ; tpad is vertical space around text, rtpad is padding to right of text
    Local $tpad = 50, $rtpad = 40
    ; bpad is space between buttons, lpad is padding left of buttons, rpad is padding right of buttons, vpad is vertical padding around button area
    Local $bpad = 8, $lpad = 42, $rpad = 10, $vpad = 12
    Local $vpad2 = $vpad * 2
    ; icon
    Local $hIcon = 0, $iSound = 0
    If $iIcon Then
        ; use system icon
        Switch $iIcon
            Case 1
                $hIcon = _WinAPI_LoadImage(0, 32513, 1, 32, 32, 0x8000) ; IDI_STOP, LR_SHARED
                $iSound = 0x10
            Case 2
                $hIcon = _WinAPI_LoadImage(0, 32514, 1, 32, 32, 0x8000) ; IDI_QUESTION
                $iSound = 0x20
            Case 3
                $hIcon = _WinAPI_LoadImage(0, 32515, 1, 32, 32, 0x8000) ; IDI_EXCLAMATION
                $iSound = 0x30
            Case 4
                $hIcon = _WinAPI_LoadImage(0, 32516, 1, 32, 32, 0x8000) ; IDI_INFORMATION
                $iSound = 0x40
        EndSwitch
    ElseIf $sIcon Then
        ; use a custom ico or icon from a dll
        If $iIndex Then
            ; use a dll
            $hIcon = DllCall('shell32.dll', 'int', 'SHExtractIconsW', 'wstr', $sIcon, 'int', $iIndex, 'int', 32, 'int', 32, 'ptr*', 0, 'ptr*', 0, 'int', 1, 'int', 0)
            If @error Or (Not $hIcon[0]) Or (Not $hIcon[5]) Then
                $hIcon = 0
            Else
                $hIcon = $hIcon[5]
            EndIf
        Else
            ; use a custom ico
            $hIcon = _WinAPI_LoadImage(0, $sIcon, 1, 32, 32, 0x10) ; LR_LOADFROMFILE
        EndIf
    EndIf
    ; total width = combined width of buttons + edge borders + bpad * (# of buttons - 1) for space between
    Local $w = ($ibWidth * UBound($aBut)) + $lpad + $rpad + ($bpad * (UBound($aBut) - 1))
    Local $h, $xText, $yText
    If $hIcon Then
        ; make room for icon
        ; x pos = icon padding + icon right edge + extra padding
        $xText = ($tpad / 2) + 32 + 8
        If $size[1] > $laHeight Then
            ; more than one line
            ; height = button padding + button height + text padding + [greater of (text height + small offset) or icon height]
            $h = $vpad2 + $ibHeight + $tpad
            If $size[1] + 1 > 32 Then
                $h += $size[1] + 1
            Else
                $h += 32
            EndIf
            ; y pos
            $yText = ($tpad / 2) + 1
        Else
            ; one line
            ; height = button area + icon height + padding
            $h = $vpad2 + $ibHeight + 32 + $tpad
            ; y pos = ((icon height + padding) / 2) - (text height / 2)
            $yText = ((32 + $tpad) / 2) - ($size[1] / 2)
        EndIf
    Else
        ; no icon
        $rtpad -= 2
        ; height = button area + padding + text height
        $h = $vpad2 + $ibHeight + $tpad + $size[1]
        $xText = $vpad
        $yText = $tpad / 2
    EndIf
    ; width check to make room for long text or set minimum width
    If ($xText + $size[0] + $rtpad) > $w Then $w = $xText + $size[0] + $rtpad
    ; minW = total button width + space between buttons + lpad (magic) + rpad
    Local $minW = (($ibWidth * UBound($aBut)) + ($bpad * (UBound($aBut) - 1))) + $lpad + $rpad
    If $w < $minW Then $w = $minW ; at least minW wide
    ; create the gui
    Local $hGui = GUICreate($sTitle, $w, $h, Default, Default, $iStyle, $iExStyle, $hParent)
;~  GUISetBkColor(_WinAPI_GetSysColor($COLOR_WINDOW))
    GUISetBkColor(0xFFFFFF)
    GUISetFont($fSize, 400, 0, $sFont)
    ; some customizations
    ; remove icon
    DllCall("user32.dll", "int", "SetClassLong", "hwnd", $hGui, "int", -14, "long", 0) ; GCL_HICON
    DllCall("user32.dll", "int", "SetClassLong", "hwnd", $hGui, "int", -34, "long", 0) ; GCL_HICONSM
    ; disable / remove menu items
    Local $hMenu = _GUICtrlMenu_GetSystemMenu($hGui)
    _GUICtrlMenu_DeleteMenu($hMenu, 0, False) ; seperator
    _GUICtrlMenu_DeleteMenu($hMenu, 0xF000, False) ; SC_SIZE
    _GUICtrlMenu_DeleteMenu($hMenu, 0xF020, False) ; SC_MINIMIZE
    _GUICtrlMenu_DeleteMenu($hMenu, 0xF030, False) ; SC_MAXIMIZE
    If Not BitAND($iOpt, 4) Then _GUICtrlMenu_DeleteMenu($hMenu, 0xF060, False) ; SC_CLOSE
    _GUICtrlMenu_DeleteMenu($hMenu, 0xF120, False) ; SC_RESTORE
    ; create shading
    GUICtrlCreateLabel("", 0, $h - ($vpad2 + $ibHeight), $w, $vpad2 + $ibHeight)
;~  GUICtrlSetBkColor(-1, _WinAPI_GetSysColor($COLOR_MENU))
    GUICtrlSetBkColor(-1, 0xF0F0F0)
    GUICtrlSetState(-1, 128) ; GUI_DISABLE
    ; create icon
    If $hIcon Then
        _SetHIcon(GUICtrlGetHandle(GUICtrlCreateIcon("", 0, $tpad / 2, $tpad / 2, 32, 32)), $hIcon)
        _WinAPI_DestroyIcon($hIcon)
    EndIf
    ; set text
    GUICtrlCreateLabel($sText, $xText, $yText)
    ; create buttons
    Local $fMakeDef = False
    For $i = 0 To UBound($aBut) - 1
        If $fDefBtn And StringLeft($aBut[$i], 1) = "*" Then
            $aBut[$i] = StringTrimLeft($aBut[$i], 1)
            $fMakeDef = True
        EndIf
        ; horizontal displacement (from left) = (total width - rpad) - ((button width * (total buttons - $i)) + (bpad * (total buttons - ($i + 1))))
        Assign("iBut" & $i, GUICtrlCreateButton($aBut[$i], ($w - $rpad) - (($ibWidth * (UBound($aBut) - $i)) + ($bpad * (UBound($aBut) - ($i + 1)))), _
                $h - ($ibHeight + $vpad), $ibWidth, $ibHeight), 1) ; force local
        If $fMakeDef Then
            $fMakeDef = False
            GUICtrlSetState(-1, 512) ; GUI_DEFBUTTON
        EndIf
    Next
    ; show it
    GUISetState(@SW_SHOW, $hGui)
    ; play sound
    If $iSound Then DllCall("user32.dll", "bool", "MessageBeep", "uint", $iSound)
    Local $msg, $ret = 0, $iTime = TimerInit()
    $iTimeout *= 1000 ; convert timeout to ms
    ; loop
    While 1
        $msg = GUIGetMsg() ; no sleep in this loop, GUIGetMsg takes care of it
        For $i = 0 To UBound($aBut) - 1
            If $msg = Eval("iBut" & $i) Then
                $ret = $i + 1
                ExitLoop 2
            EndIf
        Next
        If $iTimeout And TimerDiff($iTime) > $iTimeout Then
            $ret = -1
            ExitLoop
        EndIf
        If $msg = -3 Then ExitLoop ; GUI_EVENT_CLOSE
    WEnd
    GUIDelete($hGui)
    Opt("GUIOnEventMode", $oldOpt)
    Return $ret
EndFunc   ;==>_MsgBoxCustom

; author: trancexxx
Func _StringSize($sText, $iSize = 8.5, $iWeight = 400, $iAttrib = 0, $sName = "MS Shell Dlg", $iQuality = 2, $hWnd = 0)
    Local Const $LOGPIXELSY = 90
    Local $fItalic = BitAND($iAttrib, 2)
    Local $hDC = _WinAPI_GetDC($hWnd)
    Local $hFont = _WinAPI_CreateFont(-_WinAPI_GetDeviceCaps($hDC, $LOGPIXELSY) * $iSize / 72, 0, 0, 0, _
            $iWeight, $fItalic, BitAND($iAttrib, 4), BitAND($iAttrib, 8), 0, 0, 0, $iQuality, 0, $sName)
    Local $hOldFont = _WinAPI_SelectObject($hDC, $hFont)
    Local $tSIZE
    Local $iWidth = 0, $iHeight = 0
    Local $aArrayOfStrings = StringSplit(StringStripCR($sText), @LF, 2)
    For $sString In $aArrayOfStrings
        If $fItalic Then $sString &= " "
        $tSIZE = _WinAPI_GetTextExtentPoint32($hDC, $sString)
        If DllStructGetData($tSIZE, "X") > $iWidth Then $iWidth = DllStructGetData($tSIZE, "X")
        $iHeight += DllStructGetData($tSIZE, "Y")
    Next
    _WinAPI_SelectObject($hDC, $hOldFont)
    _WinAPI_DeleteObject($hFont)
    _WinAPI_ReleaseDC($hWnd, $hDC)
    Local $aOut[2] = [$iWidth, $iHeight]
    Return $aOut
EndFunc   ;==>_StringSize

Func _GetSysFontInfo($sElem)
    Local Const $LF_FACESIZE = 32
    ; 14 elements
    Local Const $tagLOGFONTW = "long lfHeight;long lfWidth;long lfEscapement;long lfOrientation;long lfWeight;byte lfItalic;byte lfUnderline;byte lfStrikeOut;" _
            & "byte lfCharSet;byte lfOutPrecision;byte lfClipPrecision;byte lfQuality;byte lfPitchAndFamily;wchar lfFaceName[" & $LF_FACESIZE & "]"
    ; font structs in order: lfCaptionFont, lfSmCaptionFont, lfMenuFont, lfStatusFont, lfMessageFont
    Local Const $tagNONCLIENTMETRICS = "uint cbSize;int iBorderWidth;int iScrollWidth;int iScrollHeight;int iCaptionWidth;int iCaptionHeight;" _
            & _SuffixStruct($tagLOGFONTW, 1) & ";" & "int iSmCaptionWidth;int iSmCaptionHeight;" & _SuffixStruct($tagLOGFONTW, 2) & ";int iMenuWidth;" _
            & "int iMenuHeight;" & _SuffixStruct($tagLOGFONTW, 3) & ";" & _SuffixStruct($tagLOGFONTW, 4) & ";" & _SuffixStruct($tagLOGFONTW, 5)
    Local Const $NONCLIENTMETRICS = DllStructCreate($tagNONCLIENTMETRICS)
    DllStructSetData($NONCLIENTMETRICS, "cbSize", DllStructGetSize($NONCLIENTMETRICS))
    Local $ret = DllCall("user32.dll", "bool", "SystemParametersInfoW", "uint", 41, "uint", DllStructGetSize($NONCLIENTMETRICS), _
            "ptr", DllStructGetPtr($NONCLIENTMETRICS), "uint", 0) ; 41 = SPI_GETNONCLIENTMETRICS
    Return DllStructGetData($NONCLIENTMETRICS, $sElem)
EndFunc   ;==>_GetSysFontInfo

Func _SuffixStruct($sStruct, $suff)
    ; suffixes elements in a structure with a given string
    ; useful when embedding multiple copies of a structure within another structure
    Return StringRegExpReplace(StringRegExpReplace($sStruct, "\[", $suff & "["), "([^\]])\s*;", "${1}" & $suff & ";")
EndFunc   ;==>_IncrStruct

#cs
    Title:          Support for Icons UDF Library for AutoIt3
    Filename:       Icons.au3
    Description:    Additional and corrected functions for working with icons
    Author:         Yashied
    Version:        1.8
    Requirements:   AutoIt v3.3 +, Developed/Tested on WindowsXP Pro Service Pack 2
    Uses:           Constants.au3, GDIPlus.au3, WinAPI.au3, WindowsConstants.au3
    Notes:          -

                    http://www.autoitscript.com/forum/index.php?showtopic=92675
#ce

Func _SetHIcon($hWnd, $hIcon, $hOverlap = 0)

;~  $hWnd = _Icons_Control_CheckHandle($hWnd)
    If $hWnd = 0 Then
        Return SetError(1, 0, 0)
    EndIf

;~  If Not ($hOverlap < 0) Then
;~      $hOverlap = _Icons_Control_CheckHandle($hOverlap)
;~  EndIf
;~  $hIcon = _Icons_Icon_Duplicate($hIcon)
    $hIcon = _WinAPI_CopyIcon($hIcon)
    If Not _Icons_Control_SetImage($hWnd, $hIcon, $IMAGE_ICON, $hOverlap) Then
        If $hIcon Then
            _WinAPI_DestroyIcon($hIcon)
        EndIf
        Return SetError(1, 0, 0)
    EndIf
    Return 1
EndFunc   ;==>_SetHIcon

Func _Icons_Control_SetImage($hWnd, $hImage, $iType, $hOverlap)

    Local Const $__SS_BITMAP = 0x0E
    Local Const $__SS_ICON = 0x03
    Local Const $__STM_SETIMAGE = 0x0172
    Local Const $__STM_GETIMAGE = 0x0173

    Local $Static, $Style, $Update, $tRect, $hPrev

    Switch $iType
        Case $IMAGE_BITMAP
            $Static = $__SS_BITMAP
        Case $IMAGE_ICON
            $Static = $__SS_ICON
        Case Else
            Return 0
    EndSwitch

    $Style = _WinAPI_GetWindowLong($hWnd, $GWL_STYLE)
    If @error Then
        Return 0
    EndIf
    _WinAPI_SetWindowLong($hWnd, $GWL_STYLE, BitOR($Style, $Static))
    If @error Then
        Return 0
    EndIf
    $tRect = _Icons_Control_GetRect($hWnd)
    $hPrev = _SendMessage($hWnd, $__STM_SETIMAGE, $iType, $hImage)
    If @error Then
        Return 0
    EndIf
    If $hPrev Then
        If $iType = $IMAGE_BITMAP Then
            _WinAPI_DeleteObject($hPrev)
        Else
            _WinAPI_DestroyIcon($hPrev)
        EndIf
    EndIf
    If (Not $hImage) And (IsDllStruct($tRect)) Then
        _WinAPI_MoveWindow($hWnd, DllStructGetData($tRect, 1), DllStructGetData($tRect, 2), DllStructGetData($tRect, 3) - DllStructGetData($tRect, 1), DllStructGetData($tRect, 4) - DllStructGetData($tRect, 2), 0)
    EndIf
;~  If $hOverlap Then
;~      If Not IsHWnd($hOverlap) Then
;~          $hOverlap = 0
;~      EndIf
;~      _Icons_Control_Update($hWnd, $hOverlap)
;~  Else
        _Icons_Control_Invalidate($hWnd)
;~  EndIf
    Return 1
EndFunc   ;==>_Icons_Control_SetImage

Func _Icons_Control_GetRect($hWnd)

    Local $Pos = ControlGetPos($hWnd, '', '')

    If (@error) Or ($Pos[2] = 0) Or ($Pos[3] = 0) Then
        Return 0
    EndIf

    Local $tRect = DllStructCreate($tagRECT)

    DllStructSetData($tRect, 1, $Pos[0])
    DllStructSetData($tRect, 2, $Pos[1])
    DllStructSetData($tRect, 3, $Pos[0] + $Pos[2])
    DllStructSetData($tRect, 4, $Pos[1] + $Pos[3])

    Return $tRect
EndFunc   ;==>_Icons_Control_GetRect

Func _Icons_Control_Invalidate($hWnd)

    Local $tRect = _Icons_Control_GetRect($hWnd)

    If IsDllStruct($tRect) Then
        _WinAPI_InvalidateRect(_WinAPI_GetParent($hWnd), $tRect)
    EndIf
EndFunc   ;==>_Icons_Control_Invalidate

Examples:

#NoTrayIcon
#include <_MsgBoxCustom.au3>

Dim $a[1] = ["Ok"]
ConsoleWrite(_MsgBoxCustom("My Title", "Basic Ok box.", $a) & @CRLF)
Dim $a[4] = ["Yes", "No", "Maybe", "Cancel"]
ConsoleWrite(_MsgBoxCustom("My Title", "My Text", $a, 1) & @CRLF)
ConsoleWrite(_MsgBoxCustom("My Title", "Always on top display option.", $a, 2, "", 0, 1) & @CRLF)
ConsoleWrite(_MsgBoxCustom("My Title", "My Text", $a, 3) & @CRLF)
ConsoleWrite(_MsgBoxCustom("My Title", "My Text", $a, 4) & @CRLF)
ConsoleWrite(_MsgBoxCustom("My Title", "My Text" & @CRLF & "With a second line...", $a) & @CRLF)
ConsoleWrite(_MsgBoxCustom("My Title", "My Text" & @CRLF & "Second line and icon from ICO file.", $a, 0, "C:\Program Files\AutoIt3\Icons\au3.ico") & @CRLF)
ConsoleWrite(_MsgBoxCustom("My Title", "My Text" & @CRLF & "Second line and icon from a DLL.", $a, 0, "shell32.dll", -10) & @CRLF)
ConsoleWrite(_MsgBoxCustom("My Title", "Timeout in 5 seconds." & @CRLF & "With a second line..." & @CRLF & "And a third.", _
        $a, 1, "", 0, 0, 5) & @CRLF)
Dim $a[4] = ["Yes", "No", "*Maybe", "Cancel"]
ConsoleWrite(_MsgBoxCustom("My Title", "'Maybe' as the default button." & @CRLF & "With a second line..." & @CRLF & "And a third." & @CRLF & "And a fourth.", _
        $a, 3, "", 0, 2) & @CRLF)
Edited by wraithdu
Link to comment
Share on other sites

I got white background... beside that looks very good!

P.S

The closing button (and the menu items) should be disabled only when there is a "question buttons" (Yes / No).

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Hmmm, what system color would that gray color be then? COLOR_3DFACE maybe?

Also I'm aware of the close button thing... but with totally free-form button control, I don't have a reliable way to programatically control that.

Link to comment
Share on other sites

Ok, I see. WinXP is an all gray MsgBox background... Where does Windows pull that MsgBox main background color? COLOR_WINDOW is white on both XP and 7, and COLOR_MENU=COLOR_3DFACE (which I was using) is a shade of gray on both XP and 7. So I need one COLOR value that is gray on XP and white on 7...

Edited by wraithdu
Link to comment
Share on other sites

Hmmm, what system color would that gray color be then? COLOR_3DFACE maybe?

Yes.

I don't have a reliable way to programatically control that

Well, you just need to check the buttons... but to be honest, this is not the most convinient way of using such function, i have one of my own functions to mimic the system message box, and it's as well written totaly with GUI, but uses almost the same flags as the original one, plus extra options.

If you want i can post it here, or send it to you via PM...

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Nah, that's ok. It's a trivial functional difference. Maybe I'll add another flag to the options for it. As it stands, there's no way to properly check arbitrary button text for the same type of functionality.

Anyway, see my second post above about the colors...

Edited by wraithdu
Link to comment
Share on other sites

See if this update looks a little better on XP

Is this is how it's supose to look:

Posted Image

:mellow:

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

  • 1 month later...

In windows xp, using _MsgBoxCustom will break the main gui icon.I tried using GUISetIcon to get it to go back, but it just leaves a blank system icon after _MsgBoxCustom runs.

I dont see this behavior in windows 7 though.

screenshot:

Posted Image

Link to comment
Share on other sites

  • 3 months later...

@gr1fter

Hmm, actually I see that behavior in Windows 7 and NOT Windows XP. Odd. I remove the icon from the message box with:

DllCall("user32.dll", "int", "SetClassLong", "hwnd", $hGui, "int", -14, "long", 0) ; GCL_HICON
DllCall("user32.dll", "int", "SetClassLong", "hwnd", $hGui, "int", -34, "long", 0) ; GCL_HICONSM

But I don't see why this should affect the parent window, as I specify the correct window handle.

@FeReNGi

I can't reproduce that on either Win7 or WinXP. I tried up to 6 lines of text and it resizes correctly.

EDIT:

I guess since both GUI windows have the same window class, modifying the icon of one with SetClassLong changes both.

Edited by wraithdu
Link to comment
Share on other sites

  • 1 year later...
  • 3 years later...

Old thread I know...

But this morning I have to recompile an old script (to add recognition of @osversion = "win_10").

And this UDF in no longer compiled with 3.3.14.1 (I think I compiled last time with 3.3.10.2, maybe...).

I have this error:

"C:\Program Files (x86)\AutoIt3\Include\_MsgBoxCustom.au3"(235,97) : warning: $ret: declared, but not used in func.
            "ptr", DllStructGetPtr($NONCLIENTMETRICS), "uint", 0) ; 41 = SPI_GETNONCLIENTMETRICS
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Program Files (x86)\AutoIt3\Include\_MsgBoxCustom.au3"(279,63) : warning: $hOverlap: declared, but not used in func.
Func _Icons_Control_SetImage($hWnd, $hImage, $iType, $hOverlap)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Program Files (x86)\AutoIt3\Include\_MsgBoxCustom.au3"(284,41) : warning: $__STM_GETIMAGE: declared, but not used in func.
    Local Const $__STM_GETIMAGE = 0x0173
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Program Files (x86)\AutoIt3\Include\_MsgBoxCustom.au3"(286,35) : warning: $Update: declared, but not used in func.
    Local $Static, $Style, $Update,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

Any ideas ?

 

Link to comment
Share on other sites

Au3Check is showing you warnings, though it should compile. How to fix them,  the comments are kind of obvious, do you not understand what the following means?

warning: $Update: declared, but not used in func.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...