Sign in to follow this  
Followers 0
vcrocca

InputBox Change Icon Possible

6 posts in this topic

Anyone know if it's possible to change the icon displayed in the top left corner when prompted when using InputBox?

I have searched help and this forum and cannot seem to find an answer.

Any help is appreciated.

Share this post


Link to post
Share on other sites



No except if you make your own gui. There are some threads if you search.

Share this post


Link to post
Share on other sites

Anyone know if it's possible to change the icon displayed in the top left corner when prompted when using InputBox?

I have searched help and this forum and cannot seem to find an answer.

Any help is appreciated.

The answer is the same as with the many requests for a customized MsgBox(), create your own with GuiCreate(), GuiCtrlCreateInput(), etc.

It's not that hard. Give it a shot and if you get stuck post your code for more help.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

If your script is big. You can make it in small functions, so you don't get confused with other things.

Share this post


Link to post
Share on other sites

Thanks everyone! This is what I was afraid of. It's a bit more work but it's a learning experience.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

This topic is old, sorry to resuscitate him, but maybe the code below can help coders in future. Thanks to JScript by _StringSize() function.

#include-once
#include <GUIConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>

Example()

Func Example()
    Local $text = "Alternative InputBox with automatic width/height adjustment and customizable icon line 1" & @CRLF & @CRLF & _
                "Alternative InputBox with automatic width/height adjustment and customizable icon line 2" & @CRLF & @CRLF & _
                "Alternative InputBox with automatic width/height adjustment and customizable icon line 3"

    Local $icon = @SystemDir & "\Notepad.exe"

    _InputBox("Customizable _InputBox", $text, "", "", -1, -1, Default, Default, 0, $icon)
    _InputBox("Customizable _InputBox", $text, "", "", 190, -1, Default, Default, 0, $icon)
    _InputBox("Customizable _InputBox", $text, "", "", 300, 500, Default, Default, 0, $icon)
    InputBox("Original InputBox", $text, "", "", 300, 500, Default, Default, 0, $icon)
EndFunc


; #ALTERNATIVE INPUTBOX#  =========================================================================
; AUTHOR: shuaua ==================================================================================
; =================================================================================================
; Name...........: _InputBox
; Description ...: Returns the user input or set error to 1 if user cancel
; Syntax.........: Same as original InputBox
; Parameters ....: Same as original InputBox, except $GuiIcon_or_ParentalWindow that can be a
;                  parental window, like original function, or a icon path
; Author ........: shuaua
; Obsevations....: Timer and Password Char, present in original InputBox, has not been implemented
; ==================================================================================================
Func _InputBox($title, $text, $input = "", $pwchar = "", $width = -1, $height = -1, $xpos = Default, $ypos = Default, $timeout = 0, $GuiIcon_or_ParentalWindow = "")
    ;; define font
    Local $InputBoxFontSize = 9
    Local $InputBoxFontWeight = 400
    Local $InputBoxFontName = "MS Sans Serif"
    ;; init
    Local $optbak = Opt("GUIOnEventMode")
    Opt("GUIOnEventMode", 0)
    Local $labelSize = _StringSize($text,$InputBoxFontSize,$InputBoxFontWeight,$InputBoxFontName)   ; sizes of label
    ;; default $width and $xpos
    If $width == Default Or $width <= 0 Then $width = $labelSize[0]+16          ; default width of GUI. 16 = 8+8 border distance
    If $width < 190 Then $width = 190                                           ; minimum GUI width
    If $width > 500 Then $width = 500                                           ; maximum GUI width
    If $xpos == Default Or $xpos <= 0 Then $xpos = @DesktopWidth/2-$width/2     ; horizontal coordinate
    ;; calculate line breaks
    Local $numberOfLines = StringSplit($text, @CR)                              ; number of lines in label text
    local $heightPerLine = $labelSize[1]/$numberOfLines[0]                      ; heigth of each line
    local $linesToAdd = 0                                                       ; number of aditional lines in case of line breaks
    Local $lineBreak
    Local $lineWidth
    For $i = 1 To $numberOfLines[0]
        $lineWidth = _StringSize($numberOfLines[$i],$InputBoxFontSize,$InputBoxFontWeight,$InputBoxFontName)    ; test if each line is bigger then label width
        $lineBreak = $lineWidth[0]/($width-16)                                                                  ; number of line breaks in each line of label
        If $lineBreak-0.0001 >= 1 Then
            $linesToAdd = $linesToAdd + Int($lineBreak)             ; cumulative
        EndIf
    Next
    ;; label parameters
    Local $labelWidth = $width-16                                   ; label width is the GUI width less 8+8 border distance
    Local $labelHeight = $labelSize[1]+$linesToAdd*$heightPerLine   ; fix the height according line breaks
    Local $labelXPos = 8
    Local $labelYPos = 8
    ;; input parameters
    local $editWidth = $labelWidth
    Local $editHeight = 21
    Local $editXPos = 8
    Local $editYPos = $labelHeight+6                                ; default vertical distance between controls is 6
    ;; OK button parameters
    Local $okWidth = 75
    Local $okHeight = 25
    Local $okXPos = $width/4-$okWidth/2                             ; ok button centered in 1/4 of GUI width
    Local $okYPos = $editYPos+$editHeight+6
    ;; Cancel button parameters
    Local $cancelWidth = 75
    Local $cancelHeight = 25
    Local $cancelXpos = 3/4*$width-$cancelWidth/2                   ; cancel button centered in 3/4 of GUI width
    Local $cancelYpos = $okYPos
    ;; default $height and $ypos
    If $height == Default Or $height <= 0 Then $height = $cancelYpos+$cancelHeight+$labelYPos                   ; default height of GUI. The sum of all heights and spacements
    If $height < $cancelYpos+$cancelHeight+$labelYPos Then $height = $cancelYpos+$cancelHeight+$labelYPos       ; minimum GUI heigth. The sum of all heights and spacements
    If $height > 3/4*@DesktopHeight Then $height = 3/4*@DesktopHeight                                           ; maximum GUI heigth
    If $ypos == Default Or $height <= 0 Then $ypos = @DesktopHeight/2-$height/2                                 ; vertical coordinate
    ;; fix buttons vertical positions after know GUI height
    $okYPos = $height-$labelYPos-$okHeight
    $cancelYpos = $okYPos
    $editYPos = $okYPos-6-$editHeight
    ;; InputBox GUI
    Local $GUIInputBox = GUICreate($title, $width, $height, $xpos, $ypos, $GUI_SS_DEFAULT_GUI-$WS_MINIMIZEBOX, 0, $GuiIcon_or_ParentalWindow)
    GUISetFont($InputBoxFontSize, $InputBoxFontWeight, 0, $InputBoxFontName)
    Local $labelInput = GUICtrlCreateLabel($text, $labelXPos, $labelYPos, $labelWidth, $labelHeight)
    Local $editInput = GUICtrlCreateInput($input, $editXPos, $editYPos, $editWidth, $editHeight, $GUI_SS_DEFAULT_INPUT)
    Local $ButtonOk = GUICtrlCreateButton("&OK", $okXPos, $okYPos, $okWidth, $okHeight, $BS_DEFPUSHBUTTON)
    Local $ButtonCancel = GUICtrlCreateButton("&Cancelar", $cancelXpos, $cancelYpos, $cancelWidth, $cancelHeight)
    If Not IsNumber($GuiIcon_or_ParentalWindow) Then GUISetIcon($GuiIcon_or_ParentalWindow)
    GUISetState()
    Local $error
    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                $input = ""
                $error = 1
                GUIDelete($GUIInputBox)
                ExitLoop
            Case $ButtonCancel
                $input = ""
                $error = 1
                GUIDelete($GUIInputBox)
                ExitLoop
            Case $ButtonOk
                $input = GUICtrlRead($editInput)
                $error = 0
                GUIDelete($GUIInputBox)
                ExitLoop
        EndSwitch
    WEnd
    Opt("GUIOnEventMode", $optbak)
    If $error Then SetError(1, 0, $input)
    Return $input
