PRB: Brush Permanent Handle Map Doesn't Work on Windows 95 (151865)
The information in this article applies to:
- Microsoft Visual C++ 1.0
- Microsoft Visual C++ 1.5
- Microsoft Visual C++ 1.51
- Microsoft Visual C++ 1.52
- Microsoft Visual C++ 1.52b
- Microsoft Visual C++ 2.0
- Microsoft Visual C++ 2.1
- Microsoft Visual C++ 2.2
- Microsoft Visual C++ 4.0
- Microsoft Visual C++ 4.1
This article was previously published under Q151865 SYMPTOMS
Unexpected behavior might occur if an application relies on MFC's permanent
brush handle map.
In MFC 2.0 (included with Visual C++, version 1.0), symptoms can include:
Assertion Failure, winhand.cpp - Line 129
In MFC 2.5 (included with Visual C++, version 1.5), symptoms can include:
Assertion Failure, winhand.cpp - Line 169
CAUSE
Windows 95 has been optimized to prevent individual applications from
burdening the system resources. One of the optimizations is in the area of
brush handles. Windows 95 will not always return a unique handle when a new
brush object is created. Because MFC's permanent handle map mechanism
relies on a one-to-one mapping from HANDLE-> C++ Object, this optimization
will prevent MFC's permanent brush handle map mechanism from working
properly. See the More Information section below for further details.
RESOLUTION
Do not rely on the brush permanent handle map when running on Windows 95.
You can still use the return value of any MFC function which might return a
temporary, but you should not rely on the function returning a specific
object that you expected to be in the permanent handle map.
For example, the code shown below could be re-written as:
CBrush *pBrush1 = new CBrush (RGB(255,0,0));
CBrush *pBrush2 = new CBrush (RGB(255,0,0));
CBrush *pOld = pDC->SelectObject(pBrush1);
// Do some stuff in here
// Don't rely on the return value from SelectObject being pBrush1
pDC->SelectObject(pOld);
// Instead, maintain the pointer to the object yourself
delete pBrush1;
The following functions might return an unexpected object:
SelectObject
FromHandle
FromHandlePermanent
GetCurrentBrush
GetHalftoneBrush
SelectStockObject
In MFC versions 2.0 and 2.50, the assertion failures can be ignored
although the behavior mentioned above could still cause problems. If you
cannot ignore the assertion failures if, for instance, they occur far too
often, then you can remove the assertions from the MFC source code and
rebuild the DEBUG version of the MFC libraries. For details on how to
accomplish this behavior, see the README.TXT file in the <MSVC>\MFC\SRC
directory.
STATUS
This behavior is by design.
Modification Type: | Major | Last Reviewed: | 12/1/2003 |
---|
Keywords: | kbArchitecture kbBrush kbprb KbUIDesign KB151865 |
---|
|