That is nice to know. Redownloading TB as I managed to completely bork it last night.
Printable View
That is nice to know. Redownloading TB as I managed to completely bork it last night.
I'm very close to release thinBasic Beta 1.10.5
New version will be focused on improving message handling in User Interface module.
Mainly I'm expanding the possibility to give a name to every controls (so far only available for Label, Textbox, Button and TreeView) and using that name plus the even name in callback functions it will be possible to trap specific events without the need to have big main window Select/End select cases for events.
In below example there are no callback declared in DIALOG NEW ... or CONTROL ADD ... but both Dialog and Controls has been declared with ... Name "..." ... clause that gives a name to the object like: "MyWindow", "txtFind", "CloseMe", ...
Creating a Callback function having function name equal to the Dialog or Control name followed by the event you want to handle is the only thing you need to add to do in order to trap a specific event ad act according to your needs.
I'm trying to add the most common events. Done that I will add more uncommon events.
More or less it will be like old VB6 events.
An example can show you what I mean. Also attached a Bundled example.
Code:USES "UI"
uses "console"
'---Define a button ID
begin ControlID
%ButtonClose
%ButtonNew
%lblFind
%txtFind
%lblReplace
%txtReplace
end ControlID
Dim hDlg As DWORD
DIALOG New Pixels, Name "MyWindow", 0, "Dialog to show automatic events handling",-1,-1, 640, 480,
%WS_DLGFRAME Or %DS_CENTER Or %WS_CAPTION Or %WS_SYSMENU Or %WS_OVERLAPPEDWINDOW,
0 To hDlg
CONTROL ADD Label Name "lblFind" , hDlg, %lblFind , "Find" , 10, 15, 350, 20, %SS_NOTIFY
CONTROL ADD Textbox Name "txtFind" , hDlg, %txtFind , "" , 10, 30, 350, 25, %ES_AUTOHSCROLL | %ES_LEFT | %WS_BORDER | %WS_TABSTOP
CONTROL ADD Label Name "lblReplace" , hDlg, %lblReplace , "Replace" , 10, 55, 350, 20, %SS_NOTIFY
CONTROL ADD Textbox Name "txtReplace" , hDlg, %txtReplace , "" , 10, 70, 350, 25, %ES_AUTOHSCROLL | %ES_LEFT | %WS_BORDER | %WS_TABSTOP
CONTROL ADD BUTTON Name "New" , hDlg, %ButtonNew , "New" , 480, 10, 150, 25, %BS_NOTIFY | %BS_CENTER | %BS_VCENTER | %WS_TABSTOP
CONTROL ADD BUTTON Name "CloseMe" , hDlg, %ButtonClose , "Close" , 480, 40, 150, 25, %BS_NOTIFY | %BS_CENTER | %BS_VCENTER | %WS_TABSTOP
DIALOG SHOW MODAL hDlg
'------------------------------------------------
' Callback function used to handle dialog events
' not handled by specific event functions
'------------------------------------------------
CallBack Function MyWindow_OnCallBack() As Long
'------------------------------------------------
printl Timer, Function_Name, CBMSG, "DIALOG message not handled by specific event function"
End Function
'------------------------------------------------
CallBack Function MyWindow_OnInit() As Long
'------------------------------------------------
printl Timer, Function_Name
control set Resize CBHNDL, %ButtonNew , 0, 1, 0, 0
control set Resize CBHNDL, %ButtonClose , 0, 1, 0, 0
End Function
'------------------------------------------------
CallBack Function MyWindow_OnSize() As Long
'------------------------------------------------
printl Timer, Function_Name, CBWPARAM, HIWRD(CBLPARAM), LOWRD(CBLPARAM)
End Function
'------------------------------------------------
CallBack Function MyWindow_OnMove() As Long
'------------------------------------------------
printl Timer, Function_Name, CBWPARAM, HIWRD(CBLPARAM), LOWRD(CBLPARAM)
End Function
'------------------------------------------------
CallBack Function MyWindow_OnMoving() As Long
'------------------------------------------------
printl Timer, Function_Name
End Function
'------------------------------------------------
CallBack Function MyWindow_OnMouseMove() As Long
'------------------------------------------------
printl Timer, Function_Name
End Function
'------------------------------------------------
CallBack Function MyWindow_OnNCHITTEST() As Long
'------------------------------------------------
printl Timer, Function_Name
End Function
'------------------------------------------------
CallBack Function MyWindow_OnSETCURSOR() As Long
'------------------------------------------------
printl Timer, Function_Name
End Function
'------------------------------------------------
CallBack Function MyWindow_OnLBUTTONDOWN() As Long
'------------------------------------------------
printl Timer, Function_Name
End Function
'------------------------------------------------
CallBack Function MyWindow_OnLBUTTONUP() As Long
'------------------------------------------------
printl Timer, Function_Name
End Function
'------------------------------------------------
CallBack Function MyWindow_OnLBUTTONDBLCLK() As Long
'------------------------------------------------
printl Timer, Function_Name
End Function
'------------------------------------------------
CallBack Function MyWindow_OnNCMOUSEMOVE() As Long
'------------------------------------------------
printl Timer, Function_Name
End Function
'------------------------------------------------
CallBack Function MyWindow_OnNCMOUSELEAVE() As Long
'------------------------------------------------
printl Timer, Function_Name
End Function
'------------------------------------------------
CallBack Function MyWindow_OnCommand() As Long
'------------------------------------------------
printl Timer, Function_Name
End Function
'------------------------------------------------
CallBack Function MyWindow_OnClose() As Long
'------------------------------------------------
printl Timer, Function_Name
End Function
'------------------------------------------------
CallBack Function MyWindow_OnSHOWWINDOW() As Long
'------------------------------------------------
printl Timer, Function_Name
End Function
'------------------------------------------------
CallBack Function MyWindow_OnDestroy() As Long
'------------------------------------------------
printl Timer, Function_Name
PrintL "Window just destroyed. Press a key to end" in %CCOLOR_FLIGHTRED
WaitKey
End Function
'------------------------------------------------------------------------------
' BUTTON EVENT
'------------------------------------------------------------------------------
'------------------------------------------------
CallBack Function CloseMe_OnClick() As Long
'------------------------------------------------
printl Timer, Function_Name
DIALOG End CBHNDL
End Function
'------------------------------------------------
CallBack Function CloseMe_OnSetFocus() As Long
'------------------------------------------------
printl Timer, Function_Name
End Function
'------------------------------------------------
CallBack Function CloseMe_OnKillFocus() As Long
'------------------------------------------------
printl Timer, Function_Name
End Function
'------------------------------------------------
CallBack Function New_OnClick() As Long
'------------------------------------------------
printl Timer, Function_Name
End Function
'CallBack Function CloseMe_OnCallBack() As Long
''------------------------------------------------
'
' printl Timer, Function_Name, CBMSG, "BUTTON message not handled by specific event function"
'
'End Function
'------------------------------------------------------------------------------
' LABEL EVENT
'------------------------------------------------------------------------------
'------------------------------------------------
CallBack Function lblFind_OnClick() As Long
'------------------------------------------------
printl Timer, Function_Name
End Function
'------------------------------------------------
CallBack Function lblFind_OnDblClk() As Long
'------------------------------------------------
printl Timer, Function_Name
End Function
'------------------------------------------------
CallBack Function lblFind_OnDisable() As Long
'------------------------------------------------
printl Timer, Function_Name
End Function
'------------------------------------------------
CallBack Function lblFind_OnEnable() As Long
'------------------------------------------------
printl Timer, Function_Name
End Function
'------------------------------------------------------------------------------
' TEXTBOX EVENT
'------------------------------------------------------------------------------
'------------------------------------------------
CallBack Function txtFind_OnCallback() As Long
'------------------------------------------------
printl Timer, Function_Name, CBCTLMSG
Function = %TRUE
End Function
'------------------------------------------------
CallBack Function txtFind_OnChange() As Long
'------------------------------------------------
printl Timer, Function_Name, "text changed to", Control_GetText(CBHNDL, CBCTL)
Function = %TRUE
End Function
'------------------------------------------------
CallBack Function txtFind_OnUpdate() As Long
'------------------------------------------------
printl Timer, Function_Name
Function = %TRUE
End Function
'------------------------------------------------
CallBack Function txtFind_OnSetFocus() As Long
'------------------------------------------------
printl Timer, Function_Name
End Function
'------------------------------------------------
CallBack Function txtFind_OnKillFocus() As Long
'------------------------------------------------
printl Timer, Function_Name
End Function
'------------------------------------------------
CallBack Function txtReplace_OnChange() As Long
'------------------------------------------------
printl Timer, Function_Name, "text changed to", Control_GetText(CBHNDL, CBCTL)
Function = %TRUE
End Function
'------------------------------------------------
CallBack Function txtReplace_OnUpdate() As Long
'------------------------------------------------
printl Timer, Function_Name
Function = %TRUE
End Function
'------------------------------------------------
CallBack Function txtReplace_OnSetFocus() As Long
'------------------------------------------------
printl Timer, Function_Name
End Function
'------------------------------------------------
CallBack Function txtReplace_OnKillFocus() As Long
'------------------------------------------------
printl Timer, Function_Name
End Function
Do like,
I never enjoyed those huge SELECT CASE monuments for filtering API messages :)
Petr
if you want you can make a thinbasic experimental version completely like VB6. you can host it in github site. in the days of vb6 it was nearly every day job to write something like this:
Private Sub Command1_Click()
For i = 1 To 1000
total = total + i
Next i
Text1.Text = total
End Sub
Text1 is the first Text Box, while Sub Command1_Click() is the click event of the first Button. the ""Private Sub Command1_Click()"" is opened automatically when we DBL click on the button in the vb6 Form designer.
this why is why in thinbasic i am using 2 codes : one for the GUI design (because its complexity and i don't want to see it any more) and the other for the everyday usage code such as my post here:
http://www.thinbasic.com/community/s...with-ThinBasic
the controls and Dialog codes is so complex so it is better to hide it under easy to remember clothes and names. but this suggested approach will not run the old code. this is why i suggest it as an experimental and another flavor of thinbasic to put it in github site
Thanks a lot primo.
So far I'm working on handling "events" that is "Command1_Click()" firing.
But your suggestion on control.property (Text1.Text) is inspiring me on other fields.
As soon as I will finish on control events, I will think about control properties. Control Name is already there.
Quite exciting about new features I'm adding to UI (User Interface) module for the next thinBasic version.
Dialog and controls automatic event handling functions: just give a name to windows or controls and your will have a lot of function events ready to be personalized.
Dialog and controls properties: just give a name to windows or controls and you will have a lot of easy to be used properties to get/set
An example that will be available with next thinBasic 1.10.5 as soon and it will be ready and attached a working executable:
Code:USES "UI"
'---Define a button ID
begin ControlID
%lblNum1
%txtNum1
%lblNum2
%txtNum2
%lblResult
%txtResult
%lblOp
%cbOp
%btnResult
%btnClose
end ControlID
string sOperations(4) = "+", "-", "*", "/"
dialog Font "Courier New", 12
DIALOG New Pixels , Name SimpleCalc, 0, "Basic calculator with events",-1,-1, 640, 380,
%WS_DLGFRAME | %DS_CENTER | %WS_CAPTION | %WS_SYSMENU | %WS_OVERLAPPEDWINDOW,
CONTROL ADD Label , Name lblNum1 , SimpleCalc.Handle, %lblNum1 , "Number 1" , 10, 15, 350, 20, %SS_NOTIFY
CONTROL ADD Textbox , Name txtNum1 , SimpleCalc.Handle, %txtNum1 , "" , 10, 30, 350, 30, %ES_AUTOHSCROLL | %ES_RIGHT | %WS_TABSTOP | %ES_NUMBER
CONTROL ADD Label , Name lblOp , SimpleCalc.Handle, %lblOp , "Operation" , 10, 60, 350, 20, %SS_NOTIFY
CONTROL ADD COMBOBOX, Name cbOp , SimpleCalc.Handle, %cbOp , sOperations , 10, 75, 350, 100, %CBS_DROPDOWNLIST | %WS_TABSTOP
CONTROL ADD Label , Name lblNum2 , SimpleCalc.Handle, %lblNum2 , "Number 2" , 10, 110, 350, 20, %SS_NOTIFY
CONTROL ADD Textbox , Name txtNum2 , SimpleCalc.Handle, %txtNum2 , "" , 10, 125, 350, 30, %ES_AUTOHSCROLL | %ES_RIGHT | %WS_TABSTOP '| %ES_NUMBER
CONTROL ADD Label , Name lblResult, SimpleCalc.Handle, %lblResult , "Result" , 10, 255, 350, 20, %SS_NOTIFY
CONTROL ADD Textbox , Name txtResult, SimpleCalc.Handle, %txtResult , "0" , 10, 270, 350, 30, %ES_AUTOHSCROLL | %ES_RIGHT | %WS_TABSTOP | %ES_READONLY
CONTROL ADD BUTTON , Name btnResult, SimpleCalc.Handle, %btnResult , "Result" , 480, 10, 150, 25, %BS_NOTIFY | %BS_CENTER | %BS_VCENTER | %WS_TABSTOP
CONTROL ADD BUTTON , Name btnClose , SimpleCalc.Handle, %btnClose , "Close" , 480, 340, 150, 25, %BS_NOTIFY | %BS_CENTER | %BS_VCENTER | %WS_TABSTOP
DIALOG SHOW MODAL SimpleCalc.Handle
'------------------------------------------------
' Callback function used to handle dialog events
' not handled by specific event functions
'------------------------------------------------
CallBack Function SimpleCalc_OnCallBack() As Long
'------------------------------------------------
End Function
'------------------------------------------------
CallBack Function SimpleCalc_OnLoad() As Long
'------------------------------------------------
'---Limits window minimum size
DIALOG SET MINSIZE SimpleCalc.Handle, 550, 320
'---Force resize logic
control set Resize CBHNDL, %btnResult , 0, 1, 0, 0
control set Resize CBHNDL, %btnClose , 0, 1, 0, 1
'---Select first element in combo operations
COMBOBOX SELECT SimpleCalc.Handle, %cbOp, 1
'---Some initial values
txtNum1.Text = "10"
txtNum2.Text = "20"
'---Change name to Close button
btnClose.Text = "Close Me"
End Function
'------------------------------------------------
' Function fired when SimpleCalc window will be closed
'------------------------------------------------
CallBack Function SimpleCalc_OnDestroy() As Long
'------------------------------------------------
MsgBox "Thanks for testing thinBASIC"
End Function
'------------------------------------------------
' Function fired when button Close is clicked
'------------------------------------------------
CallBack Function btnClose_OnClick() As Long
'------------------------------------------------
DIALOG End CBHNDL
End Function
'------------------------------------------------
' Function fired when drop down combo box is closed after a selection
'------------------------------------------------
callback function cbOp_ONCLOSEUP() as Long
'------------------------------------------------
CalculateResult
End Function
'------------------------------------------------
' Function fired when change selected item in a drop down combo box
'------------------------------------------------
callback function cbOp_ONSELCHANGE() as Long
'------------------------------------------------
CalculateResult
End Function
'------------------------------------------------
' Function fired when button Result is clicked
'------------------------------------------------
CallBack Function btnResult_OnClick() As Long
'------------------------------------------------
CalculateResult
End Function
'------------------------------------------------
' Function fired when text inside txtNum1 textbox is changed
'------------------------------------------------
CallBack Function txtNum1_OnChange() As Long
'------------------------------------------------
CalculateResult
End Function
'------------------------------------------------
' Function fired when text inside txtNum2 textbox is changed
'------------------------------------------------
CallBack Function txtNum2_OnChange() As Long
'------------------------------------------------
CalculateResult
End Function
'------------------------------------------------
' Calculate and fill txtResult textbox
'------------------------------------------------
Function CalculateResult() as ext
'------------------------------------------------
txtResult.BackColor = rgb(0, 255, 255)
select case cbOp.Text
case "+"
txtResult.Text = tstr$(val(txtNum1.text) + val(txtNum2.text))
case "-"
txtResult.Text = tstr$(val(txtNum1.text) - val(txtNum2.text))
case "*"
txtResult.Text = tstr$(val(txtNum1.text) * val(txtNum2.text))
case "/"
if val(txtNum2.text) Then
txtResult.Text = tstr$(val(txtNum1.text) / val(txtNum2.text))
Else
txtResult.BackColor = rgb(255, 0, 0)
txtResult.Text = "Div/0"
end If
end Select
function = txtResult.Text
End Function
Thanks Eros
this is what is needed, like the good old VB6Quote:
txtNum1.Text = "10"
txtNum2.Text = "20"
so i can hide the GUI complex code in an include file and in the working code i use the new syntax
hope also the same for the RichEdit box
but does the new version can't run the TB 1.10.4 examples or it will run the 1.10.4 examples and the newer 1.10.5 examples ??. or may be an option button in the Options settings gives the user the choice of new vb6 style or the TB 1.10.4 style
thinBasic is always (or quite always) compatible with the past.
So new features will not change anything and will remain compatible with old code.
It will be just a matter of programmer coding style
Eros,
you are on fire. Thank you very much for another bucket of hard work :).
I have an heretic suggestion - what about making the ctrlId optional for named controls? Once somebody names the control, he will probably use this magic as much as possible and that ctrlId could be generated internally automagically. What do you think?
Petr
Great idea, as usual.
First I need to get most of all possible properties available.
Than I will make it optional.
So far I've added the following control properties, most of them bot SET/GET, some only GET (read only) to Buttons, Labels, Textbox, Combobox, Canvas, Dialogs:
- Name
- Text
- Id
- Parent
- Handle
- FORECOLOR
- BACKCOLOR
- X
- Y
- W
- H
Also added many control and dialogs events.
I'm really excited. Once done code will really resemble VB6
Bad news is that it will take months to write help documentation :(