Index: trunk/src/user32/new/controls.cpp
===================================================================
--- trunk/src/user32/new/controls.cpp	(revision 819)
+++ trunk/src/user32/new/controls.cpp	(revision 821)
@@ -1,3 +1,3 @@
-/* $Id: controls.cpp,v 1.10 1999-08-31 17:14:51 sandervl Exp $ */
+/* $Id: controls.cpp,v 1.11 1999-09-04 19:42:27 sandervl Exp $ */
 /* File: controls.cpp -- Win32 common controls
  *
@@ -16,4 +16,5 @@
 #include "combo.H" //listbox,combo,edit
 #include "win32wmdiclient.h"
+#include "win32dlg.h"
 
 /* registration */
@@ -66,4 +67,7 @@
   dprintf(("Register MDICLIENT class"));
   if (!MDICLIENT_Register()) dprintf(("failed!!!"));
+
+  dprintf(("Register DIALOG class"));
+  if (!DIALOG_Register()) dprintf(("failed!!!"));
 }
 
@@ -93,4 +97,7 @@
   dprintf(("Unregister MDICLIENT class"));
   if (!MDICLIENT_Unregister()) dprintf(("failed!!!"));
+
+  dprintf(("Unregister DIALOG class"));
+  if (!DIALOG_Unregister()) dprintf(("failed!!!"));
 }
 
Index: trunk/src/user32/new/defwndproc.cpp
===================================================================
--- trunk/src/user32/new/defwndproc.cpp	(revision 819)
+++ trunk/src/user32/new/defwndproc.cpp	(revision 821)
@@ -1,3 +1,3 @@
-/* $Id: defwndproc.cpp,v 1.7 1999-08-31 17:14:51 sandervl Exp $ */
+/* $Id: defwndproc.cpp,v 1.8 1999-09-04 19:42:27 sandervl Exp $ */
 
 /*
@@ -17,4 +17,5 @@
 #include "win32wnd.h"
 #include "win32wmdichild.h"
+#include "win32dlg.h"
 
 #ifdef DEBUG
@@ -52,70 +53,25 @@
 LRESULT WIN32API DefDlgProcA(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
 {
-#ifdef DEBUG
-////    WriteLog("*DDP*");
-#endif
-    switch(Msg) {
-        case WM_SETREDRAW: //Open32 does not set the visible flag
-                if(wParam)
-                  SetWindowLongA (hwnd, GWL_STYLE, GetWindowLongA (hwnd, GWL_STYLE) | WS_VISIBLE);
-                else
-                  SetWindowLongA (hwnd, GWL_STYLE, GetWindowLongA (hwnd, GWL_STYLE) & ~WS_VISIBLE);
-                return O32_DefDlgProc(hwnd, Msg, wParam, lParam);
-        case WM_NCCREATE://SvL: YAOFM (yet another open32 feature missing)
-                return(TRUE);
-        case WM_CTLCOLORMSGBOX:
-        case WM_CTLCOLOREDIT:
-        case WM_CTLCOLORLISTBOX:
-        case WM_CTLCOLORBTN:
-        case WM_CTLCOLORDLG:
-        case WM_CTLCOLORSTATIC:
-        case WM_CTLCOLORSCROLLBAR:
-                SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW));
-                SetTextColor((HDC)wParam, GetSysColor(COLOR_WINDOWTEXT));
-                return GetSysColorBrush(COLOR_BTNFACE);
+  Win32Dialog *dialog;
 
-    case WM_PARENTNOTIFY: //Open32 doesn't like receiving those!!
-        dprintf(("DefWndProc: WM_PARENTNOTIFY for %x", hwnd));
+    dialog = (Win32Dialog *)Win32BaseWindow::GetWindowFromHandle(hwnd);
+    if(!dialog || dialog->IsWindow()) {
+        dprintf(("DefDlgProcA, window %x not found", hwnd));
         return 0;
-
-        default:
-                return O32_DefDlgProc(hwnd, Msg, wParam, lParam);
     }
+    return dialog->DefDlgProcA(Msg, wParam, lParam);
 }
 //******************************************************************************
-//NOTE: Unicode msg translation!
 //******************************************************************************
 LRESULT WIN32API DefDlgProcW(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
 {
-#ifdef DEBUG
-////    WriteLog("*DDPW*");
-#endif
-    switch(Msg) {
-        case WM_SETREDRAW: //Open32 does not set the visible flag
-                if(wParam)
-                  SetWindowLongA (hwnd, GWL_STYLE, GetWindowLongA (hwnd, GWL_STYLE) | WS_VISIBLE);
-                else
-                  SetWindowLongA (hwnd, GWL_STYLE, GetWindowLongA (hwnd, GWL_STYLE) & ~WS_VISIBLE);
-                return O32_DefDlgProc(hwnd, Msg, wParam, lParam);
-        case WM_NCCREATE://SvL: YAOFM (yet another open32 feature missing)
-                return(TRUE);
-        case WM_CTLCOLORMSGBOX:
-        case WM_CTLCOLOREDIT:
-        case WM_CTLCOLORLISTBOX:
-        case WM_CTLCOLORBTN:
-        case WM_CTLCOLORDLG:
-        case WM_CTLCOLORSTATIC:
-        case WM_CTLCOLORSCROLLBAR:
-                SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW));
-                SetTextColor((HDC)wParam, GetSysColor(COLOR_WINDOWTEXT));
-                return GetSysColorBrush(COLOR_BTNFACE);
+  Win32Dialog *dialog;
 
-    case WM_PARENTNOTIFY: //Open32 doesn't like receiving those!!
-        dprintf(("DefWndProc: WM_PARENTNOTIFY for %x", hwnd));
+    dialog = (Win32Dialog *)Win32BaseWindow::GetWindowFromHandle(hwnd);
+    if(!dialog || dialog->IsWindow()) {
+        dprintf(("DefDlgProcW, window %x not found", hwnd));
         return 0;
-
-        default:
-                return O32_DefDlgProc(hwnd, Msg, wParam, lParam);
     }
+    return dialog->DefDlgProcW(Msg, wParam, lParam);
 }
 //******************************************************************************
Index: trunk/src/user32/new/dialog.cpp
===================================================================
--- trunk/src/user32/new/dialog.cpp	(revision 819)
+++ trunk/src/user32/new/dialog.cpp	(revision 821)
@@ -1,9 +1,13 @@
-/* $Id: dialog.cpp,v 1.7 1999-09-01 19:12:20 phaller Exp $ */
+/* $Id: dialog.cpp,v 1.8 1999-09-04 19:42:27 sandervl Exp $ */
 
 /*
  * Win32 dialog API functions for OS/2
  *
- * Copyright 1998 Sander van Leeuwen
+ * Copyright 1999 Sander van Leeuwen (Wine port & OS/2 adaption)
  *
+ *
+ * Based on Wine code (990815; windows\dialog.c)
+ *
+ * Copyright 1993, 1994, 1996 Alexandre Julliard
  *
  * Project Odin Software License can be found in LICENSE.TXT
@@ -11,128 +15,135 @@
  */
 #include <os2win.h>
-#include <nameid.h>
-#include "user32.h"
-#include "wndproc.h"
-#include "wndclass.h"
+#include "win32wbase.h"
+#include "win32dlg.h"
 
 //******************************************************************************
 //******************************************************************************
-HWND WIN32API CreateDialogParamA(HINSTANCE hinst, LPCSTR lpszTemplate,
-				 HWND hwndOwner, DLGPROC dlgproc,
-				 LPARAM lParamInit)
+HWND WIN32API CreateDialogParamA(HINSTANCE hInst, LPCSTR lpszTemplate,
+                                 HWND hwndOwner, DLGPROC dlgproc,
+                                 LPARAM lParamInit)
 {
- HWND rc;
+  HANDLE hrsrc = FindResourceA( hInst, lpszTemplate, RT_DIALOGA );
 
-    if((int)lpszTemplate >> 16 != 0) {//convert string name identifier to numeric id
-#ifdef DEBUG
-         WriteLog("OS2CreateDialogParamA %s\n", lpszTemplate);
-#endif
-	 lpszTemplate = (LPCSTR)ConvertNameId(hinst, (char *)lpszTemplate);
-    }
-#ifdef DEBUG
-    else WriteLog("OS2CreateDialogParamA %d\n", (int)lpszTemplate);
-#endif
+    if (!hrsrc)
+        return 0;
 
-    return(rc);
+    return CreateDialogIndirectParamA(hInst, (DLGTEMPLATE*)LoadResource(hInst, hrsrc),
+                                      hwndOwner, dlgproc, lParamInit);
 }
 //******************************************************************************
 //******************************************************************************
