Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[Function] Custom Input box / Password box


  • Please log in to reply
4 replies to this topic
AmourSpirit
  • Members
  • 93 posts
  • Last active: Mar 01 2016 04:28 PM
  • Joined: 01 Dec 2010
Another custom input box. Reusable.
can be used as Text input or Password input

I was inspired by Icarus post [Function] Custom Msgbox / Custom Buttons
/* 
 * ======================================================================================================================================================
	cInputBox - Custom input box that can be use to capture input or passwords
	Params:
		title = The title to be displayed on the input box
		text = The text to be displayed above the input box
		InputValue = Optional - The inital value of the Inputbox
		owner = Optional - If 0, this will be a standalone dialog. If you want this dialog to be owned by another GUI, place its number here.
		isPassword = Optional - If non-zero or true then the input box will use password masking
	Usage:
		InputReslut := cInputBox("The title", "The Text", "secret",,1)
		if (InputReslut) {
			MsgBox, 64, Result Found, The result from the custom input box is: %InputReslut%
		} else {
			MsgBox, 16, Result Error, The was no result returned from the custom input box
		}
	Other Notes:
		The GuiID should be sufficent for most uses. If however it conflicts then you will need to change it in three places
			GuiID := (New ID number) - found in the second line of the cInpuBox functon
			(New ID number)GuiEscape: - Found just below cInputBox function
			(New ID number)GuiClose: - Found just below cInputBox function
 * ======================================================================================================================================================
 */
cInputBox(title, text, inputValue = "", owner=0,isPassword=0){
	Global _CInput_Result, _cInput_Value
	GuiID := 8      ; If you change, also change the subroutines below for #GuiEscape & #GuiClose
	If( owner <> 0 ) {
		Gui %owner%:+Disabled
		Gui %GuiID%:+Owner%owner%
	}
  
	Gui, %GuiID%:Add, Text, x12 y10 w320 h20 , %text%
	Gui, %GuiID%:Add, Edit, % "x12 y40 w320 h20 -VScroll v_cInput_Value" . ((isPassword <> 0) ? " Password":""), %inputValue%
	Gui, %GuiID%:Add, Button, x232 y70 w100 h30 gCInputButton, % "Cancel"
	Gui, %GuiID%:Add, Button, x122 y70 w100 h30 gCInputButton Default, % "OK"
	Gui, %GuiID%:+Toolwindow +AlwaysOnTop
	Gui %GuiID%:Show,,%title%
 
	Loop
		If( _CInput_Result )
			Break

	If( owner <> 0 )
		Gui %owner%:-Disabled
	Gui, %GuiID%:Submit, Hide

	if (_CInput_Result = "OK"){
		Result := _cInput_Value
	} else {
		Result := ""
	}
	_cInput_Value := ""
	_CInput_Result := ""
	Gui %GuiID%:Destroy
  	Return Result
}

8GuiEscape:
8GuiClose:
  _CInput_Result := "Close"
Return

CInputButton:
  StringReplace _CInput_Result, A_GuiControl, &,, All
Return
Enjoy!

Icarus
  • Members
  • 851 posts
  • Last active: Jan 02 2012 11:17 AM
  • Joined: 24 Nov 2005
Nice :)
Sector-Seven - Freeware tools built with AutoHotkey

Guest10
  • Members
  • 1216 posts
  • Last active: Oct 30 2015 05:12 PM
  • Joined: 27 Oct 2012

 An example:

 

; http://www.autohotkey.com/board/topic/42668-time-count-days-hours-minutes-seconds-between-dates/

#include C:\...\Time.ahk

	InputReslut := cInputBox("Enter Starting Data: Format: DD.MMM", "", ,1)
	if (InputReslut) {
		MsgBox, 64, Result Found, The result from the custom input box is: %InputReslut%
		Starting_Date := InputReslut
	} else {
		MsgBox, 16, Result Error, The was no result returned from the custom input box
	}

	InputReslut := cInputBox("Enter Ending Date: Format: MMM-DD", "", ,1)
	if (InputReslut) {
		MsgBox, 64, Result Found, The result from the custom input box is: %InputReslut%
		Ending_Date := InputReslut
	} else {
		MsgBox, 16, Result Error, The was no result returned from the custom input box
	}

