Announcement

Collapse
No announcement yet.

Control Set Focus

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Dave Biggs
    replied
    What I had in mind was this.
    Code:
    Sub AddLine (ByVal hWnd As Dword, ByVal nID As Long, SendText As Asciiz)
      Local ListCount As Long, pvParam As Long 
      Control Set Focus hWnd, %IDC_SEND                            ' initial focus to another ctl
      Control Send hWnd, nID, %LB_GETCOUNT, 0, 0 To ListCount
      If ListCount > 500 Then Control Send hWnd, nID, %LB_DELETESTRING, 0, 0 : Decr ListCount
      Control Send hWnd, nID, %LB_ADDSTRING, 0, VarPtr(SendText)
      Control Send hWnd, nID, %LB_SETCURSEL, ListCount, 0
      Control Set Focus hWnd, %IDC_EDIT1                           ' data in, shift focus to edit ctl
    End Sub
    It seems that when focus is shifted to EDIT1 SetFocus(?) sends a KILLFOCUS msg to the window that loses focus.
    With the mod to Sub AddLine, that is the other control - not the main window??
    Even though the list box appears to have focus when a new line is added (new line is highlighted) it doesn't
    - check in WM_COMMAND..
    Code:
         If CbCtl = %IDC_LISTBOX1 Then 
           If CbCtlMsg = %LBN_SETFOCUS Then 
             WinBeep 800, 50
           End If 
         End If

    Leave a comment:


  • Cliff Nichols
    replied
    A quick test (check the results in the "AddLine" function
    Code:
    '--------------------------------------------------------------------------------------------------
    '  Serial Communications Example for PowerBASIC for Windows
    '  Copyright (c) 1999-2005 PowerBASIC, Inc. - All Rights Reserved.
    '--------------------------------------------------------------------------------------------------
    #COMPILE EXE
    #DIM ALL
    
    %NOANIMATE         = 1  ' Animate control
    %NOBUTTON          = 1  ' Button
    %NOCOMBO           = 1  ' Combo box
    %NOCOMBOEX         = 1  ' ComboBoxEx
    %NODATETIMEPICK    = 1  ' Date/time picker
    %NODRAGLIST        = 1  ' Drag list control
    %NOEDIT            = 1  ' Edit control
    %NOFLATSBAPIS      = 1  ' Flat scroll bar
    %NOHEADER          = 1  ' Header control
    %NOHOTKEY          = 1  ' HotKey control
    %NOIMAGELIST       = 1  ' Image APIs
    %NOIPADDRESS       = 1  ' IP Address edit control
    %NOLIST            = 1  ' List box control
    %NOLISTVIEW        = 1  ' ListView control
    %NOMENUHELP        = 1  ' Menu help
    %NOMONTHCAL        = 1  ' MonthCal
    %NOMUI             = 1  ' MUI
    %NONATIVEFONTCTL   = 1  ' Native Font control
    %NOPAGESCROLLER    = 1  ' Pager
    %NOPROGRESS        = 1  ' Progress control
    %NOREBAR           = 1  ' Rebar control
    %NOSTATUSBAR       = 1  ' Status bar
    %NOTABCONTROL      = 1  ' Tab control
    %NOTOOLBAR         = 1  ' Tool bar
    %NOTOOLTIPS        = 1  ' Tool tips
    %NOTRACKBAR        = 1  ' Track bar
    %NOTRACKMOUSEEVENT = 1  ' Track Mouse Event
    %NOTREEVIEW        = 1  ' TreeView
    %NOUPDOWN          = 1  ' Up Down arrow control
    
    %USEMACROS = 1
    #INCLUDE "Win32API.inc"
    
    $AppTitle           = "PB/Win Terminal"
    
    %IDD_MAIN           = 100
    %IDC_LISTBOX1       = 101
    %IDC_EDIT1          = 102
    %IDC_SEND           = 103
    %IDC_SENDFILE       = 104
    %IDC_RECEIVEFILE    = 105
    %IDC_QUIT           = 106
    %IDC_ECHO           = 107
    %IDC_CLEAR          = 108
    %IDC_ONTOP          = 109
    
    GLOBAL nComm        AS LONG   ' file number of comm device
    GLOBAL nWriteFile   AS LONG   ' file number of output file
    GLOBAL fUpdating    AS LONG   ' flag to avoid conflicts when updating
    GLOBAL fCloseThread AS LONG   ' flag to tell thread to shut down
    GLOBAL hDlg         AS DWORD
    GLOBAL Comport      AS STRING
    GLOBAL Baudrate     AS LONG
    '--------------------------------------------------------------------------------------------------
    SUB AddLine (BYVAL hWnd AS DWORD, BYVAL nID AS LONG, SendText AS ASCIIZ)
      LOCAL ListCount AS LONG, pvParam AS LONG
      CONTROL SEND hWnd, nID, %LB_GETCOUNT, 0, 0 TO ListCount
      IF ListCount > 500 THEN CONTROL SEND hWnd, nID, %LB_DELETESTRING, 0, 0 : DECR ListCount
      CONTROL SEND hWnd, nID, %LB_ADDSTRING, 0, VARPTR(SendText)
      CONTROL SEND hWnd, nID, %LB_SETCURSEL, ListCount, 0
    '  CONTROL SET FOCUS hWnd, %IDC_EDIT1             '<--- Steals focus
      CONTROL SET FOCUS hWnd, %IDC_LISTBOX1          '<--- Does Not Steal focus
    '  CONTROL SET FOCUS hWnd, %IDC_SEND              '<--- Does Not Steal focus
    '  CONTROL SET FOCUS hWnd, %IDC_CLEAR             '<--- Does Not Steal focus
    '  CONTROL SET FOCUS hWnd, %IDC_QUIT              '<--- Does Not Steal focus
    '  CONTROL SET FOCUS hWnd, %IDC_ECHO              '<--- Does Not Steal focus
    '  CONTROL SET FOCUS hWnd, %IDC_ONTOP             '<--- Does Not Steal focus
      
    END SUB
    '--------------------------------------------------------------------------------------------------
    FUNCTION StartComms () AS LONG
      LOCAL dummy AS STRING
      COMM OPEN ComPort AS #nComm
      IF ERRCLEAR THEN EXIT FUNCTION        'Exit if port cannot be opened
    
      COMM SET #nComm, BAUD     = BaudRate  'baud rate
      COMM SET #nComm, BYTE     = 8         '8 bits
      COMM SET #nComm, PARITY   = %False    'No parity
      COMM SET #nComm, STOP     = 0         '1 stop bit
      COMM SET #nComm, TXBUFFER = 4096      '4k transmit buffer
      COMM SET #nComm, RXBUFFER = 4096      '4k receive buffer
    
      COMM PRINT #nComm, $NUL               'Issue a CR/LF and flush the receive buffer
      SLEEP 2000
      IF COMM(#nComm, RXQUE) THEN COMM RECV #nComm, COMM(#nComm, RXQUE), dummy
      FUNCTION = %TRUE
    END FUNCTION
    '--------------------------------------------------------------------------------------------------
    SUB EndComms ()
      LOCAL dummy AS STRING
      SLEEP 1000                            'Flush the RX buffer & close the port
      IF COMM(#nComm, RXQUE) THEN
        COMM RECV #nComm, COMM(#nComm, RXQUE), dummy
      END IF
      COMM CLOSE #nComm
    END SUB
    '--------------------------------------------------------------------------------------------------
    FUNCTION ReceiveData (BYVAL hWnd AS LONG) AS LONG
      LOCAL sBigBuffer AS STRING, sBuffer AS STRING, ncBytesInBuffer AS LONG
      WHILE ISFALSE fCloseThread
        ncBytesInBuffer = COMM(#nComm, RXQUE)                                           'Test the RX buffer
        IF ISFALSE ncBytesInBuffer OR fUpdating THEN                                    'Abort this iteration if sending
          SLEEP 100
          ITERATE LOOP
        END IF
        COMM RECV #nComm, ncBytesInBuffer, sBuffer                                      'Read incoming characters.
        sBigBuffer = sBigBuffer & sBuffer
        IF nWriteFile THEN PRINT #nWriteFile, sBuffer;                                  'If Receive mode is on, write raw data to the file
        REPLACE $LF WITH "" IN sBigBuffer                                               'Strip out LF characters
    
        WHILE INSTR(sBigBuffer, $CR)                                                    'Process only complete lines of text terminated by carriage returns
          AddLine hWnd, %IDC_LISTBOX1, "--> " + EXTRACT$(sBigBuffer, $CR)               'Display the data
          sBigBuffer = STRDELETE$(sBigBuffer, 1, LEN(EXTRACT$(sBigBuffer, $CR)) + 1)    'Remove the "displayed" line from the buffer
        WEND
      WEND
      FUNCTION = %TRUE
    
    END FUNCTION
    
    CALLBACK FUNCTION Dialog_Callback () AS LONG
      DIM Result AS LOCAL LONG, Rc AS RECT
      SELECT CASE CBMSG
        CASE %WM_INITDIALOG
          CONTROL SET FOCUS CBHNDL, %IDC_EDIT1                'Set focus to the edit control
          CONTROL SEND CBHNDL, %IDC_EDIT1, %EM_SETSEL, 0, -1  'Set the SELECTION range to highlight the initial entry
          FUNCTION = %FALSE                                   'Return 0 to stop the dialog box engine setting focus
        CASE %WM_COMMAND
          IF CBCTL = %IDC_ONTOP THEN
            CONTROL SEND CBHNDL, %IDC_ONTOP, %BM_GETCHECK, 0, 0 TO Result       'Check the Echo mode state
            GetWindowRect CBHNDL, Rc
            IF Result = %BST_CHECKED THEN
              SetWindowPos CBHNDL, %HWND_TOPMOST, 0, 0, Rc.nRight-Rc.nLeft, Rc.nBottom-Rc.nTop, %SWP_NOMOVE
            ELSE
              SetWindowPos CBHNDL, %HWND_NOTOPMOST, 0, 0, Rc.nRight-Rc.nLeft, Rc.nBottom-Rc.nTop, %SWP_NOMOVE
            END IF
          END IF
      END SELECT
    END FUNCTION
    '--------------------------------------------------------------------------------------------------
    CALLBACK FUNCTION Send_Callback () AS LONG
      LOCAL SendText AS ASCIIZ * 1024, Result AS LONG, hListBox AS DWORD
      CONTROL GET TEXT CBHNDL, %IDC_EDIT1 TO SendText                       'Obtain the text to send from the edit control
      fUpdating = %TRUE                                                     'Set the update flag
      COMM PRINT #nComm, SendText                                           'Send the line to the comm port
      CONTROL SEND CBHNDL, %IDC_ECHO, %BM_GETCHECK, 0, 0 TO Result          'Check the Echo mode state
      IF Result <> %BST_CHECKED THEN
        AddLine CBHNDL, %IDC_LISTBOX1, "<-- " + SendText                    'Add the echo to the listbox
      END IF
      CONTROL SEND CBHNDL, %IDC_EDIT1, %EM_SETSEL, 0, -1                    'Set the SELECTION range for the edit control so the next keypress "clears" the control
      CONTROL SET FOCUS CBHNDL, %IDC_EDIT1                                  'Restore the keyboard focus to the edit control
      fUpdating = %FALSE                                                    'Release the update flag
      FUNCTION = %TRUE
    END FUNCTION
    '--------------------------------------------------------------------------------------------------
    CALLBACK FUNCTION Quit_Callback () AS LONG
      DIALOG END CBHNDL, 0
    END FUNCTION
    '--------------------------------------------------------------------------------------------------
    CALLBACK FUNCTION Clear_Callback () AS LONG
      LISTBOX RESET CBHNDL, %IDC_LISTBOX1
    END FUNCTION
    '--------------------------------------------------------------------------------------------------
    FUNCTION PBMAIN () AS LONG
      #REGISTER NONE
      LOCAL Result      AS LONG
      LOCAL hThread     AS LONG
      DIM Txt(1 TO 1) AS STRING
    
        IF PARSECOUNT (COMMAND$, ANY " ,") <> 2 THEN
          ComPort   = "COM1"
          BaudRate  = 9600'19200  '9600
        ELSE
          Comport   = "COM" & TRIM$(PARSE$(COMMAND$, ANY " ,", 1))
          BaudRate  = VAL(PARSE$(COMMAND$, ANY " ,", 2))
        END IF
    
        ' Initialize the port ready for the session
        IF ISFALSE StartComms THEN
          MSGBOX "Failed to start communications!",, $AppTitle
          EXIT FUNCTION
        END IF
    
        DIALOG NEW 0, $AppTitle,,, 330, 203, %WS_POPUP OR %WS_VISIBLE OR %WS_CLIPCHILDREN OR %WS_CAPTION OR %WS_SYSMENU OR %WS_MINIMIZEBOX, 0 TO hDlg
        CONTROL ADD LABEL,    hDlg, -1, "Transmission &log for " & ComPort & ", speed " & FORMAT$(BaudRate) & " baud", 9, 5, 150, 10, 0
        CONTROL ADD LISTBOX,  hDlg, %IDC_LISTBOX1, Txt(), 9, 15, 313, 133, %WS_BORDER OR %LBS_WANTKEYBOARDINPUT OR %LBS_DISABLENOSCROLL OR _
                                                                           %WS_VSCROLL OR %WS_GROUP OR %WS_TABSTOP OR %LBS_NOINTEGRALHEIGHT
        CONTROL ADD LABEL,    hDlg, -1, "Te&xt to send", 9, 151, 100, 10, 0
        CONTROL ADD TEXTBOX,  hDlg, %IDC_EDIT1, "", 9, 161, 257, 12, %ES_AUTOHSCROLL OR %ES_NOHIDESEL OR %WS_BORDER OR %WS_GROUP OR %WS_TABSTOP
        CONTROL ADD BUTTON,   hDlg, %IDC_SEND, "Send &Text", 273, 160, 50, 14, %WS_GROUP OR %WS_TABSTOP OR %BS_DEFPUSHBUTTON  CALL Send_Callback
        CONTROL ADD BUTTON,   hDlg, %IDC_CLEAR, "&Clear log", 129, 182, 50, 14, %WS_GROUP OR %WS_TABSTOP CALL Clear_Callback
        CONTROL ADD BUTTON,   hDlg, %IDC_QUIT, "&Quit", 273, 182, 50, 14, %WS_GROUP OR %WS_TABSTOP CALL Quit_Callback
        CONTROL ADD CHECKBOX, hDlg, %IDC_ECHO, "Disable Local &Echo", 241, 5, 80, 10, %WS_GROUP OR %WS_TABSTOP OR %BS_AUTOCHECKBOX OR %BS_LEFTTEXT OR %BS_RIGHT
        CONTROL ADD CHECKBOX, hDlg, %IDC_ONTOP, "&Always on top", 161, 5, 80, 10, %WS_GROUP OR %WS_TABSTOP OR %BS_AUTOCHECKBOX OR %BS_LEFTTEXT OR %BS_RIGHT
    
        REDIM Txt()                                             'Erase our array to free memory no longer required
        THREAD CREATE ReceiveData(hDlg) TO hThread              'Create a "listen" thread to monitor input from the modem
        DIALOG SHOW MODAL hDlg, CALL Dialog_Callback TO Result  'Start the dialog box & run until DIALOG END executed.
        fCloseThread = %TRUE                                    'close down our "listen" thread
        DO
          THREAD CLOSE hThread TO Result
          SLEEP 0
        LOOP UNTIL ISTRUE Result
        EndComms                                                'Flush & close the comm port and close the Receive file if open
        IF nWriteFile THEN CLOSE #nWriteFile
    END FUNCTION
    and in the docs I know its trying to tell me its the default reaction for a textbox, but a listbox can recieve keyboard input too, so must be a default is not in the listbox that is in the textbox.
    The control that owns the focus will receive all keyboard messages. Many controls change their appearance when they receive (and lose) keyboard focus, usually by the display of a "focus rectangle" around or on the control that has keyboard focus. Only one control can have keyboard focus at any moment, and situations can arise where no controls have focus.

    Controls that include a "notify" style (i.e., %BS_NOTIFY) will receive a notification message when focus is gained or lost. That is, when one such control loses focus, it receives a message to that effect and the control gaining focus may also receive an appropriate focus notification message.

    Leave a comment:


  • Dave Biggs
    replied
    Dodgy workaround

    I don't really understand why, but you can overcome that strange behaviour by setting focus to one
    of the other controls 'e.g. Control Set Focus hWnd, %IDC_SEND at the beginning of Sub AddLine.

    (Forcing focus to the edit control every time a new line arrives can make tabbing around the other
    controls difficult if the data arrives quickly though..).

    Leave a comment:


  • Cliff Nichols
    replied
    Peter,
    I am guessing a sequence of which event fires 1st and what fires next, a quick test of your code showed me that the setfocus is from your sending, not receiving.

    As an added bonus, check out what happens when you add "CONTROL SET FOCUS CBHNDL, %IDC_EDIT1" as the last line in your callback....nothing happens if you click send....(I did not try the other controls, but bet they are the same)

    Leave a comment:


  • Peter Lameijn
    replied
    This is the code. The goal is to set focus to the input field after data is received. That works fine, but dialog caption is grayed-out.
    (You can change comport and baudrate on commandline: [comms.exe 2 9600] sets com2 / 9600 baud)
    Code:
    '--------------------------------------------------------------------------------------------------
    '  Serial Communications Example for PowerBASIC for Windows
    '  Copyright (c) 1999-2005 PowerBASIC, Inc. - All Rights Reserved.
    '--------------------------------------------------------------------------------------------------
    #Compile Exe
    #Dim All
    
    %NOANIMATE         = 1  ' Animate control
    %NOBUTTON          = 1  ' Button
    %NOCOMBO           = 1  ' Combo box
    %NOCOMBOEX         = 1  ' ComboBoxEx
    %NODATETIMEPICK    = 1  ' Date/time picker
    %NODRAGLIST        = 1  ' Drag list control
    %NOEDIT            = 1  ' Edit control
    %NOFLATSBAPIS      = 1  ' Flat scroll bar
    %NOHEADER          = 1  ' Header control
    %NOHOTKEY          = 1  ' HotKey control
    %NOIMAGELIST       = 1  ' Image APIs
    %NOIPADDRESS       = 1  ' IP Address edit control
    %NOLIST            = 1  ' List box control
    %NOLISTVIEW        = 1  ' ListView control
    %NOMENUHELP        = 1  ' Menu help
    %NOMONTHCAL        = 1  ' MonthCal
    %NOMUI             = 1  ' MUI
    %NONATIVEFONTCTL   = 1  ' Native Font control
    %NOPAGESCROLLER    = 1  ' Pager
    %NOPROGRESS        = 1  ' Progress control
    %NOREBAR           = 1  ' Rebar control
    %NOSTATUSBAR       = 1  ' Status bar
    %NOTABCONTROL      = 1  ' Tab control
    %NOTOOLBAR         = 1  ' Tool bar
    %NOTOOLTIPS        = 1  ' Tool tips
    %NOTRACKBAR        = 1  ' Track bar
    %NOTRACKMOUSEEVENT = 1  ' Track Mouse Event
    %NOTREEVIEW        = 1  ' TreeView
    %NOUPDOWN          = 1  ' Up Down arrow control
    
    %USEMACROS = 1
    #Include "Win32API.inc"
    
    $AppTitle           = "PB/Win Terminal"
    
    %IDD_MAIN           = 100
    %IDC_LISTBOX1       = 101
    %IDC_EDIT1          = 102
    %IDC_SEND           = 103
    %IDC_SENDFILE       = 104
    %IDC_RECEIVEFILE    = 105
    %IDC_QUIT           = 106
    %IDC_ECHO           = 107
    %IDC_CLEAR          = 108
    %IDC_ONTOP          = 109
    
    Global nComm        As Long   ' file number of comm device
    Global nWriteFile   As Long   ' file number of output file
    Global fUpdating    As Long   ' flag to avoid conflicts when updating
    Global fCloseThread As Long   ' flag to tell thread to shut down
    Global hDlg         As Dword
    Global Comport      As String
    Global Baudrate     As Long
    '--------------------------------------------------------------------------------------------------
    Sub AddLine (ByVal hWnd As Dword, ByVal nID As Long, SendText As Asciiz)
      Local ListCount As Long, pvParam As Long
      Control Send hWnd, nID, %LB_GETCOUNT, 0, 0 To ListCount
      If ListCount > 500 Then Control Send hWnd, nID, %LB_DELETESTRING, 0, 0 : Decr ListCount
      Control Send hWnd, nID, %LB_ADDSTRING, 0, VarPtr(SendText)
      Control Send hWnd, nID, %LB_SETCURSEL, ListCount, 0
      Control Set Focus hWnd, %IDC_EDIT1
    End Sub
    '--------------------------------------------------------------------------------------------------
    Function StartComms () As Long
      Local dummy As String
      Comm Open ComPort As #nComm
      If ErrClear Then Exit Function        'Exit if port cannot be opened
    
      Comm Set #nComm, Baud     = BaudRate  'baud rate
      Comm Set #nComm, Byte     = 8         '8 bits
      Comm Set #nComm, Parity   = %False    'No parity
      Comm Set #nComm, Stop     = 0         '1 stop bit
      Comm Set #nComm, TxBuffer = 4096      '4k transmit buffer
      Comm Set #nComm, RxBuffer = 4096      '4k receive buffer
    
      Comm Print #nComm, $Nul               'Issue a CR/LF and flush the receive buffer
      Sleep 2000
      If Comm(#nComm, RxQue) Then Comm Recv #nComm, Comm(#nComm, RxQue), dummy
      Function = %TRUE
    End Function
    '--------------------------------------------------------------------------------------------------
    Sub EndComms ()
      Local dummy As String
      Sleep 1000                            'Flush the RX buffer & close the port
      If Comm(#nComm, RxQue) Then
        Comm Recv #nComm, Comm(#nComm, RxQue), dummy
      End If
      Comm Close #nComm
    End Sub
    '--------------------------------------------------------------------------------------------------
    Function ReceiveData (ByVal hWnd As Long) As Long
      Local sBigBuffer As String, sBuffer As String, ncBytesInBuffer As Long
      While IsFalse fCloseThread
        ncBytesInBuffer = Comm(#nComm, RxQue)                                           'Test the RX buffer
        If IsFalse ncBytesInBuffer Or fUpdating Then                                    'Abort this iteration if sending
          Sleep 100
          Iterate Loop
        End If
        Comm Recv #nComm, ncBytesInBuffer, sBuffer                                      'Read incoming characters.
        sBigBuffer = sBigBuffer & sBuffer
        If nWriteFile Then Print #nWriteFile, sBuffer;                                  'If Receive mode is on, write raw data to the file
        Replace $Lf With "" In sBigBuffer                                               'Strip out LF characters
    
        While InStr(sBigBuffer, $Cr)                                                    'Process only complete lines of text terminated by carriage returns
          AddLine hWnd, %IDC_LISTBOX1, "--> " + Extract$(sBigBuffer, $Cr)               'Display the data
          sBigBuffer = StrDelete$(sBigBuffer, 1, Len(Extract$(sBigBuffer, $Cr)) + 1)    'Remove the "displayed" line from the buffer
        Wend
      Wend
      Function = %TRUE
    End Function
    
    CallBack Function Dialog_Callback () As Long
      Dim Result As Local Long, Rc As RECT
      Select Case CbMsg
        Case %WM_INITDIALOG
          Control Set Focus CbHndl, %IDC_EDIT1                'Set focus to the edit control
          Control Send CbHndl, %IDC_EDIT1, %EM_SETSEL, 0, -1  'Set the SELECTION range to highlight the initial entry
          Function = %FALSE                                   'Return 0 to stop the dialog box engine setting focus
        Case %WM_COMMAND
          If CbCtl = %IDC_ONTOP Then
            Control Send CbHndl, %IDC_ONTOP, %BM_GETCHECK, 0, 0 To Result       'Check the Echo mode state
            GetWindowRect CbHndl, Rc
            If Result = %BST_CHECKED Then
              SetWindowPos CbHndl, %HWND_TOPMOST, 0, 0, Rc.nRight-Rc.nLeft, Rc.nBottom-Rc.nTop, %SWP_NOMOVE
            Else
              SetWindowPos CbHndl, %HWND_NOTOPMOST, 0, 0, Rc.nRight-Rc.nLeft, Rc.nBottom-Rc.nTop, %SWP_NOMOVE
            End If
          End If
      End Select
    End Function
    '--------------------------------------------------------------------------------------------------
    CallBack Function Send_Callback () As Long
      Local SendText As Asciiz * 1024, Result As Long, hListBox As Dword
      Control Get Text CbHndl, %IDC_EDIT1 To SendText                       'Obtain the text to send from the edit control
      fUpdating = %TRUE                                                     'Set the update flag
      Comm Print #nComm, SendText                                           'Send the line to the comm port
      Control Send CbHndl, %IDC_ECHO, %BM_GETCHECK, 0, 0 To Result          'Check the Echo mode state
      If Result <> %BST_CHECKED Then
        AddLine CbHndl, %IDC_LISTBOX1, "<-- " + SendText                    'Add the echo to the listbox
      End If
      Control Send CbHndl, %IDC_EDIT1, %EM_SETSEL, 0, -1                    'Set the SELECTION range for the edit control so the next keypress "clears" the control
      Control Set Focus CbHndl, %IDC_EDIT1                                  'Restore the keyboard focus to the edit control
      fUpdating = %FALSE                                                    'Release the update flag
      Function = %TRUE
    End Function
    '--------------------------------------------------------------------------------------------------
    CallBack Function Quit_Callback () As Long
      Dialog End CbHndl, 0
    End Function
    '--------------------------------------------------------------------------------------------------
    CallBack Function Clear_Callback () As Long
      ListBox Reset CbHndl, %IDC_LISTBOX1
    End Function
    '--------------------------------------------------------------------------------------------------
    Function PBMain () As Long
      #Register None
      Local Result      As Long
      Local hThread     As Long
      Dim Txt(1 To 1) As String
    
        If ParseCount (Command$, Any " ,") <> 2 Then
          ComPort   = "COM1"
          BaudRate  = 19200  '9600
        Else
          Comport   = "COM" & Trim$(Parse$(Command$, Any " ,", 1))
          BaudRate  = Val(Parse$(Command$, Any " ,", 2))
        End If
    
        ' Initialize the port ready for the session
        If IsFalse StartComms Then
          MsgBox "Failed to start communications!",, $AppTitle
          Exit Function
        End If
    
        Dialog New 0, $AppTitle,,, 330, 203, %WS_POPUP Or %WS_VISIBLE Or %WS_CLIPCHILDREN Or %WS_CAPTION Or %WS_SYSMENU Or %WS_MINIMIZEBOX, 0 To hDlg
        Control Add Label,    hDlg, -1, "Transmission &log for " & ComPort & ", speed " & Format$(BaudRate) & " baud", 9, 5, 150, 10, 0
        Control Add ListBox,  hDlg, %IDC_LISTBOX1, Txt(), 9, 15, 313, 133, %WS_BORDER Or %LBS_WANTKEYBOARDINPUT Or %LBS_DISABLENOSCROLL Or _
                                                                           %WS_VSCROLL Or %WS_GROUP Or %WS_TABSTOP Or %LBS_NOINTEGRALHEIGHT
        Control Add Label,    hDlg, -1, "Te&xt to send", 9, 151, 100, 10, 0
        Control Add TextBox,  hDlg, %IDC_EDIT1, "", 9, 161, 257, 12, %ES_AUTOHSCROLL Or %ES_NOHIDESEL Or %WS_BORDER Or %WS_GROUP Or %WS_TABSTOP
        Control Add Button,   hDlg, %IDC_SEND, "Send &Text", 273, 160, 50, 14, %WS_GROUP Or %WS_TABSTOP Or %BS_DEFPUSHBUTTON Call Send_Callback
        Control Add Button,   hDlg, %IDC_CLEAR, "&Clear log", 129, 182, 50, 14, %WS_GROUP Or %WS_TABSTOP Call Clear_Callback
        Control Add Button,   hDlg, %IDC_QUIT, "&Quit", 273, 182, 50, 14, %WS_GROUP Or %WS_TABSTOP Call Quit_Callback
        Control Add CheckBox, hDlg, %IDC_ECHO, "Disable Local &Echo", 241, 5, 80, 10, %WS_GROUP Or %WS_TABSTOP Or %BS_AUTOCHECKBOX Or %BS_LEFTTEXT Or %BS_RIGHT
        Control Add CheckBox, hDlg, %IDC_ONTOP, "&Always on top", 161, 5, 80, 10, %WS_GROUP Or %WS_TABSTOP Or %BS_AUTOCHECKBOX Or %BS_LEFTTEXT Or %BS_RIGHT
    
        ReDim Txt()                                             'Erase our array to free memory no longer required
        Thread Create ReceiveData(hDlg) To hThread              'Create a "listen" thread to monitor input from the modem
        Dialog Show Modal hDlg, Call Dialog_Callback To Result  'Start the dialog box & run until DIALOG END executed.
        fCloseThread = %TRUE                                    'close down our "listen" thread
        Do
          Thread Close hThread To Result
          Sleep 0
        Loop Until IsTrue Result
        EndComms                                                'Flush & close the comm port and close the Receive file if open
        If nWriteFile Then Close #nWriteFile
    End Function
    Last edited by Peter Lameijn; 24 Apr 2008, 05:38 PM.

    Leave a comment:


  • Cliff Nichols
    replied
    Peter,
    Can you post the code you adapted? (I am sure I have seen this before, but can not remember what it was, except to guess a button gets focus, so the the dialog looses focus, and thusly greys-out)

    Out of curiosity, I wondered what you are doing that uses a serial port? (I work with them all the time, so curious what other ideas others are using the serial port to communicate with etc...)

    Leave a comment:


  • Peter Lameijn
    replied
    The code is a little adaptation of the comms terminal sample with PbWin8x. I can post it if you like, but it happens if serial data is received. (Or I'll have to cook-up some other code...)

    Leave a comment:


  • Fred Buffington
    replied
    Peter, can you show some compilable code that does this ?

    Leave a comment:


  • Peter Lameijn
    started a topic Control Set Focus

    Control Set Focus

    If I use Control Set Focus on a control in a dialog box, the control gets the focus (as expected), but the caption bar of the dialog is grayed... (not expected)
    Is there a way to prevent that?
Working...
X