CEdit Derived Class That Uses the Global Heap |
Q118308
The information in this article applies to:
-
The Microsoft Foundation Classes (MFC), used with:
-
Microsoft Visual C++, 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
Gedit.exe
For additional information about how to download Microsoft Support
files, click the article number below
to view the article in the Microsoft Knowledge Base:
Q119591 How to Obtain Microsoft Support Files from
Online Services
Microsoft used the most current virus detection software available
on the date of posting to scan this file for viruses. Once posted,
the file is housed on secure servers that prevent any unauthorized
changes to the file.
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