Jump to content

Centered Input Box Value


 Share

Recommended Posts

Is there a way to center the data value in an input box control? Tried $ES_CENTER but that only works on multiline input boxes according to the doc and, indeed, it doesn't work on a single line one ... trust me, I tried it ... :mellow:

TIA.

Tom

Link to comment
Share on other sites

Is this for a regular Input Box control, or a GUI one? I use $ES_CENTER on a GUI Input Box and it works fine. Make sure you've included EditConstants.au3 too.<br><br>edit: I just tried myself, and it seems the es_center style can't be used with a regular input box control. If it can though, I have no idea how to..<br>

Edited by somdcomputerguy

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Link to comment
Share on other sites

  • Moderators

tbohon,

$ES_CENTER will not work with an InputBox command as the GUI is generated internally by AutoIt - and as you can only vary those parameters available within the function call itself there is no way to apply the style. :mellow:

If you want a centred input you will have to create your own GUI to hold it: :)

#include <GUIConstantsEx.au3>
#include <EditConstants.au3>

$hGUI = GUICreate("Centred Input", 220, 80)

$hInput = GUICtrlCreateInput("", 10, 10, 200, 20, $ES_CENTER)
$hButton_1 = GUICtrlCreateButton("Cancel", 10, 40, 80, 30)
$hButton_2 = GUICtrlCreateButton("Read", 130, 40, 80, 30)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $hButton_2
            MsgBox(0, "Input", GUICtrlRead($hInput))
            ContinueCase
        Case $GUI_EVENT_CLOSE, $hButton_1
            Exit
    EndSwitch
WEnd

For me at least, $ES_CENTER works fine with an Input control - which is actually a single line Edit control. :)

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

 

Link to comment
Share on other sites

You can hook the internal InputBox to make it look like you want.

#include <WinAPI.au3>
#include <Constants.au3>

Local $hProcInputBox = DllCallbackRegister("CbtHookProcInputBox", "int", "int;int;int")
Local $TIDInputBox = _WinAPI_GetCurrentThreadId()
Local $hHookInputBox = _WinAPI_SetWindowsHookEx($WH_CBT, DllCallbackGetPtr($hProcInputBox), 0, $TIDInputBox)

Local $answer = InputBox("Question", "Where were you born?", "Planet Earth", "", -1, -1, 0, 0)

_WinAPI_UnhookWindowsHookEx($hHookInputBox)
DllCallbackFree($hProcInputBox)


#region Just for fun(key)!!
;##########################################################
Func CbtHookProcInputBox($nCode, $wParam, $lParam)
 Static $iWindowIndex = 0
    Local $RET = 0, $hBitmap = 0, $xWnd = 0
    If $nCode < 0 Then
        $RET = _WinAPI_CallNextHookEx($hHookInputBox, $nCode, $wParam, $lParam)
        Return $RET
    EndIf
    Switch $nCode
 Case 3 ;3=HCBT_CREATEWND
  If $iWindowIndex = 2 Then
   _WinAPI_SetWindowLong($wParam, $GWL_STYLE, 0x50010081)
  EndIf
  $iWindowIndex += 1
  Case 5 ;5=HCBT_ACTIVATE
            _WinAPI_SetDlgItemText($wParam, 1, "Accept")
            _WinAPI_SetDlgItemText($wParam, 2, "Abort")
    EndSwitch
    Return
EndFunc   ;==>CbtHookProcInputBox

Func _WinAPI_SetDlgItemText($hDlg, $nIDDlgItem, $lpString)
    Local $aRet = DllCall('user32.dll', "int", "SetDlgItemText", _
            "hwnd", $hDlg, _
            "int", $nIDDlgItem, _
            "str", $lpString)
    Return $aRet[0]
EndFunc   ;==>_WinAPI_SetDlgItemText

;##########################################################
#endregion Just for fun(key)!!

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

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...