EndFunc

; #STTRINGSIZE# ====================================================================================
; Name...........: _StringSize
; Description ...: Returns the size (in pixels) of an string.
; Syntax.........: _StringSize( "string" [, size [, weight [, fontname ]]] )
; Parameters ....: string - The string to evaluate the size.
; Size - [Optional] Fontsize (default is 9).
; Weight - [Optional] Font weight (default 400 = normal).
; FontName - [Optional] Font to use (OS default GUI font is used if the font is "" or is not found).
; Requirement(s).:
; Return values .: Success - Returns a 2-element array containing the following information:
; $array[0] = Width
; $array[1] = Height
; Failure - Returns the same array with 0 and sets @error to 1.
; Author ........: jscript
; Example .......: _StringSize( "Text" )
; ==================================================================================================
Func _StringSize($sString, $iSize = 8, $iWeight = 400, $sFontName = "")
    Local $hWnd, $hGuiSwitch, $iCtrlID, $aCtrlSize, $aRetSize[2] = [0, 0]
    $hWnd = GUICreate("StringExInternalWin", 0, 0, 0, 0, BitOR(0x80000000, 0x20000000), BitOR(0x00000080, 0x00000020))
    $hGuiSwitch = GUISwitch($hWnd)
    If $iSize = 65535 Then ; Used by _ImageSize
        $iCtrlID = GUICtrlCreatePic($sString, 0, 0, 0, 0)
    Else
        GUISetFont($iSize, $iWeight, -1, $sFontName, $hWnd)
        $iCtrlID = GUICtrlCreateLabel($sString, 0, 0)
    EndIf
    $aCtrlSize = ControlGetPos($hWnd, "", $iCtrlID)
    GUIDelete($hWnd)
    GUISwitch($hGuiSwitch)
    If IsArray($aCtrlSize) Then
        $aRetSize[0] = $aCtrlSize[2]; Width
        $aRetSize[1] = $aCtrlSize[3]; Height
        Return SetError(0, 0, $aRetSize)
    EndIf
    Return SetError(1, 0, $aRetSize)
EndFunc ;==>_StringSize
Edited by shuaua

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
Sign in to follow this  
Followers 0