;MsgBox % "Days: " . Time("Mar-10","1.Mar","d") ; Example (9 =10-1 excludes Mar-10)
MsgBox, 262240,, % "Days: " . Time(Ending_Date,Starting_Date,"d") ; <<<<<<<<<< Enter dates here!
ExitApp

; Function

cInputBox(title, text, inputValue = "", owner=0,isPassword=0){
	Global _CInput_Result, _cInput_Value
	GuiID := 8      ; If you change, also change the subroutines below for #GuiEscape & #GuiClose
	If( owner <> 0 ) {
		Gui %owner%:+Disabled
		Gui %GuiID%:+Owner%owner%
	}
  
	Gui, %GuiID%:Add, Text, x12 y10 w320 h20 , %text%
	Gui, %GuiID%:Add, Edit, % "x12 y40 w320 h20 -VScroll v_cInput_Value" . ((isPassword <> 0) ? " Password":""), %inputValue%
	Gui, %GuiID%:Add, Button, x232 y70 w100 h30 gCInputButton, % "Cancel"
	Gui, %GuiID%:Add, Button, x122 y70 w100 h30 gCInputButton Default, % "OK"
	Gui, %GuiID%:+Toolwindow +AlwaysOnTop
	Gui %GuiID%:Show,,%title%
 
	Loop
		If( _CInput_Result )
			Break

	If( owner <> 0 )
		Gui %owner%:-Disabled
	Gui, %GuiID%:Submit, Hide

	if (_CInput_Result = "OK"){
		Result := _cInput_Value
	} else {
		Result := ""
	}
	_cInput_Value := ""
	_CInput_Result := ""
	Gui %GuiID%:Destroy
  	Return Result
}

8GuiEscape:
8GuiClose:
  _CInput_Result := "Close"
Return

CInputButton:
  StringReplace _CInput_Result, A_GuiControl, &,, All
Return

 

; http://www.autohotkey.com/board/topic/42668-time-count-days-hours-minutes-seconds-between-dates/
; Time() - Count Days, hours, minutes, seconds between dates

#NoEnv
SetBatchLines,-1
/*
MsgBox % "Count days from 12 May until 15 May`n"
		. Time("May-15","12.May","d")

MsgBox % "Working hours from 01.05.2009 00:00:00   to   10.05.09 09:30:00`n"
		. "Count only working hours from 09 to 17 and consider weekends and 01.May bank holiday`n"
		. Time("20090504093000","20090501000000","h","W1.7 H9-17 B0105")

MsgBox % "Days to work till end of 2009`n" . Time("01.01.2010","","d","W1.7")

MsgBox % "Hours to work till end of 2009 from 09 - 17`n" . Time("01.01.2010","","h","W1.7 H9-17")

ExitApp
*/

; Time() Function

