Announcement

Collapse

Maintenance

The forum could be offline for 30-60 minutes in the very near future for maintenance (said 3pm Pacific). I was behind on getting this notice. I do apologize.
See more
See less

How to hide the blinking caret in a textbox?

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

  • How to hide the blinking caret in a textbox?

    Anybody know? im having no luck with the HideCaret api call, even though it only has one parameter - hWnd


    ------------------
    -

  • #2
    Textbox must have focus for these calls to work. Working sample:
    Code:
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Test of HideCaret and ShowCaret functions
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    #COMPILE EXE
    #INCLUDE "WIN32API.INC"
    %ID_TEXT = 20
     
    DECLARE CALLBACK FUNCTION DlgProc() AS LONG
     
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Create dialog and controls, etc
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    FUNCTION PBMAIN () AS LONG
      LOCAL hDlg AS LONG
     
      DIALOG NEW 0, "Hide/Show Caret test ",,, 180, 60, %WS_SYSMENU, 0 TO hDlg
      CONTROL ADD BUTTON, hDlg, 10, "Hide caret", 30, 4, 60, 14, %WS_BORDER
      CONTROL ADD BUTTON, hDlg, 11, "Show caret", 90, 4, 60, 14, %WS_BORDER
      CONTROL ADD TEXTBOX, hDlg, %ID_TEXT, "", 4, 25, 166, 14, %WS_CHILD OR %ES_NOHIDESEL, _
                           %WS_EX_CLIENTEDGE CALL DlgProc
      CALL SetFocus(GetDlgItem(hDlg, %ID_TEXT))
     
      DIALOG SHOW MODAL hDlg CALL DlgProc
     
    END FUNCTION
     
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Main callback
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    CALLBACK FUNCTION DlgProc() AS LONG
      LOCAL lRes AS LONG
      SELECT CASE CBMSG
         CASE %WM_COMMAND
            IF CBCTLMSG = %BN_CLICKED THEN
               IF CBCTL = 10 THEN
                  CALL SetFocus(GetDlgItem(CBHNDL, %ID_TEXT)) 'textbox must have focus
                  lRes = HideCaret (GetDlgItem(CBHNDL, %ID_TEXT))
                  'MSGBOX FORMAT$(lRes) 'if we want to check result
               ELSEIF CBCTL = 11 THEN
                  CALL SetFocus(GetDlgItem(CBHNDL, %ID_TEXT))
                  lRes =  ShowCaret(GetDlgItem(CBHNDL, %ID_TEXT))
                  'MSGBOX FORMAT$(lRes) 'if we want to check result
               END IF
               CALL SetFocus(GetDlgItem(CBHNDL, %ID_TEXT))
               FUNCTION = 0 : EXIT FUNCTION
            END IF
     
      END SELECT
     
    END FUNCTION

    ------------------


    [This message has been edited by Borje Hagsten (edited March 04, 2001).]

    Comment


    • #3
      perfect, thanks
      when I ported it over to my code, it (the two main lines of SetFocus and HideCaret) wouldn't work - possibly because my dialog is in a seperate thread, but i was able to get it to work by showing the form initially as modeless just to have it visible, and then hide the cursor before going modal:
      Code:
       DIALOG SHOW MODELESS hDlg Call DlgProc
       CALL SetFocus(GetDlgItem(hDlg , 400))
       HideCaret GetDlgItem(hDlg , 400)
       DIALOG SHOW MODAL hDlg Call DlgProc

      ------------------
      -

      Comment

      Working...
      X