Jump to content

Hide text-cursor (caret) in edit control


hausl78
 Share

Go to solution Solved by jguinch,

Recommended Posts

Hello,

i try to hide the caret in an edit-control. The only way to do this ist this one - it seems to work, this was from a thread here from the board, which is 9 years old, so i should/want to ask if this is a "best practise" way to do this :)

Thank you!

#include <GUIConstants.au3>

$hGUI = GUICreate("test",400,200, -1, 200, $WS_SIZEBOX +  $WS_MAXIMIZEBOX + $WS_MINIMIZEBOX)

$hEdit  = GUICtrlCreateEdit("",20,20,200,100, $WS_HSCROLL + $WS_VSCROLL + $ES_READONLY)

$hButton  = GUICtrlCreateButton("Click me!", 250, 50, 70, 30)

GUISetState()

While 1
    
    DllCall("user32.dll","int","HideCaret","int",0)

    $msg = GUIGetMsg()

    if $msg = $GUI_EVENT_CLOSE Then
        Exit
    EndIf

    if $msg = $hButton Then
        GUICtrlSetData($hEdit, "Thank you!" & @CRLF & @CRLF)
    EndIf
WEnd
Edited by hausl78
Link to comment
Share on other sites

  • Solution

Something like this ?

#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>

GUIRegisterMsg($WM_COMMAND, 'WM_COMMAND')

Local $msg

Local $hForm = GUICreate('Test ' , 400, 250)
Local $Input = GUICtrlCreateEdit('', 10, 10, 380, 200, $WS_HSCROLL + $WS_VSCROLL + $ES_READONLY)
Local $Button = GUICtrlCreateButton('Exit', 300, 220, 90, 20)

GUISetState()


While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE OR $msg = $Button Then Exit
WEnd


Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    Local $nNotifyCode = BitShift($wParam, 16)

    Switch $lParam
        Case GUICtrlGetHandle($Input)
            Switch $nNotifyCode
                Case $EN_SETFOCUS
                    DllCall('user32.dll', 'int', 'HideCaret', 'hwnd', $lParam) ; => _WinAPI_HideCaret($lParam)
            EndSwitch
    EndSwitch
    
    Return $GUI_RUNDEFMSG

EndFUnc
Edited by jguinch
Link to comment
Share on other sites

  • 2 years later...

I have tried the jguinch solution to this and cannot get it to work,

Here is my code:

Func WM_COMMAND($hWnd, $iMsg, $iwparam, $ilparam)
 Local $iIDFrom = BitAND($iwparam, 0xFFFF)
 Local $iCode = BitShift($iwparam, 16)
 
 Switch $ilparam

   Case $grichtext

   Switch $iCode


   Case $EN_SETFOCUS

   DllCall('user32.dll', 'int', 'HideCaret', 'hwnd', $ilParam) ;_WinAPI_HideCaret($lParam)

 EndSwitch

Thanks in advance.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...