Index: trunk/src/gdi32/dibitmap.cpp
===================================================================
--- trunk/src/gdi32/dibitmap.cpp	(revision 5387)
+++ trunk/src/gdi32/dibitmap.cpp	(revision 5390)
@@ -1,3 +1,3 @@
-/* $Id: dibitmap.cpp,v 1.14 2001-01-14 17:17:45 sandervl Exp $ */
+/* $Id: dibitmap.cpp,v 1.15 2001-03-27 20:47:52 sandervl Exp $ */
 
 /*
@@ -307,5 +307,5 @@
         DIBSection *dsect;
 
-        dsect = DIBSection::find((DWORD)hBitmap);
+        dsect = DIBSection::findObj(hBitmap);
         if(dsect) {
            return dsect->SetDIBits(hdc, hBitmap, startscan, numlines, pBits, (BITMAPINFOHEADER_W *)&pBitmapInfo->bmiHeader, usage);
Index: trunk/src/gdi32/dibsect.cpp
===================================================================
--- trunk/src/gdi32/dibsect.cpp	(revision 5387)
+++ trunk/src/gdi32/dibsect.cpp	(revision 5390)
@@ -1,3 +1,3 @@
-/* $Id: dibsect.cpp,v 1.47 2001-03-21 12:31:36 sandervl Exp $ */
+/* $Id: dibsect.cpp,v 1.48 2001-03-27 20:47:52 sandervl Exp $ */
 
 /*
@@ -39,5 +39,6 @@
 //******************************************************************************
 DIBSection::DIBSection(BITMAPINFOHEADER_W *pbmi, char *pColors, DWORD iUsage, DWORD hSection, DWORD dwOffset, DWORD handle, int fFlip)
-                : bmpBits(NULL), pOS2bmp(NULL), next(NULL), bmpBitsDblBuffer(NULL)
+                : bmpBits(NULL), pOS2bmp(NULL), next(NULL), bmpBitsDblBuffer(NULL),
+                  hdc(0), hwndParent(0)
 {
  int  palsize=0;
@@ -723,5 +724,5 @@
 //******************************************************************************
 //******************************************************************************
-DIBSection *DIBSection::find(DWORD handle)
+DIBSection *DIBSection::findObj(HANDLE handle)
 {
  DIBSection *dsect = section;
@@ -759,7 +760,7 @@
 //******************************************************************************
 //******************************************************************************
-void DIBSection::deleteSection(DWORD handle)
-{
- DIBSection *dsect = find(handle);
+void DIBSection::deleteSection(HANDLE handle)
+{
+ DIBSection *dsect = findObj(handle);
 
   if(dsect)
Index: trunk/src/gdi32/dibsect.h
===================================================================
--- trunk/src/gdi32/dibsect.h	(revision 5387)
+++ trunk/src/gdi32/dibsect.h	(revision 5390)
@@ -1,3 +1,3 @@
-/* $Id: dibsect.h,v 1.23 2001-03-19 19:27:53 sandervl Exp $ */
+/* $Id: dibsect.h,v 1.24 2001-03-27 20:47:52 sandervl Exp $ */
 
 /*
@@ -109,7 +109,7 @@
 
  static DIBSection *getSection() { return section; } ;
- static DIBSection *find(DWORD handle);
+ static DIBSection *findObj(HANDLE handle);
  static DIBSection *findHDC(HDC hdc);
- static       void  deleteSection(DWORD handle);
+ static       void  deleteSection(HANDLE handle);
 protected:
 
Index: trunk/src/gdi32/gdi32.DEF
===================================================================
--- trunk/src/gdi32/gdi32.DEF	(revision 5387)
+++ trunk/src/gdi32/gdi32.DEF	(revision 5390)
@@ -1,3 +1,3 @@
-; $Id: gdi32.DEF,v 1.15 2001-01-09 18:12:58 sandervl Exp $
+; $Id: gdi32.DEF,v 1.16 2001-03-27 20:47:52 sandervl Exp $
 
 ;Created by BLAST for IBM's compiler
@@ -373,4 +373,4 @@
     _setWinDeviceRegionFromPMDeviceRegion@16                    @1211 NONAME
 
-
-
+    _UnselectGDIObjects@4                                       @1212 NONAME
+
Index: trunk/src/gdi32/gdi32.cpp
===================================================================
--- trunk/src/gdi32/gdi32.cpp	(revision 5387)
+++ trunk/src/gdi32/gdi32.cpp	(revision 5390)
@@ -1,3 +1,3 @@
-/* $Id: gdi32.cpp,v 1.66 2001-02-01 18:01:52 sandervl Exp $ */
+/* $Id: gdi32.cpp,v 1.67 2001-03-27 20:47:53 sandervl Exp $ */
 
 /*
@@ -184,4 +184,13 @@
   }
   SetLastError(ERROR_SUCCESS);
+
+  DIBSection *dsect = DIBSection::findHDC(hdc);
+  if(dsect)
+  {
+      //remove previously selected dibsection
+      dprintf(("DeleteDC %x, unselect DIB section %x", hdc, dsect->GetBitmapHandle()));
+      dsect->UnSelectDIBObject();
+  }
+
   //Must call ReleaseDC for window dcs
   if(pHps->hdcType == TYPE_1) {
@@ -1247,6 +1256,7 @@
 BOOL WIN32API GdiComment(HDC hdc, UINT cbSize, CONST BYTE *lpData)
 {
-  dprintf(("GDI32: GdiComment, not implemented (TRUE)\n"));
-  return(TRUE);
+  dprintf(("GDI32: GdiComment %x %d %x NOT IMPLEMENTED", hdc, cbSize, lpData));
+//  return O32_GdiComment(hdc, cbSize, lpData);
+  return TRUE;
 }
 //******************************************************************************
Index: trunk/src/gdi32/objhandle.cpp
===================================================================
--- trunk/src/gdi32/objhandle.cpp	(revision 5387)
+++ trunk/src/gdi32/objhandle.cpp	(revision 5390)
@@ -1,3 +1,3 @@
-/* $Id: objhandle.cpp,v 1.11 2001-01-18 18:13:18 sandervl Exp $ */
+/* $Id: objhandle.cpp,v 1.12 2001-03-27 20:47:53 sandervl Exp $ */
 /*
  * Win32 Handle Management Code for OS/2
@@ -177,5 +177,5 @@
   if(DIBSection::getSection() != NULL)
   {
-        DIBSection *dsect = DIBSection::find(hObject);
+        DIBSection *dsect = DIBSection::findObj(hObject);
         if(dsect)
         {
@@ -236,17 +236,18 @@
 {
  HGDIOBJ rc;
-
-    dprintf2(("GDI32: SelectObject %x %x", hdc, hObj));
-
-    if(ObjGetHandleType(hObj) == GDIOBJ_REGION) {
+ DWORD   handleType = GetObjectType(hObj);
+
+    dprintf2(("GDI32: SelectObject %x %x type %x", hdc, hObj, handleType));
+
+    if(handleType == GDIOBJ_REGION) {
         //Return complexity here; not previously selected clip region
         return (HGDIOBJ)SelectClipRgn(hdc, hObj);
     }
 
-    if(DIBSection::getSection() != NULL)
+    if(handleType == OBJ_BITMAP && DIBSection::getSection() != NULL)
     {
         DIBSection *dsect;
 
-        dsect = DIBSection::find(hdc);
+        dsect = DIBSection::findHDC(hdc);
         if(dsect)
         {
@@ -254,5 +255,5 @@
             dsect->UnSelectDIBObject();
         }
-        dsect = DIBSection::find((DWORD)hObj);
+        dsect = DIBSection::findObj(hObj);
         if(dsect)
         {
@@ -261,7 +262,7 @@
     }
     rc = O32_SelectObject(hdc, hObj);
-    if(rc != 0 && DIBSection::getSection != NULL)
-    {
-        DIBSection *dsect = DIBSection::find((DWORD)rc);
+    if(rc != 0 && GetObjectType(rc) == OBJ_BITMAP && DIBSection::getSection != NULL)
+    {
+        DIBSection *dsect = DIBSection::findObj(rc);
         if(dsect)
         {
@@ -270,5 +271,5 @@
     }
 #ifdef USING_OPEN32
-    if(O32_GetObjectType(hObj) == OBJ_BITMAP)
+    if(handleType == OBJ_BITMAP)
     {
         //SvL: Open32 messes up the height of the hdc (for windows)
@@ -286,4 +287,18 @@
 }
 //******************************************************************************
+//Called from user32 ReleaseDC (for non CS_OWNDC hdcs)
+//******************************************************************************
+VOID WIN32API UnselectGDIObjects(HDC hdc)
+{
+    DIBSection *dsect;
+
+    dsect = DIBSection::findHDC(hdc);
+    if(dsect)
+    {
+        //remove previously selected dibsection
+        dsect->UnSelectDIBObject();
+    }
+}
+//******************************************************************************
 //******************************************************************************
 DWORD WIN32API GetObjectType( HGDIOBJ hObj)
Index: trunk/src/user32/dc.cpp
===================================================================
--- trunk/src/user32/dc.cpp	(revision 5387)
+++ trunk/src/user32/dc.cpp	(revision 5390)
@@ -1,3 +1,3 @@
-/* $Id: dc.cpp,v 1.95 2001-03-14 15:55:43 sandervl Exp $ */
+/* $Id: dc.cpp,v 1.96 2001-03-27 20:47:22 sandervl Exp $ */
 
 /*
@@ -35,4 +35,5 @@
 #include <dcdata.h>
 #include <codepage.h>
+#include <wingdi32.h>
 
 #define INCLUDED_BY_DC
@@ -966,4 +967,5 @@
    }
    else {
+        UnselectGDIObjects(hdc);
         rc = O32_ReleaseDC (0, hdc);
    }
