How to Create a Read-Only Text Box Using SendMessage APILast reviewed: July 20, 1995Article ID: Q110403 |
The information in this article applies to:
- Standard and Professional Editions of Microsoft Visual Basic for Windows, versions 2.0 and 3.0
SUMMARYVisual Basic does not have a Read-Only property for a text box. But you can create a read-only text box by calling the Windows API SendMessage function with the EM_SETREADONLY message.
MORE INFORMATIONSetting the text box state to read-only allows the user to scroll and highlight the text in the text box, but does not allow them to edit it. The program can still modify the text by changing the text property. To create a read-only text box, call the Windows API SendMessage function, using the EM_SETREADONLY message constant as the second parameter. The SendMessage function requires the following parameters:
ret& = SendMessage(hWnd%, uMsg%, wParam%, lParam&)where:
ret& holds the return value of the function call. hWnd% identifies the window handle that is to receive the message. uMsg% the message to be sent (EM_SETREADONLY). wParam% specifies whether to set or remove the read-only state of the edit control. A value of TRUE sets the state to read-only; a value of FALSE sets the state to read/write. lParam& not used for this message, set its value to 0&.The return value of this function is nonzero if the function was successful, and it is zero if an error occurred.
Step-by-Step ExampleThe following example loads a file into a text box, and then sets the text box state to read-only:
|
Additional reference words: 2.00 3.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |