Sign in to follow this  
Followers 0
charvi

Func _Caret_

12 posts in this topic

#1 ·  Posted (edited)

Referring to my topic about the Solid Block Caret (http://www.autoitscript.com/forum/index.php?showtopic=94323), I am now trying to create a general function that everybody can use in AutoIt to change the caret type in input fields.

The function Caret Mode 2 does not work well, the underscore does not remain an underscore while typing. I hope that someone has the solution!

Enjoy!

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <WinAPI.au3>
$hWnd = GUICreate("Input with a selected Caret", 400, 300)
GUISetFont(12, 400, 1, "Courier")

$btnOK = GUICtrlCreateButton("&OK", 260, 248, 80, 30, 0)
$input1 = GUICtrlCreateInput("input1", 20, 24, 200, 21)
$input2 = GUICtrlCreateInput("input2", 20, 80, 200, 21)
$input3 = GUICtrlCreateInput("input3", 20, 136, 200, 21)
$input4 = GUICtrlCreateInput("input4", 20, 192, 200, 21)
$input5 = GUICtrlCreateInput("input5", 20, 248, 200, 21)
GUISetState()

_Caret_(4)
GUICtrlSetState($input2, $GUI_FOCUS); here we focus to the second input

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case -3, $GUI_EVENT_CLOSE, $btnOK
            Exit
    EndSwitch
WEnd




#==================================================================================================
; Function Name .....:  _Caret_
; Description .......:  Caret Setup
; Syntax ............:  _Caret_($i_CaretMode)
; Parameters ........:  $i_CaretMode            0 = invisible
;                                               1 = blinking vertical line caret
;                                               2 = DOS blinking underscore
;                                               3 = immobile solid block caret
;                                               4 = blinking solid block caret
; Return values .....:  None
; Creation Date .....:  2009-05-09
; Version ...........:  0.0.0.1
; Version Date ......:  2009-05-09
; Remarks ...........:  For blinking underscore like MS-DOS, try $i_CaretW = 10, $i_CaretH = 2, $i_CaretX = 0, $i_CaretY = 18
;                       The caret size to be used depends of the size of the used font and its size.
#==================================================================================================
Func _Caret_($i_CaretMode)
    Global $i_CaretX, $i_CaretY, $i_CaretW, $i_CaretH, $i_CaretSpeed, $hBitmap
    Switch $i_CaretMode
        Case 0; invisible
            $i_CaretX = 0
            $i_CaretY = 0
            $i_CaretW = 0
            $i_CaretH = 0
            $i_CaretSpeed = -1
        Case 1; blinking vertical line caret
            $i_CaretX = 0
            $i_CaretY = 0
            $i_CaretW = 1
            $i_CaretH = 18
            $i_CaretSpeed = 500
        Case 2; DOS blinking underscore
            $i_CaretX = 0
            $i_CaretY = 18
            $i_CaretW = 10
            $i_CaretH = 2
            $i_CaretSpeed = 500
        Case 3; immobile solid block caret
            $i_CaretX = 0
            $i_CaretY = 0
            $i_CaretW = 10
            $i_CaretH = 18
            $i_CaretSpeed = -1
        Case 4; blinking solid block caret
            $i_CaretX = 0
            $i_CaretY = 0
            $i_CaretW = 10
            $i_CaretH = 18
            $i_CaretSpeed = 500
;EndCase
    EndSwitch
    GUIRegisterMsg($WM_COMMAND, "_Caret_WM_COMMAND_"); Set the Function
EndFunc;==>_Caret_

Func _Caret_WM_COMMAND_($hWnd, $iMsg, $wParam, $lParam)
    If $hBitmap = "" Then $hBitmap = _WinAPI_CreateSolidBitmap(0, 0xffffff, $i_CaretW, $i_CaretH); color ori was 0x66FFFF
    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)
            Sleep(10)
            DllCall("User32.dll", 'int', 'SetCaretPos', 'int', $i_CaretX, 'int', $i_CaretY)
            DllCall('user32.dll', 'int', 'SetCaretBlinkTime', 'uint', $i_CaretSpeed)
            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;==>_Caret_WM_COMMAND_
Edited by charvi

Share this post


Link to post
Share on other sites



Apparently, you wish to be the Author of this function that was designed mostly by Yashied.

... and not giving him nor anyone who helped you credit, is not looked upon as favorable here!

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I come to the conclusion that you do not know what to do and how it works. Look closely at the examples in your previous topic.

EDIT: You have not done anything new here, just added a lot of mistakes.

Edited by Yashied

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I come to the conclusion that you do not know what to do and how it works. Look closely at the examples in your previous topic.

Valuater is right, I forgot to add some credits. Apologies!

Yashied, indeed, I do not know exactly why the mode 2 is not working well, I am not an WinAPI specialist. I am collecting the elements that seem the easiest to use and hope they work. Experts like you can perhaps tell us what is missing in the code.

Edited by charvi

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Edited by Yashied

Share this post


Link to post
Share on other sites

Yashied, I'm getting an em when starting your script above: "_WinAPI_DrawIconEx: Invalid cursor handle."

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, I'm getting an em when starting your script above: "_WinAPI_DrawIconEx: Invalid cursor handle."

UEZ

Me too... so I am unable to test your script. I'm using Vista 32.

Yashied, I must tell you that I am appreciating your immense effort...

Share this post


Link to post
Share on other sites

When I put AutoIt code in my post, the char "\" disappears. I corrected it.

Nice work Yashied! It is working properly now :)

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

#10 ·  Posted

When I put AutoIt code in my post, the char "\" disappears. I corrected it.

Very impressive WinAPI scripting, this is still far away of my programming knowledge. Good that you made them all in separate functions, so they can be used without too much knowledge.

Thank you very much, Yashied.

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Very impressive WinAPI scripting, this is still far away of my programming knowledge. Good that you made them all in separate functions, so they can be used without too much knowledge.

Thank you very much, Yashied.

Charvi, write Caret UDF is a good idea. But you must take into account the many nuances, so that the UDF could use the majority of interested people for their needs. This is not a trivial work. Look at Hotkeys Input Control UDF Library from my signature. This will be a good example for you.

Good luck.

EDIT: Charvi, I AM NOT THE AUTHOR OF YOUR (SEE FIRST POST) FUNCTION, PLEASE REMOVE MY NICKNAME FROM THERE.

Edited by Yashied

Share this post


Link to post
Share on other sites

EDIT: Charvi, I AM NOT THE AUTHOR OF YOUR (SEE FIRST POST) FUNCTION, PLEASE REMOVE MY NICKNAME FROM THERE.

@charvi,

Likewise there is no need to credit me in that function, as in your other thread I only pointed you to Kip's function.

Remove my name also. Thanks.

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