-HWND WIN32API CreateDialogParamW(HINSTANCE hinst, LPCWSTR lpszTemplate,
-				 HWND hwndOwner, DLGPROC dlgproc,
-				 LPARAM lParamInit)
+HWND WIN32API CreateDialogParamW(HINSTANCE hInst, LPCWSTR lpszTemplate,
+                 HWND hwndOwner, DLGPROC dlgproc,
+                 LPARAM lParamInit)
 {
- HWND rc;
+  HANDLE hrsrc = FindResourceW( hInst, lpszTemplate, RT_DIALOGW );
 
-    if((int)lpszTemplate >> 16 != 0) {//convert string name identifier to numeric id
-	 char *astring = UnicodeToAsciiString((LPWSTR)lpszTemplate);
-#ifdef DEBUG
-         WriteLog("OS2CreateDialogParamW %s\n", astring);
-#endif
-	 lpszTemplate = (LPWSTR)ConvertNameId(hinst, astring);
-	 FreeAsciiString(astring);
-    }
-#ifdef DEBUG
-    else WriteLog("OS2CreateDialogParamW %d\n", (int)lpszTemplate);
-#endif
+    if (!hrsrc)
+        return 0;
 
-    return(rc);
+    return CreateDialogIndirectParamW(hInst, (DLGTEMPLATE*)LoadResource(hInst, hrsrc),
+                                      hwndOwner, dlgproc, lParamInit);
 }
 //******************************************************************************
 //******************************************************************************
-HWND WIN32API CreateDialogIndirectParamA(HINSTANCE hinst,
-				         DLGTEMPLATE *dlgtemplate,
-				         HWND hwndParent, DLGPROC dlgproc,
-				         LPARAM lParamInit)
+HWND WIN32API CreateDialogIndirectParamA(HINSTANCE hInst,
+                         DLGTEMPLATE *dlgtemplate,
+                         HWND hwndParent, DLGPROC dlgproc,
+                         LPARAM lParamInit)
 {
- HWND hwnd;
+ Win32Dialog *dialog;
 
-    return(0);
+    dprintf(("CreateDialogIndirectParamA: %x %x %x %x %x", hInst, dlgtemplate, hwndParent, dlgproc, lParamInit));
+
+    if (!dlgtemplate) return 0;
+
+  	dialog = new Win32Dialog(hInst, (LPCSTR)dlgtemplate, hwndParent, dlgproc, lParamInit, FALSE);
+
+    if(dialog == NULL)
+    {
+        dprintf(("Win32Dialog creation failed!!"));
+        return 0;
+    }
+    if(GetLastError() != 0)
+    {
+        dprintf(("Win32Dialog error found!!"));
+        delete dialog;
+        return 0;
+    }
+    return dialog->getWindowHandle();
 }
 //******************************************************************************
 //******************************************************************************
-HWND WIN32API CreateDialogIndirectParamW(HINSTANCE hinst,
-				         DLGTEMPLATE *dlgtemplate,
-				         HWND hwndParent, DLGPROC dlgproc,
-				         LPARAM lParamInit)
+HWND WIN32API CreateDialogIndirectParamW(HINSTANCE hInst,
+                         DLGTEMPLATE *dlgtemplate,
+                         HWND hwndParent, DLGPROC dlgproc,
+                         LPARAM lParamInit)
 {
- HWND hwnd;
+ Win32Dialog *dialog;
 
-    return(0);
+    dprintf(("CreateDialogIndirectParamW: %x %x %x %x %x", hInst, dlgtemplate, hwndParent, dlgproc, lParamInit));
+
+    if (!dlgtemplate) return 0;
+
+  	dialog = new Win32Dialog(hInst, (LPCSTR)dlgtemplate, hwndParent, dlgproc, lParamInit, TRUE);
+
+    if(dialog == NULL)
+    {
+        dprintf(("Win32Dialog creation failed!!"));
+        return 0;
+    }
+    if(GetLastError() != 0)
+    {
+        dprintf(("Win32Dialog error found!!"));
+        delete dialog;
+        return 0;
+    }
+    return dialog->getWindowHandle();
 }
 //******************************************************************************
 //******************************************************************************
-INT  WIN32API DialogBoxIndirectParamA(HINSTANCE hinst,
-				      DLGTEMPLATE *dlgtemplate,
-				      HWND hwndParent, DLGPROC dlgproc,
- 				      LPARAM lParamInit)
+INT  WIN32API DialogBoxIndirectParamA(HINSTANCE hInst,
+                      DLGTEMPLATE *dlgtemplate,
+                      HWND hwndParent, DLGPROC dlgproc,
+                      LPARAM lParamInit)
 {
-    return(0);
+    HWND hwnd = CreateDialogIndirectParamA(hInst, dlgtemplate, hwndParent, dlgproc,
+                                           lParamInit);
+    //TODO:
+    if (hwnd) return 1; //return DIALOG_DoDialogBox( hwnd, owner );
+    return -1;
 }
 //******************************************************************************
 //******************************************************************************
-INT  WIN32API DialogBoxIndirectParamW(HINSTANCE hinst,
-				      DLGTEMPLATE *dlgtemplate,
-				      HWND hwndParent, DLGPROC dlgproc,
-				      LPARAM lParamInit)
+INT  WIN32API DialogBoxIndirectParamW(HINSTANCE hInst, DLGTEMPLATE *dlgtemplate,
+                                      HWND hwndParent, DLGPROC dlgproc,
+                                      LPARAM lParamInit)
 {
-    return(0);
+    HWND hwnd = CreateDialogIndirectParamW(hInst, dlgtemplate, hwndParent, dlgproc,
+                                           lParamInit);
+    //TODO:
+    if (hwnd) return 1; //return DIALOG_DoDialogBox( hwnd, owner );
+    return -1;
 }
 //******************************************************************************
 //******************************************************************************
-int WIN32API DialogBoxParamA(HINSTANCE hinst, LPCSTR lpszTemplate, HWND hwndOwner,
- 	  	    	     DLGPROC dlgprc, LPARAM  lParamInit)
+int WIN32API DialogBoxParamA(HINSTANCE hInst, LPCSTR lpszTemplate, HWND hwndOwner,
+                     DLGPROC dlgproc, LPARAM  lParamInit)
 {
- int rc;
-
-    if((int)lpszTemplate >> 16 != 0) {//convert string name identifier to numeric id
-	dprintf(("DialogBoxParam %s\n", lpszTemplate));
-	lpszTemplate = (LPCSTR)ConvertNameId(hinst, (char *)lpszTemplate);
-    }
-    else {	
-	dprintf(("DialogBoxParam %d\n", (int)lpszTemplate));
-    }
-
-    return(0);
+    HWND hwnd = CreateDialogParamA( hInst, lpszTemplate, hwndOwner, dlgproc, lParamInit);
+    //TODO:
+    if (hwnd) return 1; //return DIALOG_DoDialogBox( hwnd, owner );
+    return -1;
 }
 //******************************************************************************
 //******************************************************************************
-int WIN32API DialogBoxParamW(HINSTANCE arg1, LPCWSTR arg2, HWND arg3,
-		  	     DLGPROC arg4, LPARAM arg5)
+int WIN32API DialogBoxParamW(HINSTANCE hInst, LPCWSTR lpszTemplate, HWND hwndOwner,
+                             DLGPROC dlgproc, LPARAM lParamInit)
 {
- int   rc;
- char *astring = NULL;
-
-
-    if((int)arg2 >> 16 != 0) {
-	    astring = UnicodeToAsciiString((LPWSTR)arg2);
-    }
-    else    astring = (char *)arg2;
-    dprintf(("OS2DialogBoxParamW\n"));
-
-    if((int)astring >> 16 != 0)	FreeAsciiString(astring);
-
-    dprintf(("OS2DialogBoxIndirectParamA returned %d\n", rc));
-
-    return(0);
+    HWND hwnd = CreateDialogParamW( hInst, lpszTemplate, hwndOwner, dlgproc, lParamInit);
+    //TODO:
+    if (hwnd) return 1; //return DIALOG_DoDialogBox( hwnd, owner );
+    return -1;
 }
 //******************************************************************************
Index: trunk/src/user32/new/makefile
===================================================================
--- trunk/src/user32/new/makefile	(revision 819)
+++ trunk/src/user32/new/makefile	(revision 821)
@@ -1,3 +1,3 @@
-# $Id: makefile,v 1.41 1999-09-04 17:56:40 dengert Exp $
+# $Id: makefile,v 1.42 1999-09-04 19:42:27 sandervl Exp $
 
 #
@@ -67,5 +67,5 @@
 dde.obj: dde.cpp
 hook.obj: hook.cpp hooks.h
