SAMPLE: CEdit Derived Class That Uses the Global HeapLast reviewed: March 2, 1998Article ID: Q118308 |
1.00 1.50
WINDOWS
kbprg kbfile
The information in this article applies to:
SUMMARYThe GEDIT sample demonstrates how to create a CEdit derived class that uses a globally allocated memory segment instead of the application's local heap, thereby increasing the maximum contents of the edit control to the full 64K. To obtain the GEDIT sample, download GEDIT.EXE, a self-extracting file, from the Microsoft Software Library (MSL) on the following services:
MORE INFORMATIONUnder Windows, edit controls use the application's local heap to store their text data. Unfortunately this can greatly limit their maximum capacity of 64K if the application uses a large portion of the local heap. In order to be able to utilize the entire 64K capability of the edit control it must have its own segment. Windows edit controls determine the local heap of the application by using the instance handle of the application. The instance handle of an application is just the data segment address (segment only). Therefore the edit control just uses the instance handle directly as the segment selector for its memory allocations. In order to get the edit control to have its own segment, PreCreateWindow must be overridden in a CEdit derived class. In this overridden member function GlobalAlloc is called to allocate a portion of memory from the global heap (the size is not important since the edit control will grow the segment as necessary). The handle returned from the GlobalAlloc is locked and the segment portion of the pointer is stored as the hInstance member of the CREATESTRUCT passed into the overridden PreCreateWindow. A LocalInit must also be called to set up the newly allocated memory as a heap. Once the hInstance variable contains the segment selector of this new segment the CEdit derived class will allocate memory from this segment instead of the application's local heap.
|
Additional reference words: kbinf 1.00 1.50 2.00 2.50 gedit globedit
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |