Microsoft KB Archive/94318

= How to Change the Size of the Text Cursor in a Text Box =

Article ID: 94318

Article Last Modified on 11/18/2003

-

APPLIES TO


 * Microsoft Visual Basic 1.0 Standard Edition
 * Microsoft Visual Basic 2.0 Standard Edition
 * Microsoft Visual Basic 3.0 Professional Edition

-



This article was previously published under Q94318



SUMMARY
Although there is no property that will allow you to change the appearance of the text cursor (text caret) in a Visual Basic text box, you can use the Windows API call CreateCaret function to do so.



API Calls
In the example below, API calls change the size of the text cursor. The CreateCaret function creates a new shape for the system caret and assigns ownership of the caret to the given window. The caret shape can be a line, block, or bitmap. Here's the syntax: Void CreateCaret(hwnd, hbmp,nwidth,nheight)   HWND hwnd      - handle of owner window HBITMAP hbmp  - handle of bitmap for caret shape int nwidth    - caret width int nheight   - caret height The ShowCaret function shows the caret on the screen at the caret's current position. Once shown, the caret begins flashing automatically. Void ShowCaret(hwnd)   HWND hwnd     - handle of window with caret The GetFocus function retrieves the handle of the window that currently has the input focus. HWND GetFocus(void)

Example Code
To see these API calls in action do the following:

 Start Visual Basic or start a new project (ALT, F, N). Add two text boxes to Form1.  Add the following declarations to the General Declarations section of Form1. Note that you must enter each declaration on a single line even though, for readability, the first declaration is shown on two lines: Declare Sub CreateCaret Lib &quot;user&quot; (ByVal w%, ByVal x%,        ByVal y%, ByVal z%) Declare Function showcaret% Lib &quot;user&quot; (ByVal x%) Declare Function getfocus% Lib &quot;user&quot;   Add the following code to the Command1_Click event: Sub Text1_GotFocus h% = getfocus%               ' get the handle to the text box Call createcaret(h%, 0, 3, 24) ' create new caret size x% = showcaret%(h%)            ' show the new caret End Sub  Run the program.</ol>

You will see that while the focus is on Text1 the size of the text caret in the text box appears larger than normal.

Additional query words: 2.00 3.00

Keywords: KB94318

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.