big InputBox via DialogBoxIndirectParam

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

big InputBox via DialogBoxIndirectParam

30 Dec 2018, 18:24

The resource in AutoHotkey.exe, IDD_INPUTBOX := 205, visible with Resource Hacker, can be copied and edited and used as the basis for a custom InputBox with a custom size font via DialogBoxIndirectParam.

Code: Select all

q:: ;big InputBox
AX_InputBoxFontSize := 18
vRet := InputBoxBig("PROMPT", "TITLE", "", "DEFAULT")
InputBox, vInput, TITLE, PROMPT,,,,,,,, DEFAULT
AX_InputBoxFontSize := 10
MsgBox, % ErrorLevel "`r`n" vRet
vRet := InputBoxBig("PROMPT", "TITLE", "w800 Password~", "DEFAULT")
return

;note: doesn't handle timeout
;note: doesn't handle X/Y/W/H correctly (controls not resized)
InputBoxBig(oParams*) ;Text, Title, Options, Default
{
	local
	global AX_InputBoxFontSize
	static vPfx := RegExMatch(10, 1,, -1) ? "O" : ""
	static vData, vIsReady := 0, pRes
	if !vIsReady
	{
		hModule := 0
		hResInfo := DllCall("kernel32\FindResource", Ptr,hModule, Ptr,205, Ptr,5, Ptr)
		vSize := DllCall("kernel32\SizeofResource", Ptr,hModule, Ptr,hResInfo, UInt)
		hResData := DllCall("kernel32\LoadResource", Ptr,hModule, Ptr,hResInfo, Ptr)
		pRes := DllCall("kernel32\LockResource", Ptr,hResData, Ptr)
		;note: the 232 bytes appear to differ each time the script is run
		VarSetCapacity(vData, vSize)
		DllCall("msvcrt\memmove", Ptr,&vData, Ptr,pRes, UPtr,vSize, "Cdecl Ptr")
		pRes := &vData
		vIsReady := 1
	}
	if AX_InputBoxFontSize
		NumPut(AX_InputBoxFontSize, pRes+0, 44, "UShort") ;pointsize
	Text := oParams.1
	Title := !oParams.HasKey(2) ? A_ScriptName : (oParams.2 = "") ? " " : oParams.2
	Options := oParams.3
	Default := oParams.4

	; v2 validates the value of a particular option:
	; X and Y = integer (can be negative)
	; W and H = postive integer only
	; T = postive integer/float
	; Credits to Lexikos [https://goo.gl/VjMTYu , https://goo.gl/ebEjon]
	RegExMatch(Options, vPfx "i)^[ \t]*(?:(?:X(?<X>-?\d+)|Y(?<Y>-?\d+)|W(?<W>\d+)"
		. "|H(?<H>\d+)|T(?<T>\d+(?:\.\d+)?)|(?<P>Password\S?)"
		. "|(?<Err>\S+)(*ACCEPT)"
		. ")(?=[ \t]|$)[ \t]*)*$", oMatch)

	if (oMatch.Err != "")
		throw Exception("Invalid option.", -1, oMatch.Err)
	oParams.3 := oMatch

	hWnd := A_ScriptHwnd
	VarSetCapacity(vInput, 1000000*2, 0) ;arbitrary limit 1M characters
	vInput := Default
	;note: custom choice made to send pointer to a variable (&vInput) to InputBox proc function
	InputBoxBigProc(0, oParams, 0, 0)
	;vRet := DllCall("user32\DialogBoxParam", Ptr,0, Ptr,205, Ptr,hWnd, Ptr,RegisterCallback(A_ThisFunc "Proc"), Ptr,&vInput, Ptr) ;IDD_INPUTBOX := 205
	vRet := DllCall("user32\DialogBoxIndirectParam", Ptr,0, Ptr,pRes, Ptr,hWnd, Ptr,RegisterCallback(A_ThisFunc "Proc"), Ptr,&vInput, Ptr)
	vRet := !(vRet = 1)
	ErrorLevel := vRet
	if vRet
		return
	VarSetCapacity(vInput, -1)
	return vInput
}

InputBoxBigProc(hDlg, uMsg, wParam, lParam)
{
	local
	static pInput
	static oParams
	if (hDlg = 0)
		oParams := uMsg
	if (uMsg = 0x110) ;WM_INITDIALOG := 0x110
	{
		pInput := lParam
		SendMessage, 0xC, 0, % pInput, Edit1, % "ahk_id " hDlg ;WM_SETTEXT := 0xC
		DllCall("user32\SetForegroundWindow", Ptr,hDlg)
		;Control, Hide,, Edit1, % "ahk_id " hDlg
		vDHW := A_DetectHiddenWindows
		DetectHiddenWindows, On
		WinSetTitle, % "ahk_id " hDlg,, % oParams.2
		ControlSetText, Static1, % oParams.1, % "ahk_id " hDlg
		ControlSetText, Edit1, % oParams.4, % "ahk_id " hDlg
		if !(oParams.4 = "")
			SendMessage, 0xB1, 0, -1, Edit1, % "ahk_id " hDlg ;EM_SETSEL := 0xB1 ;select all
		WinMove, % "ahk_id " hDlg,, % oParams.3.X, % oParams.3.Y, % oParams.3.W, % oParams.3.H
		if !(oParams.3.P = "")
			SendMessage, 0xCC, % Ord(SubStr(oParams.3.P, 9)),, Edit1, % "ahk_id " hDlg ;EM_SETPASSWORDCHAR := 0xCC
		hIcon := LoadPicture(A_AhkPath, "w16 h16", vType)
		SendMessage, 0x80, 0, % hIcon,, % "ahk_id " hDlg ;WM_SETICON := 0x80 ;sets title bar icon + taskbar icon
		;SendMessage, 0x80, 1, % hIcon,, % "ahk_id " hDlg ;WM_SETICON := 0x80 ;sets alt+tab icon
		DetectHiddenWindows, % vDHW
	}
	else if (uMsg = 0x111) ;WM_COMMAND := 0x111
	&& ((wParam = 1) || (wParam = 2)) ;IDOK := 1 ;IDCANCEL := 2 ;source: WinUser.h
	{
		SendMessage, 0xE, 0, 0, Edit1, % "ahk_id " hDlg ;WM_GETTEXTLENGTH := 0xE
		vChars := Min(ErrorLevel+1, 1000000)
		SendMessage, 0xD, vChars, % pInput, Edit1, % "ahk_id " hDlg ;WM_GETTEXT := 0xD
		DllCall("user32\EndDialog", Ptr,hDlg, Ptr,wParam&1)
	}
}

;==================================================

;IDD_INPUTBOX DIALOGEX 0, 0, 210, 83
;STYLE DS_SETFONT | DS_SETFOREGROUND | DS_FIXEDSYS | DS_CENTER | WS_POPUP |
;    WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
;CAPTION "Dialog"
;FONT 18, "MS Shell Dlg", 400, 0, 0x0
;BEGIN
;    EDITTEXT        IDC_INPUTEDIT,2,51,207,12,ES_AUTOHSCROLL
;    DEFPUSHBUTTON   "OK",IDOK,51,67,31,12
;    PUSHBUTTON      "Cancel",IDCANCEL,129,67,31,12
;    LTEXT           "Prompt",IDC_INPUTPROMPT,3,2,205,48
;END

;DLGTEMPLATEEX structure | Microsoft Docs
;https://msdn.microsoft.com/en-us/library/ms645398(v=VS.85).aspx
;DLGITEMTEMPLATEEX structure | Microsoft Docs
;https://msdn.microsoft.com/en-us/library/ms645389(v=VS.85).aspx

;DLGTEMPLATEEX (1 struct):
;1,0 ;dlgVer
;255,255 ;signature
;0,0,0,0 ;helpID
;0,0,0,0 ;exStyle
;72,10,204,128 ;style ;0x80CC0A48
;4,0 ;cDlgItems
;0,0 ;x
;0,0 ;y
;210,0 ;cx
;83,0 ;cy
;0,0 ;menu
;0,0 ;windowClass
;68,0,105,0,97,0,108,0,111,0,103,0,0,0 ;title ;'Dialog'
;10,0 ;pointsize
;144,1 ;weight ;400
;0 ;italic
;0 ;charset
;77,0,83,0,32,0,83,0,104,0,101,0,108,0,108,0,32,0,68,0,108,0,103,0,0,0 ;typeface ;'MS Shell Dlg'

;DLGITEMTEMPLATEEX (4 structs):
;0,0,0,0 ;helpID
;0,0,0,0 ;exStyle
;128,0,129,80 ;style
;2,0,51,0,207,0,12,0 ;x/y/cx/cy
;201,0,0,0 ;id
;255,255,129,0 ;windowClass
;0,0 ;title
;0,0 ;extraCount

;0,0,0,0 ;helpID
;0,0,0,0 ;exStyle
;1,0,1,80 ;style
;51,0,67,0,31,0,12,0 ;x/y/cx/cy
;1,0,0,0 ;id
;255,255,128,0 ;windowClass
;79,0,75,0,0,0 ;title ;'OK'
;0,0 ;extraCount

;0,0,0,0 ;helpID
;0,0,0,0 ;exStyle
;0,0,1,80 ;style
;129,0,67,0,31,0,12,0 ;x/y/cx/cy
;2,0,0,0 ;id
;255,255,128,0 ;windowClass
;67,0,97,0,110,0,99,0,101,0,108,0,0,0 ;'Cancel'
;0,0 ;extraCount

;0,0,0,0 ;helpID
;0,0,0,0 ;exStyle
;0,0,2,80 ;style
;3,0,2,0,205,0,48,0 ;x/y/cx/cy
;204,0,0,0 ;id
;255,255,130,0 ;windowClass
;80,0,114,0,111,0,109,0,112,0,116,0,0,0 ;title ;'Prompt'
;0,0 ;extraCount

;==================================================
Last edited by jeeswg on 08 Feb 2019, 15:59, edited 1 time in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
kczx3
Posts: 1640
Joined: 06 Oct 2015, 21:39

Re: big InputBox via DialogBoxIndirectParam

30 Dec 2018, 19:30

Screenshots are always helpful for those of us browsing on mobile 😁
burque505
Posts: 1736
Joined: 22 Jan 2017, 19:37

Re: big InputBox via DialogBoxIndirectParam

31 Dec 2018, 17:45

YWIMC :)
Attachments
Bee-eeg-Input-Box.gif
Bee-eeg-Input-Box.gif (242.57 KiB) Viewed 1347 times

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: gwarble and 135 guests