Results 1 to 5 of 5

Thread: script control of button

  1. #1
    Member
    Join Date
    Jan 2007
    Age
    76
    Posts
    426
    Rep Power
    60

    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
    Join Date
    May 2007
    Location
    UK
    Posts
    1,427
    Rep Power
    160

    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]
    Home Desktop : Windows 7 - 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 : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
    Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370

  3. #3
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,153
    Rep Power
    736

    Re: script control of button

    Hi,

    thanks guys for another scripts from UI world!


    Bye,
    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  4. #4
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,817
    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/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  5. #5
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    68
    Posts
    3,865
    Rep Power
    405

    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.
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

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

Members who have read this thread: 1

Posting Permissions

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