Jump to content
Melba23

Extended Message Box - New Version: 2 Aug 18

Recommended Posts

I believe it is because StringSize, or the EMB is creating ControlIDs that are causing the media player's control IDs to get changed, so I'm updating the wrong controls after calling this function.

Sorry, but that is complete garbage. ;)

AutoIt ControlIDs are internally organised by AutoIt so unless we are using exactly the same variable names in Global scope there is no way any UDF can change the ControlIDs within a script calling it.

The only Global constants and variable names in the release version of ExtMsgBox are:

; #GLOBAL CONSTANTS# =================================================================================================
Global Const $MB_IConstop   = 16 ; Stop-sign icon
Global Const $MB_ICONQUERY  = 32 ; Question-mark icon
Global Const $MB_ICONEXCLAM = 48 ; Exclamation-point icon
Global Const $MB_ICONINFO   = 64 ; Icon consisting of an 'i' in a circle

; #GLOBAL VARIABLES# =================================================================================================
Global $iDef_EMB_Font_Size = _GetDefaultEMBFont(0)
Global $sDef_EMB_Font_Name = _GetDefaultEMBFont(1)
Global $iEMB_Style = 0
Global $iEMB_Just = 0
Global $iEMB_BkCol = Default
Global $iEMB_Col   = Default
Global $sEMB_Font_Name = $sDef_EMB_Font_Name
Global $iEMB_Font_Size = $iDef_EMB_Font_Size

There are none at all in StringSize. All other variables are Local in scope.

So unless your media player controls store their ControlIDs in variables with exactly those names, there cannot be any interference. I use EMB all the time in my own media player (which includes timers, progress bars and volume controls) and have absolutely no problems at all. :)

I am happy to try and help you solve the problem you are having with your script, but it is certainly not what you are currently suggesting. ;)

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

I found out why it was doing this after I looked at the variables I was using to call the EMB function, and found that it wasn't the UDF that was messing it up, it was me using variable names in the calling routine that was doing it.

What I had done was to copy the _ExtMsgBox function routine from your UDF (_ExtMsgBox($iIcon, $iButton, $sTitle, $sText, $iTimeout = 0, $hWin = "", $iVPos = 0)) then used that as the method to call the function in my script because I wanted to make sure that I called it with the correct parameters in the correct places, totally forgetting that some of the variable names you used in your function were the same as some of the variable names I was using in my script. So of course it was screwing up my script because I wasn't paying attention as I should have when using it.

I feel pretty dumb at the moment, but I view it as a learning experience and hopefully won't make this same mistake in the future. ;)

I apologize for any misinformation that I posted about this excellent function because as I have said before, I really find it to be invaluable to have in my toolbox.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

BrewManNH,

No problem. Thanks for owning up and clearing my UDF. ;)

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

AWESOME UDF.

I'm trying the example right now and I can't figure out why the first msgBox (the one with 1 to 4 buttons) doesn't disable the parent GUI. I didn't change any code in the example script.

I'm using AutoIt version 3.3.6.1.

Share this post


Link to post
Share on other sites

leomoon,

why the first msgBox (the one with 1 to 4 buttons) doesn't disable the parent GUI

