Function Reference


_WinAPI_CreateCaret

Creates a new shape for the system caret and assigns ownership of the caret to the specified window

#include <WinAPIRes.au3>
_WinAPI_CreateCaret ( $hWnd, $hBitmap [, $iWidth = 0 [, $iHeight = 0]] )

Parameters

$hWnd Handle to the window that owns the caret.
$hBitmap Handle to the bitmap that defines the caret shape.
If this parameter is 0, the caret is solid.
If this parameter is 1, the caret is gray. If this parameter is a bitmap handle, the caret is the specified bitmap.
$iWidth [optional] The width of the caret in logical units.
If this parameter is 0 (Default), the width is set to the system-defined window border width.
If $hBitmap is a bitmap handle, _WinAPI_CreateCaret() ignores this parameter.
$iHeight [optional] The height of the caret in logical units.
If this parameter is 0 (Default), the height is set to the system-defined window border height.
If $hBitmap is a bitmap handle, _WinAPI_CreateCaret() ignores this parameter.

Return Value

Success: True.
Failure: False, call _WinAPI_GetLastError() to get extended error information.

Remarks

_WinAPI_CreateCaret() automatically destroys the previous caret shape, if any, regardless of the window that owns the caret.
The caret is hidden until the application calls the _WinAPI_ShowCaret() function to make the caret visible.

The system provides one caret per queue. A window should create a caret only when it has the keyboard focus or is active.
The window should destroy the caret before losing the keyboard focus or becoming inactive.

You can retrieve the width or height of the system's window border by using the _WinAPI_GetSystemMetrics() function, specifying the $SM_CXBORDER and $SM_CYBORDER values. Using the window border width or height guarantees that the caret will be visible on a high-resolution screen.

Related

_WinAPI_GetSystemMetrics, _WinAPI_ShowCaret

See Also

Search CreateCaret in MSDN Library.

Example

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WinAPIConv.au3>
#include <WinAPIGdi.au3>
#include <WinAPIHObj.au3>
#include <WinAPIRes.au3>
#include <WindowsConstants.au3>

Global $g_vDuration = Default, $g_hBitmap = _WinAPI_CreateSolidBitmap(0, 0x00AEFF, 10, 14)

OnAutoItExitRegister('OnAutoItExit')

Local $hForm = GUICreate('Test ' & StringReplace(@ScriptName, '.au3', '()'), 400, 93)
Local $idInput = GUICtrlCreateInput('', 20, 20, 360, 20)
Local $idButton = GUICtrlCreateButton('Exit', 165, 59, 70, 23)
GUIRegisterMsg($WM_COMMAND, 'WM_COMMAND')
GUISetState(@SW_SHOW)

While 1
        Switch GUIGetMsg()
                Case $GUI_EVENT_CLOSE, $idButton
                        ExitLoop
        EndSwitch
WEnd

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
        #forceref $iMsg

        Switch $hWnd
                Case $hForm
                        Switch _WinAPI_LoWord($wParam)
                                Case $idInput
                                        Switch _WinAPI_HiWord($wParam)
                                                Case $EN_KILLFOCUS
                                                        _WinAPI_HideCaret($lParam)
                                                        _WinAPI_DestroyCaret()
                                                        _WinAPI_SetCaretBlinkTime($g_vDuration)
                                                        $g_vDuration = Default
                                                Case $EN_SETFOCUS
                                                        $g_vDuration = _WinAPI_SetCaretBlinkTime(-1)
                                                        _WinAPI_CreateCaret($lParam, $g_hBitmap)
                                                        _WinAPI_ShowCaret($lParam)
                                        EndSwitch
                        EndSwitch
        EndSwitch
        Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

Func OnAutoItExit()
        _WinAPI_DeleteObject($g_hBitmap)
        If Not IsKeyword($g_vDuration) Then
                _WinAPI_SetCaretBlinkTime($g_vDuration)
        EndIf
EndFunc   ;==>OnAutoItExit