Jump to content

Inputbox text not center vertically


Recommended Posts

Hi guys,

I have searched around but i don't have find nothing about this:

The test script:

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

$Form1 = GUICreate("Form1", 237, 93, 192, 124)
$Input1 = GUICtrlCreateInput("Center vertically is correct", 16, 16, 201, 21)
$Input2 = GUICtrlCreateInput("I'm not center vertically", 16, 48, 201, 21, 0, $WS_EX_WINDOWEDGE)
GUISetState(@SW_SHOW)

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd

If i remove the border for the 2° inputbox the text isn't vertically center. I have try some other syle without success, like $SS_CENTERIMAGE...work for label but not for inputbox

Some suggestion?

Thanks ;)

Edited by johnmcloud
Link to comment
Share on other sites

$ES_CENTER maybe? If this doesn't work, could you elaborate further? Thanks.

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

  • Moderators

johnmcloud,

I have try some other syle without success, like $SS_CENTERIMAGE...work for label but not for inputbox

That style works fine for me when I use it: ;)

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

$Form1 = GUICreate("Form1", 237, 93, 192, 124)
GUISetBkColor(0xC4C4C4)
$Input1 = GUICtrlCreateInput("Center vertically is correct", 16, 16, 201, 21)
$Input2 = GUICtrlCreateInput("I'm not center vertically", 16, 48, 201, 21, 0, BitOr($WS_EX_WINDOWEDGE, $WS_EX_CLIENTEDGE)) ; <<<<<<<<<<<<<
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

How did you try to apply the style? :huh:

M23

Edit: Now shows the correct way to do it - what I had originally posted was a lucky mix of styles (thanks funkey). :>

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

 

Link to comment
Share on other sites

Hi guinness,

Not horizontal, but vertically

Posted Image

1° inputbox is correct

2° inputbox isn't, is more on the top side of the inputbox

EDIT: Melba, I have applied the style in this way, wrong:

$Input2 = GUICtrlCreateInput("I'm not center vertically", 16, 48, 201, 21, $SS_CENTERIMAGE, $WS_EX_WINDOWEDGE)

I don't have think to use BitOr :sweating:

Yes is vertically centered, thanks

Edited by johnmcloud
Link to comment
Share on other sites

Yeh, my bad I totally misunderstood and I couldn't see the difference on my machine.

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

$Input2 = GUICtrlCreateInput("I'm not center vertically", 16, 48, 201, 21, 0, BitOr($WS_EX_WINDOWEDGE, $SS_CENTERIMAGE)) ; <<<<<<<<<<<<<

How did you try to apply the style? :huh:

M23

BitOr some Style and ExStyle is not right.

BitOr($WS_EX_WINDOWEDGE, $WS_EX_CLIENTEDGE) has the same effect and is afaik the correct use of it.

Edited by funkey

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

  • Moderators

funkey,

Oops! I just added the new style and did not notice that the existing style was an extended one. :>

Thanks for pointing out my stupid mistake - and providing the correct answer. :)

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

I have a problem:

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

$Form1 = GUICreate("Form1", 209, 114, 192, 124)
GUISetBkColor(0x000000)
$Input1 = GUICtrlCreateInput("Not Vertical centered - No border", 16, 16, 177, 21, 0, $WS_EX_WINDOWEDGE)
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0xff0000)
$Input2 = GUICtrlCreateInput("I see the border - Vertical OK", 18, 50, 186, 21, 0, BitOr($WS_EX_WINDOWEDGE, $WS_EX_CLIENTEDGE))
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0x000000)
GUISetState(@SW_SHOW)

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd

If i set a font color i see the border? :D

Edited by johnmcloud
Link to comment
Share on other sites

Try if this workaround fits your needs.

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

Global $hGui = GUICreate("Input without border", 215, 214, 192, 124)
;~ GUISetBkColor(0x000000)

Global $Input0 = GUICtrlCreateInput("Standard input control", 16, 10, 180, 20, $ES_CENTER)

Global $Input1 = _CreateInputWithoutBorderAndVerticalCenteredWithBgColor($hGui, "This is an input control", 16, 40, 180, 20, 0xFF0000, $ES_CENTER)
Global $Input2 = _CreateInputWithoutBorderAndVerticalCenteredWithBgColor($hGui, "and there is no border", 16, 70, 180, 51, 0x00FF00, $ES_CENTER)
Global $Input3 = _CreateInputWithoutBorderAndVerticalCenteredWithBgColor($hGui, "and it is vertical centered ;)", 16, 130, 180, 31, 0x00FFFF, $ES_CENTER)

Global $Input4 = GUICtrlCreateInput("Standard input control", 16, 170, 180, 36, $ES_CENTER)

Global $nTabFix = GUICtrlCreateDummy()
Global $AccelKeys[1][2] = [["{TAB}", $nTabFix]]

GUISetAccelerators($AccelKeys)

ControlFocus($hGui, "", $Input0)
GUICtrlSendMsg($Input0, $EM_SETSEL, 0, -1)

GUISetState(@SW_SHOW)

Global $nMsg, $nFocused

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $nTabFix
            $nFocused = _WinAPI_GetDlgCtrlID(ControlGetHandle($hGui, "", ControlGetFocus($hGui)))
            Switch $nFocused
                Case $Input0
                    ControlFocus($hGui, "", $Input1)
                    GUICtrlSendMsg($Input1, $EM_SETSEL, 0, -1)
                Case $Input1
                    ControlFocus($hGui, "", $Input2)
                    GUICtrlSendMsg($Input2, $EM_SETSEL, 0, -1)
                Case $Input2
                    ControlFocus($hGui, "", $Input3)
                    GUICtrlSendMsg($Input3, $EM_SETSEL, 0, -1)
                Case $Input3
                    ControlFocus($hGui, "", $Input4)
                    GUICtrlSendMsg($Input4, $EM_SETSEL, 0, -1)
                Case Else
                    GUISetAccelerators(0)
                    Send("{TAB}")
                    GUISetAccelerators($AccelKeys)
            EndSwitch
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func _CreateInputWithoutBorderAndVerticalCenteredWithBgColor($hParent, $sText, $iX, $iY, $iW, $iH, $iColor, $iStyle = -1, $iExStyle = 0)
    GUICreate("", $iW, $iH, $iX, $iY, $WS_CHILD, 0, $hParent)
    GUISetBkColor($iColor)
    Local $nInput = GUICtrlCreateInput($sText, 0, $iH / 2 - 6, $iW, 20, $iStyle, $iExStyle)
    GUICtrlSetBkColor(-1, $iColor)
    GUISetState()
    GUISwitch($hParent)
    Return $nInput
EndFunc   ;==>_CreateInputWithoutBorderAndVerticalCenteredWithBgColor

Edit: Show how to handle the TAB message.

Edited by funkey

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

Thanks funkey

You have forgot the font color :D

Func _GUICtrlCreateInput($hParent, $sText, $iX, $iY, $iW, $iH, $iColorBackground, $iColorFont, $iStyle = -1, $iExStyle = 0)
    GUICreate("", $iW, $iH, $iX, $iY, $WS_CHILD, 0, $hParent)
    GUISetBkColor($iColorBackground)
    Local $nInput = GUICtrlCreateInput($sText, 0, $iH / 2 - 6, $iW, 20, $iStyle, $iExStyle)
    GUICtrlSetBkColor(-1, $iColorBackground)
GUICtrlSetColor(-1, $iColorFont)
    GUISetState()
    GUISwitch($hParent)
    Return $nInput
EndFunc   ;==>_GUICtrlCreateInput
Link to comment
Share on other sites

Thanks funkey

You have forgot the font color :D

I knew you can do this alone. :D

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

  • 11 years later...

Hello @funkey

Though the thread is old, I'm posting a script which is directly related to your post above.
Based on your script, my goal was to create a resizable GUI, with child windows resizing accordingly and input controls still centered vertically :

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

Opt("MustDeclareVars", 1) ;0=no, 1=require pre-declaration

Global $hGui = GUICreate("Input without border #2 (resizable GUI)", 215, 214, 192, 124, $WS_OVERLAPPEDWINDOW, $WS_EX_COMPOSITED)

Global $Input0 = GUICtrlCreateInput("Standard input control", 16, 10, 180, 20, BitOr($ES_CENTER, $ES_AUTOHSCROLL))

Global $aChild[3][6] ; 3 rows as 3 vertical centered Input . 6 cols (see func _CreateInput... below)
Global $Input1 = _CreateInputWithoutBorderAndVerticalCenteredWithBgColor($hGui, "This is an input control", _
    16, 40, 180, 20, 0xFF0000, BitOr($ES_CENTER, $ES_AUTOHSCROLL))
Global $Input2 = _CreateInputWithoutBorderAndVerticalCenteredWithBgColor($hGui, "and there is no border", _
    16, 70, 180, 51, 0x00FF00, BitOr($ES_CENTER, $ES_AUTOHSCROLL))
Global $Input3 = _CreateInputWithoutBorderAndVerticalCenteredWithBgColor($hGui, "and it is vertical centered ;)", _
    16, 130, 180, 31, 0x00FFFF, BitOr($ES_CENTER, $ES_AUTOHSCROLL))

Global $Input4 = GUICtrlCreateInput("Standard input control", 16, 170, 180, 36, BitOr($ES_CENTER, $ES_AUTOHSCROLL))

ControlFocus($hGui, "", $Input0)
GUICtrlSendMsg($Input0, $EM_SETSEL, 0, -1)

GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_SIZE, "WM_SIZE")
GUIRegisterMsg($WM_SYSCOMMAND, "WM_SYSCOMMAND") ; prevent child GUI's from being dragged (autoit hijacked $WS_EX_CONTROLPARENT ex style)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

;===========================================
Func _CreateInputWithoutBorderAndVerticalCenteredWithBgColor($hParent, $sText, $iX, $iY, $iW, $iH, $iColor, $iStyle = -1, $iExStyle = 0)

    Local $hChild = GUICreate("", $iW, $iH, $iX, $iY, $WS_CHILD, $WS_EX_CONTROLPARENT, $hParent) ; ex style from "12d - chez mikell.au3"
    GUISetBkColor($iColor)

    Local $nInput = GUICtrlCreateInput($sText, 0, $iH / 2 - 6, $iW, 20, $iStyle, $iExStyle) ; how did funkey find the good - 6 ?
    GUICtrlSetBkColor(-1, $iColor)

    Local Static $iRow = -1, $aParent = WinGetClientSize($hParent)
    $iRow += 1 ; 0+
    $aChild[$iRow][0] = $hChild
    $aChild[$iRow][1] = $iX / $aParent[0]
    $aChild[$iRow][2] = $iY / $aParent[1]
    $aChild[$iRow][3] = $iW / $aParent[0]
    $aChild[$iRow][4] = $iH / $aParent[1]
    $aChild[$iRow][5] = $nInput

    GUISetState()
    GUISwitch($hParent)
    Return $nInput
EndFunc   ;==>_CreateInputWithoutBorderAndVerticalCenteredWithBgColor

;===========================================
Func WM_SIZE($hWnd, $iMsg, $wParam, $lParam)

    If $hWnd = $hGUI Then
        Local $iParentNewCliW = BitAND($lParam, 0xFFFF) ; low word
        Local $iParentNewCliH = BitShift($lParam, 16) ; high word

        For $i = 0 To Ubound($aChild) - 1
            WinMove($aChild[$i][0], "", $iParentNewCliW * $aChild[$i][1], $iParentNewCliH * $aChild[$i][2], _
                $iParentNewCliW * $aChild[$i][3], $iParentNewCliH * $aChild[$i][4]) ; WinMove will use Int coords

            ; GUICtrlSetPos($aChild[$i][5], 0, ($iParentNewCliH * $aChild[$i][4]) / 2 - 6) ; bad display after restore event
            ControlMove($aChild[$i][0], "", $aChild[$i][5], 0, ($iParentNewCliH * $aChild[$i][4]) / 2 - 6) ; good display in all cases
        Next
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_SIZE

;===========================================
Func WM_SYSCOMMAND($hWnd, $iMsg, $wParam, $lParam)

    For $i = 0 To Ubound($aChild) - 1
        If $hWnd = $aChild[$i][0] Then
            If BitAND($wParam, 0xFFF0) = 0xF010 Then Return False ; $SC_MOVE = 0xF010
        EndIf
    Next
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_SYSCOMMAND

VerticallycenteredinputinresizableGUI.png.3de4a9ac916ad0405c50af9e855711aa.png

Have a great evening :)

Edit #1: I have an issue with this line (found in WM_SIZE function) :

GUICtrlSetPos($aChild[$i][5], 0, ($iParentNewCliH * $aChild[$i][4]) / 2 - 6)

1) When it's uncommented, then the vertical position of input controls is perfect while resizing (as in the pic shown above), BUT as soon as you minimize / restore the GUI, then issues appear in the text of the input controls.

2) When it's commented out, then the vertical position of input controls is not perfect, BUT there is no problem after you minimize / restore the GUI

What should be done to have everything work fine in all cases ?
I'll try to find a solution, but if you guys have some ideas about this, thanks for sharing them here.