I thought it did! :(

You can certainly action the buttons on the parent "EMB Test" GUI but are you saying that they actually work while the "Test 1" EMB is displayed? If so I would like to know as they certainly do not work when I run the example. :graduated:

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Oo. Maybe I don't know how it's spouse to work. I though when you run the first msbBox it should disable the parent so you can not click the parent anymore. No? If it just disables the buttons on the parent GUI then it works perfect. :graduated: It's ok now. I got it working with a few more lines.

Also with the centering msgBox to the main GUI or to the desktop, it does not work on multi monitors. When you move the parent GUI to the second monitor (right monitor), the msgBox will appear at the edge of the first monitor... So I modified your code a bit to make it work for multi monitor:

#include-once

;Getting true desktop with and height
$aTSR = _GetTotalScreenResolution()

;Original code by Larry.
;Edited by BrettF
Func _GetTotalScreenResolution()
    Local $aRet[2]
    Global Const $SM_VIRTUALWIDTH = 78
    Global Const $SM_VIRTUALHEIGHT = 79
    $VirtualDesktopWidth = DllCall("user32.dll", "int", "GetSystemMetrics", "int", $SM_VIRTUALWIDTH)
    $aRet[0] = $VirtualDesktopWidth[0]
    $VirtualDesktopHeight = DllCall("user32.dll", "int", "GetSystemMetrics", "int", $SM_VIRTUALHEIGHT)
    $aRet[1] = $VirtualDesktopHeight[0]
    Return $aRet
EndFunc

; #INDEX# ============================================================================================================
; Title .........: ExtMsgBox
; AutoIt Version : v3.2.12.1 or higher
; Language ......: English
; Description ...: Generates user defined message boxes centred on an owner, on screen or at defined coordinates
; Remarks .......:
; Note ..........:
; Author(s) .....: Melba23, based on some original code by photonbuddy & YellowLab
; ====================================================================================================================

;#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6

; #INCLUDES# =========================================================================================================
#include "StringSize.au3"

; #GLOBAL CONSTANTS# =================================================================================================
Global Const $MB_IConstop   = 16 ; Stop-sign icon
Global Const $MB_ICONQUERY  = 32 ; Question-mark icon
Global Const $MB_ICONEXCLAM = 48 ; Exclamation-point icon
Global Const $MB_ICONINFO   = 64 ; Icon consisting of an 'i' in a circle

; #GLOBAL VARIABLES# =================================================================================================
Global $iDef_EMB_Font_Size = _GetDefaultEMBFont(0)
Global $sDef_EMB_Font_Name = _GetDefaultEMBFont(1)
Global $iEMB_Style = 0
Global $iEMB_Just = 0
Global $iEMB_BkCol = Default
Global $iEMB_Col   = Default
Global $sEMB_Font_Name = $sDef_EMB_Font_Name
Global $iEMB_Font_Size = $iDef_EMB_Font_Size

; #CURRENT# ==========================================================================================================
; _ExtMsgBoxSet: Sets the GUI style, justification, colours and font for subsequent _ExtMsgBox function calls
; _ExtMsgBox:    Generates user defined message boxes centred on an owner, on screen or at defined coordinates
; ====================================================================================================================

; #INTERNAL_USE_ONLY#=================================================================================================
; _GetDefaultEMBFont: Determines Windows default MsgBox font size and name
; ====================================================================================================================

; #FUNCTION# =========================================================================================================
; Name...........: _ExtMsgBoxSet
; Description ...: Sets the GUI style, justification, colours and font for subsequent _ExtMsgBox function calls
; Syntax.........: _ExtMsgBoxSet($iStyle, $iJust, [$iBkCol, [$iCol, [$sFont_Size, [$iFont_Name]]]])
; Parameters ....: $iStyle      -> 0 = Normal - Button appears on TaskBar (Default), 1 = Button does not appear on TaskBar
;                   >>>>>>>>>>     Setting this parameter to 'Default' will reset ALL parameters to default values <<<<<<<<<<
;                  $iJust       -> 0 = Left justified (Default), 1 = Centred , 2 = Right justified
;                                  + 4 = Centred single button.  Note: multiple buttons are always centred
;                                  ($SS_LEFT, $SS_CENTER, $SS_RIGHT can also be used)
;                   $iBkCol     -> The colour for the message box background.  Default = system colour
;                   $iCol       -> The colour for the message box text.  Default = system colour
;                                  Omitting a colour parameter or setting -1 leaves it unchanged
;                                  Setting a colour parameter to Default resets the system message box colour
;                   $iFont_Size -> The font size in points to use for the message box. Default = system font size
;                   $sFont_Name -> The font to use for the message box. Default = system font
;                                  Omitting a font parameter or setting  font size to -1 or font name to "" = unchanged
;                                  Setting a font parameter to Default resets the system message box font and size
; Requirement(s).: v3.2.12.1 or higher
; Return values .: Success - Returns 1
;                  Failure - Returns 0 and sets @error to 1 with @extended set to parameter index number
; Remarks .......;
; Author ........: Melba23
; Example........; Yes
;=====================================================================================================================

Func _ExtMsgBoxSet($iStyle = 0, $iJust = 0, $iBkCol = -1, $iCol = -1, $iFont_Size = -1, $sFont_Name = "")

    Local $aRet

    ; Set global EMB variables to required values
    Switch $iStyle
        Case Default
            $iEMB_Style = 0
            $iEMB_Just = 0 ; $SS_LEFT
            $aRet = DllCall("User32.dll", "int", "GetSysColor", "int", 5) ; $COLOR_WINDOW = 5
            $iEMB_BkCol = $aRet[0]
            $aRet = DllCall("User32.dll", "int", "GetSysColor", "int", 8) ; $COLOR_WINDOWTEXT = 8
            $iEMB_Col = $aRet[0]
            $sEMB_Font_Name = $sDef_EMB_Font_Name
            $iEMB_Font_Size = $iDef_EMB_Font_Size
            Return
        Case 0, 1
            $iEMB_Style = $iStyle
        Case Else
            Return SetError(1, 1, 0)
    EndSwitch

    Switch $iJust
        Case 0, 1, 2, 4, 5, 6
            $iEMB_Just = $iJust
        Case Else
            Return SetError(1, 2, 0)
    EndSwitch

    Switch $iBkCol
        Case Default
            $aRet = DllCall("User32.dll", "int", "GetSysColor", "int", 5) ; $COLOR_WINDOW = 5
            $iEMB_BkCol = $aRet[0]
        Case -1
            ; Do nothing
        Case 0 To 0xFFFFFF
            $iEMB_BkCol = $iBkCol
        Case Else
            Return SetError(1, 3, 0)
    EndSwitch

    Switch $iCol
        Case Default
            $aRet = DllCall("User32.dll", "int", "GetSysColor", "int", 8) ; $COLOR_WINDOWTEXT = 8
            $iEMB_Col = $aRet[0]
        Case -1
            ; Do nothing
        Case 0 To 0xFFFFFF
            $iEMB_Col = $iCol
        Case Else
            Return SetError(1, 4, 0)
    EndSwitch

    Switch $iFont_Size
        Case Default
            $iEMB_Font_Size = $iDef_EMB_Font_Size
        Case 8 To 72
            $iEMB_Font_Size = Int($iFont_Size)
        Case -1
            ; Do nothing
        Case Else
            Return SetError(1, 5, 0)
    EndSwitch

    Switch $sFont_Name
        Case Default
            $sEMB_Font_Name = $sDef_EMB_Font_Name
        Case ""
            ; Do nothing
        Case Else
            If IsString($sFont_Name) Then
                $sEMB_Font_Name = $sFont_Name
            Else
                Return SetError(1, 6, 0)
            EndIf
    EndSwitch

    Return 1

EndFunc

; #FUNCTION# =========================================================================================================
; Name...........: _ExtMsgBox
; Description ...: Generates user defined message boxes centred on an owner, on screen or at defined coordinates
; Syntax.........: _ExtMsgBox ($iIcon, $iButton, $sTitle, $sText, [$iTimeout, [$hWin, [$iTop]]])
; Parameters ....: $iIcon       -> The $MB_ICON constant for the icon to use:
;                                  0 - No icon, 16 - Stop, 32 - Query, 48 - Exclamation, 64 - Information
;                                  Any other value returns -1, error 1
;                   $iButton    -> Button text separated with "|" character. An ampersand (&)before the text indicates
;                                  the default button. Two focus ampersands returns -1, error 2.
;                                  Can also use $MB_ button constants:
;                                  0 = "OK", 1 = "OK|Cancel", 2 = "Abort|Retry|Ignore", 3 = "Yes|No|Cancel"
;                                  4 = "Yes|No", 5 = "Retry|Cancel" Incorrect constant returns -1, error 3
;                                  Default max width of 370 gives 1-4 buttons @ width 80, 5 @ width 60, 6 @ width 50
;                                  Min button width set at 50, so 7 buttons returns -1, error 4 unless default changed
;                   $sTitle     -> The title of the message box
;                   $sText      -> The text to be displayed. Long lines will wrap. The box depth is adjusted to fit
;                   $iTimeout   -> Timeout delay before EMB closes. 0 = no timeout (Default)
;                   $hWin       -> Handle of the window in which EMB is centred
;                                  If window is hidden or no handle passed EMB centred in display (Default)
;                                  If parameter holds number which is not a valid window handle,
;                                  it is interpreted as horizontal coordinate for EMB location
;                   $iVPos      -> Vertical parameter for EMB location, only if $hWin parameter is
;                                  interpreted as horizontal coordinate.  (Default = 0)
; Requirement(s).: v3.2.12.1 or higher
; Return values .: Success: Returns 1-based index of the button pressed, counting from the LEFT.
;                           Returns 0 if closed by a "CloseGUI" event (i.e. click [X] or press Escape)
;                           Returns 9 if timed out
;                  Failure: Returns -1 and sets @error as follows:
;                               1 - Icon error
;                               2 - Multiple default button error
;                               3 - Button constant error
;                               4 - Too many buttons to fit max GUI size
;                               5 - StringSize error
;                               6 - GUI creation error
; Remarks .......; EMB position automatically adjusted to appear on screen
; Author ........: Melba23, based on some original code by photonbuddy & YellowLab
; Example........; Yes
;=====================================================================================================================

Func _ExtMsgBox($iIcon, $iButton, $sTitle, $sText, $iTimeout = 0, $hWin = "", $iVPos = 0)

    Local $iParent_Win = 0

    Local $nOldOpt = Opt('GUIOnEventMode', 0)

    ; Set default sizes for message box
    Local $iMsg_Width_max = 370, $iMsg_Width_min = 150
    Local $iMsg_Height_min = 100
    Local $iButton_Width_max = 80, $iButton_Width_min = 50

    ; Declare local variables
    Local $iButton_Width_Req, $iButton_Width, $iButton_Xpos, $iRet_Value, $iHpos, $iIcon_Style

    ; Check for icon
    Local $iIcon_Reduction = 50
    Switch $iIcon
        Case 0
            $iIcon_Reduction = 0
        Case 16 ; Stop
            $iIcon_Style = -4
        Case 32 ; Query
            $iIcon_Style = -3
        Case 48 ; Exclam
            $iIcon_Style = -2
        Case 64 ; Info
            $iIcon_Style = -5
        Case Else
            $nOldOpt = Opt('GUIOnEventMode', $nOldOpt)
            Return SetError(1, 0, -1)
    EndSwitch

    ; Check if using constants or text
    If IsNumber($iButton) Then
        Switch $iButton
            Case 0
                $iButton = "OK"
            Case 1
                $iButton = "OK|Cancel"
            Case 2
                $iButton = "Abort|Retry|Ignore"
            Case 3
                $iButton = "Yes|No|Cancel"
            Case 4
                $iButton = "Yes|No"
            Case 5
                $iButton = "Retry|Cancel"
            Case Else
                $nOldOpt = Opt('GUIOnEventMode', $nOldOpt)
                Return SetError(3, 0, -1)
        EndSwitch
    EndIf

    ; Check if two buttons are seeking focus
    If StringInStr($iButton, "&", 0, 2) <> 0 Then
        $nOldOpt = Opt('GUIOnEventMode', $nOldOpt)
        Return SetError(2, 0, -1)
    EndIf

    ; Get individual button text
    Local $aButtons = StringSplit($iButton, "|")
    ; Get minimum GUI width needed for buttons
    Local $iMsg_Width_Button = ($iButton_Width_max + 10) * $aButtons[0] + 10
    ; If shorter than min width
    If $iMsg_Width_Button < $iMsg_Width_min Then
        ; Set buttons to max size and leave box min width unchanged
        $iButton_Width = $iButton_Width_max
    Else
        ; Check button width needed to fit within max box width
        $iButton_Width_Req = ($iMsg_Width_max - (($aButtons[0] + 1) * 10)) / $aButtons[0]
        ; Button width less than min button width permitted
        If $iButton_Width_Req < $iButton_Width_min Then
            $nOldOpt = Opt('GUIOnEventMode', $nOldOpt)
            Return SetError(4, 0, -1)
            ; Buttons only need resizing to fit
        ElseIf $iButton_Width_Req < $iButton_Width_max Then
            ; Set box to max width and set button size as required
            $iMsg_Width_Button = $iMsg_Width_max
            $iButton_Width = $iButton_Width_Req
            ; Buttons can be max size
        Else
            ; Set box min width to fit buttons
            $iButton_Width = $iButton_Width_max
            $iMsg_Width_min = $iMsg_Width_Button
        EndIf
    EndIf

    ; Now get message label size
    Local $aLabel_Pos = _StringSize($sText, $iEMB_Font_Size, Default, Default, $sEMB_Font_Name, $iMsg_Width_max - 20 - $iIcon_Reduction)
    If @error Then
        $nOldOpt = Opt('GUIOnEventMode', $nOldOpt)
        Return SetError(5, 0, -1)
    EndIf

    ; Reset text to wrapped version
    $sText = $aLabel_Pos[0]

    ; Set label size
    Local $iLabel_Width = $aLabel_Pos[2]
    Local $iLabel_Height = $aLabel_Pos[3]
    ; Set GUI size
    Local $iMsg_Width = $iLabel_Width + 20 + $iIcon_Reduction
    If $iMsg_Width < $iMsg_Width_min Then
        $iMsg_Width = $iMsg_Width_min
        $iLabel_Width = $iMsg_Width_min - 20
    EndIf
    Local $iMsg_Height = $iLabel_Height + 65
    If $iMsg_Height < $iMsg_Height_min Then $iMsg_Height = $iMsg_Height_min

    ; If only single line, lower label to to centre text on icon
    Local $iLabel_Vert = 20
    If StringInStr($sText, @CRLF) = 0 Then $iLabel_Vert = 27

    ; Check for style required
    If $iEMB_Style = 1 Then ; Hide taskbar button so create as child
        If IsHWnd($hWin) Then
            $iParent_Win = $hWin ; Make child of that window
        Else
            $iParent_Win = WinGetHandle(AutoItWinGetTitle()) ; Make child of AutoIt window
        EndIf
    EndIf

    ; Determine EMB location
    If $hWin = "" Then
        ; No handle or position passed so centre on screen
        $iHpos = ($aTSR[0] - $iMsg_Width) / 2
        $iVPos = ($aTSR[1] - $iMsg_Height) / 2
    Else
        If IsHWnd($hWin) Then
            ; Get parent GUI pos if visible
            If BitAND(WinGetState($hWin), 2) Then
                ; Set EMB to centre on parent
                Local $aPos = WinGetPos($hWin)
                $iHpos = ($aPos[2] - $iMsg_Width) / 2 + $aPos[0] - 3
                $iVPos = ($aPos[3] - $iMsg_Height) / 2 + $aPos[1] - 20
            Else
                ; Set EMB to centre om screen
                $iHpos = ($aTSR[0] - $iMsg_Width) / 2
                $iVPos = ($aTSR[1] - $iMsg_Height) / 2
            EndIf
        Else
            ; Assume parameter is horizontal coord
            $iHpos = $hWin ; $iVpos already set
        EndIf
    EndIf

    ; Now check to make sure GUI is visible on screen
    ; First horizontally
    If $iHpos < 10 Then $iHpos = 10
    If $iHpos + $iMsg_Width > $aTSR[0] - 20 Then $iHpos = $aTSR[0] - 20 - $iMsg_Width
    ; Then vertically
    If $iVPos < 10 Then $iVPos = 10
    If $iVPos + $iMsg_Height > $aTSR[1] - 60 Then $iVPos = $aTSR[1] - 60 - $iMsg_Height

    ; Create GUI with $WS_POPUPWINDOW, $WS_CAPTION style and $WS_EX_TOPMOST extended style
    Local $hMsgGUI = GUICreate($sTitle, $iMsg_Width, $iMsg_Height, $iHpos, $iVPos, BitOR(0x80880000, 0x00C00000), 0x00000008, $iParent_Win)
    If @error Then
        $nOldOpt = Opt('GUIOnEventMode', $nOldOpt)
        Return SetError(6, 0, -1)
    EndIf
    GUISetFont($iEMB_Font_Size, Default, Default, $sEMB_Font_Name)
    If $iEMB_BkCol <> Default Then GUISetBkColor($iEMB_BkCol)

    ; Set centring parameter
    Local $iLabel_Style = 0 ; $SS_LEFT
    If BitAND($iEMB_Just, 1) = 1 Then
        $iLabel_Style = 1 ; $SS_CENTER
    ElseIf BitAND($iEMB_Just, 2) = 2 Then
        $iLabel_Style = 2 ; $SS_RIGHT
    EndIf

    ; Create label
    GUICtrlCreateLabel($sText, 10 + $iIcon_Reduction, $iLabel_Vert, $iLabel_Width, $iLabel_Height, $iLabel_Style)
    GUICtrlSetFont(-1, $iEMB_Font_Size, 400, 0, $sEMB_Font_Name)
    If $iEMB_Col <> Default Then GUICtrlSetColor(-1, $iEMB_Col)

    ; Create icon
    If $iIcon_Reduction Then GUICtrlCreateIcon("user32.dll", $iIcon_Style, 10, 20)

    ; Create buttons
    Local $iDef_Button = 0
    ; Calculate button horizontal start
    If $aButtons[0] = 1 Then
        If BitAND($iEMB_Just, 4) = 4 Then
            ; Single centred button
            $iButton_Xpos = ($iMsg_Width - $iButton_Width) / 2
        Else
            ; Single offset button
            $iButton_Xpos = $iMsg_Width - $iButton_Width - 10
        EndIf
    Else
        ; Multiple centred buttons
        $iButton_Xpos = 10 + ($iMsg_Width - $iMsg_Width_Button) / 2
    EndIf
    ; Create dummy to calculate return value
    Local $hButton_Start = GUICtrlCreateDummy()
    ; Work through button list
    For $i = 0 To $aButtons[0] - 1
        Local $iButton_Text = $aButtons[$i + 1]
        ; See if button is default
        If StringLeft($iButton_Text, 1) = "&" Then
            $iDef_Button = 0x0001
            $aButtons[$i + 1] = StringTrimLeft($iButton_Text, 1)
        EndIf
        ; Draw button
        GUICtrlCreateButton($aButtons[$i + 1], $iButton_Xpos + ($i * ($iButton_Width + 10)), $iMsg_Height - 35, $iButton_Width, 25, $iDef_Button)
        ; Reset default parameter
        $iDef_Button = 0
    Next

    ; Show GUI
    GUISetState(@SW_SHOW, $hMsgGUI)

    ; Begin timeout counter
    Local $iTimeout_Begin = TimerInit()

    ; Much faster to declare GUIGetMsg return array here and not in loop
    Local $aMsg

    While 1
        $aMsg = GUIGetMsg(1)

        If $aMsg[1] = $hMsgGUI Then

            Select
                Case $aMsg[0] = -3 ; $GUI_EVENT_CLOSE
                    $iRet_Value = 0
                    ExitLoop
                Case $aMsg[0] > $hButton_Start
                    ; Button handle minus dummy handle will give button index
                    $iRet_Value = $aMsg[0] - $hButton_Start
                    ExitLoop
            EndSelect
        EndIf

        ; Timeout if required
        If TimerDiff($iTimeout_Begin) / 1000 >= $iTimeout And $iTimeout > 0 Then
            $iRet_Value = 9
            ExitLoop
        EndIf

    WEnd

    $nOldOpt = Opt('GUIOnEventMode', $nOldOpt)

    GUIDelete($hMsgGUI)

    Return $iRet_Value

EndFunc   ;==>_ExtMsgBox

; #INTERNAL_USE_ONLY#============================================================================================================
; Name...........: _GetDefaultEMBFont
; Description ...: Determines Windows default MsgBox font size and name
; Syntax.........: _GetDefaultEMBFont([$iData)
; Parameters ....: $iData   => 0 = point size, 1 = font name
; Return values .: Success - return value as requested by $iData
;                : Failure - default values
; Author ........: Melba 23, based on some original code by Larrydalooza
; Remarks .......: Used internally by ExtMsgBox UDF
; ===============================================================================================================================
Func _GetDefaultEMBFont($iData)

    ; Get default system font data
    Local $tNONCLIENTMETRICS = DllStructCreate("uint;int;int;int;int;int;byte[60];int;int;byte[60];int;int;byte[60];byte[60];byte[60]")
    DLLStructSetData($tNONCLIENTMETRICS, 1, DllStructGetSize($tNONCLIENTMETRICS))
    DLLCall("user32.dll", "int", "SystemParametersInfo", "int", 41, "int", DllStructGetSize($tNONCLIENTMETRICS), "ptr", DllStructGetPtr($tNONCLIENTMETRICS), "int", 0)
    ; Read font data for MsgBox font
    Local $tLOGFONT = DllStructCreate("long;long;long;long;long;byte;byte;byte;byte;byte;byte;byte;byte;char[32]", DLLStructGetPtr($tNONCLIENTMETRICS, 15))
    If @error Then
        Switch $iData
            Case 0
                Return 9
            Case 1
                Return "Tahoma"
        EndSwitch
    Else
        Switch $iData
            Case 0
                Return Int((Abs(DllStructGetData($tLOGFONT, 1)) + 1) * .75) ; Font size as integer
            Case 1
                Return DllStructGetData($tLOGFONT, 14)                      ; Font name
        EndSwitch
    EndIf

EndFunc ;=>_GetDefaultEMBFont

Share this post


Link to post
Share on other sites

leomoon,

Glad you got it working as you wanted - I presume you added a couple of GUISetState lines. :graduated:

And thanks for the multiple monitor code. I will not add it into the main release because I do not have multiple monitors and so cannot test or maintain it. But I will point to your code from the first post so others know how it can be done. :(

M23

Edit: Typnig!

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Awesome! :graduated:

Yea it should work with single, and dual and I think even triple+. I tested with single and dual monitors. It works exactly the way you want it. If the parent GUI is outside of monitor(s) the msgbox will appear on the edge of the monitor...

Share this post


Link to post
Share on other sites

Hello,

I have one more question. Is there any option to make the msgBox not "always on top"? I checked the example and read the udf information. I couldn't find anything. I tried to add an option to enable or disable "always on top" but the udf is a little bit advanced for me. :graduated:

Share this post


Link to post
Share on other sites

leomoon,

I thought the whole idea was to have the EMB "topmost" so that the user would action it! :(

However, "the customer is king", so if you change this line:

; Create GUI with $WS_POPUPWINDOW, $WS_CAPTION style and $WS_EX_TOPMOST extended style
    Local $hMsgGUI = GUICreate($sTitle, $iMsg_Width, $iMsg_Height, $iHpos, $iVPos, BitOR(0x80880000, 0x00C00000), 0x00000008, $iParent_Win)

to read:

Local $hMsgGUI = GUICreate($sTitle, $iMsg_Width, $iMsg_Height, $iHpos, $iVPos, BitOR(0x80880000, 0x00C00000), -1, $iParent_Win)

you remove the $WS_EX_TOPMOST style. :graduated:

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Melba23, never really played with this before, but I must admit, its a very nice UDF.

I do have to agree that removing the topmost bit as a default style would be better though, or optional, since a typical messagebox won't be set as always-on-top. Its easy enough to change the code as you point out, but with any new version the scripter would have to constantly revise that line..

Great job otherwise though!


Share this post


Link to post
Share on other sites

The reason for removing top most is that if the main GUI and EMB exist at the same time, if you move another window over them, EMB goes on top and main GUI goes behind the other window.

Furthermore if you remove the EMB taskbar button and disable the main gui when the EMB is activated, when you click on the taskbar button it will bring the main gui with the EMB on top anyways... Which is EXACTLY what I want.

Again GREATE UDF. I already voted 5/5, I wish I could vote multiple. :graduated:

Share this post


Link to post
Share on other sites

Ascend4nt & leomoon,

Thanks for the compliments. :graduated:

I see what you mean about the TOPMOST style - I wonder how best to offer a choice to the user? I am loath to add yet another parameter to the already crowded _ExtMsgBox function - I am tempted to use the $iStyle parameter in the _ExtMsgBoxSet function to do something along these lines:

; Parameters ....: $iStyle      -> 0 = Normal - Button appears on TaskBar (Default), 1 = Button does not appear on TaskBar
;                               -> Adding 2 to the parameter will create an EMB without the TOPMOST style
;                   >>>>>>>>>>     Setting this parameter to 'Default' will reset ALL parameters to default values <<<<<<<<<<

Any thoughts? :(

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

What I've done with the EMB calling routine, is just add things to it on my own and just set a default value if not used. I added some things to it, changed some things in it and just added parameters to the end as I went along.

Here's how I've modified it to work better for my style:

Func _ExtMsgBox($iIcon, $iButton, $sTitle, $sText, $iTimeout = 0, $hWin = "", $iVPos = 0, $Random = 0, $MaxWidth = 370, $MinWidth = 150)

I don't think you should need to add or change things when you have the full source code available and anyone can change it to suit their needs, as I have done. The change that was mentioned, changing the top most flag, can be done with an additional parameter to the calling routine and adding a variable to be set to either set or unset the topmost flag, but asking to have you do it for them is just pushing it I think. But, that's just me, I don't like asking others to do something for me if I'm not willing to do it for myself.

Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Melba23, that sounds like a sensible solution.

And @BrewMan:

I and others here gladly take any suggestions into consideration when creating and furthering development of UDFs. Heck, I've created a lot of additions to different UDF's per other's requests & suggestions, and additionally provided many solutions to help people out.

And hey, its not like anyone's forcing someone to change something. Melba23 can do whatever he likes with our suggestions :graduated:


Share this post


Link to post
Share on other sites

Hi,

[NEW VERSION] 3 Dec 10 - Added the abilty to turn off the TOPMOST style if required.

The _ExtMsgBoxSet function header gives details of how to do this:

; Parameters ....: $iStyle      -> 0 (Default) - Button on TaskBar and TOPMOST style set.  Combine following to change:
;                                  1 = Button does not appear on TaskBar
;                                  2 = TOPMOST Style not set

and the example script shows all combinations.

If you do not want to change the TOPMOST setting you need change nothing in your current scripts. :graduated:

New UDF, example script and zip in the first post. :(

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Hi m8 :shifty:,

was playing around with this UDF to see if I could utilize it in SMF :P ... and noticed that your default msgbox font and size looks different to me then if I would call a standard msgbox().

You extract the data from the $tNONCLIENTMETRICS structure, this results in "Tahoma"/(11) for me.

Looking at a standard msgbox() results in "MS Shell Dlg"/(10) for me.

I changed the function _GetDefaultEMBFont() just a little and now the standard font looks exactly the same in your msgboxex() example and a standard msgbox(). Maybe you could x-check this? Had to add WinApi.au3 and left a lot of old comments in the code, definitely would need a clean up :nuke:.

Edit: Wrapped into a single call :lol:...

Edit2: Does the font object obtained with "Local $hFont = _SendMessage($hCtrl, 0x0031) ; $WM_GETFONT" call need to be deleted with _WinAPI_DeleteObject($hFont)? Added this for now... also I noticed now, if I start the example and immediately press "Exit", the first time the confirmation box is not white. Press "No" and retry and suddenly the color is right... check, check, :x also happens in your original post, so I didn't mess up :(...

Edit3: *sigh*... if _GetDefaultEMBFont() produces an error, the standard font size on my system is 10... but it of course needs to be 8 as an integer (Int((Abs(10) + 1) * .75))...

Edited by KaFu

Share this post


Link to post
Share on other sites

KaFu,

Hmmm - on my Vista machine I get the same font (Segoe UI, 9) in both Windows' MsgBox and my UDF version. Using your version I get a different smaller font (MS Shell Dlg, 8) in the EMB which does not match the normal MsgBox.

By the way, I always thought that MS Shell Dlg and MS Shell Dlg2 were shorthand for the real font names stored under HKLM\Software\Microsoft\Windows NT\Currentversion\FontSubstitutes - I have MS Sans Serif and Tahoma as the values in my registry. As neither of them appear in my Windows MsgBox, although it does look as if I have MS Sans Serif as the default GUI font so your function returning it is perhaps not surprising. Are you sure that MsgBoxes use the default GUI font? It does not appear so on my machine and I know I spent considerable time searching for the default MsgBox font location when I first wrote the UDF.

If I remember correctly, you run Win7. Have you set any particular styles which might have changed the default fonts? Do the values in the FontSubstitutes registry entry reflect the fonts you see in your GUIs and MsgBoxes? Does my original _GetDefaultEMBFont function return data from the $tNONCLIENTMETRICS structure or from the @error default for you - perhaps Win7 no longer stores the values there?

start the example and immediately press "Exit", the first time the confirmation box is not white. Press "No" and retry and suddenly the color is right

Definitely does not happen for me with either the original or your version. The EMB comes up in the default "whitish" colour all the time.

Please do not think I am not being defensive here, I would like to get the bottom of it but it is a bit difficult if I cannot reproduce the problems you are having. :x

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...