Jump to content

How to autosize an Inputbox


Recommended Posts

Hi guys,

i am using a script to fill out the form for our remoteaccess tool. The source of the data ist a .txt-file which constantly is growing in size (as new access data is filled in). How do i make the inputbox to always show the full text from the source without having to alter the script manually each time?

This is how the line is at the moment:

$Eingabe = InputBox("xxx", $chars, "", "", 250, 350, 0, 30)

The height of 350 is fully used now. But I would like it to check the height of the source and adjust the inputbox adequately. Any ideas?

Wiegand

Link to comment
Share on other sites

Hi guys,

i am using a script to fill out the form for our remoteaccess tool. The source of the data ist a .txt-file which constantly is growing in size (as new access data is filled in). How do i make the inputbox to always show the full text from the source without having to alter the script manually each time?

This is how the line is at the moment:

$Eingabe = InputBox("xxx", $chars, "", "", 250, 350, 0, 30)

The height of 350 is fully used now. But I would like it to check the height of the source and adjust the inputbox adequately. Any ideas?

Wiegand

Welcome! Try this:

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

Global Const $EM_SETSEL = 0xB1

Global $hCallBack = DllCallbackRegister("_AutoSize", "none", "hwnd;int;int;dword")

Global $aStrings[4]
$aStrings[0] = 3
$aStrings[1] = "Some long long long data, bla bla bla bla bla bla bla"
$aStrings[2] = "Some long long long data, bla bla bla bla bla bla bla Some long long long data, bla bla bla bla bla bla bla"
$aStrings[3] = "Some long long long data"


For $i = 1 To $aStrings[0]
    $IDTimer = DllCall("user32.dll", "int", "SetTimer", "hwnd", 0, "int", 0, "int", 10, "ptr", DllCallbackGetPtr($hCallBack))
    
    $answer = InputBox("MyProgram", "Type data here", $aStrings[$i])
Next

DllCallbackFree($hCallBack)

Func _AutoSize($hWnd, $Msg, $IdTimer, $dwTime)
    If WinExists("MyProgram") Then
        
        DllCall("user32.dll", "int", "KillTimer", "hwnd", 0, "int", $IDTimer)
        
        Local $hEdit, $aPos, $hFont, $hDC, $hOldFont, $sText, $tSize
        
        $hWnd = WinGetHandle("MyProgram")
        $hEdit = ControlGetHandle("MyProgram", "", "Edit1")
        $aPos = WinGetPos("MyProgram")
        
        $hFont = _SendMessage($hEdit, $WM_GETFONT)
        $hDC = _WinAPI_GetDC($hEdit)
        
        $hOldFont = _WinAPI_SelectObject($hDC, $hFont)
        
        $sText = ControlGetText($hWnd, "", $hEdit)
        $tSize = _WinAPI_GetTextExtentPoint32($hDC, $sText & " ")
        
        _WinAPI_SelectObject($hDC, $hOldFont)
        _WinAPI_ReleaseDC($hEdit, $hDC)
        
        WinMove($hWnd, "", $aPos[0], $aPos[1], DllStructGetData($tSize, "X") + 38, $aPos[3])
        _SendMessage($hEdit, $EM_SETSEL, 0, 0)
    EndIf
EndFunc

:P

Link to comment
Share on other sites

Well,

I tried to figure what you did but alas I do not get half of a quarter of it. However I focused and came up with this solution:

; Figures the number of lines

$AnzahlZeilenSrc = 1

While 1

$Line = FileReadLine("source.txt", $AnzahlZeilenSrc)

If @error = -1 Then ExitLoop

$AnzahlZeilenSrc = $AnzahlZeilenSrc + 1

Wend

; Multiplying the height with the number of lines

$InputboxHoehe = $AnzahlZeilenSrc*19

; Putting the number in the Inputbox-line

$Chars = FileRead("source.txt")

$Eingabe = InputBox("xxx", $chars, "", "", 250, $InputboxHoehe, 0, 30)

If @error = 1 Then

MsgBox(0, "xxx", "OK. Tschüss!")

Exit

EndIf

Maybe not the most convenient piece of work. But it will work for now. I will review your code to understand it and to see if it works for me, not today though ^^

bb Wiegand

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