Index: trunk/src/user32/win32wbase.cpp
===================================================================
--- trunk/src/user32/win32wbase.cpp	(revision 7887)
+++ trunk/src/user32/win32wbase.cpp	(revision 7890)
@@ -1,3 +1,3 @@
-/* $Id: win32wbase.cpp,v 1.313 2002-02-05 17:59:00 sandervl Exp $ */
+/* $Id: win32wbase.cpp,v 1.314 2002-02-12 18:07:20 sandervl Exp $ */
 /*
  * Win32 Window Base Class for OS/2
@@ -279,7 +279,20 @@
         if(getParent()->IsWindowDestroyed())
         {
+            Win32BaseWindow *wndparent = (Win32BaseWindow *)ChildWindow::getParentOfChild();
+            RELEASE_WNDOBJ(wndparent);
             setParent(NULL);  //or else we'll crash in the dtor of the ChildWindow class
         }
     }
+    else 
+    {
+        Win32BaseWindow *wndparent = (Win32BaseWindow *)ChildWindow::getParentOfChild();
+        if(wndparent && !fDestroyAll) {
+            RELEASE_WNDOBJ(wndparent);
+        }
+    }
+    if(owner && !fDestroyAll) {
+        RELEASE_WNDOBJ(owner);
+    }
+
     /* Decrement class window counter */
     if(windowClass) {
@@ -314,11 +327,4 @@
     if(propertyList) {
         removeWindowProps();
-    }
-    Win32BaseWindow *wndparent = (Win32BaseWindow *)ChildWindow::getParentOfChild();
-    if(wndparent && !fDestroyAll) {
-        RELEASE_WNDOBJ(wndparent);
-    }
-    if(owner && !fDestroyAll) {
-        RELEASE_WNDOBJ(owner);
     }
 }
@@ -957,5 +963,5 @@
     else {
         //make sure no message can ever arrive for this window again (PM or from other win32 windows)
-        dprintf(("Mark window %x (%x) as deleted", getWindowHandle(), this));
+        dprintf(("Mark window %x (%x) as deleted; refcount %d", getWindowHandle(), this, getRefCount()));
         markDeleted();
         OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, 0);
Index: trunk/src/user32/windlg.cpp
===================================================================
--- trunk/src/user32/windlg.cpp	(revision 7887)
+++ trunk/src/user32/windlg.cpp	(revision 7890)
@@ -1,3 +1,3 @@
-/* $Id: windlg.cpp,v 1.29 2001-11-30 18:45:51 sandervl Exp $ */
+/* $Id: windlg.cpp,v 1.30 2002-02-12 18:07:21 sandervl Exp $ */
 /*
  * Win32 dialog apis for OS/2
@@ -443,4 +443,5 @@
 {
   Win32BaseWindow *dlgcontrol;
+  int              ret;
 
     dlgcontrol = Win32BaseWindow::GetWindowFromHandle(hwnd);
@@ -451,5 +452,7 @@
     }
     dprintf(("USER32: GetDlgCtrlID %x", hwnd));
-    return dlgcontrol->getWindowId();
+    ret = dlgcontrol->getWindowId();
+    RELEASE_WNDOBJ(dlgcontrol);
+    return ret;
 }
 //******************************************************************************
@@ -458,4 +461,5 @@
 {
   Win32Dialog *dialog;
+  BOOL         ret;
 
     dialog = (Win32Dialog *)Win32BaseWindow::GetWindowFromHandle(hwnd);
@@ -465,6 +469,7 @@
         return 0;
     }
-    dprintf(("USER32: EndDialog %x %d", hwnd, retval));
-    return dialog->endDialog(retval);
+    ret = dialog->endDialog(retval);
+    RELEASE_WNDOBJ(dialog);
+    return ret;
 }
 //******************************************************************************
Index: trunk/src/user32/window.cpp
===================================================================
--- trunk/src/user32/window.cpp	(revision 7887)
+++ trunk/src/user32/window.cpp	(revision 7890)
@@ -1,3 +1,3 @@
-/* $Id: window.cpp,v 1.119 2002-02-12 13:10:14 sandervl Exp $ */
+/* $Id: window.cpp,v 1.120 2002-02-12 18:07:21 sandervl Exp $ */
 /*
  * Win32 window apis for OS/2
@@ -1102,5 +1102,5 @@
     if(wndFrom != windowDesktop)
     {
-    window = wndFrom;
+        window = wndFrom;
         while(window)
         {
@@ -1114,5 +1114,5 @@
     if(wndTo != windowDesktop)
     {
-    window = wndTo;
+        window = wndTo;
         while(window)
         {
@@ -1208,7 +1208,7 @@
 HWND WIN32API GetDesktopWindow(void)
 {
-    HWND DesktopWindow = windowDesktop->getWindowHandle();
-    dprintf2(("USER32: GetDesktopWindow, returned %x\n", DesktopWindow));
-    return DesktopWindow;
+    HWND hDesktopWindow = windowDesktop->getWindowHandle();
+    dprintf2(("USER32: GetDesktopWindow, returned %x\n", hDesktopWindow));
+    return hDesktopWindow;
 }
 //******************************************************************************
