SAMPLE: CEdit Derived Class That Uses the Global Heap
ID: Q118308
|
The information in this article applies to:
-
The Microsoft Foundation Classes (MFC), included with:
-
Microsoft Visual C++ for Windows, 16-bit edition, versions 1.0, 1.5
SUMMARY
The 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.
MORE INFORMATION
The following file is available for download from the Microsoft Software
Library:
GEDIT.EXE
For more information about downloading files from the Microsoft Software
Library, please see the following article in the Microsoft Knowledge Base:
Q119591 How to Obtain Microsoft Support Files from Online Services
GEDIT.ZIP can also be found in library 8 of the MSMFC forum as
GEDITMP.ZIP
Under 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 query words:
kbinf 1gedit globedit
Keywords : kb16bitonly kbnokeyword kbMFC kbVC
Version : 1.00 1.50
Platform : WINDOWS
Issue type :
Last Reviewed: July 30, 1999