PDA

View Full Version : New in UI module: Controls CALLBACKs



ErosOlmi
10-07-2008, 17:47
Next UI module will have Controls CALLBACKS implemented for at least basic Controls.
_________________________________________________
What are CALLBACKS? Are special functions associated with UI Controls (Buttons, Labels, ...) that are automaticalli executed when the relevant control is activated by an event.

For example, so far, when you wanted to handle a Button Click you had to add a SELECT CASE %WM_COMMAND in the main dialog message pump and than make a SELECT to determine which control fired the event, ... and so on.

In next UI module you will just tell the control which script funtion will be in charge to handle its events with the following syntax:


CONTROL ADD BUTTON, hwnd, ctrlID, txt, _
xPos, yPos, Width, Height, _
Style, _
ExStyle, _
CALL StringExpression _

Example:

callback function cbButton_Click() as long
printl CBHNDL, CBCTL, CBCTLMSG, CBLPARAM, CBWPARAM
'---Do something

function = %TRUE
end function

control add button, hDlg, %ID_CONTROL, "My Button", _
200, 270, 65, 14, _
%WS_CHILD or %WS_VISIBLE or %WS_TABSTOP or %BS_FLAT, _
0 _
CALL "cbButton_Click"

Inside a CALLBACK function 5 automatic variables will be populated:
CBHNDL: handle of the control parent window
CBCTL: control ID
CBCTLMSG: Message sent to the control
CBLPARAM: wParam
CBWPARAM: lParam

Hope you like it.
Eros

Petr Schreiber
10-07-2008, 17:58
Hi Eros,

very nice addition, thanks!
It can help to keep code modular.


Petr

catventure
10-07-2008, 18:02
Ooh! I think I'm going to like that - A LOT! ;D

Code should be clearer, easier to write and to read too...

Can we still use the old way as well? Or does everything have to change from existing message pump method to new callback function way?

Anyhow it looks like a great improvement ( my personal opinion ) and an exciting development in thinBasic.

catventure.

ErosOlmi
10-07-2008, 19:27
:D I'm quite excited too.

Standard syntax will still be valid of course. Both syntaxes can be used at the same time control by control.
For the moment it is active only for BUTTONS.

I hope I will be able add it to all controls. I'm checking possible negative implications. I have doubts possible in sync parsing problems can arise ...

Anyhow, attached a test DLLs. Please keep your original ones, the attached one are very very under development ;)

Updated ZIP file: forgot to add needed files for example to run.

Attached file revomed. See updated post at: http://community.thinbasic.com/index.php?topic=1882.msg13893#msg13893

ErosOlmi
10-07-2008, 20:42
Updated example in attached file.

catventure
10-07-2008, 21:18
Hi Eros,

Button example worked fine here.

catventure.

Michael Clease
10-07-2008, 21:44
I like the idea and it will clean up code but is there any reason that the callback is required before the function?

ErosOlmi
10-07-2008, 22:00
The main reason is that when such functions are executed, thinBasic has to automatically create the specified variables:

CBHNDLhandle of the control parent window
CBCTLcontrol ID that fired the message (event)
CBCTLMSG message sent to the control
CBLPARAMwParam
CBWPARAMlParam


Without those variables, there is no way to know (for inside the callback function) where and what event has occurred. So, as you can see, those are special function not to be executed by themself.

Also, because those fucntions are special, I want to be aware the programmer fully understand them making mandatory to add CALLBACK in front. When you specify one of these fucntions in a CONTROL ADD BUTTON ... thinBasic checks that the indicated fucntion has been defined as CALLBACK.

Ok, at the end it is not 100% needed by the thinBasic engine but I prefer (so far) to leave it.

Ciao
Eros

kryton9
11-07-2008, 02:16
That is really nice Eros, thanks a lot.

Michael Hartlef
11-07-2008, 07:20
Thanks Eros,

that is a great addition. But I think if you ever plan on writing a compiler for thinBasic, don't touch it.

There are so many options now in the language alone, that this flexiblity is definately a better realized in an interpreted environment.

Michael

ErosOlmi
11-07-2008, 07:26
Do not worry.
Writing a compileris something outside my capacity range ;D

Michael Clease
11-07-2008, 14:23
I get your point (4 posts back Eros) and agree it does make sense

If you could do this with menus that would be great. No pressure ;)


MENU ADD STRING, hPopup1, "&Open", %ID_OPEN, %MF_CHECKED or %MF_GRAYED, Call "FileOpen"

so its the same format.

I think this addition to the UI of TB is a nice leap, and will be more logical in the coding structure.

Thanks Eros

ErosOlmi
11-07-2008, 14:48
That's a good idea and I think I can do it.

So far I've added CALLBACKS for the following controls: BUTTON, LABEL, TEXTBOX. All seems working fine.

I've also done it for LISTVIEW but it needs to be a little tuned: there is something not working as I expected in PowerBasic.
I've sent a mail to PB support, I'm waiting reply. Maybe it's just me.

Ciao
Eros

ErosOlmi
12-07-2008, 16:45
Thread closed.
It continues at: http://community.thinbasic.com/index.php?topic=1882.msg13893#msg13893