Using Windows API Functions to Better Manipulate Text Boxes (141073)
The information in this article applies to:
- Microsoft Visual Basic Professional Edition, 16-bit, for Windows 4.0
- Microsoft Visual Basic Enterprise Edition, 16-bit, for Windows 4.0
This article was previously published under Q141073 SUMMARY
By calling Windows API functions from Microsoft Visual Basic for Windows,
you can retrieve text box (or edit control) information that you cannot
obtain using only Visual Basic for Windows's built-in features.
NOTE: In Visual Basic versions 2.0, 3.0, and 4.0 for Windows, you can use
the new HWND property of a text box instead of calling the GetFocus()
function.
This article supplies a sample program that performs the following useful
features (making use of the Windows message constants shown in parentheses,
obtained by calling Windows API routines):
- Copies a specific line of text from the text box (EM_GETLINE).
- Retrieves the number of lines within the text box (EM_GETLINECOUNT).
- Positions the cursor at a specific character location (EM_GETSEL) in the
text box.
- Retrieves the line number of a specific character location in the text
box (EM_LINEFROMCHAR).
- Retrieves the amount of lines before a specified character position in
the text box (EM_LINEINDEX).
- Retrieves the amount of characters in a specified line in the text box
(EM_LINELENGTH).
- Replaces specified text with another text string (EM_REPLACESEL).
For additional information, please see the following article in the
Microsoft Knowledge Base:
72677
: How to Limit User Input in VB Combo Box with SendMessage API
REFERENCES
"Programming Windows: The Microsoft Guide to Writing Applications for
Windows 3," Charles Petzold, Microsoft Press, 1990
"Microsoft Windows Software Development Kit: Reference Volume 1,"
version 3.0.
WINSDK.HLP file shipped with Microsoft Windows 3.0 Software Development Kit
The Professional and Enterprise Editions of Visual Basic 4.0 contain all
the necessary SDK references in the MSDN/VB Starter Kit.
Modification Type: | Minor | Last Reviewed: | 1/8/2003 |
---|
Keywords: | kbhowto KB141073 |
---|
|