Jump to content

Recommended Posts

Posted

Is there a way to get longer strings via InputBox?  I assume I can resort to a GUI, but it changes a six line program into something much more complicated (and more likely to trigger anti-virus warnings).

Posted

Not that I know of. InputBox is limited to 254 characters.
Creating a GUI is quite easy. Open the help file (F1 in SciTE) and search for GUICtrlCreateInput. At the end of the page you will find a simple example that can be stripped down to just a few lines of code.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted (edited)

It is possible but I am not sure you will like the solution.  It requires a bit of additional code, however it's not that complicated.  Anyway, here you go :

; From Nine
#include <GUIConstants.au3>
#include <WinAPI.au3>
#include <String.au3>

Opt("MustDeclareVars", True)

Global Const $HCBT_DESTROYWND = 4
Global $sAnswer, $hHook

Example()

Func Example()
  Local $hGUI = GUICreate("Test")
  Local $idBut = GUICtrlCreateButton("Show", 100, 100, 80, 20)

  Local $hStub = DllCallbackRegister(WH_CBT, "lresult", "int;wparam;lparam")
  $hHook = _WinAPI_SetWindowsHookEx($WH_CBT, DllCallbackGetPtr($hStub), 0, _WinAPI_GetCurrentThreadId())
  GUISetState()

  While True
    Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE
        ExitLoop
      Case $idBut
        ClipPut(_StringRepeat("1234567890", 30)) ; for testing longer than 254 characters
        InputBox("InputBox", "Enter value", "", "", 500, 140)
        If Not @error Then
          ConsoleWrite(StringLen($sAnswer) & "/" & $sAnswer & @CRLF)
        EndIf
    EndSwitch
  WEnd

  _WinAPI_UnhookWindowsHookEx($hHook)
  DllCallbackFree($hStub)
EndFunc   ;==>Example

Func WH_CBT($nCode, $wParam, $lParam)
  Local $hWnd = HWnd($wParam)
  If $nCode = $HCBT_DESTROYWND And _WinAPI_GetClassName($hWnd) = "#32770" And ControlGetHandle($hWnd, "", "Edit1") Then
    $sAnswer = ControlGetText($hWnd, "", "Edit1")
  EndIf
  Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
EndFunc   ;==>WH_CBT

 

Edited by Nine

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...