Results 1 to 3 of 3

Thread: text input ui + dialogs

  1. #1

    text input ui + dialogs

    good morning. I need help, sorry.

    perhaps somebody has time to update this ui code for current and modern callbacks and text input with %VK_Return messages. Found this example at this board. made some tests. but if I close my seconde dialog the first dialog with textbuffer and enter key disappear too.

    it's antique to use this dialog form for first main dialog isn't it ? I am confused. be gentle, it's only a test example, not perfect.

    my test example:
    [code=thinbasic]' Empty GUI script created on 04-19-2010 08:34:14 by denis (ThinAIR)

    Uses "UI"

    Dim Msg As Long
    Dim wParam As Long
    Dim lParam As Long
    Dim hDlg As Long
    Dim sInput As String
    Dim myNewString As String
    Dim sBuffer As String

    Dim wx As Long
    Dim hy As Long
    Dim Counter As Long

    '---Control IDs
    %ID_TXTBUFFER = 10
    %ID_LBLENTER = 20
    %ID_TXTENTER = 30
    %ID_TXTMY = 40
    %ID_TXTENTER2 = 50
    %ID_Button = 60
    %ButtonClose = 1001
    %ButtonDialog = 1002
    %ID_TXTBOX = 1003
    %ButtonClose2 = 1004

    '---Set starting width and height of the window
    wx = 240
    hy = 300

    Function TBMain() As Long

    '---Create main dialog
    Dialog New 0, "Sample using Enter key from input field", -1, -1, wx, hy, _
    %WS_DLGFRAME Or _
    %DS_CENTER Or _
    %WS_CAPTION Or _
    %WS_SYSMENU Or _
    %WS_OVERLAPPEDWINDOW , _
    0 To hDlg

    '---Show dialog
    Dialog Show Modeless hDlg

    '---Now start window message pump loop
    While IsWindow(hDlg)

    '---Get the message and fill wParam and lParam
    Msg = GetMessage(hDlg, wParam, lParam)

    If GetWindowKeyState (hdlg, %VK_RETURN) <> 0 Then
    DoTheJob(%ID_TXTENTER, %ID_TXTBUFFER, "")
    Sleep 150
    End If

    '---Test the returned message
    Select Case Msg

    '---Message fired at the very beginning when dialog is initialized
    '---We use it to add necessary controls
    Case %WM_INITDIALOG

    Control Add Textbox , hDlg, %ID_TXTBUFFER, "textbuffer" , 2, 2, wx - 5, hy - 70, _
    %WS_TABSTOP Or _
    %ES_WANTRETURN Or _
    %ES_MULTILINE Or _
    %ES_AUTOHSCROLL Or _
    %ES_AUTOVSCROLL Or _
    %WS_VSCROLL Or _
    %WS_HSCROLL

    Control Add Label , hDlg, %ID_LBLENTER, "Type some text in textbox below and press <ENTER> key", 2, hy - 46, wx - 5, 12
    Control Add Textbox , hDlg, %ID_TXTENTER, "here to type in words!" , 2, hy - 20, wx - 5, 12, %WS_TABSTOP
    Control Add Textbox , hDlg, %ID_TXTENTER2, "", 2, hy - 60, wx - 5, 12, %WS_TABSTOP
    Control Add Button , hDlg, %ID_Button, "< more >", 2, hy - 34, wx - 5, 12, Call newDialog

    '---Configure the controls to automatically resize as needed
    Control Set Resize hDlg, %ID_TXTBUFFER, 1, 1, 1, 1 '---This control must resize every side
    Control Set Resize hDlg, %ID_LBLENTER , 1, 1, 0, 1 '---This control must have top size movable
    Control Set Resize hDlg, %ID_TXTENTER , 1, 1, 0, 1 '---This control must have top size movable


    Case %WM_SYSCOMMAND
    Select Case wParam
    Case %SC_CLOSE
    Exit While
    End Select

    End Select

    Wend

    Dialog End hDlg
    End Function
    '-----------------------------------------------------------------------------------------------

    Function DoTheJob(ByVal ID_In As Long, ByVal ID_Out As Long, AdditionalText As String) As Long

    Control Get Text hDlg, ID_In To sInput
    If Trim$(sInput) = "" Then
    sInput = "<<<- Please type some text ->>>"
    End If
    Counter += 1
    sInput = AdditionalText & Format$(Counter, "000000") & " " & sInput

    Control Get Text hDlg, ID_Out To sBuffer
    Control Set Text hDlg, ID_Out, sInput & $CRLF & sBuffer
    Control Set Text hDlg, ID_In, ""

    End Function

    '------------------------------------------------
    ' Callback function used to handle dialog events
    '------------------------------------------------
    CallBack Function cbDialog() As Long

    Select Case CBMSG
    Case %WM_COMMAND
    If CBWPARAM = %ButtonClose Then Dialog End CBHNDL

    Case %WM_DESTROY
    MsgBox 0, "Window is to be destroyed."

    End Select

    End Function


    '-callback ----------------------------------------------------------------------------------------------
    CallBack Function newDialog() As Long

    Select Case CBMSG
    Case %WM_COMMAND
    If CBWPARAM = %ButtonClose Then Dialog End CBHNDL
    If CBWPARAM = %ID_BUTTON Then
    Dialog New 0, "test",-1,-1, 330, 203, _
    %WS_POPUP Or _
    %WS_VISIBLE Or _
    %WS_CLIPCHILDREN Or _
    %WS_CAPTION Or _
    %WS_SYSMENU Or _
    %WS_MINIMIZEBOX, _
    0 To hDlg

    Control Add Button, hDlg, %ButtonClose, "Click to kill", 240, 50, 60, 60
    Control Add Button, hDlg, %ButtonDialog, "new Dialog", 180, 50, 60, 60, Call newDialog2
    Control Add Textbox , hDlg, %ID_TXTBOX, "test more text lines", 10, 50, 150, 82, _
    %WS_TABSTOP Or _
    %ES_WANTRETURN Or _
    %ES_MULTILINE Or _
    %ES_AUTOHSCROLL Or _
    %ES_AUTOVSCROLL Or _
    %WS_VSCROLL Or _
    %WS_HSCROLL

    Dialog Show Modal hDlg Call cbDialog

    End If

    Case %WM_DESTROY
    MsgBox 0, "Window is to be destroyed."
    End Select
    End Function

    '-----------------------------------------
    CallBack Function newDialog2() As Long
    '-----------------------------------------

    Select Case CBMSG
    Case %WM_COMMAND
    If CBWPARAM = %ButtonClose Then Dialog End CBHNDL
    If CBWPARAM = %ButtonDialog Then

    Dialog New 0, "Sample 2 using Enter key from input field", -1, -1, 200, 260, _ 'wx, hy, _
    %WS_DLGFRAME Or _
    %DS_CENTER Or _
    %WS_CAPTION Or _
    %WS_SYSMENU Or _
    %WS_OVERLAPPEDWINDOW , _
    0 To hDlg

    Control Add Button, hDlg, %ButtonClose, "Click to kill", 40, 50, 60, 60

    Dialog Show Modal hDlg Call cbDialog

    End If

    Case %WM_DESTROY
    MsgBox 0, "Window is to be destroyed."
    End Select
    End Function
    '-----------------------------------------------------------------------------------

    '--sub only for testing ------------------------------------------------------------------------

    Sub mydialog()

    Dialog New 0, "test Dialog1",-1,-1, 330, 203, _
    %WS_POPUP Or _
    %WS_VISIBLE Or _
    %WS_CLIPCHILDREN Or _
    %WS_CAPTION Or _
    %WS_SYSMENU Or _
    %WS_MINIMIZEBOX, _
    0 To hDlg

    Control Add Button, hDlg, %ButtonClose, "Click to kill", 90, 50, 150, 100

    Dialog Show Modal hDlg Call cbDialog

    End Sub
    '-------------- test ends[/code]

    want to understand more about ui and dialogs.

    for what cases better to use "dialog new" and where "dialog pixels" ?

    thanks. bye, denis
    Attached Images Attached Images
    Attached Files Attached Files

  2. #2
    Senior Member Lionheart008's Avatar
    Join Date
    Sep 2008
    Location
    Germany, Bad Sooden-Allendorf
    Age
    51
    Posts
    934
    Rep Power
    109

    Re: text input ui + dialogs

    [code=thinbasic] USES "UI", "Console"

    global wx as long '---Used to get client width
    global hy as long '---Used to get client height

    begin const
    '---Control IDs
    %ID_MAGICBUTTON = %IDOK
    %ID_TXTBUFFER = 1000 '---Output field
    %ID_LBLENTER '---Input field label
    %ID_TXTENTER '---Input field
    end const
    function TBMain()
    DIM hDlg AS LONG '---Dialog handle

    '---Set starting width and height of the window
    wx = 250
    hy = 250

    '---Create main dialog
    DIALOG NEW 0, "Sample using Enter key from input field", -1, -1, wx, hy, _
    %WS_DLGFRAME OR _
    %DS_CENTER OR _
    %WS_CAPTION OR _
    %WS_SYSMENU OR _
    %WS_OVERLAPPEDWINDOW , _
    0 TO hDlg

    '---Show dialog
    DIALOG SHOW MODAL hDlg, call dlgCallback
    end function

    callback function dlgCallback() as long
    printl cbmsg, cbwparam, cblparam

    '---Test the returned message
    SELECT CASE cbMsg

    '---Message fired at the very beginning when dialog is initialized
    '---We use it to add necessary controls
    case %WM_INITDIALOG

    CONTROL ADD TEXTBOX , cbHndl, %ID_TXTBUFFER, "" , 2, 2, wx - 5, hy - 50, _
    %WS_TABSTOP OR _
    %ES_WANTRETURN OR _
    %ES_MULTILINE OR _
    %ES_AUTOHSCROLL OR _
    %ES_AUTOVSCROLL OR _
    %WS_VSCROLL OR _
    %WS_HSCROLL

    CONTROL ADD label , cbHndl, %ID_LBLENTER, "Type some text and press <ENTER> key", 2, hy - 40, wx - 5, 12
    CONTROL ADD TEXTBOX , cbHndl, %ID_TXTENTER, "" , 2, hy - 20, wx - 5, 12, %WS_TABSTOP
    CONTROL ADD BUTTON , cbHndl, %ID_MAGICBUTTON, "" , 1000,1000, 1, 1

    '---Configure the controls to automatically resize as needed
    CONTROL SET RESIZE cbHndl, %ID_TXTBUFFER, 1, 1, 1, 1 '---This control must resize every side
    CONTROL SET RESIZE cbHndl, %ID_LBLENTER , 1, 1, 0, 1 '---This control must have top size movable
    CONTROL SET RESIZE cbHndl, %ID_TXTENTER , 1, 1, 0, 1 '---This control must have top size movable

    control set focus cbHndl, %ID_TXTENTER

    '---In case of keyboard pressed ...
    CASE %wm_command

    '---Check which key using wParam
    SELECT CASE cbCtl
    '---In case of <ENTER> key ...
    case %ID_MAGICBUTTON
    if cbCtlMsg = %BN_CLICKED then
    DoTheJob(cbHndl, %ID_TXTENTER, %ID_TXTBUFFER, "")
    end if

    end select


    case %WM_NOTIFY
    printl "notify"

    END SELECT

    end function


    function DoTheJob(hDlg as dword, byval ID_In as long, byval ID_Out as long, AdditionalText as string) as long
    DIM sInput AS string '---Used to get input from field
    static counter as long
    control get text hDlg, ID_In to sInput
    if trim$(sInput) = "" then
    sInput = "<<<- Please type some text ->>>"
    end if
    Counter += 1
    sInput = AdditionalText & format$(Counter, "000000") & " " & sInput

    control appendtotop text hDlg, ID_Out, sInput & $crlf
    control set text hDlg, ID_In, ""
    CONTROL set focus hDlg, ID_In

    end function
    [/code]

    modern version you can see in thinair folder: SampleScripts/UI/Textbox (Enter Key) example
    you've used an old example.

    I am not really here.
    frank
    you can't always get what you want, but if you try sometimes you might find, you get what you need

  3. #3

    Re: text input ui + dialogs

    thanks frank. example works! found thinair sample script folder, fine! but it's not a great different between first and second example I see
    good luck for your private things. back to school again, must to learn a lot of things about statistics this week. tbgl and ui is more exciting.
    bye, denis

Similar Threads

  1. 2 openGL dialogs with thinbasic?
    By largo_winch in forum TBGL General
    Replies: 3
    Last Post: 10-05-2011, 23:54
  2. UI text input and "focus"
    By TheOne in forum UI (User Interface)
    Replies: 2
    Last Post: 15-03-2011, 19:58

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

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