-defwndproc.obj: defwndproc.cpp syscolor.h win32wmdiclient.h win32wbase.h win32wnd.h
+defwndproc.obj: defwndproc.cpp syscolor.h win32wmdiclient.h win32wbase.h win32wnd.h win32dlg.h
 hooks.obj: hooks.cpp hooks.h
 initterm.obj: initterm.cpp $(PDWIN32_INCLUDE)\spy.h pmwindow.h heapshared.h
@@ -76,5 +76,5 @@
 spy.obj: spy.cpp $(PDWIN32_INCLUDE)\spy.h
 
-controls.obj: controls.cpp $(PDWIN32_INCLUDE)\win\controls.h win32wmdiclient.h
+controls.obj: controls.cpp $(PDWIN32_INCLUDE)\win\controls.h win32wmdiclient.h win32dlg.h
 button.obj: button.cpp $(PDWIN32_INCLUDE)\win\button.h
 static.obj: static.cpp $(PDWIN32_INCLUDE)\win\static.h
Index: trunk/src/user32/new/oslibres.cpp
===================================================================
--- trunk/src/user32/new/oslibres.cpp	(revision 819)
+++ trunk/src/user32/new/oslibres.cpp	(revision 821)
@@ -1,3 +1,3 @@
-/* $Id: oslibres.cpp,v 1.7 1999-08-31 14:38:08 sandervl Exp $ */
+/* $Id: oslibres.cpp,v 1.8 1999-09-04 19:42:28 sandervl Exp $ */
 /*
  * Window API wrappers for OS/2
@@ -45,5 +45,4 @@
 }
 //******************************************************************************
-//TODO: handle single icons
 //******************************************************************************
 HANDLE OSLibWinCreateIcon(PVOID iconbitmap)
@@ -70,5 +69,6 @@
 	bafh     = (BITMAPARRAYFILEHEADER2 *)bfhBW; //for calculation bitmap offset
     }
-    hps = WinGetPS(HWND_DESKTOP);
+    hps = WinGetScreenPS(HWND_DESKTOP);
+
     hbmColor = GpiCreateBitmap(hps, &bfhColor->bmp2, CBM_INIT, 
 	     	               (char *)bafh + bfhColor->offBits,
@@ -118,5 +118,5 @@
     }
     //skip xor/and mask
-    hps = WinGetPS(HWND_DESKTOP);
+    hps = WinGetScreenPS(HWND_DESKTOP);
     hbmColor = GpiCreateBitmap(hps, &bfh->bmp2, CBM_INIT, 
 	     	               (char *)bfh + bfh->offBits,
Index: trunk/src/user32/new/user32.cpp
===================================================================
--- trunk/src/user32/new/user32.cpp	(revision 819)
+++ trunk/src/user32/new/user32.cpp	(revision 821)
@@ -1,3 +1,3 @@
-/* $Id: user32.cpp,v 1.17 1999-09-03 15:09:44 sandervl Exp $ */
+/* $Id: user32.cpp,v 1.18 1999-09-04 19:42:28 sandervl Exp $ */
 
 /*
@@ -1188,4 +1188,25 @@
 }
 //******************************************************************************
+/* Not support by Open32 (not included are the new win9x parameters):
+      case SPI_GETFASTTASKSWITCH:
+      case SPI_GETGRIDGRANULARITY:
+      case SPI_GETICONTITLELOGFONT:
+      case SPI_GETICONTITLEWRAP:
+      case SPI_GETMENUDROPALIGNMENT:
+      case SPI_ICONHORIZONTALSPACING:
+      case SPI_ICONVERTICALSPACING:
+      case SPI_LANGDRIVER:
+      case SPI_SETFASTTASKSWITCH:
+      case SPI_SETGRIDGRANULARITY:
+      case SPI_SETICONTITLELOGFONT:
+      case SPI_SETICONTITLEWRAP:
+      case SPI_SETMENUDROPALIGNMENT:
+      case SPI_GETSCREENSAVEACTIVE:
+      case SPI_GETSCREENSAVETIMEOUT:
+      case SPI_SETDESKPATTERN:
+      case SPI_SETDESKWALLPAPER:
+      case SPI_SETSCREENSAVEACTIVE:
+      case SPI_SETSCREENSAVETIMEOUT:
+*/
 //******************************************************************************
 BOOL WIN32API SystemParametersInfoA(UINT uiAction, UINT uiParam, PVOID pvParam, UINT fWinIni)
@@ -1225,6 +1246,22 @@
         break;
     case SPI_GETICONTITLELOGFONT:
+    {
+	LPLOGFONTA lpLogFont = (LPLOGFONTA)pvParam;
+
+	/* from now on we always have an alias for MS Sans Serif */
+	strcpy(lpLogFont->lfFaceName, "MS Sans Serif");
+	lpLogFont->lfHeight = -GetProfileIntA("Desktop","IconTitleSize", 8);
+	lpLogFont->lfWidth = 0;
+	lpLogFont->lfEscapement = lpLogFont->lfOrientation = 0;
+	lpLogFont->lfWeight = FW_NORMAL;
+	lpLogFont->lfItalic = FALSE;
+	lpLogFont->lfStrikeOut = FALSE;
+	lpLogFont->lfUnderline = FALSE;
+	lpLogFont->lfCharSet = ANSI_CHARSET;
+	lpLogFont->lfOutPrecision = OUT_DEFAULT_PRECIS;
+	lpLogFont->lfClipPrecision = CLIP_DEFAULT_PRECIS;
+	lpLogFont->lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
 	break;
-
+    }
     case SPI_GETBORDER:
 	*(INT *)pvParam = GetSystemMetrics( SM_CXFRAME );
@@ -1283,4 +1320,23 @@
         pvParamA = &clientMetricsA;
         break;
+    case SPI_GETICONTITLELOGFONT:
+    {
+	LPLOGFONTW lpLogFont = (LPLOGFONTW)pvParam;
+
+	/* from now on we always have an alias for MS Sans Serif */
+	lstrcpyW(lpLogFont->lfFaceName, (LPCWSTR)L"MS Sans Serif");
+	lpLogFont->lfHeight = -GetProfileIntA("Desktop","IconTitleSize", 8);
+	lpLogFont->lfWidth = 0;
+	lpLogFont->lfEscapement = lpLogFont->lfOrientation = 0;
+	lpLogFont->lfWeight = FW_NORMAL;
+	lpLogFont->lfItalic = FALSE;
+	lpLogFont->lfStrikeOut = FALSE;
+	lpLogFont->lfUnderline = FALSE;
+	lpLogFont->lfCharSet = ANSI_CHARSET;
+	lpLogFont->lfOutPrecision = OUT_DEFAULT_PRECIS;
+	lpLogFont->lfClipPrecision = CLIP_DEFAULT_PRECIS;
+	lpLogFont->lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
+	return TRUE;
+    }
     default:
         pvParamA = pvParam;
Index: trunk/src/user32/new/win32dlg.cpp
===================================================================
--- trunk/src/user32/new/win32dlg.cpp	(revision 819)
+++ trunk/src/user32/new/win32dlg.cpp	(revision 821)
@@ -1,9 +1,11 @@
-/* $Id: win32dlg.cpp,v 1.2 1999-08-30 11:59:53 sandervl Exp $ */
+/* $Id: win32dlg.cpp,v 1.3 1999-09-04 19:42:28 sandervl Exp $ */
 /*
  * Win32 Dialog Code for OS/2
  *
- *
- * Copyright 1998-1999 Sander van Leeuwen (sandervl@xs4all.nl)
- *
+ * Copyright 1999 Sander van Leeuwen (sandervl@xs4all.nl) (Wine port & OS/2 adaption)
+ *
+ * Based on Wine code (990815; windows\dialog.c)
+ *
+ * Copyright 1993, 1994, 1996 Alexandre Julliard
  *
  * Project Odin Software License can be found in LICENSE.TXT
@@ -11,4 +13,5 @@
  */
 #include <os2win.h>
+#include <windowsx.h>
 #include <stdlib.h>
 #include <string.h>
@@ -18,6 +21,168 @@
 //******************************************************************************
 //******************************************************************************
