Index: trunk/src/user32/new/heapshared.cpp
===================================================================
--- trunk/src/user32/new/heapshared.cpp	(revision 728)
+++ trunk/src/user32/new/heapshared.cpp	(revision 729)
@@ -1,5 +1,9 @@
-/* $Id: heapshared.cpp,v 1.1 1999-08-28 14:09:57 sandervl Exp $ */
+/* $Id: heapshared.cpp,v 1.2 1999-08-28 19:32:46 sandervl Exp $ */
 /*
  * Shared heap functions for OS/2
+ *
+ * Initially commit 16 kb, add more when required
+ *
+ * NOTE: Hardcoded limit of 256 KB per process (increase when required)
  *
  * Copyright 1999 Sander van Leeuwen (sandervl@xs4all.nl)
@@ -12,8 +16,7 @@
 #include "heapshared.h"
 
-#define INITIAL_HEAPSIZE	(64*1024)
-
-Heap_t  sharedHeap = 0;
-PVOID   pSharedMem = NULL;
+       Heap_t  sharedHeap = 0;
+static PVOID   pSharedMem = NULL;
+static BYTE    pageBitmap[MAX_HEAPPAGES] = {0};
 
 void * _LNK_CONV getmoreShared(Heap_t pHeap, size_t *size, int *clean);
@@ -27,10 +30,15 @@
 
   dprintf(("USER32: InitializeSharedHeap"));
-  rc = DosAllocSharedMem(&pSharedMem, NULL, INITIAL_HEAPSIZE, PAG_READ|PAG_WRITE|PAG_COMMIT|OBJ_GIVEABLE);
+  rc = DosAllocSharedMem(&pSharedMem, NULL, MAX_HEAPSIZE, PAG_READ|PAG_WRITE|OBJ_GETTABLE);
   if(rc != 0) {
 	dprintf(("InitializeSharedHeap: DosAllocSharedMem failed with %d", rc));
 	return FALSE;
   }
-  sharedHeap = _ucreate(pSharedMem, INITIAL_HEAPSIZE, _BLOCK_CLEAN, 
+  rc = DosSetMem(pSharedMem, INCR_HEAPSIZE, PAG_READ|PAG_WRITE|PAG_COMMIT);
+  if(rc != 0) {
+	dprintf(("InitializeSharedHeap: DosSetMem failed with %d", rc));
+	return FALSE;
+  }
+  sharedHeap = _ucreate(pSharedMem, INCR_HEAPSIZE, _BLOCK_CLEAN, 
                         _HEAP_REGULAR|_HEAP_SHARED,
                         getmoreShared, releaseShared);
@@ -39,4 +47,7 @@
 	dprintf(("InitializeSharedHeap: _ucreate failed!"));
 	return FALSE;
+  }
+  for(int i=0;i<INCR_HEAPSIZE/PAGE_SIZE;i++) {
+  	pageBitmap[i] = 1; //mark as committed
   }
   return TRUE;
@@ -65,4 +76,15 @@
 //******************************************************************************
 //******************************************************************************
+ULONG GetPageRangeFree(ULONG pageoffset)
+{
+  for(int i=pageoffset;i<MAX_HEAPPAGES;i++) {
+	if(pageBitmap[i] == 1) {
+		break;
+	}
+  }
+  return i-pageoffset;
+}
+//******************************************************************************
+//******************************************************************************
 void * _LNK_CONV getmoreShared(Heap_t pHeap, size_t *size, int *clean)
 {
@@ -71,15 +93,31 @@
  PVOID newblock;
 
-  /* round the size up to a multiple of 64K */
-  *size = (*size / 65536) * 65536 + 65536;
+  /* round the size up to a multiple of 4K */
+  *size = (*size / 4096) * 4096 + 4096;
+  *size = max(*size, INCR_HEAPSIZE);
 
-  rc = DosAllocSharedMem(&newblock, NULL, *size, PAG_READ|PAG_WRITE|PAG_COMMIT|OBJ_GIVEABLE);
-  if(rc != 0) {
-	dprintf(("getmoreShared: DosAllocSharedMem failed with %d", rc));
-	return NULL;
+  for(int i=0;i<MAX_HEAPPAGES;i++) 
+  {
+	int nrpagesfree = GetPageRangeFree(i);
+	if(nrpagesfree >= *size/PAGE_SIZE) {
+  		newblock = (PVOID)((ULONG)pSharedMem + i*PAGE_SIZE);
+  		rc = DosSetMem(newblock, *size, PAG_READ|PAG_WRITE|PAG_COMMIT);
+  		if(rc != 0) {
+			dprintf(("getmoreShared: DosSetMem failed with %d", rc));
+			return NULL;
+  		}
+  		for(int j=i;j<i+*size/PAGE_SIZE;i++) {
+  			pageBitmap[i] = 1; //mark as committed
+  		}
+
+		*clean = _BLOCK_CLEAN;
+		dprintf(("USER32: getmoreShared %x %d", newblock, *size));
+		return newblock;
+	}
+	if(nrpagesfree)
+		i += nrpagesfree-1;
   }
-  *clean = _BLOCK_CLEAN;
-
-  return newblock;
+  dprintf(("USER32: getmoreShared NOTHING LEFT (%d)", *size));
+  return NULL;
 }
 //******************************************************************************
@@ -87,6 +125,21 @@
 void _LNK_CONV releaseShared(Heap_t pHeap, void *block, size_t size)
 {
-  DosFreeMem(block);
+ ULONG pagenr;
+
+  dprintf(("USER32: releaseShared %x %d", block, size));
+  DosSetMem(block, size, PAG_READ|PAG_WRITE|PAG_DECOMMIT);
+
+  pagenr  = (ULONG)block - (ULONG)pSharedMem;
+  pagenr /= PAGE_SIZE;
+  for(int i=pagenr;i<pagenr+size/PAGE_SIZE;i++) {
+  	pageBitmap[i] = 0; //mark as decommitted
+  }
 }
 //******************************************************************************
 //******************************************************************************
