The information in this article applies to:
SUMMARYIn some situations, an application may contain text that is displayed for the user to read, which is undesirable for the user to modify. The application can use a static control to contain this text if the message is short. However, for larger amounts of text, which require scrolling to display all the text in the allotted area, something closer to an edit control is required. This article, and its associated sample code, details how to make an edit control "read- only." MORE INFORMATIONThe following files are available for download from the Microsoft
Download Center. Click the file names below to download the files: http://www.microsoft.com/downloads/search.aspand then click How to use the Microsoft Download Center. An application can create a read-only edit control by subclassing or superclassing a standard edit control. The subclass procedure filters out messages that change the contents of the edit control. The following code fragment demonstrates this process:
In the example above, the subclass procedure traps mouse clicks,
keystrokes, and the cut, copy, and paste commands. It also traps the
WM_GETDLGCODE message to prevent an edit control in a dialog box from
receiving the input focus.
The following example demonstrates superclassing an edit control to create a new ROEDIT-class control that behaves similar to a read-only edit control. A ROEDIT control implements the window procedure provided above. It also changes the cursor to an arrow instead of an I-beam, which provides an additional indication to the user that the contents of the control cannot be changed. Using an ROEDIT control eliminates the necessity of subclassing each control after it is created. When the application creates a control from the ROEDIT class, the read-only behavior is provided automatically. The following code demonstrates superclassing an edit control as described above:
In Windows 3.1, there is a new style bit for the edit control (ES_READONLY)
that removes the editing capabilities of the edit control, leaving only the
viewing capabilities. This style is useful when the application shows the
user a body of static text that the user reads and does not modify.
Additional query words:
Keywords : kbfile kbsample kb16bitonly kbCtrl kbEditCtrl kbGrpUser kbWinOS310 |
Last Reviewed: December 8, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |