Donate Now Goal amount for this month: 100 USD, Received: 0 USD (0%)
Donate to support this site and ThinBASIC project development

Results 1 to 5 of 5

Thread: script control of button

  1. #1

    script control of button

    Here is an example of using the script to control when a button works.

    [code=thinbasic]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
    [/code]

    Thanks
    Sandy

  2. #2
    thinBasic MVPs Michael Clease's Avatar
    Join Date
    May 2007
    Posts
    1,414
    Blog Entries
    1
    Rep Power
    149

    Re: script control of button

    I wrote this a while back when I first looked at controls.

    [code=thinbasic]
    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



    [/code]
    Why is the world full of nobs trying to push my buttons!!

    Home Desktop : WinXP Pro SP3 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
    Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
    Home Laptop : WinXP Pro SP3 - Intel Pentium 4 - 3 Ghz - 512 MB - ATI Mobile Radeon 7000 IGP
    Work Desktop : WinXP Pro SP3 - Intel core 2 Quad Q8200 - 2.33 Ghz - 2 Gb - Quadro Fx 370

  3. #3
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    6,399
    Rep Power
    649

    Re: script control of button

    Hi,

    thanks guys for another scripts from UI world!


    Bye,
    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 7 64bit - Intel Core 2 Duo T6600 @ 2.2GHz - 4 GB RAM - NVIDIA GeForce G210M 512MB
    Windows 8 64bit - Intel Core i5-3350P @ 3.1GHz - 8 GB RAM - NVIDIA GeForce GT640 3GB

  4. #4
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    47
    Posts
    7,556
    Blog Entries
    2
    Rep Power
    10

    Re: script control of button

    Thanks a lot Sandy / Abraxas for those examples.

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

    Ciao
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | psch.thinbasic.com
    Win7Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

  5. #5
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Clearwater, Florida, USA
    Posts
    3,802
    Rep Power
    388

    Re: script control of button

    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.

Similar Threads

  1. Button Styles
    By Michael Clease in forum Sources, Templates, Code Snippets, Tips and Tricks, Do you know ...
    Replies: 4
    Last Post: 21-11-2007, 14:51

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •