Jump to content
Sign in to follow this  
charvi

Solid Block Cursor in Input Fields

Recommended Posts

charvi

Sunny May's Sunday greeting you! ^_^

How can I transform my thin blinking vertical cursor to a (preferably non-blinking) solid black solid block cursor?

It will be used with a large monospaced font, so the block should be the size of the character. And when using the backspace key, the character over which it is, must remain visible in reversed colours.

This may look old-fashioned, but when using many input fields, it is good to see where the cursor is. I have seen a Windows application before using a solid block cursor, so I believe it is possible. How can we get it in AutoIt?

Cheers, charvi

Share this post


Link to post
Share on other sites
Yashied

Sunny May's Sunday greeting you! ^_^

How can I transform my thin blinking vertical cursor to a (preferably non-blinking) solid black solid block cursor?

It will be used with a large monospaced font, so the block should be the size of the character. And when using the backspace key, the character over which it is, must remain visible in reversed colours.

This may look old-fashioned, but when using many input fields, it is good to see where the cursor is. I have seen a Windows application before using a solid block cursor, so I believe it is possible. How can we get it in AutoIt?

Cheers, charvi

Maybe this.

#include <WindowsConstants.au3>
#include <Constants.au3>
#include <WinAPI.au3>

Opt('MustDeclareVars', 1)

global $Button, $Input, $hInput, $hBitmap, $pHook, $hProc, $Msg, $BlinkTime = default

GUICreate('Test', 400, 100)
$Input = GUICtrlCreateInput("", 20, 20, 360, 20)
$hInput = GUICtrlGetHandle($Input)
$Button = GUICtrlCreateButton('Exit', 165, 60, 70, 23)
$hBitmap = _WinAPI_CreateSolidBitmap(0, 0x66FFFF, 10, 14)
$pHook = DllCallbackRegister('_InputProc', 'ptr', 'hwnd;uint;long;ptr')
$hProc = _WinAPI_SetWindowLong($hInput, $GWL_WNDPROC, DllCallbackGetPtr($pHook))
GUISetState()

while 1
    $Msg = GUIGetMsg()
    switch $Msg
        case -3, $Button
            exit
    endswitch
wend

func _InputProc($hWnd, $uiMsg, $wParam, $lParam)
    
    local $Res = _WinAPI_CallWindowProc($hProc, $hWnd, $uiMsg, $wParam, $lParam)
    
    switch $uiMsg
        case $WM_SETFOCUS
            DllCall('user32.dll', 'int', 'CreateCaret', 'hwnd', $hWnd, 'ptr', $hBitmap, 'int', 0, 'int', 0)
            DllCall('user32.dll', 'int', 'ShowCaret', 'hwnd', $hWnd)
            $BlinkTime = DllCall('user32.dll', 'int', 'GetCaretBlinkTime')
            $BlinkTime = $BlinkTime[0]
            DllCall('user32.dll', 'int', 'SetCaretBlinkTime', 'uint', -1)
        case $WM_KILLFOCUS
            DllCall('user32.dll', 'int', 'HideCaret', 'hwnd', $hWnd)
            DllCall('user32.dll', 'int', 'DestroyCaret')
            DllCall('user32.dll', 'int', 'SetCaretBlinkTime', 'uint', $BlinkTime)
    endswitch
    return $Res
endfunc; _InputProc

func OnAutoItExit()
    _WinAPI_SetWindowLong($hInput, $GWL_WNDPROC, $hProc)
    DllCallBackFree($pHook)
    if $BlinkTime <> default then
        DllCall('user32.dll', 'int', 'SetCaretBlinkTime', 'uint', $BlinkTime)
    endif
endfunc; OnAutoItExit
Edited by Yashied

Share this post


Link to post
Share on other sites
KaFu
Melba23

Yashied,

Поздравляю вас!

M23

P.S. I hope the spelling is correct this time!


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Yashied
UEZ

Maybe this.

#include <WindowsConstants.au3>
#include <Constants.au3>
#include <WinAPI.au3>

Opt('MustDeclareVars', 1)

global $Button, $Input, $hInput, $hBitmap, $pHook, $hProc, $Msg, $BlinkTime = default

GUICreate('Test', 400, 100)
$Input = GUICtrlCreateInput("", 20, 20, 360, 20)
$hInput = GUICtrlGetHandle($Input)
$Button = GUICtrlCreateButton('Exit', 165, 60, 70, 23)
$hBitmap = _WinAPI_CreateSolidBitmap(0, 0x66FFFF, 10, 14)
$pHook = DllCallbackRegister('_InputProc', 'ptr', 'hwnd;uint;long;ptr')
$hProc = _WinAPI_SetWindowLong($hInput, $GWL_WNDPROC, DllCallbackGetPtr($pHook))
GUISetState()

while 1
    $Msg = GUIGetMsg()
    switch $Msg
        case -3, $Button
            exit
    endswitch
wend

func _InputProc($hWnd, $uiMsg, $wParam, $lParam)
    
    local $Res = _WinAPI_CallWindowProc($hProc, $hWnd, $uiMsg, $wParam, $lParam)
    
    switch $uiMsg
        case $WM_SETFOCUS
            DllCall('user32.dll', 'int', 'CreateCaret', 'hwnd', $hWnd, 'ptr', $hBitmap, 'int', 0, 'int', 0)
            DllCall('user32.dll', 'int', 'ShowCaret', 'hwnd', $hWnd)
            $BlinkTime = DllCall('user32.dll', 'int', 'GetCaretBlinkTime')
            $BlinkTime = $BlinkTime[0]
            DllCall('user32.dll', 'int', 'SetCaretBlinkTime', 'uint', -1)
        case $WM_KILLFOCUS
            DllCall('user32.dll', 'int', 'HideCaret', 'hwnd', $hWnd)
            DllCall('user32.dll', 'int', 'DestroyCaret')
            DllCall('user32.dll', 'int', 'SetCaretBlinkTime', 'uint', $BlinkTime)
    endswitch
    return $Res
endfunc; _InputProc

func OnAutoItExit()
    _WinAPI_SetWindowLong($hInput, $GWL_WNDPROC, $hProc)
    DllCallBackFree($pHook)
    if $BlinkTime <> default then
        DllCall('user32.dll', 'int', 'SetCaretBlinkTime', 'uint', $BlinkTime)
    endif
endfunc; OnAutoItExit
For what is the variable $BlinkTime? Should the cursor blink?

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
Authenticity

haha... kakdila Yashied, very nice example.

Share this post


Link to post
Share on other sites
Yashied

Share this post


Link to post
Share on other sites
Valuater

For what is the variable $BlinkTime? Should the cursor blink?

UEZ

This is with the blink and you may note the $BlinkTime attributes

#Include <WindowsConstants.au3>
#Include <Constants.au3>
#Include <WinAPI.au3>

Opt('MustDeclareVars', 1)

global $Button, $Input, $hInput, $hBitmap, $pHook, $hProc, $Msg, $BlinkTime

GUICreate('Test', 400, 100)
$Input = GUICtrlCreateInput("", 20, 20, 360, 20)
$hInput = GUICtrlGetHandle($Input)
$Button = GUICtrlCreateButton('Exit', 165, 60, 70, 23)
$hBitmap = _WinAPI_CreateSolidBitmap(0, 0x66FFFF, 10, 14)
$pHook = DllCallbackRegister('_InputProc', 'ptr', 'hwnd;uint;long;ptr')
$hProc = _WinAPI_SetWindowLong($hInput, $GWL_WNDPROC, DllCallbackGetPtr($pHook))
GUISetState()

while 1
    $Msg = GUIGetMsg()
    switch $Msg
        case -3, $Button
            exit
    endswitch
wend

func _InputProc($hWnd, $uiMsg, $wParam, $lParam)
   
    local $Res = _WinAPI_CallWindowProc($hProc, $hWnd, $uiMsg, $wParam, $lParam)
   
    switch $uiMsg
        case $WM_SETFOCUS
            DllCall('user32.dll', 'int', 'CreateCaret', 'hwnd', $hWnd, 'ptr', $hBitmap, 'int', 0, 'int', 0)
            DllCall('user32.dll', 'int', 'ShowCaret', 'hwnd', $hWnd)
            ;$BlinkTime = DllCall('user32.dll', 'int', 'GetCaretBlinkTime')
            ;$BlinkTime = $BlinkTime[0]
            ;DllCall('user32.dll', 'int', 'SetCaretBlinkTime', 'uint', -1)
        case $WM_KILLFOCUS
            DllCall('user32.dll', 'int', 'HideCaret', 'hwnd', $hWnd)
            DllCall('user32.dll', 'int', 'DestroyCaret')
            ;DllCall('user32.dll', 'int', 'SetCaretBlinkTime', 'uint', $BlinkTime)
    endswitch
    return $Res
endfunc; _InputProc

func OnAutoItExit()
    _WinAPI_SetWindowLong($hInput, $GWL_WNDPROC, $hProc)
    DllCallBackFree($pHook)
endfunc; OnAutoItExit

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites
UEZ

Thanks, but I'm not familiar with WinAPI respectively C++. So, how can I set the blinking time?

-> thanks Valuater for the response! I posted shortly after your post!

Btw, very nice example Yasied!

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
Yashied

Thanks, but I'm not familiar with WinAPI respectively C++. So, how can I set the blinking time? -> thanks Valuater for the response! I posted shortly after your post!

Btw, very nice example Yasied!

UEZ

Replace (-1) to other value (in milliseconds).

DllCall('user32.dll', 'int', 'SetCaretBlinkTime', 'uint', $MyBlinkTime)

Share this post


Link to post
Share on other sites
UEZ

Replace (-1) to other value (in milliseconds).

DllCall('user32.dll', 'int', 'SetCaretBlinkTime', 'uint', $MyBlinkTime)

Thanks, working excellent ^_^

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
charvi

Yashied, I am truly very happy with your example! Many many thanks! And yes, it works like a charm too. Perfect with monospaced characters with adjusted width and height in the _WinAPI_CreateSolidBitmap statement.

I wish I could say 'Thank You' in your language... I know in Polish it is 'dziekuje bardzo' but not yet in Russian lol. Isn't what Melba23 said to you?

And also thanks to the others who were interested in the BlinkTime... I think it is now time for AutoIt to blink like the Sun, isn't it? lol

Cheers! charvi

Share this post


Link to post
Share on other sites
charvi

I was just wondering if there is also a way to get an underscore blinking cursor, to imitate the MS-DOS look & feel ?

This just for completeness ^_^

Share this post


Link to post
Share on other sites
Valuater

Using GUIRegisterMsg for Multiple inputs

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

Global $hBitmap

$frmGlobalDefaults = GUICreate("Edit Focus", 400, 300)
$btnBrowse = GUICtrlCreateButton("&Browse", 240, 24, 60, 248, 0)
$inptbxRegFileName = GUICtrlCreateInput("inptbxRegFileName " & $btnBrowse + 1, 20, 24, 200, 21)
$inptbxDirBase = GUICtrlCreateInput("inptbxDirBase " & $btnBrowse + 2, 20, 80, 200, 21)
$inptbxDirAlbum = GUICtrlCreateInput("inptbxDirAlbum " & $btnBrowse + 3, 20, 136, 200, 21)
$inptbxDirSettings = GUICtrlCreateInput("inptbxDirSettings " & $btnBrowse + 4, 20, 192, 200, 21)
$inptbxDirHP = GUICtrlCreateInput("inptbxDirHP " & $btnBrowse + 5, 20, 248, 200, 21)
GUISetState()

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") ; Set the Function

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    If $hBitmap = "" Then $hBitmap = _WinAPI_CreateSolidBitmap(0, 0x66FFFF, 10, 14)
    Local $nNotifyCode = BitShift($wParam, 16)
    Switch $nNotifyCode; Edit control event messages only
        Case $EN_SETFOCUS; Edit (Input) control has focus
            DllCall('user32.dll', 'int', 'CreateCaret', 'hwnd', $lParam, 'ptr', $hBitmap, 'int', 0, 'int', 0)
            DllCall('user32.dll', 'int', 'ShowCaret', 'hwnd', $lParam)
        Case $EN_KILLFOCUS; Edit (Input) control lost focus
            DllCall('user32.dll', 'int', 'HideCaret', 'hwnd', $lParam)
            DllCall('user32.dll', 'int', 'DestroyCaret')
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

I like the Blinking... 8)

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites
UEZ

I was just wondering if there is also a way to get an underscore blinking cursor, to imitate the MS-DOS look & feel ?

This just for completeness ^_^

Good idea but I looked at MSDN -> SetCaretPos Function but I don't know how to implement it.

My try was : DllCall('user32.dll', 'int', 'SetCaretPos', 'int', 8, 'int', 15) but it isn't working.

Further how can the GetCaretPos Function be implemented?

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
UEZ

Kip also posted a Caret UDF that even alows you to use custom images:

http://www.autoitscript.com/forum/index.ph...st&p=574055

Thanks, that is the answer of my question!

I really need to start to learn C++

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
charvi

Valuater,

I appreciate the easy programming example for multi-inputs. I played with your example today and could not make it working. I do not see why nor see any error.

Below is my attempt. I was trying to stimulate a DOS environment, creating an invisible button so the Enter key accepts the input. But why does the input not show a block caret???

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <WinAPI.au3>
#include <ButtonConstants.au3>
#include <Constants.au3>

Global $hBitmap, $h_WinMain, $hiddenbutton, $input

;~ $frmGlobalDefaults = GUICreate("Edit Focus", 400, 300)
;~ $btnBrowse = GUICtrlCreateButton("&Browse", 240, 24, 60, 248, 0)
;~ $inptbxRegFileName = GUICtrlCreateInput("inptbxRegFileName " & $btnBrowse + 1, 20, 24, 200, 21)
;~ $inptbxDirBase = GUICtrlCreateInput("inptbxDirBase " & $btnBrowse + 2, 20, 80, 200, 21)
;~ $inptbxDirAlbum = GUICtrlCreateInput("inptbxDirAlbum " & $btnBrowse + 3, 20, 136, 200, 21)
;~ $inptbxDirSettings = GUICtrlCreateInput("inptbxDirSettings " & $btnBrowse + 4, 20, 192, 200, 21)
;~ $inptbxDirHP = GUICtrlCreateInput("inptbxDirHP " & $btnBrowse + 5, 20, 248, 200, 21)

    
$h_WinMain = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP)
GUISetBkColor(0x000000, $h_WinMain)
GUISetFont(14, 800, 0, "Courier New")
GUICtrlCreateLabel("AUTOIT-DOS 2009", 0, 0, 500, 20)
GUICtrlSetColor(-1, 0x00ff00)
GUICtrlCreateLabel(">", 0, 30, 20, 20)
GUICtrlSetColor(-1, 0x00ff00)

$hiddenbutton = GUICtrlCreateButton("OK", 260, 90, 100, 30, $BS_DEFPUSHBUTTON)
GUICtrlSetState(-1, $GUI_HIDE)

$input = GUICtrlCreateInput("", 10, 30, 500, 21, -1, 0)
GUICtrlSetBkColor(-1, 0x000000)
GUICtrlSetColor(-1, 0x00ff00)
GUICtrlSetState(-1, $GUI_FOCUS)

GUISetState()

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND"); Set the Function

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case -3, $GUI_EVENT_CLOSE
            Exit
        Case $hiddenbutton
            GUICtrlSetState($hiddenbutton, $GUI_FOCUS)
            GUICtrlCreateLabel("BAD COMMAND OR FILE NAME", 0, 60, 500, 20)
            GUICtrlSetColor(-1, 0xff0000)
            Sleep(3000)
            Exit
    EndSwitch
WEnd

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    If $hBitmap = "" Then $hBitmap = _WinAPI_CreateSolidBitmap(0, 0x66FFFF, 10, 14)
    Local $nNotifyCode = BitShift($wParam, 16)
    Switch $nNotifyCode; Edit control event messages only
        Case $EN_SETFOCUS; Edit (Input) control has focus
            DllCall('user32.dll', 'int', 'CreateCaret', 'hwnd', $lParam, 'ptr', $hBitmap, 'int', 0, 'int', 0)
            DllCall('user32.dll', 'int', 'ShowCaret', 'hwnd', $lParam)
        Case $EN_KILLFOCUS; Edit (Input) control lost focus
            DllCall('user32.dll', 'int', 'HideCaret', 'hwnd', $lParam)
            DllCall('user32.dll', 'int', 'DestroyCaret')
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc  ;==>WM_COMMAND

Using GUIRegisterMsg for Multiple inputs

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

Global $hBitmap

$frmGlobalDefaults = GUICreate("Edit Focus", 400, 300)
$btnBrowse = GUICtrlCreateButton("&Browse", 240, 24, 60, 248, 0)
$inptbxRegFileName = GUICtrlCreateInput("inptbxRegFileName " & $btnBrowse + 1, 20, 24, 200, 21)
$inptbxDirBase = GUICtrlCreateInput("inptbxDirBase " & $btnBrowse + 2, 20, 80, 200, 21)
$inptbxDirAlbum = GUICtrlCreateInput("inptbxDirAlbum " & $btnBrowse + 3, 20, 136, 200, 21)
$inptbxDirSettings = GUICtrlCreateInput("inptbxDirSettings " & $btnBrowse + 4, 20, 192, 200, 21)
$inptbxDirHP = GUICtrlCreateInput("inptbxDirHP " & $btnBrowse + 5, 20, 248, 200, 21)
GUISetState()

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") ; Set the Function

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    If $hBitmap = "" Then $hBitmap = _WinAPI_CreateSolidBitmap(0, 0x66FFFF, 10, 14)
    Local $nNotifyCode = BitShift($wParam, 16)
    Switch $nNotifyCode; Edit control event messages only
        Case $EN_SETFOCUS; Edit (Input) control has focus
            DllCall('user32.dll', 'int', 'CreateCaret', 'hwnd', $lParam, 'ptr', $hBitmap, 'int', 0, 'int', 0)
            DllCall('user32.dll', 'int', 'ShowCaret', 'hwnd', $lParam)
        Case $EN_KILLFOCUS; Edit (Input) control lost focus
            DllCall('user32.dll', 'int', 'HideCaret', 'hwnd', $lParam)
            DllCall('user32.dll', 'int', 'DestroyCaret')
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

I like the Blinking... 8)

8)

Share this post


Link to post
Share on other sites
Yashied

See closely.

...
$input = GUICtrlCreateInput("", 10, 30, 500, 21, -1, 0)
GUICtrlSetBkColor(-1, 0x000000)
GUICtrlSetColor(-1, 0x00ff00)
;GUICtrlSetState(-1, $GUI_FOCUS)

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND"); Set the Function
GUISetState()
...

EDIT: Use GUISetCursor(16) for better DOS emulation.

Edited by Yashied

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  

×