Jump to content

Expanding box [SOLVED]


Recommended Posts

anyone know of a beter more accurate way of doing this.....

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <Misc.au3>

Opt("GUIOnEventMode", 1)
$len=0
$Form1 = GUICreate("Form1", 24,26, 300, 300, $WS_POPUP, $WS_EX_TOPMOST)
$input=GUICtrlCreateInput("",2,2,20,22)
GUISetBkColor(0xaaaaaa)
GUISetState(@SW_SHOW)
while 1
    
sleep(50)
$len_new=StringLen(guictrlread($input))
if $len_new<>$len Then
    GUICtrlSetPos($input,2,2,int(20+($len_new*4.5)),22)
    $pos = ControlGetPos("Form1","",$input)
    WinMove("Form1","",300,300,$pos[2]+2,26)
    $len=$len_new
EndIf
WEnd
Edited by Aceguy
Link to comment
Share on other sites

I came up with this, but it only works well after about 6 characters.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <Misc.au3>

Opt("GUIOnEventMode", 1)
$len=0
$Form1 = GUICreate("Form1", 24,26, 300, 300, $WS_POPUP, $WS_EX_TOPMOST)
$input=GUICtrlCreateInput("",2,2,20,22)
GUISetBkColor(0xaaaaaa)
GUISetState(@SW_SHOW)
while 1
   
sleep(50)
$len_new=StringLen(guictrlread($input))
if $len_new<>$len Then
    $width = Int(20+($len_new*4.5))
    GUICtrlSetPos($input,2,2,$width,22)
    $pos = ControlGetPos("Form1","",$input)
    WinMove("Form1","",300,300,$width + 4,26)
    $len=$len_new
EndIf
WEnd

Edit: also if you backspace, it doesn't move the window down a size... Idono

Edited by youknowwho4eva

Giggity

Link to comment
Share on other sites

  • Moderators

Aceguy,

Try this version:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#include <SendMessage.au3>
#include <WinAPI.au3>

Opt("GUIOnEventMode", 1)

Opt("OnExitFunc", "_On_Exit")
$len = 0
$Form1 = GUICreate("Form1", 24, 26, 300, 300, $WS_POPUP, $WS_EX_TOPMOST)
$input = GUICtrlCreateInput("", 2, 2, 20, 22)
GUISetBkColor(0xaaaaaa)
GUISetState(@SW_SHOW)

; Create label to hold line as it grows
$hText_Label = GUICtrlCreateLabel("", 0, -50)
; Initialise Point32 method
$hWnd = ControlGetHandle($Form1, "", $hText_Label)
$hFont = _SendMessage($hWnd, $WM_GETFONT)
$hDC = _WinAPI_GetDC($hWnd)
$oFont = _WinAPI_SelectObject($hDC, $hFont)

While 1

    $len_new = _String_Len(GUICtrlRead($input))
;ConsoleWrite($len_new & @CRLF)
    If $len_new <> $len Then
        
        WinMove("Form1", "", 300, 300, $len_new + 24, 26)
        GUICtrlSetPos($input, 2, 2, $len_new + 20, 22)
        
        $len = $len_new
    EndIf
WEnd

Func _String_Len($sString)
    
    GUICtrlSetData($hText_Label, $sString)
    $tSize = _WinAPI_GetTextExtentPoint32($hDC, $sString)
    Return DllStructGetData($tSize, "X")
    
EndFunc

Func _On_Exit()
    _WinAPI_ReleaseDC($hWnd, $hDC)
EndFunc

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

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