+DWORD  HeapGetSharedMemBase()
+{
+  return (DWORD) pSharedMem;
+}
+//******************************************************************************
+//******************************************************************************
Index: trunk/src/user32/new/heapshared.h
===================================================================
--- trunk/src/user32/new/heapshared.h	(revision 728)
+++ trunk/src/user32/new/heapshared.h	(revision 729)
@@ -1,3 +1,3 @@
-/* $Id: heapshared.h,v 1.1 1999-08-28 14:09:58 sandervl Exp $ */
+/* $Id: heapshared.h,v 1.2 1999-08-28 19:32:46 sandervl Exp $ */
 /*
  * Shared heap functions for OS/2
@@ -13,8 +13,14 @@
 #include <umalloc.h>
 
+#define PAGE_SIZE		4096
+#define MAX_HEAPSIZE            (256*1024)
+#define MAX_HEAPPAGES		(MAX_HEAPSIZE/PAGE_SIZE)
+#define INCR_HEAPSIZE		(16*1024)
+
 extern Heap_t sharedHeap;
 
 BOOL   InitializeSharedHeap();
 void   DestroySharedHeap();
+DWORD  HeapGetSharedMemBase();
 
 void  *_smalloc(size_t size);
Index: trunk/src/user32/new/makefile
===================================================================
--- trunk/src/user32/new/makefile	(revision 728)
+++ trunk/src/user32/new/makefile	(revision 729)
@@ -1,3 +1,3 @@
-# $Id: makefile,v 1.34 1999-08-28 14:09:29 sandervl Exp $
+# $Id: makefile,v 1.35 1999-08-28 19:32:46 sandervl Exp $
 
 #
@@ -22,5 +22,5 @@
 
 OBJS =  user32.obj dialog.obj loadres.obj \
-        dde.obj heapshared.obj\
+        dde.obj heapshared.obj win32wndhandle.obj \
         icon.obj hook.obj hooks.obj winmenu.obj \
         usrcall.obj defwndproc.obj syscolor.obj char.obj initterm.obj \
@@ -31,5 +31,5 @@
         controls.obj button.obj static.obj scroll.obj listbox.obj \
         combo.obj edit.obj clipboard.obj winicon.obj \
-        oslibutil.obj oslibmsg.obj dib.obj \
+        oslibutil.obj oslibmsg.obj dib.obj oslibdos.obj \
         winprop.obj wingdi.obj oslibgdi.obj winaccel.obj winscrollbar.obj \
         nativerc.obj oslibres.obj dummy.obj \
@@ -98,8 +98,9 @@
 windlg.obj:    windlg.cpp win32wnd.h win32dlg.h
 windlgmsg.obj: windlgmsg.cpp win32class.h win32wnd.h win32dlg.h win32wndchild.h
+win32wndhandle.obj: win32wndhandle.cpp win32wndhandle.h
 
 pmwindow.obj:   pmwindow.cpp win32class.h win32wnd.h win32dlg.h pmwindow.h win32wndchild.h $(PDWIN32_INCLUDE)\wprocess.h oslibgdi.h oslibwin.h
 win32class.obj: win32class.cpp win32class.h win32wnd.h win32dlg.h gen_object.h heapshared.h oslibwin.h win32wndchild.h
-win32wnd.obj:   win32wnd.cpp win32class.h win32wnd.h win32dlg.h gen_object.h heapshared.h oslibwin.h win32wndchild.h  $(PDWIN32_INCLUDE)\winres.h oslibres.h
+win32wnd.obj:   win32wnd.cpp win32class.h win32wnd.h win32dlg.h gen_object.h heapshared.h oslibwin.h win32wndchild.h  $(PDWIN32_INCLUDE)\winres.h oslibres.h win32wndhandle.h oslibdos.h
 win32dlg.obj:   win32dlg.cpp win32class.h win32wnd.h win32dlg.h gen_object.h heapshared.h oslibwin.h win32wndchild.h
 win32wndchild.obj: win32wndchild.cpp win32wndchild.h
@@ -110,4 +111,5 @@
 oslibgdi.obj:   oslibgdi.cpp oslibgdi.h
 oslibres.obj:   oslibres.cpp oslibwin.h oslibres.h $(PDWIN32_INCLUDE)\winconst.h
+oslibdos.obj:   oslibdos.cpp oslibdos.h
 
 clipboard.obj:  clipboard.cpp
Index: trunk/src/user32/new/oslibdos.cpp
===================================================================
--- trunk/src/user32/new/oslibdos.cpp	(revision 729)
+++ trunk/src/user32/new/oslibdos.cpp	(revision 729)
@@ -0,0 +1,37 @@
+/* $Id: oslibdos.cpp,v 1.1 1999-08-28 19:33:04 sandervl Exp $ */
+/*
+ * Dos* api wrappers for OS/2
+ *
+ *
+ * Copyright 1999 Sander van Leeuwen (sandervl@xs4all.nl)
+ *
+ *
+ * Project Odin Software License can be found in LICENSE.TXT
+ *
+ */
+#define INCL_BASE
+#define INCL_DOSEXCEPTIONS
+#define INCL_DOSMEMMGR
+#define INCL_DOSPROCESS
+#include <os2wrap.h>
+#include <win32type.h>
+#include <misc.h>
+#include "oslibdos.h"
+
+//******************************************************************************
+//Map shared memory into our address space
+//******************************************************************************
+DWORD OSLibDosGetSharedMem(PVOID addr, DWORD size, DWORD flags)
+{
+ DWORD os2flags = 0, rangesize, rangeflags;
+
+  if(flags & OSLIB_PAG_READ)
+	os2flags |= PAG_READ;
+  if(flags & OSLIB_PAG_WRITE)
+	os2flags |= PAG_WRITE;
+
+  return DosGetSharedMem(addr, os2flags);
+}
+//******************************************************************************
+//******************************************************************************
+
Index: trunk/src/user32/new/oslibdos.h
===================================================================
--- trunk/src/user32/new/oslibdos.h	(revision 729)
+++ trunk/src/user32/new/oslibdos.h	(revision 729)
@@ -0,0 +1,20 @@
+/* $Id: oslibdos.h,v 1.1 1999-08-28 19:33:04 sandervl Exp $ */
+/*
+ * Dos* api wrappers for OS/2
+ *
+ *
+ * Copyright 1999 Sander van Leeuwen (sandervl@xs4all.nl)
+ *
+ *
+ * Project Odin Software License can be found in LICENSE.TXT
+ *
+ */
+#ifndef __OSLIBDOS_H__
+#define __OSLIBDOS_H__
+
+#define OSLIB_PAG_READ	1
+#define OSLIB_PAG_WRITE	2
+
+DWORD OSLibDosGetSharedMem(PVOID addr, DWORD size, DWORD flags);
+
+#endif //__OSLIBDOS_H__
Index: trunk/src/user32/new/pmwindow.cpp
===================================================================
--- trunk/src/user32/new/pmwindow.cpp	(revision 728)
+++ trunk/src/user32/new/pmwindow.cpp	(revision 729)
@@ -1,3 +1,3 @@
-/* $Id: pmwindow.cpp,v 1.23 1999-08-28 17:24:45 dengert Exp $ */
+/* $Id: pmwindow.cpp,v 1.24 1999-08-28 19:32:46 sandervl Exp $ */
 /*
  * Win32 Window Managment Code for OS/2
@@ -77,5 +77,5 @@
      (PFNWP)Win32WindowProc,            /* Address of window procedure  */
      CS_SIZEREDRAW | CS_HITTEST,
