Sign in to follow this  
Followers 0
hausl78

Hide text-cursor (caret) in edit control

6 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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
2 people like this

Share this post


Link to post
Share on other sites

Sorry, im not quite sure what you mean. My issue is: I have a read-only edit-control and want the blinking text-pipe-cursor to hide/disappear within this read-only edit-control.

Share this post


Link to post
Share on other sites

My mistake, sorry!  It works now, THANK you a lot !!

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
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
Sign in to follow this  
Followers 0