Announcement

Collapse
No announcement yet.

Unselect Combobox TExt?

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

  • Unselect Combobox TExt?

    Here is what I want to do:

    I want to put text into the edit box of a combobox control, put the caret at the end of the field, NOT select the text and have the control gain the keyboard focus.

    Here is what I have tried (wParam = handle to combobox)
    Code:
        SetWindowText  wParam, szText   ' but do not select?
       'set caret at end of field (character # 8, zero based
       'SendMessage    wParam, %CB_SETEDITSEL, %NULL, MAKDWD(9%,9%) ' selecting all so is 8.8
       'SendMessage    wParam, %CB_SETEDITSEL, %NULL, MAKDWD(0%,0%)
       ' SendMessage    wParam, %CB_SETEDITSEL, %NULL, MAKDWD(-1%,-1%) ' still selects
        SendMessage    wParam, %CB_SETEDITSEL, %NULL, MAKDWD(-1%,8%)
    ..
       SetFocus  wparam
    All the above end up selecting the entire text, so the next key erases the text, which is exactly what I don't want to happen.

    I am sure I am missing something obvious but darned if I know what it is.

    Thanks,
    MCM
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

  • #2
    MCM,
    From MSDN:
    The low-order word of lParam specifies the starting position. If the low-order word is –1, the selection, if any, is removed.
    The high-order word of lParam specifies the ending position. If the high-order word is –1, all text from the starting position to the last character in the edit control is selected.
    So I'd try MAKDWD(0,-1)


    Paul.

    Comment


    • #3
      try Postmessage 9,9

      added demo:
      ...grabbed one of Borje's old examples and changed it ever so slightly...

      HTH
      Regards,
      Jules

      Code:
      #COMPILE EXE
      #INCLUDE "WIN32API.INC"
      '----------------------------------------------------------------------
      %IDC_COMBOBOX1      = 121
      %IDC_BUTTON1        = 141
      %IDC_BUTTON2        = 142
      
      
      '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
      FUNCTION PBMAIN() AS LONG
      '----------------------------------------------------------------------
        ' Program entrance
        '--------------------------------------------------------------------
        LOCAL hDlg AS DWORD
      
        DIALOG NEW 0, "Combo Test",,, 115, 45, %WS_CAPTION OR %WS_SYSMENU, 0 TO hDlg
      
        CONTROL ADD COMBOBOX, hDlg, %IDC_COMBOBOX1, , 5, 5, 105, 12
        CONTROL SET TEXT hDlg, %IDC_COMBOBOX1, "Some text"
        CONTROL ADD BUTTON, hDlg, %IDC_BUTTON1, "Select", 5, 25, 50, 14
        CONTROL ADD BUTTON, hDlg, %IDC_BUTTON2, "Unselect", 60, 25, 50, 14
      
        DIALOG SHOW MODAL hDlg, CALL DlgProc
      
      END FUNCTION
      
      
      '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
      CALLBACK FUNCTION DlgProc() AS LONG
      '----------------------------------------------------------------------
        ' Main Dialog procedure
        '--------------------------------------------------------------------
      
        SELECT CASE CBMSG
           CASE %WM_COMMAND
              SELECT CASE CBCTL
                 CASE %IDC_BUTTON1
                    IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                        CONTROL SEND CBHNDL, %IDC_COMBOBOX1, %CB_SETEDITSEL, 0, MAKLNG(0, -1)
                    END IF
      
                 CASE %IDC_BUTTON2
                    IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                        CONTROL POST CBHNDL, %IDC_COMBOBOX1, %CB_SETEDITSEL, 0, MAKLNG(9, 9)
                        Setfocus GetDlgItem(CBHNDL, %IDC_COMBOBOX1)
                    END IF
      
                 CASE %IDCANCEL
                    IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                       DIALOG END CBHNDL, 0
                    END IF
              END SELECT
      
        END SELECT
      
      END FUNCTION
      Last edited by Jules Marchildon; 2 Feb 2009, 07:52 PM.

      Comment


      • #4
        WINNER:
        Code:
        Postmessage    wParam, %CB_SETEDITSEL, %NULL, MAKLNG(9,9)
        Thank you.



        MCM
        Michael Mattias
        Tal Systems (retired)
        Port Washington WI USA
        [email protected]
        http://www.talsystems.com

        Comment


        • #5


          I just figured it out.

          Setting the focus to the CB results in the default behavior of selecting the text, as with all edit controls.

          By *posting* the message, the text is UN-selected AFTER that default behavior has happened.
          Michael Mattias
          Tal Systems (retired)
          Port Washington WI USA
          [email protected]
          http://www.talsystems.com

          Comment

          Working...
          X