Time(to,from="",units="d",params=""){
	static _:="0000000000",s:=1,m:=60,h:=3600,d:=86400
				,Jan:="01",Feb:="02",Mar:="03",Apr:="04",May:="05",Jun:="06",Jul:="07",Aug:="08",Sep:="09",Okt:=10,Nov:=11,Dec:=12
	r:=0
	units:=units ? %units% : 8640
	If (InStr(to,"/") or InStr(to,"-") or InStr(to,".")){
		Loop,Parse,to,/-.,%A_Space%
			_%A_Index%:=RegExMatch(A_LoopField,"\d+") ? A_LoopField : %A_LoopField%
			,_%A_Index%:=(StrLen(_%A_Index%)=1 ? "0" : "") . _%A_Index%
		to:=SubStr(A_Now,1,8-StrLen(_1 . _2 . _3)) . _3 . (RegExMatch(SubStr(to,1,1),"\d") ? (_2 . _1) : (_1 . _2))
		_1:="",_2:="",_3:=""
	}
	If (from and InStr(from,"/") or InStr(from,"-") or InStr(from,".")){
		Loop,Parse,from,/-.,%A_Space%
			_%A_Index%:=RegExMatch(A_LoopField,"\d+") ? A_LoopField : %A_LoopField%
			,_%A_Index%:=(StrLen(_%A_Index%)=1 ? "0" : "") . _%A_Index%
		from:=SubStr(A_Now,1,8-StrLen(_1 . _2 . _3)) . _3 . (RegExMatch(SubStr(from,1,1),"\d") ? (_2 . _1) : (_1 . _2))
	}
   count:=StrLen(to)<9 ? "days" : StrLen(to)<11 ? "hours" : StrLen(to)<13 ? "minutes" : "seconds"
	to.=SubStr(_,1,14-StrLen(to)),(from ? from.=SubStr(_,1,14-StrLen(from)))
	Loop,Parse,params,%A_Space%
		If (unit:=SubStr(A_LoopField,1,1))
			 %unit%1:=InStr(A_LoopField,"-") ? SubStr(A_LoopField,2,InStr(A_LoopField,"-")-2) : ""
			,%unit%2:=SubStr(A_LoopField,InStr(A_LoopField,"-") ? (InStr(A_LoopField,"-")+1) : 2)
	count:=!params ? count : "seconds"
	add:=!params ? 1 : (S2="" ? (M2="" ? (H2="" ? ((D2="" and B2="" and W="") ? d : h) : m) : s) : s)
	While % (from<to){
		FormatTime,year,%from%,YYYY
		FormatTime,month,%from%,MM
		FormatTime,day,%from%,dd
		FormatTime,hour,%from%,H
		FormatTime,minute,%from%,m
		FormatTime,second,%from%,s
		FormatTime,WDay,%from%,WDay
		EnvAdd,from,%add%,%count%
		If (W1 or W2){
			If (W1=""){
				If (W2=WDay or InStr(W2,"." . WDay) or InStr(W2,WDay . ".")){
					Continue=1
				}
			} else If WDay not Between %W1% and %W2%
				Continue=1
			;else if (Wday=W2)
			;	Continue=1
			If (Continue){
				tempvar:=SubStr(from,1,8)
				EnvAdd,tempvar,1,days
				EnvSub,tempvar,%from%,seconds
				EnvAdd,from,%tempvar% ,seconds
				Continue=
				continue
			}
		}
		If (D1 or D2 or B2){
			If (D1=""){
				If (D2=day or B2=(day . month) or InStr(B2,"." . day . month) or InStr(B2,day . month . ".") or InStr(D2,"." . day) or InStr(D2,day . ".")){
					Continue=1
				}
			} else If day not Between %D1% and %D2%
				Continue=1
			;else if (day=D2)
			;	Continue=1
			If (Continue){
				tempvar:=SubStr(from,1,8)
				EnvAdd,tempvar,1,days
				EnvSub,tempvar,%from%,seconds
				EnvAdd,from,%tempvar% ,seconds
				Continue=
				continue
			}
		}
		If (H1 or H2){
			If (H1=""){
				If (H2=hour or InStr(H2,hour . ".") or InStr(H2,"." hour)){
					Continue=1
				}
			} else If hour not Between %H1% and %H2%
				continue=1
			;else if (hour=H2)
			;	continue=1
			If (continue){
				tempvar:=SubStr(from,1,10)
				EnvAdd,tempvar,1,hours
				EnvSub,tempvar,%from%,seconds
				EnvAdd,from,%tempvar% ,seconds
				continue=
				continue
			}
		}
		If (M1 or M2){
			If (M1=""){
				If (M2=minute or InStr(M2,minute . ".") or InStr(M2,"." minute)){
					Continue=1
				}
			} else If minute not Between %M1% and %M2%
				continue=1
			;else if (minute=M2)
			;	continue=1
			If (continue){
				tempvar:=SubStr(from,1,12)
				EnvAdd,tempvar,1,minutes
				EnvSub,tempvar,%from%,seconds
				EnvAdd,from,%tempvar% ,seconds
				continue=
				continue
			}
		}
		If (S1 or S2){
			If (S1=""){
				If (S2=second or InStr(S2,second . ".") or InStr(S2,"." second)){
					Continue
				}
			} else if (second!=S2)
				If second not Between %S1% and %S2%
					continue
		}
		r+=add
	}
	tempvar:=SubStr(count,1,1)
	tempvar:=%tempvar%
	Return (r*tempvar)/units
}


jNizM
  • Members
  • 928 posts
  • Last active: Jan 12 2018 09:23 AM
  • Joined: 01 Aug 2012
It's a function
You need to call it

See Usage:
[AHK] 1.1.27.04 x64 Unicode | [WIN] 10 Pro (Version 1709)
My GitHub Profile | Donations are appreciated if I could help you

Guest10
  • Members
  • 1216 posts
  • Last active: Oct 30 2015 05:12 PM
  • Joined: 27 Oct 2012

Thanks! I updated my initial post.