PDA

View Full Version : script control of button



sandyrepope
10-08-2007, 05:26
Here is an example of using the script to control when a button works.


uses "UI" 'use UI module

DIM hDlg AS DWORD 'dialog number assigned by OS
dim Msg, wparam,lparam as dword 'parameters used for os messages
%id_button = 10 'assign number to button to identify it


'make a window
DIALOG NEW 0, "Button FUN", -1, -1, 150, 100, _
%WS_DLGFRAME OR %DS_CENTER OR %WS_CAPTION OR %WS_SYSMENU OR %WS_OVERLAPPEDWINDOW, _
0 TO hDlg
'add a button to it
control add button, hDlg, %id_button, "CLICK ME", 5, 5, 50, 50, %ws_border

DIALOG SHOW modeless hDlg 'make window visible

while isWindow(hDlg) 'while loop to handle messages from OS
Msg = GetMessage(hDlg, wParam, lParam) 'get latest message

select case Msg 'message that was recieved
case %wm_command 'check command
select case wParam 'it will be here
case %id_button 'was button clicked?

control disable hDlg, %id_button 'disable button
sleep 1000 'do a little wait and then
control enable hDlg, %id_button 'make button work again

end select
CASE %WM_SYSCOMMAND 'system command?
SELECT CASE wParam 'check variable
CASE %SC_CLOSE 'if close button in bar clicked then
EXIT WHILE 'exit while which will end program
END SELECT
END SELECT

wend

DIALOG END hDlg 'ends the program


Thanks
Sandy

Michael Clease
10-08-2007, 08:47
I wrote this a while back when I first looked at controls.



USES "UI"

Dim hDlg As DWORD
Dim Msg, wparam,lparam As DWORD

%width = 500
%height = 350

dim txt1(5) as string
dim txt2(5) AS STRING
DIM txt3(5) AS STRING
DIM txt4(5) AS STRING
dim mynumber as double

%width = 500
%height = 350

DIALOG New 0, "ThinBasic",-1,-1, %width, %height, _
%WS_POPUP Or _
%WS_VISIBLE Or _
%WS_CLIPCHILDREN Or _
%WS_CAPTION Or _
%WS_SYSMENU Or _
%WS_MINIMIZEBOX, _
0 To hDlg

txt1(1) = "1"
txt1(2) = "2"
txt1(3) = "3"
txt1(4) = "4"
txt1(5) = "5"
txt2(1) = "A"
txt2(2) = "B"
txt2(3) = "C"
txt2(4) = "D"
txt2(5) = "E"

CONTROL ADD BUTTON, hDlg, 1001, "1", 50,125,60, 15
CONTROL ADD BUTTON, hDlg, 1002, "2", 150,125,60, 15
CONTROL ADD BUTTON, hDlg, 1003, "3", 250,125,60, 15
CONTROL ADD BUTTON, hDlg, 1004, "4", 350,125,60, 15

CONTROL ADD Checkbox, hDlg, 2001, "1", 50,200,30, 15
CONTROL ADD Checkbox, hDlg, 2002, "2", 150,200,60, 15
CONTROL ADD Checkbox, hDlg, 2003, "3", 250,200,60, 15
CONTROL ADD Checkbox, hDlg, 2004, "4", 350,200,60, 15

CONTROL ADD OPTION, hDlg, 3001, "1", 50,275,30, 30
CONTROL ADD OPTION, hDlg, 3002, "2", 150,275,30, 30
CONTROL ADD OPTION, hDlg, 3003, "3", 250,275,30, 30
CONTROL ADD OPTION, hDlg, 3004, "4", 350,275,30, 30

CONTROL ADD COMBOBOX, hDlg, 4002, TXT1(), 50,250,30, 30
CONTROL ADD COMBOBOX, hDlg, 4002, TXT2(), 150,250,30, 30

CONTROL DISABLE hDlg, 1002
CONTROL DISABLE hDlg, 1003
CONTROL DISABLE hDlg, 1004

CONTROL DISABLE hDlg, 2002
CONTROL DISABLE hDlg, 2003
CONTROL DISABLE hDlg, 2004

CONTROL DISABLE hDlg, 3002
CONTROL DISABLE hDlg, 3003
CONTROL DISABLE hDlg, 3004

DIALOG SHOW MODELESS hDlg

txt1(1) = "hhh"

While ISWINDOW(hDlg)

Msg = GETMESSAGE(hDlg, wParam, lParam)


Select Case Msg

Case %WM_Command

If wParam = 1001 Then CONTROL ENABLE hDlg, 1002
If wParam = 1002 Then CONTROL ENABLE hDlg, 1003
If wParam = 1003 Then CONTROL ENABLE hDlg, 1004
If wParam = 1004 Then EXiT WHILE

If wParam = 2001 Then CONTROL ENABLE hDlg, 2002
If wParam = 2002 Then CONTROL ENABLE hDlg, 2003
If wParam = 2003 Then CONTROL ENABLE hDlg, 2004
If wParam = 2004 Then EXiT WHILE

If wParam = 3001 Then CONTROL ENABLE hDlg, 3002
If wParam = 3002 Then CONTROL ENABLE hDlg, 3003
If wParam = 3003 Then CONTROL ENABLE hDlg, 3004
If wParam = 3004 Then EXiT WHILE

Case %WM_SYSCOMMAND

If wParam = %SC_Close Then Exit While

End Select

Wend

DIALOG End hDlg

DIALOG SHOW MODELESS hDlg

STOP

Petr Schreiber
10-08-2007, 08:51
Hi,

thanks guys for another scripts from UI world!


Bye,
Petr

ErosOlmi
10-08-2007, 09:53
Thanks a lot Sandy / Abraxas for those examples.

I've moved your post in this more appropriate forum.

Ciao
Eros

kryton9
10-08-2007, 23:30
Thanks Sandy and Abraxas, having different control examples are very nice. It is easy to forget how to use them if you don't for awhile so nice to have samples to refer too.