Edit #2: I just found the solution :)
ControlMove does the job nicely, instead of GUICtrlSetPos (maybe because GUICtrlSetPos should be used more carefully in this context, when there is a main GUI with several Child GUI's)

Edit #3: added $WS_EX_CONTROLPARENT ex style to navigate in child GUI's using the Tab key

Edited by pixelsearch
added $WS_EX_CONTROLPARENT ex style to navigate in child GUI's using the Tab key
Link to comment
Share on other sites

variation

#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPIGdi.au3>

Global $hGui = GUICreate("Input without border #3 (resizable GUI)", 215, 214, 192, 124, $WS_OVERLAPPEDWINDOW, $WS_EX_COMPOSITED)

Global $Input0 = GUICtrlCreateInput("Standard input control", 16, 10, 180, 20, BitOR($ES_CENTER, $ES_AUTOHSCROLL))
Global $Input1 = _CreateInput("This is an input control gg", 16, 40, 180, 20, 0xFF0000, BitOR($ES_CENTER, $ES_AUTOHSCROLL))
Global $Input2 = _CreateInput("and there is no border", 16, 70, 180, 51, 0x00FF00, BitOR($ES_CENTER, $ES_AUTOHSCROLL))
Global $Input3 = _CreateInput("and it is vertical centered ;)", 16, 130, 180, 31, 0x00FFFF, BitOR($ES_CENTER, $ES_AUTOHSCROLL))
Global $Input4 = GUICtrlCreateInput("Standard input control" & @CRLF & "with out border", 16, 170, 180, 36, BitOR($ES_CENTER, $ES_AUTOHSCROLL, $ES_MULTILINE ), 0)

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_RESIZED, $GUI_EVENT_MAXIMIZE, $GUI_EVENT_RESTORE
            _OrderPos()

    EndSwitch
WEnd

;--------------------------------------------------------------------------------------------------------------------------------
Func _CreateInput($Text, $Left, $Top, $Width, $Height, $FullColor = "0xFFFFFF", $iStyle = -1)
    Local $idInput = GUICtrlCreateInput($Text, $Left + 1, $Top + ($Height - 16) / 2, $Width - 2, 18, $iStyle, $WS_EX_TOOLWINDOW)
    ConsoleWrite("$idInput=" & $idInput & @CRLF)
    GUICtrlSetBkColor(-1, $FullColor)
    GUICtrlCreateLabel("", $Left, $Top, $Width, $Height)
    GUICtrlSetBkColor(-1, $FullColor)
    GUICtrlSetState(-1, $GUI_DISABLE)
    Return $idInput
EndFunc   ;==>_CreateInput
;--------------------------------------------------------------------------------------------------------------------------------
Func _OrderPos()
    Local $aPos
    For $iCtrl = 4 To 8 Step 2
        $aPos = ControlGetPos($hGUI, "", $iCtrl + 1)
        GUICtrlSetPos($iCtrl, $aPos[0] + 1, $aPos[1] + ($aPos[3] - 16) / 2, $aPos[2] - 2)
    Next

EndFunc   ;==>_OrderPos
;--------------------------------------------------------------------------------------------------------------------------------

 

Edited by ioa747
remove unnecessarily

I know that I know nothing

Link to comment
Share on other sites

Hi @ioa747
Yes it works too using the "disable label way" as you did. There is a little problem as shown in the following pic, but I guess we can live with that.

Note: I changed the GUI title in your script (it indicates now #3) to differentiate the scripts :

Noverticalcenterwhiledragging.png.7e32ef382c208d1bec59e98d72a9cac8.png

As you see, while dragging the right bottom corner (notice in the pic the Gui cursor #12 SizeNWSE) then the vertical alignment is not done until we stop the drag process and only now $GUI_EVENT_RESIZED is processed to redraw everything correctly when your function _OrderPos() is called.

It seems hard to have a correct vertical positioning during the drag process if you don't register the WM_SIZE message. I remember @Melba23 doing it in a special way to take care of all events when he wrote in this post from 2020 :

On Mon Oct 26 2020 (GMT+0000) at 9:03 AM, Melba23 said:

jcpetu,

The script works if you resize the GUI by dragging the mouse - I suspect in the case above you are using the minimize/maximize buttons of the GUI. In that case we need to widen the events that trigger the resizing - like this [...]

I never forgot the 2 "successive" functions M23 scripted, presented like this, very clever !

Func _WM_SIZE($hWnd, $iMsg, $wParam, $lParam)
    ; If it is our GUI
    If $hWnd = $GuiMain Then
        _Resize()
    EndIf
EndFunc

Func _Resize()
    ; Get the new position and size of the labels
    ...
    ; And set the RichEdits to the same position and size
    ...
EndFunc

 

Edited by pixelsearch
typo
Link to comment
Share on other sites

after a few tests:

at first i disabled

;~      Case $GUI_EVENT_RESIZED, $GUI_EVENT_MAXIMIZE, $GUI_EVENT_RESTORE
;~          _OrderPos()

and added

GUIRegisterMsg($WM_SIZE, "WM_SIZE")

with

Func _WM_SIZE($hWnd, $iMsg, $wParam, $lParam)
    ; If it is our GUI
    If $hWnd = $hGUI Then
        _OrderPos()
    EndIf
EndFunc

result:

240716-045221-988_AutoIt3_usol3.png

 

 

as seen in the image the Input controls
do not follow the orders of the _OrderPos() function

 

 

 

 

 

then i replaced it

;~ GUIRegisterMsg($WM_SIZE, "WM_SIZE")
GUIRegisterMsg($WM_SIZING, "_WM_SIZE")

result:

240716-071717-103_AutoIt3_ZeqHl.png


as shown in the image the Input controls
have better behavior and do not go outside the Label control

 

however, it is not exactly in the middle
of the Label control vertically
(sometimes depending on the speed of the drag)

 

I also noticed that during the drag the Input controls blink slightly
Which was overcome by adding the $WS_EX_LAYERED parameter
in the
GUICreate("Input without border #3 (resizable GUI)", 215, 214, 192, 124, _
$WS_OVERLAPPEDWINDOW, BitOR($WS_EX_COMPOSITED, $WS_EX_LAYERED))

 

 

 

 

 

 

 

 

then I enabled again

Case $GUI_EVENT_RESIZED, $GUI_EVENT_MAXIMIZE, $GUI_EVENT_RESTORE
            _OrderPos()

and disabled

;~ GUIRegisterMsg($WM_SIZE, "WM_SIZE")
;~ GUIRegisterMsg($WM_SIZING, "_WM_SIZE")

and remove $WS_EX_LAYERED

result:

Clipboard_07-16-2024_01.pngin this set I have the best behavior
and the Input controls are aligned exactly in the middle

 

I also noticed that as long as I hold
the mouse button down while dragging,
my window doesn't redraw at all,
until I release the mouse button

 

the only thing that changes is the white frame
that shows the new position of the window.

 

 

 

I imagine the computer setting will play a role in this,
which I did not get into the process of exploring further.
however, I am attaching an illustration

240716-080505-399_SystemPropertiesAdvanced_LdjSP.png

:) I hope I concluded positively so that correct conclusions can be drawn
Thank you very much

I know that I know nothing

Link to comment
Share on other sites

@ioa747 that's why I prefer my "ratio way" instead of the "disabled label way", to avoid the problems you're describing in your last post. I guess, from now on, I'll always use the ratio way in this kind of script.

By the way, I just changed a bit the code in my script above, maybe @funkey will be interested in this final change as it concerns all the lines he used to be able to Tab in all Input controls, as stated in his code edit reason.

So I deleted all his lines related to the dummy control, the accelerators, no need of _WinAPI_GetDlgCtrlID() or all the lines related to Switch $nFocused in main loop.

Instead, I did 2 things :
1) Added the $WS_EX_CONTROLPARENT ex style when creating the child GUI's (i.e. the GUI's with $WS_CHILD style)
2) Registered $WM_SYSCOMMAND to prevent the child GUI's from being draggable.

The reason I had to register $WM_SYSCOMMAND is because AutoIt hijacked the $WS_EX_CONTROLPARENT ex style a long time ago (to make some GUI/controls draggable) but in our script we don't want this special behavior, we just need the normal behavior (Tab key goes to next control, even if this control is placed in a Child GUI)

ioa747, could you please confirm that when you run my script above, everything goes fine on your computer ?
If anything goes wrong, please indicate it here, thanks !

Edited by pixelsearch
typo
Link to comment
Share on other sites

2 hours ago, pixelsearch said:

could you please confirm that when you run my script above, everything goes fine on your computer ?

Work perfect.
No flickering, and the Input controls are aligned exactly in the middle

I know that I know nothing

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

×
×
  • Create New...