-Win32Dialog::Win32Dialog() : Win32BaseWindow(OBJTYPE_DIALOG)
-{
+Win32Dialog::Win32Dialog(HINSTANCE hInst, LPCSTR dlgTemplate, HWND owner,
+                         DLGPROC dlgProc, LPARAM param, BOOL isUnicode)
+                    : Win32BaseWindow(OBJTYPE_DIALOG)
+{
+  RECT rect;
+  WORD style;
+  ATOM classAtom;
+
+    this->isUnicode = isUnicode;
+    hUserFont        = 0;
+    hMenu        = 0;
+	hwndFocus    = 0;
+    Win32DlgProc = 0;
+    msgResult    = 0;
+    userDlgData  = 0;
+    idResult     = 0;
+    dialogFlags  = 0;
+    memset(&dlgInfo, 0, sizeof(dlgInfo));
+
+    if(fInitialized == FALSE) {
+        if(DIALOG_Init() == FALSE) {
+            dprintf(("DIALOG_Init FAILED!"));
+            DebugInt3();
+            SetLastError(ERROR_GEN_FAILURE);
+            return;
+        }
+        fInitialized = TRUE;
+    }
+    xUnit = xBaseUnit;
+    yUnit = yBaseUnit;
+
+    /* Parse dialog template */
+    dlgTemplate = parseTemplate(dlgTemplate, &dlgInfo);
+
+    /* Load menu */
+    if (dlgInfo.menuName)
+    {
+        hMenu = LoadMenuW( hInst, (LPCWSTR)dlgInfo.menuName );
+    }
+
+    /* Create custom font if needed */
+    if (dlgInfo.style & DS_SETFONT)
+    {
+        /* The font height must be negative as it is a point size */
+        /* (see CreateFont() documentation in the Windows SDK).   */
+        hUserFont = CreateFontW(dlgInfo.pointSize, 0, 0, 0,
+                            dlgInfo.weight, dlgInfo.italic, FALSE,
+                            FALSE, DEFAULT_CHARSET, 0, 0, PROOF_QUALITY,
+                            FF_DONTCARE, (LPCWSTR)dlgInfo.faceName );
+        if (hUserFont)
+        {
+            SIZE charSize;
+            getCharSize(hUserFont,&charSize);
+            xBaseUnit = charSize.cx;
+            yBaseUnit = charSize.cy;
+        }
+    }
+
+    /* Create dialog main window */
+    rect.left = rect.top = 0;
+    rect.right = dlgInfo.cx * xUnit / 4;
+    rect.bottom = dlgInfo.cy * yUnit / 8;
+    if (dlgInfo.style & DS_MODALFRAME)
+        dlgInfo.exStyle |= WS_EX_DLGMODALFRAME;
+
+    AdjustWindowRectEx( &rect, dlgInfo.style, hMenu ? TRUE : FALSE , dlgInfo.exStyle );
+    rect.right -= rect.left;
+    rect.bottom -= rect.top;
+
+    if ((INT16)dlgInfo.x == CW_USEDEFAULT16)
+    {
+        rect.left = rect.top = CW_USEDEFAULT;
+    }
+    else
+    {
+        if (dlgInfo.style & DS_CENTER)
+        {
+            rect.left = (GetSystemMetrics(SM_CXSCREEN) - rect.right) / 2;
+            rect.top = (GetSystemMetrics(SM_CYSCREEN) - rect.bottom) / 2;
+        }
+        else
+        {
+            rect.left += dlgInfo.x * xUnit / 4;
+            rect.top += dlgInfo.y * yUnit / 8;
+        }
+        if ( !(dlgInfo.style & WS_CHILD) )
+        {
+            INT dX, dY;
+
+            if( !(dlgInfo.style & DS_ABSALIGN) )
+                ClientToScreen(owner, (POINT *)&rect );
+
+            /* try to fit it into the desktop */
+
+            if( (dX = rect.left + rect.right + GetSystemMetrics(SM_CXDLGFRAME)
+                 - GetSystemMetrics(SM_CXSCREEN)) > 0 ) rect.left -= dX;
+            if( (dY = rect.top + rect.bottom + GetSystemMetrics(SM_CYDLGFRAME)
+                 - GetSystemMetrics(SM_CYSCREEN)) > 0 ) rect.top -= dY;
+            if( rect.left < 0 ) rect.left = 0;
+            if( rect.top < 0 ) rect.top = 0;
+        }
+    }
+
+    /* Create the dialog window */
+
+    /* Find the class atom */
+    if (HIWORD(dlgInfo.className))
+    {
+        classAtom = (ATOM)LOWORD(dlgInfo.className);
+    }
+    else
+    if(!(classAtom = GlobalFindAtomA(dlgInfo.className)))
+    {
+        SetLastError(ERROR_INVALID_PARAMETER);
+        return;
+    }
+    CREATESTRUCTA cs;
+    cs.lpCreateParams = NULL;
+    cs.hInstance      = hInst;
+    cs.hMenu          = hMenu;
+    cs.hwndParent     = owner;
+    cs.x              = rect.left;
+    cs.y              = rect.top;
+    cs.cx             = rect.right;
+    cs.cy             = rect.bottom;
+    cs.style          = dlgInfo.style & ~WS_VISIBLE;
+    cs.lpszName       = dlgInfo.caption;
+    cs.lpszClass      = dlgInfo.className;
+    cs.dwExStyle      = dlgInfo.exStyle;
+
+    CreateWindowExA(&cs, classAtom);
+
+    if (!getWindowHandle())
+    {
+        if (hUserFont) DeleteObject( hUserFont );
+        if (hMenu) DestroyMenu( hMenu );
+        return;
+    }
+    fIsDialog = TRUE;
+
+//TODO:
+//    wndPtr->helpContext = helpId;
+    Win32DlgProc = dlgProc;
+
+    if (hUserFont)
+        SendMessageA(WM_SETFONT, (WPARAM)hUserFont, 0 );
+
+    /* Create controls */
+    if (createControls(dlgTemplate, hInst))
+    {
+        /* Send initialisation messages and set focus */
+        hwndFocus = GetNextDlgTabItem( getWindowHandle(), 0, FALSE );
+
+        if (::SendMessageA(hwndFocus, WM_INITDIALOG, (WPARAM)hwndFocus, param ))
+            SetFocus( hwndFocus );
+
+        if (dlgInfo.style & WS_VISIBLE && !(getStyle() & WS_VISIBLE))
+        {
+            ShowWindow( SW_SHOWNORMAL );    /* SW_SHOW doesn't always work */
+            ::UpdateWindow( getWindowHandle() );
+        }
+        return;
+    }
+    DestroyWindow();
 }
 //******************************************************************************
@@ -25,5 +190,655 @@
 Win32Dialog::~Win32Dialog()
 {
-
+    if (hUserFont) DeleteObject( hUserFont );
+    if (hMenu) DestroyMenu( hMenu );
+
+}
+/***********************************************************************
+ *           DIALOG_Init
+ *
+ * Initialisation of the dialog manager.
+ */
+BOOL Win32Dialog::DIALOG_Init(void)
+{
+    HDC hdc;
+    SIZE size;
+
+    /* Calculate the dialog base units */
+    if (!(hdc = CreateDCA( "DISPLAY", NULL, NULL, NULL ))) return FALSE;
+    if (!getCharSizeFromDC( hdc, 0, &size )) return FALSE;
+    DeleteDC( hdc );
+    xBaseUnit = size.cx;
+    yBaseUnit = size.cy;
+
+    return TRUE;
+}
+/***********************************************************************
+ *           DIALOG_GetCharSizeFromDC
+ *
+ *
+ *  Calculates the *true* average size of English characters in the
+ *  specified font as oppposed to the one returned by GetTextMetrics.
+ */
+BOOL Win32Dialog::getCharSizeFromDC( HDC hDC, HFONT hUserFont, SIZE * pSize )
+{
+    BOOL Success = FALSE;
+    HFONT hUserFontPrev = 0;
+    pSize->cx = xBaseUnit;
+    pSize->cy = yBaseUnit;
+
+    if ( hDC )
+    {
+        /* select the font */
+        TEXTMETRICA tm;
+        memset(&tm,0,sizeof(tm));
+        if (hUserFont) hUserFontPrev = SelectFont(hDC,hUserFont);
+        if (GetTextMetricsA(hDC,&tm))
+        {
+            pSize->cx = tm.tmAveCharWidth;
+            pSize->cy = tm.tmHeight;
+
+            /* if variable width font */
+            if (tm.tmPitchAndFamily & TMPF_FIXED_PITCH)
+            {
+                SIZE total;
+                static const char szAvgChars[53] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
+
+                /* Calculate a true average as opposed to the one returned
+                 * by tmAveCharWidth. This works better when dealing with
+                 * proportional spaced fonts and (more important) that's
+                 * how Microsoft's dialog creation code calculates the size
+                 * of the font
+                 */
+                if (GetTextExtentPointA(hDC,szAvgChars,sizeof(szAvgChars),&total))
+                {
+                   /* round up */
+                    pSize->cx = ((2*total.cx/sizeof(szAvgChars)) + 1)/2;
+                    Success = TRUE;
+                }
+            }
+            else
+            {
+                Success = TRUE;
+            }
+        }
+
+        /* select the original font */
+        if (hUserFontPrev) SelectFont(hDC,hUserFontPrev);
+    }
+    return (Success);
+}
+/***********************************************************************
+ *           DIALOG_GetCharSize
+ *
+ *
+ *  Calculates the *true* average size of English characters in the
+ *  specified font as oppposed to the one returned by GetTextMetrics.
+ *  A convenient variant of DIALOG_GetCharSizeFromDC.
+ */
+BOOL Win32Dialog::getCharSize( HFONT hUserFont, SIZE * pSize )
+{
+    HDC  hDC = GetDC(0);
+    BOOL Success = getCharSizeFromDC( hDC, hUserFont, pSize );
+    ReleaseDC(0, hDC);
+    return Success;
+}
+/***********************************************************************
+ *           DIALOG_ParseTemplate32
+ *
+ * Fill a DLG_TEMPLATE structure from the dialog template, and return
+ * a pointer to the first control.
+ */
+LPCSTR Win32Dialog::parseTemplate( LPCSTR dlgtemplate, DLG_TEMPLATE * result )
+{
+    const WORD *p = (const WORD *)dlgtemplate;
+
+    result->style = GET_DWORD(p); p += 2;
+    if (result->style == 0xffff0001)  /* DIALOGEX resource */
+    {
+        result->dialogEx = TRUE;
+        result->helpId   = GET_DWORD(p); p += 2;
+        result->exStyle  = GET_DWORD(p); p += 2;
+        result->style    = GET_DWORD(p); p += 2;
+    }
+    else
+    {
+        result->dialogEx = FALSE;
+        result->helpId   = 0;
+        result->exStyle  = GET_DWORD(p); p += 2;
+    }
+    result->nbItems = GET_WORD(p); p++;
+    result->x       = GET_WORD(p); p++;
+    result->y       = GET_WORD(p); p++;
+    result->cx      = GET_WORD(p); p++;
+    result->cy      = GET_WORD(p); p++;
+
+    /* Get the menu name */
+
+    switch(GET_WORD(p))
+    {
+    case 0x0000:
+        result->menuName = NULL;
+        p++;
+        break;
+    case 0xffff:
+        result->menuName = (LPCSTR)(UINT)GET_WORD( p + 1 );
+        p += 2;
+        break;
+    default:
+        result->menuName = (LPCSTR)p;
+        p += lstrlenW( (LPCWSTR)p ) + 1;
+        break;
+    }
+
+    /* Get the class name */
+    switch(GET_WORD(p))
+    {
+    case 0x0000:
+        result->className = (LPCSTR)DIALOG_CLASS_ATOM;
+        p++;
+        break;
+    case 0xffff:
+        result->className = (LPCSTR)(UINT)GET_WORD( p + 1 );
+        p += 2;
+        break;
+    default:
+        result->className = (LPCSTR)p;
+        p += lstrlenW( (LPCWSTR)p ) + 1;
+        break;
+    }
+
+    /* Get the window caption */
+
+    result->caption = (LPCSTR)p;
+    p += lstrlenW( (LPCWSTR)p ) + 1;
+
+    /* Get the font name */
+
+    if (result->style & DS_SETFONT)
+    {
+        result->pointSize = GET_WORD(p);
+        p++;
+        if (result->dialogEx)
+        {
+            result->weight = GET_WORD(p); p++;
+            result->italic = LOBYTE(GET_WORD(p)); p++;
+        }
+        else
+        {
+            result->weight = FW_DONTCARE;
+            result->italic = FALSE;
+        }
+        result->faceName = (LPCSTR)p;
+        p += lstrlenW( (LPCWSTR)p ) + 1;
+    }
+
+    /* First control is on dword boundary */
+    return (LPCSTR)((((int)p) + 3) & ~3);
+}
+/***********************************************************************
+ *           DIALOG_GetControl32
+ *
+ * Return the class and text of the control pointed to by ptr,
+ * fill the header structure and return a pointer to the next control.
+ */
+WORD *Win32Dialog::getControl(const WORD *p, DLG_CONTROL_INFO *info, BOOL dialogEx)
+{
+    if (dialogEx)
+    {
+        info->helpId  = GET_DWORD(p); p += 2;
+        info->exStyle = GET_DWORD(p); p += 2;
+        info->style   = GET_DWORD(p); p += 2;
+    }
+    else
+    {
+        info->helpId  = 0;
+        info->style   = GET_DWORD(p); p += 2;
+        info->exStyle = GET_DWORD(p); p += 2;
+    }
+    info->x       = GET_WORD(p); p++;
+    info->y       = GET_WORD(p); p++;
+    info->cx      = GET_WORD(p); p++;
+    info->cy      = GET_WORD(p); p++;
+
+    if (dialogEx)
+    {
+        /* id is a DWORD for DIALOGEX */
+        info->id = GET_DWORD(p);
+        p += 2;
+    }
+    else
+    {
+        info->id = GET_WORD(p);
+        p++;
+    }
+
+    if (GET_WORD(p) == 0xffff)
+    {
+        static const WCHAR class_names[6][10] =
+        {
+            { 'B','u','t','t','o','n', },             /* 0x80 */
+            { 'E','d','i','t', },                     /* 0x81 */
+            { 'S','t','a','t','i','c', },             /* 0x82 */
+            { 'L','i','s','t','B','o','x', },         /* 0x83 */
+            { 'S','c','r','o','l','l','B','a','r', }, /* 0x84 */
+            { 'C','o','m','b','o','B','o','x', }      /* 0x85 */
+        };
+        WORD id = GET_WORD(p+1);
+        if ((id >= 0x80) && (id <= 0x85))
+            info->className = (LPCSTR)class_names[id - 0x80];
+        else
+        {
+            info->className = NULL;
+            dprintf(("Unknown built-in class id %04x\n", id ));
+        }
+        p += 2;
+    }
+    else
+    {
+        info->className = (LPCSTR)p;
+        p += lstrlenW( (LPCWSTR)p ) + 1;
+    }
+
+    if (GET_WORD(p) == 0xffff)  /* Is it an integer id? */
+    {
+	    info->windowName = (LPCSTR)(UINT)GET_WORD(p + 1);
+	    p += 2;
+    }
+    else
+    {
+	    info->windowName = (LPCSTR)p;
+        p += lstrlenW( (LPCWSTR)p ) + 1;
+    }
+
+    if (GET_WORD(p))
+    {
+        info->data = (LPVOID)(p + 1);
+        p += GET_WORD(p) / sizeof(WORD);
+    }
+    else info->data = NULL;
+    p++;
+
+    /* Next control is on dword boundary */
+    return (WORD *)((((int)p) + 3) & ~3);
+}
+
+
+/***********************************************************************
+ *           DIALOG_CreateControls
+ *
+ * Create the control windows for a dialog.
+ */
+BOOL Win32Dialog::createControls(LPCSTR dlgtemplate, HINSTANCE hInst)
+{
+    DLG_CONTROL_INFO info;
+    HWND hwndCtrl, hwndDefButton = 0;
+    INT items = dlgInfo.nbItems;
+
+    while (items--)
+    {
+        dlgtemplate = (LPCSTR)getControl( (WORD *)dlgtemplate, &info, dlgInfo.dialogEx );
+
+        hwndCtrl = CreateWindowExW( info.exStyle | WS_EX_NOPARENTNOTIFY,
+                                    (LPCWSTR)info.className,
+                                    (LPCWSTR)info.windowName,
+                                    info.style | WS_CHILD,
+                                    info.x * xUnit / 4,
+                                    info.y * yUnit / 8,
+                                    info.cx * xUnit / 4,
+                                    info.cy * yUnit / 8,
+                                    getWindowHandle(), (HMENU)info.id,
+                                    hInst, info.data );
+
+        if (!hwndCtrl) return FALSE;
+
+            /* Send initialisation messages to the control */
+        if (hUserFont) ::SendMessageA( hwndCtrl, WM_SETFONT, (WPARAM)hUserFont, 0 );
+
+        if (::SendMessageA(hwndCtrl, WM_GETDLGCODE, 0, 0) & DLGC_DEFPUSHBUTTON)
+        {
+            /* If there's already a default push-button, set it back */
+            /* to normal and use this one instead. */
+            if (hwndDefButton)
+                ::SendMessageA( hwndDefButton, BM_SETSTYLE,
+                                BS_PUSHBUTTON,FALSE );
+            hwndDefButton = hwndCtrl;
+            idResult = ::GetWindowWord( hwndCtrl, GWW_ID );
+        }
+    }
+    return TRUE;
+}
+/***********************************************************************
+ *           DEFDLG_Proc
+ *
+ * Implementation of DefDlgProc(). Only handle messages that need special
+ * handling for dialogs.
+ */
+LRESULT Win32Dialog::DefDlg_Proc(UINT msg, WPARAM wParam, LPARAM lParam)
+{
+    switch(msg)
+    {
+    case WM_ERASEBKGND:
+    {
+      RECT rect;
+      int rc;
+        /*  Since WM_ERASEBKGND may receive either a window dc or a    */
+        /*  client dc, the area to be erased has to be retrieved from  */
+        /*  the device context.                    */
+        rc = GetClipBox( (HDC)wParam, &rect );
+        if ((rc == SIMPLEREGION) || (rc == COMPLEXREGION))
+            FillRect( (HDC)wParam, &rect, windowClass->getBackgroundBrush());
+	    return 1;
+    }
+	case WM_NCDESTROY:
+	      /* Free dialog heap (if created) */
+#if 0	
+	    if (dlgInfo->hDialogHeap)
+	    {
+    		GlobalUnlock16(dlgInfo->hDialogHeap);
+	    	GlobalFree16(dlgInfo->hDialogHeap);
+		    dlgInfo->hDialogHeap = 0;
+	    }
+#endif
+	      /* Delete font */
+	    if (hUserFont)
+	    {
+    		DeleteObject( hUserFont );
+	    	hUserFont = 0;
+	    }
+
+	      /* Delete menu */
+	    if (hMenu)
+	    {		
+		    DestroyMenu( hMenu );
+		    hMenu = 0;
+	    }
+
+        /* Delete window procedure */
+        Win32DlgProc = 0;
+        dialogFlags |= DF_END;  /* just in case */
+
+	      /* Window clean-up */
+	    return DefWindowProcA(msg, wParam, lParam );
+
+	case WM_SHOWWINDOW:
+	    if (!wParam) saveFocus();
+	    return DefWindowProcA(msg, wParam, lParam );
+
+	case WM_ACTIVATE:
+	    if (wParam) {
+	            restoreFocus();
+	    }
+	    else    saveFocus();
+	    return 0;
+
+	case WM_SETFOCUS:
+	    restoreFocus();
+	    return 0;
+
+    case DM_SETDEFID:
+        if (dialogFlags & DF_END)
+            return 1;
+
+        setDefButton(wParam ? GetDlgItem( getWindowHandle(), wParam ) : 0 );
+        return 1;
+
+    case DM_GETDEFID:
+    {
+        HWND hwndDefId;
+        if (dialogFlags & DF_END) return 0;
+        if (idResult)
+            return MAKELONG( idResult, DC_HASDEFID );
+        if ((hwndDefId = findDefButton()))
+            return MAKELONG( GetDlgCtrlID( hwndDefId ), DC_HASDEFID);
+
+	    return 0;
+    }
+
+	case WM_NEXTDLGCTL:
+	{
+        HWND hwndDest = (HWND)wParam;
+        if (!lParam)
+            hwndDest = GetNextDlgTabItem(getWindowHandle(), GetFocus(), wParam);
+        if (hwndDest) setFocus( hwndDest );
+        setDefButton( hwndDest );
+        return 0;
+    }
+
+    case WM_ENTERMENULOOP:
+    case WM_LBUTTONDOWN:
+    case WM_NCLBUTTONDOWN:
+    {
+        HWND hwndCurFocus = GetFocus();
+        if (hwndCurFocus)
+        {
+#if 0
+            WND *wnd = WIN_FindWndPtr( hwndFocus );
+
+            if( wnd )
+            {
+                /* always make combo box hide its listbox control */
+                if( WIDGETS_IsControl( wnd, BIC32_COMBO ) )
+                    SendMessageA( hwndFocus, CB_SHOWDROPDOWN, FALSE, 0 );
+                else
+                if( WIDGETS_IsControl( wnd, BIC32_EDIT ) &&
+                    WIDGETS_IsControl( wnd->parent, BIC32_COMBO ))
+                    SendMessageA(CB_SHOWDROPDOWN, FALSE, 0 );
+            }
+#endif
+        }
+	    return DefWindowProcA( msg, wParam, lParam );
+    }
+
+	case WM_GETFONT:
+        return hUserFont;
+
+    case WM_CLOSE:
+        PostMessageA(WM_COMMAND, IDCANCEL, (LPARAM)GetDlgItem( getWindowHandle(), IDCANCEL ) );
+        return 0;
+
+    case WM_NOTIFYFORMAT:
+	    return DefWindowProcA(msg, wParam, lParam );
+    }
+    return 0;
+}
+//******************************************************************************
+//******************************************************************************
+LRESULT Win32Dialog::DefDlgProcA(UINT Msg, WPARAM wParam, LPARAM lParam)
+{
+    BOOL result = FALSE;
+
+    msgResult = 0;
+
+    if (Win32DlgProc) {      /* Call dialog procedure */
+        result = Win32DlgProc(getWindowHandle(), Msg, wParam, lParam);
+    }
+
+    if (!result && IsWindow())
+    {
+        /* callback didn't process this message */
+        switch(Msg)
+        {
+            case WM_ERASEBKGND:
+            case WM_SHOWWINDOW:
+            case WM_ACTIVATE:
+            case WM_SETFOCUS:
+            case DM_SETDEFID:
+            case DM_GETDEFID:
+            case WM_NEXTDLGCTL:
+            case WM_GETFONT:
+            case WM_CLOSE:
+            case WM_NCDESTROY:
+            case WM_ENTERMENULOOP:
+            case WM_LBUTTONDOWN:
+            case WM_NCLBUTTONDOWN:
+                 return DefDlg_Proc(Msg, (WPARAM)wParam, lParam);
+
+            case WM_INITDIALOG:
+            case WM_VKEYTOITEM:
+            case WM_COMPAREITEM:
+            case WM_CHARTOITEM:
+                 break;
+
+            default:
+                 return DefWindowProcA(Msg, wParam, lParam );
+        }
+    }
+    return DefDlg_Epilog(Msg, result);
+}
+//******************************************************************************
+//******************************************************************************
+LRESULT Win32Dialog::DefDlgProcW(UINT Msg, WPARAM wParam, LPARAM lParam)
+{
+    BOOL result = FALSE;
+
+    msgResult = 0;
+
+    if (Win32DlgProc) {      /* Call dialog procedure */
+        result = Win32DlgProc(getWindowHandle(), Msg, wParam, lParam);
+    }
+
+    if (!result && IsWindow())
+    {
+        /* callback didn't process this message */
+        switch(Msg)
+        {
+            case WM_ERASEBKGND:
+            case WM_SHOWWINDOW:
+            case WM_ACTIVATE:
+            case WM_SETFOCUS:
+            case DM_SETDEFID:
+            case DM_GETDEFID:
+            case WM_NEXTDLGCTL:
+            case WM_GETFONT:
+            case WM_CLOSE:
+            case WM_NCDESTROY:
+            case WM_ENTERMENULOOP:
+            case WM_LBUTTONDOWN:
+            case WM_NCLBUTTONDOWN:
+                 return DefDlg_Proc(Msg, (WPARAM)wParam, lParam);
+
+            case WM_INITDIALOG:
+            case WM_VKEYTOITEM:
+            case WM_COMPAREITEM:
+            case WM_CHARTOITEM:
+                 break;
+
+            default:
+                 return DefWindowProcW(Msg, wParam, lParam );
+        }
+    }
+    return DefDlg_Epilog(Msg, result);
+}
+/***********************************************************************
+ *           DEFDLG_Epilog
+ */
+LRESULT Win32Dialog::DefDlg_Epilog(UINT msg, BOOL fResult)
+{
+    /* see SDK 3.1 */
+    if ((msg >= WM_CTLCOLORMSGBOX && msg <= WM_CTLCOLORSTATIC) ||
+	     msg == WM_CTLCOLOR || msg == WM_COMPAREITEM ||
+         msg == WM_VKEYTOITEM || msg == WM_CHARTOITEM ||
+         msg == WM_QUERYDRAGICON || msg == WM_INITDIALOG)
+        return fResult;
+
+    return msgResult;
+}
+/***********************************************************************
+ *           DEFDLG_SetFocus
+ *
+ * Set the focus to a control of the dialog, selecting the text if
+ * the control is an edit dialog.
+ */
+void Win32Dialog::setFocus(HWND hwndCtrl )
+{
+    HWND hwndPrev = GetFocus();
+
+    if (IsChild( hwndPrev ))
+    {
+        if (::SendMessageA( hwndPrev, WM_GETDLGCODE, 0, 0 ) & DLGC_HASSETSEL)
+            ::SendMessageA( hwndPrev, EM_SETSEL, TRUE, MAKELONG( -1, 0 ) );
+    }
+    if (::SendMessageA(hwndCtrl, WM_GETDLGCODE, 0, 0 ) & DLGC_HASSETSEL)
+        ::SendMessageA(hwndCtrl, EM_SETSEL, FALSE, MAKELONG( 0, -1 ) );
+    SetFocus( hwndCtrl );
+}
+
+
+/***********************************************************************
+ *           DEFDLG_SaveFocus
+ */
+BOOL Win32Dialog::saveFocus()
+{
+    HWND hwndCurrentFocus = GetFocus();
+
+    if (!hwndCurrentFocus || !IsChild( hwndCurrentFocus )) return FALSE;
+
+    hwndFocus = hwndCurrentFocus;
+      /* Remove default button */
+    return TRUE;
+}
+
+
+/***********************************************************************
+ *           DEFDLG_RestoreFocus
+ */
+BOOL Win32Dialog::restoreFocus()
+{
+    if (!hwndFocus || IsIconic()) return FALSE;
+
+    if (!::IsWindow( hwndFocus )) return FALSE;
+
+    /* Don't set the focus back to controls if EndDialog is already called.*/
+    if (!(dialogFlags & DF_END))
+       setFocus(hwndFocus);
+
+    /* This used to set infoPtr->hwndFocus to NULL for no apparent reason,
+       sometimes losing focus when receiving WM_SETFOCUS messages. */
+    return TRUE;
+}
+
+
+/***********************************************************************
+ *           DEFDLG_FindDefButton
+ *
+ * Find the current default push-button.
+ */
+HWND Win32Dialog::findDefButton()
+{
+    HWND hwndChild = GetWindow( GW_CHILD );
+    while (hwndChild)
+    {
+        if (::SendMessageA( hwndChild, WM_GETDLGCODE, 0, 0 ) & DLGC_DEFPUSHBUTTON)
+            break;
+        hwndChild = ::GetWindow( hwndChild, GW_HWNDNEXT );
+    }
+    return hwndChild;
+}
+
+
+/***********************************************************************
+ *           DEFDLG_SetDefButton
+ *
+ * Set the new default button to be hwndNew.
+ */
+BOOL Win32Dialog::setDefButton(HWND hwndNew )
+{
+    if (hwndNew &&
+        !(::SendMessageA(hwndNew, WM_GETDLGCODE, 0, 0 ) & DLGC_UNDEFPUSHBUTTON))
+        return FALSE;  /* Destination is not a push button */
+
+    if (idResult)  /* There's already a default pushbutton */
+    {
+        HWND hwndOld = GetDlgItem( getWindowHandle(), idResult );
+        if (::SendMessageA( hwndOld, WM_GETDLGCODE, 0, 0) & DLGC_DEFPUSHBUTTON)
+            ::SendMessageA( hwndOld, BM_SETSTYLE, BS_PUSHBUTTON, TRUE );
+    }
+    if (hwndNew)
+    {
+        ::SendMessageA( hwndNew, BM_SETSTYLE, BS_DEFPUSHBUTTON, TRUE );
+        idResult = GetDlgCtrlID( hwndNew );
+    }
+    else idResult = 0;
+    return TRUE;
 }
 //******************************************************************************
@@ -76,2 +891,32 @@
 //******************************************************************************
 //******************************************************************************
+BOOL DIALOG_Register()
+{
+    WNDCLASSA wndClass;
+
+    if (GlobalFindAtomA(DIALOG_CLASS_NAME)) return FALSE;
+
+    ZeroMemory(&wndClass,sizeof(WNDCLASSA));
+    wndClass.style         = CS_GLOBALCLASS | CS_SAVEBITS;
+    wndClass.lpfnWndProc   = (WNDPROC)DefDlgProcA;
+    wndClass.cbClsExtra    = 0;
+    wndClass.cbWndExtra    = 0;
+    wndClass.hCursor       = (HCURSOR)IDC_ARROWA;
+    wndClass.hbrBackground = LTGRAY_BRUSH;
+    wndClass.lpszClassName = DIALOG_CLASS_NAME;
+
+    return RegisterClassA(&wndClass);
+}
+//******************************************************************************
+//******************************************************************************
+BOOL DIALOG_Unregister()
+{
+    if (GlobalFindAtomA(DIALOG_CLASS_NAME))
+            return UnregisterClassA(DIALOG_CLASS_NAME,(HINSTANCE)NULL);
+    else    return FALSE;
+}
+//******************************************************************************
+//******************************************************************************
+BOOL Win32Dialog::fInitialized = FALSE;
+int  Win32Dialog::xBaseUnit    = 0;
+int  Win32Dialog::yBaseUnit    = 0;
Index: trunk/src/user32/new/win32dlg.h
===================================================================
--- trunk/src/user32/new/win32dlg.h	(revision 819)
+++ trunk/src/user32/new/win32dlg.h	(revision 821)
@@ -1,3 +1,3 @@
-/* $Id: win32dlg.h,v 1.3 1999-08-30 11:59:53 sandervl Exp $ */
+/* $Id: win32dlg.h,v 1.4 1999-09-04 19:42:29 sandervl Exp $ */
 /*
  * Win32 Dialog Code for OS/2
@@ -17,9 +17,55 @@
 #ifdef __cplusplus
 
+#define DF_END  0x0001
+
+  /* Dialog control information */
+typedef struct
+{
+    DWORD      style;
+    DWORD      exStyle;
+    DWORD      helpId;
+    INT        x;
+    INT        y;
+    INT        cx;
+    INT        cy;
+    UINT       id;
+    LPCSTR     className;
+    LPCSTR     windowName;
+    LPVOID     data;
+} DLG_CONTROL_INFO;
+
+/* Dialog template */
+typedef struct
+{
+    DWORD      style;
+    DWORD      exStyle;
+    DWORD      helpId;
+    UINT       nbItems;
+    INT        x;
+    INT        y;
+    INT        cx;
+    INT        cy;
+    LPCSTR     menuName;
+    LPCSTR     className;
+    LPCSTR     caption;
+    WORD       pointSize;
+    WORD       weight;
+    BOOL       italic;
+    LPCSTR     faceName;
+    BOOL       dialogEx;
+} DLG_TEMPLATE;
+
 class Win32Dialog : public Win32BaseWindow
 {
 public:
- 	 Win32Dialog();
+         Win32Dialog(HINSTANCE hInst, LPCSTR dlgTemplate, HWND owner,
+                     DLGPROC dlgProc, LPARAM param, BOOL isUnicode);
+
 virtual ~Win32Dialog();
+
+       LRESULT  DefDlgProcA(UINT Msg, WPARAM wParam, LPARAM lParam);
+       LRESULT  DefDlgProcW(UINT Msg, WPARAM wParam, LPARAM lParam);
+
+       LRESULT  DefDlg_Epilog(UINT msg, BOOL fResult);
 
 virtual  ULONG  MsgOS2Create(HWND hwndOS2, ULONG initParam);
@@ -29,4 +75,18 @@
 
 protected:
+	BOOL    DIALOG_Init(void);
+	BOOL    getCharSizeFromDC( HDC hDC, HFONT hFont, SIZE * pSize );
+	BOOL    getCharSize( HFONT hFont, SIZE * pSize);
+	LPCSTR  parseTemplate( LPCSTR dlgtemplate, DLG_TEMPLATE *result);
+        WORD   *getControl(const WORD *p, DLG_CONTROL_INFO *info, BOOL dialogEx);
+	BOOL    createControls(LPCSTR dlgtemplate, HINSTANCE hInst);
+	
+	LRESULT DefDlg_Proc(UINT msg, WPARAM wParam, LPARAM lParam);
+	BOOL    setDefButton(HWND hwndNew );
+	HWND    findDefButton();
+	BOOL    saveFocus();
+	BOOL    restoreFocus();
+	void    setFocus(HWND hwndCtrl );
+
 	// values normally contained in the standard dialog words
       DLGPROC	Win32DlgProc;	//DWL_WNDPROC
@@ -34,7 +94,25 @@
 	ULONG	userDlgData;	//DWL_USER
 
+   DLG_TEMPLATE dlgInfo;
+	WORD    xUnit;
+	WORD    yUnit;
+	HWND    hwndFocus;
+	HFONT   hUserFont;
+	HMENU   hMenu;
+	DWORD   idResult;
+	DWORD   dialogFlags;
+
 private:
+ static BOOL    fInitialized;
+ static int     xBaseUnit;
+ static int     yBaseUnit;
 };
 
+/* Built-in class names (see _Undocumented_Windows_ p.418) */
+#define DIALOG_CLASS_NAME    "#32770"  /* Dialog */
+#define DIALOG_CLASS_ATOM    32770     /* Dialog */
+
+BOOL DIALOG_Register();
+BOOL DIALOG_Unregister();
 
 #endif //__cplusplus
Index: trunk/src/user32/new/win32wbase.cpp
===================================================================
--- trunk/src/user32/new/win32wbase.cpp	(revision 819)
+++ trunk/src/user32/new/win32wbase.cpp	(revision 821)
@@ -1,3 +1,3 @@
-/* $Id: win32wbase.cpp,v 1.6 1999-09-04 17:56:41 dengert Exp $ */
+/* $Id: win32wbase.cpp,v 1.7 1999-09-04 19:42:29 sandervl Exp $ */
 /*
  * Win32 Window Base Class for OS/2
@@ -75,4 +75,5 @@
   fCreated         = FALSE;
   fFirstShow       = TRUE;
+  fIsDialog        = FALSE;
 
   windowNameA      = NULL;
Index: trunk/src/user32/new/win32wbase.h
===================================================================
--- trunk/src/user32/new/win32wbase.h	(revision 819)
+++ trunk/src/user32/new/win32wbase.h	(revision 821)
@@ -1,3 +1,3 @@
-/* $Id: win32wbase.h,v 1.4 1999-09-04 17:56:41 dengert Exp $ */
+/* $Id: win32wbase.h,v 1.5 1999-09-04 19:42:29 sandervl Exp $ */
 /*
  * Win32 Window Base Class for OS/2
@@ -148,5 +148,6 @@
          BOOL   CloseWindow();
   static HWND   GetActiveWindow();
-         BOOL   IsWindow();
+	 //Window handle has already been verified, so just return true
+         BOOL   IsWindow()                    { return TRUE; };
          BOOL   IsWindowEnabled();
          BOOL   IsWindowVisible();
@@ -154,6 +155,6 @@
 
          BOOL   GetWindowRect(PRECT pRect);
-         int    GetWindowTextLengthA();
-         int    GetWindowTextA(LPSTR lpsz, int cch);
+         int    GetWindowTextLength();
+         int    GetWindowText(LPSTR lpsz, int cch);
          BOOL   SetWindowText(LPSTR lpsz);
           BOOL  hasWindowName(LPSTR wndname, BOOL fUnicode = 0);
@@ -198,4 +199,7 @@
 
 protected:
+#ifndef OS2_INCLUDED
+        BOOL  CreateWindowExA(CREATESTRUCTA *lpCreateStruct, ATOM classAtom);
+#endif
        LRESULT  SendInternalMessageA(ULONG msg, WPARAM wParam, LPARAM lParam);
        LRESULT  SendInternalMessageW(ULONG msg, WPARAM wParam, LPARAM lParam);
@@ -227,4 +231,5 @@
         BOOL    fCreated;
         BOOL    fFirstShow;
+	BOOL    fIsDialog;
 
    Win32BaseWindow *owner;
@@ -250,6 +255,4 @@
 private:
 #ifndef OS2_INCLUDED
-        BOOL  CreateWindowExA(CREATESTRUCTA *lpCreateStruct, ATOM classAtom);
-
         void  GetMinMaxInfo(POINT *maxSize, POINT *maxPos, POINT *minTrack, POINT *maxTrack );
 
Index: trunk/src/user32/new/win32wmdichild.cpp
===================================================================
--- trunk/src/user32/new/win32wmdichild.cpp	(revision 819)
+++ trunk/src/user32/new/win32wmdichild.cpp	(revision 821)
@@ -1,3 +1,3 @@
-/* $Id: win32wmdichild.cpp,v 1.3 1999-09-03 15:09:46 sandervl Exp $ */
+/* $Id: win32wmdichild.cpp,v 1.4 1999-09-04 19:42:29 sandervl Exp $ */
 /*
  * Win32 MDI Child Window Class for OS/2
@@ -335,6 +335,6 @@
 #if 0
                     MDI_AugmentFrameMenu( ci, w->parent, hwnd );
+#endif
                     client->updateFrameText(MDI_REPAINTFRAME, NULL );
-#endif
                 }
             }
Index: trunk/src/user32/new/win32wmdiclient.cpp
===================================================================
--- trunk/src/user32/new/win32wmdiclient.cpp	(revision 819)
+++ trunk/src/user32/new/win32wmdiclient.cpp	(revision 821)
@@ -1,3 +1,3 @@
-/* $Id: win32wmdiclient.cpp,v 1.4 1999-09-03 15:09:46 sandervl Exp $ */
+/* $Id: win32wmdiclient.cpp,v 1.5 1999-09-04 19:42:29 sandervl Exp $ */
 /*
  * Win32 MDI Client Window Class for OS/2
@@ -819,10 +819,10 @@
 
     ZeroMemory(&wndClass,sizeof(WNDCLASSA));
-    wndClass.style         = CS_GLOBALCLASS | CS_HREDRAW | CS_VREDRAW | CS_PARENTDC | CS_DBLCLKS;
+    wndClass.style         = CS_GLOBALCLASS;
     wndClass.lpfnWndProc   = (WNDPROC)MDIClientWndProc;
     wndClass.cbClsExtra    = 0;
     wndClass.cbWndExtra    = 0;
     wndClass.hCursor       = 0;
-    wndClass.hbrBackground = (HBRUSH)0;
+    wndClass.hbrBackground = (HBRUSH)LTGRAY_BRUSH;
     wndClass.lpszClassName = MDICLIENTCLASSNAMEA;
 
Index: trunk/src/user32/new/window.cpp
===================================================================
--- trunk/src/user32/new/window.cpp	(revision 819)
+++ trunk/src/user32/new/window.cpp	(revision 821)
@@ -1,3 +1,3 @@
-/* $Id: window.cpp,v 1.21 1999-08-31 17:14:52 sandervl Exp $ */
+/* $Id: window.cpp,v 1.22 1999-09-04 19:42:30 sandervl Exp $ */
 /*
  * Win32 window apis for OS/2
@@ -558,5 +558,5 @@
     }
     dprintf(("GetWindowTextLength %x", hwnd));
-    return window->GetWindowTextLengthA();
+    return window->GetWindowTextLength();
 }
 //******************************************************************************
@@ -565,4 +565,5 @@
 {
    Win32BaseWindow *window;
+   int rc;
 
     window = Win32BaseWindow::GetWindowFromHandle(hwnd);
@@ -571,6 +572,7 @@
         return 0;
     }
-    dprintf(("GetWindowTextA %x", hwnd));
-    return window->GetWindowTextA(lpsz, cch);
+    rc = window->GetWindowText(lpsz, cch);
+    dprintf(("GetWindowTextA %x %s", hwnd, lpsz));
+    return rc;
 }
 //******************************************************************************
@@ -585,17 +587,13 @@
 int WIN32API GetWindowTextW(HWND hwnd, LPWSTR lpsz, int cch)
 {
- char title[128];
- int  rc;
-
-   rc = O32_GetWindowText(hwnd, title, sizeof(title));
-#ifdef DEBUG
-   WriteLog("USER32:  GetWindowTextW returned %s\n", title);
-#endif
-   if(rc > cch) {
-    title[cch-1] = 0;
-    rc = cch;
-   }
-   AsciiToUnicode(title, lpsz);
-   return(rc);
+   Win32BaseWindow *window;
+
+    window = Win32BaseWindow::GetWindowFromHandle(hwnd);
+    if(!window) {
+        dprintf(("GetWindowTextW, window %x not found", hwnd));
+        return 0;
+    }
+    dprintf(("GetWindowTextW %x", hwnd));
+    return window->GetWindowText((LPSTR)lpsz, cch);
 }
 //******************************************************************************
@@ -615,13 +613,15 @@
 //******************************************************************************
 //******************************************************************************
-BOOL WIN32API SetWindowTextW( HWND arg1, LPCWSTR arg2)
-{
- char *astring = UnicodeToAsciiString((LPWSTR)arg2);
- BOOL  rc;
-
-   rc = SetWindowTextA(arg1, (LPCSTR)astring);
-   dprintf(("USER32:  SetWindowTextW %X %s returned %d\n", arg1, astring, rc));
-   FreeAsciiString(astring);
-   return(rc);
+BOOL WIN32API SetWindowTextW( HWND hwnd, LPCWSTR lpsz)
+{
+   Win32BaseWindow *window;
+
+    window = Win32BaseWindow::GetWindowFromHandle(hwnd);
+    if(!window) {
+        dprintf(("SetWindowTextA, window %x not found", hwnd));
+        return 0;
+    }
+    dprintf(("SetWindowTextW %x", hwnd));
+    return window->SetWindowText((LPSTR)lpsz);
 }
 /*******************************************************************
