' thinBasic UI-script-Template TextIn & TextOut
#Region "Preprocessing"
'---------------------------------------------------------------
Uses "UI", "INI", "OS"
'---------------------------------------------------------------
#EndRegion
'##############################################################################################
#Region "Equatification"
'---------------------------------------------------------------
begin Const
$APP_Title = "NewScript_Untitled" ' use chars taht are valid in filenames
$Prompt = "Ready >"
%LenPrompt = lenf($Prompt) ' do not recalculate, it will not change
' FONTS: use 3: %monospaced, %regularFont + %HeaderFont
' prepared to use an non-OOBE-font (OOBE=Out Of the Box-Experience)
' so if a fonts was not shipped with windows not every user has it.
' therefore check and provide a fallback-font if we don't ship the
' font with this app.
' replace "PT MONO" with your favorite monospaced font if you don't
' have it on your system - or fallback to Courier New
%monoSpaced = iif$( instr(1, ucase$(Font_List), "PT MONO"),
font_new("PT Mono",10), Font_New("Courier New",10) )
' header-font for captions headers, menus
%HeaderFont = iif$( instr(1, Ucase$(Font_List), "OPENDYSLEXIC"),
font_new("OpenDyslexic",12), Font_new("Tahoma",12 ) )
' for usual text, information, description
%regularFont = iif$( instr(1, Ucase$(Font_List), "SERGOE UI"),
font_new("Sergoe UI",10), Font_new("MS Sans Serif",10 ) )
%hDlgMain ' slot for window-handle of dialog main
%hTextOut ' require handle to send text from another
%Not_CaseSensitive = 0
%thisProcess = OS_GetCurrentProcessId ' process to get displayed here
' %EvalScriptName = app_scriptpath & "QuestionToCore.tBasic"
' %EvalScriptHeader = Load_File(app_scriptpath & "QuestionTemplate.tBasicI")
end Const
begin ControlID
%tbX_OUT 'Output
%tbx_IN 'Input
%btn_Exit 'Stop
' timer to invoke ReDraw after user is
' done with the size-adjustmments to avoid
' repeatedly refresh while still sizing
%delayToRefresh
'--------------- MenuBar-popups
'--------------- Menuitems
end ControlID
'---------------------------------------------------------------
#EndRegion
'##############################################################################################sub CreateMainWindow( byref hDlg as Dword,
#Region "Global Variables"
'---------------------------------------------------------------
global Script2Eval as string
'---------------------------------------------------------------
#EndRegion
'##############################################################################################sub CreateMainWindow( byref hDlg as Dword,
' >> setup procedure of the applications main window <<
Sub CreateMainWindow( byref hDlg as dword,
optional byval Title$ as string,
byval hParent AS DWORD )
'------------------------------------------------------------------
' -- set initial window position & size for first execution
long x = -1
long y = -1
long w = 360
long h = 270
long lStyle = %WS_CLIPCHILDREN | %WS_CLIPSIBLINGS | %WS_DLGFRAME |
%WS_CAPTION | %WS_SYSMENU | %WS_OVERLAPPEDWINDOW
Long lExStyle = %WS_EX_TOOLWINDOW
boolean SkipIniSettings ' = True ' override Inifile temporary
' --------------------------------------------------------------------
long cW, cH
Desktop get client to cW, cH
' -- if positions not in range then use centered
if not between(X, 0, cW-W) then x = minmax(cW/2 - w/2, 0, cW - W)
if not between(Y, 0, cH-H) then y = minmax(cH/2 - h/2, 0, cH - H)
if Not SkipIniSettings Then
' -- if no caption passed use the app-title as windoow-caption
if Title$ = "" then Title$ = $App_Title
' -- check the inifile for the last settings
x = val( ini_getkey(App_inifile, "DlgMain", "X", str$(X)))
y = val( ini_getkey(App_inifile, "DlgMain", "Y", str$(Y)))
w = val( ini_getkey(App_inifile, "DlgMain", "W", str$(W)))
h = val( ini_getkey(App_inifile, "DlgMain", "H", str$(H)))
EndIf
' -- apply all settings to new created dialog
Dialog New Pixels, Name DlgMain, hParent, Title$,
x, y, w, h,
lStyle, lExstyle To hDlg
dialog get client hDlg to cW, cH
' -- Dialog ready to take controls now
' use monospaced fonts for a console alike impression at TextIn & TextOut
SendMessage(hDlg, %WM_FONTCHANGE, %monospaced, 0)
local hCtrl as dword at varptr(%hTextOut)
hCtrl = Control Add Textbox, Name TextOut, hDlg, %tbx_Out, "", 5, 5, cW-10, cH - 105,
%ES_MULTILINE | %ES_AUTOHSCROLL | %ES_AUTOVSCROLL | %WS_VSCROLL | %ES_ReadOnly,
%WS_EX_StaticEDGE | %ws_ex_left
Control set font hDlg, %tbx_OUT, %monospaced
control set Resize hDlg, %tBX_Out, 1, 1, 1, 1
Control Add Textbox, Name TextIn, hDlg, %tbx_In, $Prompt, 5, cH-95, cW-10, 60,
%WS_Tabstop | %ES_MULTILINE | %ES_AUTOHSCROLL | %ES_AUTOVSCROLL | %WS_VSCROLL | %Es_WantReturn,
%WS_EX_CLIENTEDGE | %ws_ex_left
control set Resize hDlg, %tBX_IN, 1, 1, 0, 1
Control Set Font hDlg, %tbx_IN, %monospaced
Control set Focus hDlg, %tbx_IN
control Append text hDlg, %tbx_IN, $Spc ' to prevent selection of $Prompt
' change font to HeaderFont for all other controls
SendMessage(hDlg, %WM_FONTCHANGE, %HeaderFont, 0)
control add button, Name btnExit, hDlg, %btn_Exit, "Exit", cW * 0.667, ch-32, cW * 0.333-5, 30, %BS_DEFAULT
Control set Font hDlg, %btn_Exit, %HeaderFont
control set Resize hDlg, %btn_Exit, 0, 1, 0, 1
'----------------------------------------------------------------
End sub
'###############################################################
' >> check the input for contained message <<
Function IsPossible(Byref sInPut As String) As Boolean
Long lSpace
Number ExecutionTime, ExecDuration
'---------------------------------------------------------------
if startswith(sInput, "cmd", %Not_CaseSensitive) then
TextOut.Text &= Shell_CaptureInput(sInput,,,5000) & CRLF
elseif startswith(sInput, "Run ", %Not_CaseSensitive) then
sInput = Remain$(sInput, "Run ", %Not_CaseSensitive))
if Any ( Endswith(sInput, ".exe", %Not_CaseSensitive),
Endswith(sInput, ".msi", %Not_CaseSensitive),
Endswith(sInput, ".mmc", %Not_CaseSensitive),
Endswith(sInput, ".lnk", %Not_CaseSensitive),
Endswith(sInput, ".symlnk", %Not_CaseSensitive) ) Then
' not passing parameters
TextOut.Text &= "Executing " & sInput & "..." & CRLF
shell(sInput,,true)
' elseIf startswith(sInput, "RunAs ", %Not_CaseSensitive) then
'[todo] run as AdMin
endif
else
if Instr(2, sInput Any " /-+:=" & $DQ ) > 0 then
' some parametes obviouslay, append a file where
' to put the results. Make sure it contains the right message if failure...
Save_File(App_Scriptpath & "returned.txt", sInput & " did not return any usable result" & crlf)
sInput &= " > " & App_Scriptpath & "returned.txt"
Shell(sInput,"")
TextOut.Text &= Load_File(App_Scriptpath & "returned.txt")
endif
endif
sTextOut.Text &= crlf
'---------------------------------------------------------------
End Function
'####################################################################################################
#Region "Callback Functions" '### Callback Functions ### Callback Functions### Callback Functions ###
'####################################################################################################
' >> Refresh of the dialog is invoked after resizing by a timer <<
CallBack Function DlgMain_OnTimer() As Long
long W,H
'-------------------------------------------------------------------
if cbctl = %delayToRefresh then
dialog get size cbhndl to w, h
dialog set size cbhndl, w + 1, h ' tiny movements horizontal
dialog set size cbhndl, w, h + 1 ' & vertical to make the
dialog set size cbhndl, w, h ' controls looking good again
dialog Redraw cbhndl
dialog kill timer cbhndl, cbctl
Endif
function=true ' reply the callback - else it will not
' bother to send messages. if no reply
' it will not waste any more energy to
' call on functions that seem not to exist
' nor such that seem to have no body
'-------------------------------------------------------------------'-------------------------------------------------------------------
End Function
'##############################################################################################
' >> after dialog got resized its time to redraw all objects <<
CallBack Function DlgMain_OnSizing() As Long
'-------------------------------------------------------------------
Dialog set Timer %hDlgMain, %delayToRefresh, 200
' use of a timer to redraw the window content after resizing
' the window to prevent the content from flickering
function = true
'-------------------------------------------------------------------
End Function
'##############################################################################################
CallBack Function DlgMain_OnDestroy() As Long
'-------------------------------------------------------------------
Long x, y
'-------------------------------------------------------------------
' -- final save of settings
dialog Get loc %hDlgMain to x,y
ini_setkey(App_inifile, "DlgMain", "X", str$(X))
ini_Setkey(App_inifile, "DlgMain", "Y", str$(Y))
dialog get size %hDlgMain to x, y
ini_Setkey(App_inifile, "DlgMain", "W", str$(X))
ini_Setkey(App_inifile, "DlgMain", "H", str$(Y))
'-------------------------------------------------------------------
End Function
'##############################################################################################
CallBack Function TextIn_OnChange() As Long
String sInput
'-------------------------------------------------------------------
'--- SELECTION START HERE --- SELECTION START HERE --- SELECTION START HERE ---
' V
' V select this part and cut it
' V
' V
' V
'[todo] check this out: old syntax not functioning
if all(cbmsg=%WM_command, getasynckeystate(%VK_Return)) then
' V
' V
' V
control get text %hDlgMain, %tbx_IN to sInput
if startswith(sInput, $Prompt) Then
' V
sInput= trimfull$( Remove$(sInput, $Prompt) )
control_appendtext( %hDlgMain, %tbx_OUT, sInput & crlf )
' V
control set Text %hDlgMain, %tbx_IN, $Prompt
' V
control append text %hDlgMain, %tbx_IN, $SPC
endif
endif
' V
' V
' V
if GetAsyncKeyState(-1) then nop 'clear it...
function = true
end Function
CallBack Function ERASE_THIS_LINE(SELECTTION_Start_At_MARKED_LINE_244,
GO_DOWN_TO_SELECT_UNTIL_LINE_270,
THEN_DELETE_SELECTION_AND_RUN_AGAIN) As Long
' V
' V
' V
' --- SELECTION END HERE --- SELECTION END HERE --- SELECTION END HERE ---
if GetAsyncKeyState(%VK_RETURN) then
sInput = trimfull$(remove$(TextIn.Text, crlf))
TextIn.Text = ""
textOut.Text = textOut.Text & sInput & CRLF
select case lCase$(sInput)
case "cls", "clr"
TextOut.Text = ""
case "exit", "stop", "quit"
dialog end %hDlgMain
case Else
if Not IsPossible(sInput) then
textOut.Text = textOut.Text & "unable to process " & $DQ & sInput & $DQ & crlf
EndIf
end select
endif
' request to clear (-1) and take the result from stack
sInput = mkl$(GetAsyncKeyState(-1))
function = true ' reply to continue receiving messages
'-------------------------------------------------------------------
end Function
'##############################################################################################
CallBack Function btnExit.onClick() As Long
'----------------------------------------------------------------------------------------------
dialog end %hDlgMain
function = true
end Function
'----------------------------------------------------------------------------------------------
#EndRegion
'##############################################################################################
'### TBMain() ### TBMain() ### TBMain() ### TBMain() ### TBMain() ### TBMain() ### TBMain() ###
'###############################################################################################
Function TBMain() As Long
'---------------------------------------------------------------------
CreateMainWindow(%hDlgMain) ' call to create the main dialog
dialog set Minsize %hDlgMain, 160, 120 ' apply the minimum size
DIALOg show Modeless %hDlgMain ' use automatic Callback
if HiResTimer_Init then nop ' will use HiResTimer sometimes
' -- entering the
' MAIN LOOP
' -- >>>
repeat
DoEvents
until NOT isWindow( %hDlgMain )
' -- hurry, the rats are leaving the ship!
'---------------------------------------------------------------------
End Function
'#####################################################################################
'### EOF ### EOF ### EOF ### EOF ### EOF ### EOF ### EOF ### EOF ### EOF ### EOF ###
'#####################################################################################
Bookmarks