ErosOlmi
16-10-2018, 15:01
thinBasic 1.10.5 introduces CODEPTR, a new feature usually not available in interpreted languages that do not have scripts compiled in binary code.
https://www.thinbasic.com/public/products/thinBasic/help/html/index.html?codeptr.htm
CODEPTR is the equivalent of a pointer to a sub/function or in general a pointer to an execution memory address.
It is used to pass to external library a pointer to a function in such a way external library can invoke back the function.
For example Windows SDK programming uses it for events callbacks.
In thinBasic you can use CODEPTR in many ways, let's see some examples.
Subclassing a control (textbox, button, ...)
"If a control does almost everything you want, but you need a few more features, you can change or add features to the original control by subclassing it.
A subclass can have all the features of an existing class as well as any additional features you want to give it."
More info at https://docs.microsoft.com/en-us/windows/desktop/controls/subclassing-overview
You can get an example in \thinBasic\SampleScripts\UI\SDK\TextBox_SubClass.tbasic script.
In that example we have a textbox that does ALMOST what we need because we want also: no space allowed in the textbox, not possible to paste text using copy/paste.
Subclassing means: substitute standard events function of the control with your own one in order to receive events before the standard events function.
You can decide which events to handle and which events pass to original events function
Allows external library call your script functions when needed
There are some libraries that needs to talk back to the caller in order to signal that something has happened and a decision on what to do must be taken.
This is topical of User Interface libraries when an event is fired but the decision of what to do is not to be taken by the library but by the caller.
Have a look at IUP library: http://iup.sourceforge.net/
IUP is a User Interface library that implement a simple way to develop Windows with controls and interact with them
In thinBasic see example \thinBasic\SampleScripts\IUP\_IUP_NotePad.tbasic
A simple (not yet finished) example of a simple Notepad like window.
At some point, for every command, you need to decide what to do. To do so you need to tell IUP what script function to call for a certain control.
In IUP you call IupSetCallback function telling what control you want to handle events, and which script function call when an event occurs:
IupSetCallback(item_exit, "ACTION", CodePtr(exit_cb))
Write pure Windows SDK programming
This is quite complex at first but when mastered ... you can do what you want the way you want in Windows.
A thinBasic example showing how to create a Window in SDK programming can be found at: \thinBasic\SampleScripts\UI\SDK\WinApp_SDK.tbasic
It is very basic but only using Windows API:
[*=1]creates a pure SDK window
[*=1]add a menu
[*=1]react to some events showing into a console some data
You can make a copy of this script and add more functionalities.
Please read thinBasic CODEPTR help at https://www.thinbasic.com/public/products/thinBasic/help/html/index.html?codeptr.htm
reading how such functionality has been developed and what are the current limitations.
Hope you like it.
https://www.thinbasic.com/public/products/thinBasic/help/html/index.html?codeptr.htm
CODEPTR is the equivalent of a pointer to a sub/function or in general a pointer to an execution memory address.
It is used to pass to external library a pointer to a function in such a way external library can invoke back the function.
For example Windows SDK programming uses it for events callbacks.
In thinBasic you can use CODEPTR in many ways, let's see some examples.
Subclassing a control (textbox, button, ...)
"If a control does almost everything you want, but you need a few more features, you can change or add features to the original control by subclassing it.
A subclass can have all the features of an existing class as well as any additional features you want to give it."
More info at https://docs.microsoft.com/en-us/windows/desktop/controls/subclassing-overview
You can get an example in \thinBasic\SampleScripts\UI\SDK\TextBox_SubClass.tbasic script.
In that example we have a textbox that does ALMOST what we need because we want also: no space allowed in the textbox, not possible to paste text using copy/paste.
Subclassing means: substitute standard events function of the control with your own one in order to receive events before the standard events function.
You can decide which events to handle and which events pass to original events function
Allows external library call your script functions when needed
There are some libraries that needs to talk back to the caller in order to signal that something has happened and a decision on what to do must be taken.
This is topical of User Interface libraries when an event is fired but the decision of what to do is not to be taken by the library but by the caller.
Have a look at IUP library: http://iup.sourceforge.net/
IUP is a User Interface library that implement a simple way to develop Windows with controls and interact with them
In thinBasic see example \thinBasic\SampleScripts\IUP\_IUP_NotePad.tbasic
A simple (not yet finished) example of a simple Notepad like window.
At some point, for every command, you need to decide what to do. To do so you need to tell IUP what script function to call for a certain control.
In IUP you call IupSetCallback function telling what control you want to handle events, and which script function call when an event occurs:
IupSetCallback(item_exit, "ACTION", CodePtr(exit_cb))
Write pure Windows SDK programming
This is quite complex at first but when mastered ... you can do what you want the way you want in Windows.
A thinBasic example showing how to create a Window in SDK programming can be found at: \thinBasic\SampleScripts\UI\SDK\WinApp_SDK.tbasic
It is very basic but only using Windows API:
[*=1]creates a pure SDK window
[*=1]add a menu
[*=1]react to some events showing into a console some data
You can make a copy of this script and add more functionalities.
Please read thinBasic CODEPTR help at https://www.thinbasic.com/public/products/thinBasic/help/html/index.html?codeptr.htm
reading how such functionality has been developed and what are the current limitations.
Hope you like it.