-     8)) {
+     NROF_WIN32WNDBYTES)) {
         dprintf(("WinRegisterClass Win32Window failed"));
         return(FALSE);
@@ -108,27 +108,11 @@
         goto RunDefWndProc;
   }
+  if(msg > WIN32APP_USERMSGBASE) {
+	//win32 app user message
+	dprintf(("PMWINDOW: Message %x (%x,%x) posted to window %x", (ULONG)msg-WIN32APP_USERMSGBASE, mp1, mp2, hwnd));
+        win32wnd->SendMessageA((ULONG)msg-WIN32APP_USERMSGBASE, (ULONG)mp1, (ULONG)mp2);
+  }
   switch( msg )
   {
-    //internal messages
-    case WM_WIN32_POSTMESSAGEA:
-        postmsg = (POSTMSG_PACKET *)mp1;
-        if(postmsg == NULL) {
-            dprintf(("WM_WIN32_POSTMESSAGEA, postmsg NULL!!"));
-            break;
-        }
-        win32wnd->SendMessageA(postmsg->Msg, postmsg->wParam, postmsg->lParam);
-        free(postmsg);
-        break;
-
-    case WM_WIN32_POSTMESSAGEW:
-        postmsg = (POSTMSG_PACKET *)mp1;
-        if(postmsg == NULL) {
-            dprintf(("WM_WIN32_POSTMESSAGEW, postmsg NULL!!"));
-            break;
-        }
-        win32wnd->SendMessageW(postmsg->Msg, postmsg->wParam, postmsg->lParam);
-        free(postmsg);
-        break;
-
     //OS/2 msgs
     case WM_CREATE:
@@ -199,5 +183,5 @@
         {
            Win32Window *wndAfter = Win32Window::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
-           wp.hwndInsertAfter = wndAfter->getWindowHandle();
+           if(wndAfter) wp.hwndInsertAfter = wndAfter->getWindowHandle();
         }
         win32wnd->MsgPosChanging((LPARAM)&wp);
Index: trunk/src/user32/new/user32.def
===================================================================
--- trunk/src/user32/new/user32.def	(revision 728)
+++ trunk/src/user32/new/user32.def	(revision 729)
@@ -1,7 +1,11 @@
-; $Id: user32.def,v 1.5 1999-08-23 13:56:47 sandervl Exp $
+; $Id: user32.def,v 1.6 1999-08-28 19:32:46 sandervl Exp $
 
 ;Created by BLAST for IBM's compiler
-LIBRARY USER32 INITINSTANCE
-DATA MULTIPLE NONSHARED
+LIBRARY USER32 INITINSTANCE TERMINSTANCE
+DATA MULTIPLE NONSHARED LOADONCALL
+CODE SHARED LOADONCALL
+
+SEGMENTS
+   _GLOBALDATA CLASS 'DATA'       SHARED LOADONCALL READWRITE
 
 EXPORTS
Index: trunk/src/user32/new/win32wnd.cpp
===================================================================
--- trunk/src/user32/new/win32wnd.cpp	(revision 728)
+++ trunk/src/user32/new/win32wnd.cpp	(revision 729)
@@ -1,3 +1,3 @@
-/* $Id: win32wnd.cpp,v 1.33 1999-08-28 17:24:45 dengert Exp $ */
+/* $Id: win32wnd.cpp,v 1.34 1999-08-28 19:32:47 sandervl Exp $ */
 /*
  * Win32 Window Code for OS/2
@@ -23,5 +23,4 @@
 #include <assert.h>
 #include <misc.h>
-#include <handlemanager.h>
 #include <heapstring.h>
 #include <win32wnd.h>
@@ -33,6 +32,9 @@
 #include <oslibgdi.h>
 #include <oslibres.h>
+#include "oslibdos.h"
 #include <winres.h>
 #include "syscolor.h"
+#include "win32wndhandle.h"
+#include "heapshared.h"
 
 #define HAS_DLGFRAME(style,exStyle) \
@@ -86,11 +88,9 @@
   Win32Hwnd        = 0;
 
-  if(HMHandleAllocate(&Win32Hwnd, (ULONG)this) != 0)
+  if(HwAllocateWindowHandle(&Win32Hwnd, (ULONG)this) == FALSE)
   {
-        dprintf(("Win32Window::Init HMHandleAllocate failed!!"));
+        dprintf(("Win32Window::Init HwAllocateWindowHandle failed!!"));
         DebugInt3();
   }
-  Win32Hwnd       &= 0xFFFF;
-  Win32Hwnd       |= 0x68000000;
 
   posx = posy      = 0;
@@ -124,5 +124,6 @@
 
   if(Win32Hwnd)
-        HMHandleFree(Win32Hwnd & 0xFFFF);
+        HwFreeWindowHandle(Win32Hwnd);
+
   if(userWindowLong)
         free(userWindowLong);
@@ -269,5 +270,5 @@
         if(owner == NULL)
         {
-            dprintf(("HMHandleTranslateToOS2 couldn't find owner window %x!!!", cs->hwndParent));
+            dprintf(("HwGetWindowHandleData couldn't find owner window %x!!!", cs->hwndParent));
             return FALSE;
         }
@@ -283,5 +284,5 @@
             if(owner == NULL)
             {
-                dprintf(("HMHandleTranslateToOS2 couldn't find owner window %x!!!", cs->hwndParent));
+                dprintf(("HwGetWindowHandleData couldn't find owner window %x!!!", cs->hwndParent));
                 return FALSE;
             }
@@ -403,4 +404,9 @@
         return FALSE;
   }
+  //SvL: Need to store the shared memory base, or else other apps can map it into their memory space
+  if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_SHAREDMEM, HeapGetSharedMemBase()) == FALSE) {
+        dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2Hwnd));
+        return FALSE;
+  }
 #if 0
   if(OS2Hwnd != OS2HwndFrame) {
@@ -410,4 +416,9 @@
     }
     if(OSLibWinSetWindowULong(OS2HwndFrame, OFFSET_WIN32PM_MAGIC, WIN32PM_MAGIC) == FALSE) {
+            dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2HwndFrame));
+            return FALSE;
+    }
+    //SvL: Need to store the shared memory base, or else other apps can map it into their memory space
+    if(OSLibWinSetWindowULong(OS2HwndFrame, OFFSET_WIN32PM_SHAREDMEM, HeapGetSharedMemBase()) == FALSE) {
             dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2HwndFrame));
             return FALSE;
@@ -1334,15 +1345,5 @@
 BOOL Win32Window::PostMessageA(ULONG msg, WPARAM wParam, LPARAM lParam)
 {
- POSTMSG_PACKET *postmsg;
-
-  postmsg = (POSTMSG_PACKET *)malloc(sizeof(POSTMSG_PACKET));
-  if(postmsg == NULL) {
-    dprintf(("Win32Window::PostMessageA: malloc returned NULL!!"));
-    return 0;
-  }
-  postmsg->Msg    = msg;
-  postmsg->wParam = wParam;
-  postmsg->lParam = lParam;
-  return OSLibPostMessage(OS2Hwnd, WM_WIN32_POSTMESSAGEA, (ULONG)postmsg, 0);
+  return OSLibPostMessage(OS2Hwnd, WIN32APP_USERMSGBASE+msg, wParam, lParam);
 }
 //******************************************************************************
@@ -1350,15 +1351,5 @@
 BOOL Win32Window::PostMessageW(ULONG msg, WPARAM wParam, LPARAM lParam)
 {
- POSTMSG_PACKET *postmsg;
-
-  postmsg = (POSTMSG_PACKET *)malloc(sizeof(POSTMSG_PACKET));
-  if(postmsg == NULL) {
-    dprintf(("Win32Window::PostMessageW: malloc returned NULL!!"));
-    return 0;
-  }
-  postmsg->Msg    = msg;
-  postmsg->wParam = wParam;
-  postmsg->lParam = lParam;
-  return OSLibPostMessage(OS2Hwnd, WM_WIN32_POSTMESSAGEW, (ULONG)postmsg, 0);
+  return OSLibPostMessage(OS2Hwnd, WIN32APP_USERMSGBASE+msg, wParam, lParam);
 }
 //******************************************************************************
@@ -1743,18 +1734,24 @@
         while(hwnd)
         {
-            HWND hwndClient;
-
             wnd = GetWindowFromOS2Handle(hwnd);
             if(wnd == NULL) {
-                hwndClient = OSLibWinQueryClientWindow(hwnd);
-                if(hwndClient)  wnd = GetWindowFromOS2Handle(hwndClient);
+                hwnd = OSLibWinQueryClientWindow(hwnd);
+                if(hwnd)  wnd = GetWindowFromOS2Handle(hwnd);
             }
 
-            if(wnd && wnd->getWindowClass()->hasClassName(lpszClass, fUnicode) &&
-               (!lpszWindow || wnd->hasWindowName(lpszWindow, fUnicode)))
-            {
-                OSLibWinEndEnumWindows(henum);
-                dprintf(("FindWindowEx: Found window %x", wnd->getWindowHandle()));
-                return wnd->getWindowHandle();
+            if(wnd) {
+                LPVOID sharedmembase = (LPVOID)OSLibWinGetWindowULong(hwnd, OFFSET_WIN32PM_SHAREDMEM);
+
+                if(OSLibDosGetSharedMem(sharedmembase, MAX_HEAPSIZE, OSLIB_PAG_READ) != 0) {
+                    dprintf(("OSLibDosGetSharedMem returned error for %x", wnd));
+                    break;
+                }
+                if(wnd->getWindowClass()->hasClassName(lpszClass, fUnicode) &&
+                   (!lpszWindow || wnd->hasWindowName(lpszWindow, fUnicode)))
+                {
+                    OSLibWinEndEnumWindows(henum);
+                    dprintf(("FindWindowEx: Found window %x", wnd->getWindowHandle()));
+                    return wnd->getWindowHandle();
+                }
             }
             hwnd = OSLibWinGetNextWindow(henum);
@@ -2033,9 +2030,5 @@
  Win32Window *window;
 
-   if(HIWORD(hwnd) != 0x6800) {
-        return NULL;
-   }
-
-   if(HMHandleTranslateToOS2(LOWORD(hwnd), (PULONG)&window) == NO_ERROR) {
+   if(HwGetWindowHandleData(hwnd, (DWORD *)&window) == TRUE) {
         return window;
    }
Index: trunk/src/user32/new/win32wnd.h
===================================================================
--- trunk/src/user32/new/win32wnd.h	(revision 728)
+++ trunk/src/user32/new/win32wnd.h	(revision 729)
@@ -1,3 +1,3 @@
-/* $Id: win32wnd.h,v 1.27 1999-08-28 14:09:30 sandervl Exp $ */
+/* $Id: win32wnd.h,v 1.28 1999-08-28 19:32:47 sandervl Exp $ */
 /*
  * Win32 Window Code for OS/2
@@ -23,9 +23,13 @@
 class Win32Window;
 
-#define OFFSET_WIN32WNDPTR      0
-#define OFFSET_WIN32PM_MAGIC    4
+#define OFFSET_WIN32WNDPTR        0
+#define OFFSET_WIN32PM_MAGIC      4
+#define OFFSET_WIN32PM_SHAREDMEM  8
+#define NROF_WIN32WNDBYTES        12
 
 #define WIN32PM_MAGIC           0x12345678
 #define CheckMagicDword(a)      (a==WIN32PM_MAGIC)
+
+#define WIN32APP_USERMSGBASE		0x1000
 
 typedef struct {
Index: trunk/src/user32/new/win32wndhandle.cpp
===================================================================
--- trunk/src/user32/new/win32wndhandle.cpp	(revision 729)
+++ trunk/src/user32/new/win32wndhandle.cpp	(revision 729)
@@ -0,0 +1,93 @@
+/* $Id: win32wndhandle.cpp,v 1.1 1999-08-28 19:32:47 sandervl Exp $ */
+/*
+ * Win32 Handle Management Code for OS/2
+ *
+ *
+ * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
+ *
+ *
+ * TODO: The table should be dynamically increased when necessary
+ *       This is just a quick and dirty implementation 
+ * TODO: Probably need to clean up the table when app closes
+ *       (also store PID and remove all handles with PID of terminating app)
+ * 
+ * Project Odin Software License can be found in LICENSE.TXT
+ *
+ */
+
+#include <os2win.h>
+#include <vmutex.h>
+#include "win32wndhandle.h"
+
+#define MAX_WINDOW_HANDLES	 1024
+#define WNDHANDLE_MAGIC_HIGHWORD 0x68000000
+#define WNDHANDLE_MAGIC_MASK     0x0000FFFF
+
+//******************************************************************************
+
+//Global DLL Data
+#pragma data_seg(_GLOBALDATA)
+ULONG  WindowHandleTable[MAX_WINDOW_HANDLES] = {0};
+VMutex tableMutex(TRUE);
+ULONG  lowestFreeIndex = 0;
+#pragma data_seg()
+
+//******************************************************************************
+//******************************************************************************
+BOOL HwAllocateWindowHandle(HWND *hwnd, DWORD dwUserData)
+{
+  tableMutex.enter();
+  if(lowestFreeIndex == -1) {
+	//oops, out of handles
+	dprintf(("USER32: HwAllocateWindowHandle OUT OF WINDOW HANDLES!!"));
+	DebugInt3();
+	tableMutex.leave();
+	return FALSE;
+  }
+  *hwnd           = lowestFreeIndex;
+  *hwnd          |= WNDHANDLE_MAGIC_HIGHWORD;
+  WindowHandleTable[lowestFreeIndex] = dwUserData;
+
+  lowestFreeIndex = -1;
+
+  //find next free handle
+  for(int i=0;i<MAX_WINDOW_HANDLES;i++) {
+	if(WindowHandleTable[i] == 0) {
+		lowestFreeIndex = i;
+		break;
+	}
+  }
+  tableMutex.leave();
+  return TRUE;
+}
+//******************************************************************************
+//******************************************************************************
+void HwFreeWindowHandle(HWND hwnd)
+{
+  hwnd &= WNDHANDLE_MAGIC_MASK;
+  if(hwnd < MAX_WINDOW_HANDLES) {
+	tableMutex.enter();
+	WindowHandleTable[hwnd] = 0;
+	if(lowestFreeIndex == -1 || hwnd < lowestFreeIndex) 
+		lowestFreeIndex = hwnd;
+
+	tableMutex.leave();
+  }
+}
+//******************************************************************************
+//******************************************************************************
+BOOL HwGetWindowHandleData(HWND hwnd, DWORD *pdwUserData)
+{
+  if((hwnd & 0xFFFF0000) != WNDHANDLE_MAGIC_HIGHWORD) {
+	return FALSE; //unknown window (PM?)
+  }
+  hwnd &= WNDHANDLE_MAGIC_MASK;
+  if(hwnd < MAX_WINDOW_HANDLES) {
+	*pdwUserData = WindowHandleTable[hwnd];
+	return TRUE;
+  }
+  *pdwUserData = 0;
+  return FALSE;
+}
+//******************************************************************************
+//******************************************************************************
Index: trunk/src/user32/new/win32wndhandle.h
===================================================================
--- trunk/src/user32/new/win32wndhandle.h	(revision 729)
+++ trunk/src/user32/new/win32wndhandle.h	(revision 729)
@@ -0,0 +1,19 @@
+/* $Id: win32wndhandle.h,v 1.1 1999-08-28 19:32:47 sandervl Exp $ */
+/*
+ * Win32 Handle Management Code for OS/2
+ *
+ *
+ * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
+ *
+ *
+ * Project Odin Software License can be found in LICENSE.TXT
+ *
+ */
+#ifndef __WIN32WNDHANDLE_H__
+#define __WIN32WNDHANDLE_H__
+
+BOOL  HwAllocateWindowHandle(HWND *hwnd, DWORD dwUserData);
+void  HwFreeWindowHandle(HWND hwnd);
+BOOL  HwGetWindowHandleData(HWND hwnd, DWORD *pdwUserData);
+
+#endif //__WIN32WNDHANDLE_H__
