changeset 32:2985239119a3

Widget
author Frank Benoit <benoit@tionex.de>
date Mon, 28 Jan 2008 14:13:08 +0100
parents 92c102dd64a3
children 39a9959ef14d
files dwt/internal/win32/OS.d dwt/internal/win32/WINAPI.d dwt/internal/win32/WINTYPES.d dwt/widgets/Display.d dwt/widgets/Menu.d dwt/widgets/Widget.d
diffstat 6 files changed, 384 insertions(+), 262 deletions(-) [+]
line wrap: on
line diff
--- a/dwt/internal/win32/OS.d	Mon Jan 28 04:47:28 2008 +0100
+++ b/dwt/internal/win32/OS.d	Mon Jan 28 14:13:08 2008 +0100
@@ -4122,6 +4122,11 @@
 alias WINAPI.DrawStateW DrawStateW;
 alias WINAPI.DrawTextA DrawTextA;
 alias WINAPI.DrawTextW DrawTextW;
+alias WINAPI.DrawThemeBackground DrawThemeBackground;
+alias WINAPI.DrawThemeEdge DrawThemeEdge;
+alias WINAPI.DrawThemeIcon DrawThemeIcon;
+alias WINAPI.DrawThemeParentBackground DrawThemeParentBackground;
+alias WINAPI.DrawThemeText DrawThemeText;
 alias WINAPI.Ellipse Ellipse;
 alias WINAPI.EnableMenuItem EnableMenuItem;
 alias WINAPI.EnableScrollBar EnableScrollBar;
@@ -4142,6 +4147,7 @@
 alias WINAPI.EnumSystemLocalesW EnumSystemLocalesW;
 alias WINAPI.EqualRect EqualRect;
 alias WINAPI.EqualRgn EqualRgn;
+alias STDWIN.ExcludeClipRect ExcludeClipRect;
 alias WINAPI.ExpandEnvironmentStringsA ExpandEnvironmentStringsA;
 alias WINAPI.ExpandEnvironmentStringsW ExpandEnvironmentStringsW;
 alias WINAPI.ExtTextOutA ExtTextOutA;
@@ -4327,6 +4333,7 @@
 alias WINAPI.IntersectRect IntersectRect;
 alias WINAPI.InvalidateRect InvalidateRect;
 alias WINAPI.InvalidateRgn InvalidateRgn;
+alias WINAPI.IsAppThemed IsAppThemed;
 alias WINAPI.IsDBCSLeadByte IsDBCSLeadByte;
 alias WINAPI.IsIconic IsIconic;
 alias WINAPI.IsWindow IsWindow;
@@ -4470,6 +4477,7 @@
 alias WINAPI.SetMenuInfo SetMenuInfo;
 alias WINAPI.SetMenuItemInfoA SetMenuItemInfoA;
 alias WINAPI.SetMenuItemInfoW SetMenuItemInfoW;
+alias STDWIN.SetMetaRgn SetMetaRgn;
 alias WINAPI.SetPaletteEntries SetPaletteEntries;
 alias WINAPI.SetParent SetParent;
 alias WINAPI.SetPixel SetPixel;
--- a/dwt/internal/win32/WINAPI.d	Mon Jan 28 04:47:28 2008 +0100
+++ b/dwt/internal/win32/WINAPI.d	Mon Jan 28 14:13:08 2008 +0100
@@ -59,6 +59,56 @@
   SCRIPT_CONTROL* psc,
   SCRIPT_STATE* pss
 );
+
+// UxTheme.dll
+BOOL IsAppThemed();
+
+HRESULT DrawThemeBackground(
+    HTHEME hTheme,
+    HDC hdc,
+    int iPartId,
+    int iStateId,
+    RECT *pRect,
+    RECT *pClipRect
+);
+HRESULT DrawThemeEdge(
+    HTHEME hTheme,
+    HDC hdc,
+    int iPartId,
+    int iStateId,
+    LPCRECT pDestRect,
+    UINT uEdge,
+    UINT uFlags,
+    LPRECT pContentRect
+);
+HRESULT DrawThemeIcon(
+    HTHEME hTheme,
+    HDC hdc,
+    int iPartId,
+    int iStateId,
+    LPCRECT pRect,
+    HIMAGELIST himl,
+    int iImageIndex
+);
+HRESULT DrawThemeParentBackground(
+    HWND hwnd,
+    HDC hdc,
+    RECT *prc
+);
+HRESULT DrawThemeText(
+    HTHEME hTheme,
+    HDC hdc,
+    int iPartId,
+    int iStateId,
+    LPCWSTR pszText,
+    int iCharCount,
+    DWORD dwTextFlags,
+    DWORD dwTextFlags2,
+    LPCRECT pRect
+);
+
+
+
 }
 
 
--- a/dwt/internal/win32/WINTYPES.d	Mon Jan 28 04:47:28 2008 +0100
+++ b/dwt/internal/win32/WINTYPES.d	Mon Jan 28 14:13:08 2008 +0100
@@ -29,6 +29,8 @@
   DWORD dwReserved;
 }
 
+alias HANDLE HTHEME;
+
 // ....
 
 
--- a/dwt/widgets/Display.d	Mon Jan 28 04:47:28 2008 +0100
+++ b/dwt/widgets/Display.d	Mon Jan 28 14:13:08 2008 +0100
@@ -13,15 +13,44 @@
 module dwt.widgets.Display;
 
 import dwt.graphics.Device;
+import dwt.widgets.Control;
 import dwt.widgets.Tray;
+import dwt.widgets.Event;
+import dwt.internal.win32.OS;
+
+import tango.core.Thread;
 
 class Display : Device {
+    RECT clickRect;
+    int clickCount, lastTime, lastButton, lastClickHwnd;
+    int lastKey, lastAscii, lastMouse;
+    bool lastVirtual, lastNull, lastDead;
+    byte [] keyboard = new byte [256];
+    bool accelKeyHit, mnemonicKeyHit;
+    bool lockActiveWindow, captureChanged, xMouse;
     Tray tray;
+    Thread thread;
     void wakeThread();
     public void wake () ;
     public bool isValidThread() ;
     static Display getDefault();
     static Display getCurrent();
+bool filterEvent (Event event) ;
+bool filters (int eventType) ;
+bool filterMessage (MSG msg) ;
+int getLastEventTime () ;
+void postEvent (Event event) ;
+int getClickCount (int type, int button, HWND hwnd, int lParam) ;
+static int translateKey (int key) ;
+bool translateMnemonic (MSG msg, Control control) ;
+bool translateTraversal (MSG msg, Control control) ;
+static char mbcsToWcs (int ch) ;
+static char mbcsToWcs (int ch, int codePage) ;
+int numpadKey (int key) ;
+int asciiKey (int key) ;
+int shiftedKey (int key) ;
+int controlKey (int key) ;
+HTHEME hEditTheme () ;
 }
 /++
 import dwt.DWT;
--- a/dwt/widgets/Menu.d	Mon Jan 28 04:47:28 2008 +0100
+++ b/dwt/widgets/Menu.d	Mon Jan 28 14:13:08 2008 +0100
@@ -15,6 +15,8 @@
 import dwt.widgets.Widget;
 class Menu : Widget {
     this( Widget, int );
+public void setLocation (int x, int y) ;
+public void setVisible (bool visible) ;
 }
 /++
 import dwt.DWT;
--- a/dwt/widgets/Widget.d	Mon Jan 28 04:47:28 2008 +0100
+++ b/dwt/widgets/Widget.d	Mon Jan 28 14:13:08 2008 +0100
@@ -10,8 +10,7 @@
  *******************************************************************************/
 module dwt.widgets.Widget;
 
-import dwt.widgets.Display;
-
+/++
 class Widget {
     Display display;
     void checkWidget();
@@ -25,21 +24,32 @@
     this () ;
     this (Widget parent, int style) ;
 }
-/++
+++/
+
+enum LRESULT {
+    NULL = -1,
+    ZERO = 0,
+    ONE = 1,
+}
+
 import dwt.DWT;
 import dwt.DWTException;
 import dwt.events.DisposeListener;
 import dwt.graphics.GC;
 import dwt.graphics.GCData;
 import dwt.internal.DWTEventListener;
-import dwt.internal.win32.LRESULT;
-import dwt.internal.win32.MSG;
 import dwt.internal.win32.OS;
-import dwt.internal.win32.PAINTSTRUCT;
-import dwt.internal.win32.POINT;
-import dwt.internal.win32.RECT;
-import dwt.internal.win32.SHRGINFO;
-import dwt.internal.win32.TRACKMOUSEEVENT;
+import dwt.widgets.Display;
+import dwt.widgets.EventTable;
+import dwt.widgets.Listener;
+import dwt.widgets.Event;
+import dwt.widgets.Menu;
+import dwt.widgets.TypedListener;
+
+import tango.text.convert.Format;
+import tango.io.Stdout;
+import tango.core.Thread;
+import dwt.dwthelper.utils;
 
 /**
  * This class is the abstract superclass of all user interface objects.
@@ -75,46 +85,46 @@
     Object data;
 
     /* Global state flags */
-    static final int DISPOSED       = 1<<0;
-    static final int CANVAS         = 1<<1;
-    static final int KEYED_DATA     = 1<<2;
-    static final int DISABLED       = 1<<3;
-    static final int HIDDEN         = 1<<4;
+    static const int DISPOSED       = 1<<0;
+    static const int CANVAS         = 1<<1;
+    static const int KEYED_DATA     = 1<<2;
+    static const int DISABLED       = 1<<3;
+    static const int HIDDEN         = 1<<4;
 
     /* A layout was requested on this widget */
-    static final int LAYOUT_NEEDED  = 1<<5;
+    static const int LAYOUT_NEEDED  = 1<<5;
 
     /* The preferred size of a child has changed */
-    static final int LAYOUT_CHANGED = 1<<6;
+    static const int LAYOUT_CHANGED = 1<<6;
 
     /* A layout was requested in this widget hierarchy */
-    static final int LAYOUT_CHILD = 1<<7;
+    static const int LAYOUT_CHILD = 1<<7;
 
     /* Background flags */
-    static final int THEME_BACKGROUND = 1<<8;
-    static final int DRAW_BACKGROUND = 1<<9;
-    static final int PARENT_BACKGROUND = 1<<10;
+    static const int THEME_BACKGROUND = 1<<8;
+    static const int DRAW_BACKGROUND = 1<<9;
+    static const int PARENT_BACKGROUND = 1<<10;
 
     /* Dispose and release flags */
-    static final int RELEASED       = 1<<11;
-    static final int DISPOSE_SENT   = 1<<12;
+    static const int RELEASED       = 1<<11;
+    static const int DISPOSE_SENT   = 1<<12;
 
     /* More global widget state flags */
-    static final int TRACK_MOUSE    = 1<<13;
-    static final int FOREIGN_HANDLE = 1<<14;
-    static final int DRAG_DETECT    = 1<<15;
+    static const int TRACK_MOUSE    = 1<<13;
+    static const int FOREIGN_HANDLE = 1<<14;
+    static const int DRAG_DETECT    = 1<<15;
 
     /* Default size for widgets */
-    static final int DEFAULT_WIDTH  = 64;
-    static final int DEFAULT_HEIGHT = 64;
+    static const int DEFAULT_WIDTH  = 64;
+    static const int DEFAULT_HEIGHT = 64;
 
     /* Check and initialize the Common Controls DLL */
-    static final int MAJOR = 5, MINOR = 80;
-    static {
-        if (!OS.IsWinCE) {
+    static const int MAJOR = 5, MINOR = 80;
+    static this() {
+        static if (!OS.IsWinCE) {
             if (OS.COMCTL32_VERSION < OS.VERSION (MAJOR, MINOR)) {
-                System.out.println ("***WARNING: DWT requires comctl32.dll version " + MAJOR + "." + MINOR + " or greater"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-                System.out.println ("***WARNING: Detected: " + OS.COMCTL32_MAJOR + "." + OS.COMCTL32_MINOR); //$NON-NLS-1$ //$NON-NLS-2$
+                Stdout.formatln ("***WARNING: DWT requires comctl32.dll version {}.{} or greater", MAJOR, MINOR); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+                Stdout.formatln ("***WARNING: Detected: {}.{}", OS.COMCTL32_MAJOR, OS.COMCTL32_MINOR); //$NON-NLS-1$ //$NON-NLS-2$
             }
         }
         OS.InitCommonControls ();
@@ -123,7 +133,7 @@
 /**
  * Prevents uninitialized instances from being created outside the package.
  */
-Widget () {
+this () {
 }
 
 /**
@@ -155,7 +165,7 @@
  * @see #checkSubclass
  * @see #getStyle
  */
-public Widget (Widget parent, int style) {
+public this (Widget parent, int style) {
     checkSubclass ();
     checkParent (parent);
     this.style = style;
@@ -222,7 +232,7 @@
     addListener (DWT.Dispose, typedListener);
 }
 
-int callWindowProc (int hwnd, int msg, int wParam, int lParam) {
+int callWindowProc (HWND hwnd, int msg, int wParam, int lParam) {
     return 0;
 }
 
@@ -347,7 +357,7 @@
 protected void checkWidget () {
     Display display = this.display;
     if (display is null) error (DWT.ERROR_WIDGET_DISPOSED);
-    if (display.thread !is Thread.currentThread ()) error (DWT.ERROR_THREAD_INVALID_ACCESS);
+    if (display.thread !is Thread.getThis ()) error (DWT.ERROR_THREAD_INVALID_ACCESS);
     if ((state & DISPOSED) !is 0) error (DWT.ERROR_WIDGET_DISPOSED);
 }
 
@@ -374,7 +384,7 @@
     releaseHandle ();
 }
 
-int DeferWindowPos(int hWinPosInfo, int hWnd, int hWndInsertAfter, int X, int Y, int cx, int cy, int uFlags){
+HDWP DeferWindowPos(HDWP hWinPosInfo, HWND hWnd, HWND hWndInsertAfter, int X, int Y, int cx, int cy, int uFlags){
     if (OS.IsWinCE) {
         /*
         * Feature in Windows.  On Windows CE, DeferWindowPos always causes
@@ -383,8 +393,8 @@
         * SWP_NOSIZE.
         */
         if ((uFlags & OS.SWP_NOSIZE) is 0) {
-            RECT lpRect = new RECT ();
-            OS.GetWindowRect (hWnd, lpRect);
+            RECT lpRect;
+            OS.GetWindowRect (hWnd, &lpRect);
             if (cy is lpRect.bottom - lpRect.top && cx is lpRect.right - lpRect.left) {
                 /*
                 * Feature in Windows.  On Windows CE, DeferWindowPos when called
@@ -434,14 +444,14 @@
     release (true);
 }
 
-bool dragDetect (int hwnd, int x, int y, bool filter, bool [] detect, bool [] consume) {
+bool dragDetect (HWND hwnd, int x, int y, bool filter, bool [] detect, bool [] consume) {
     if (consume !is null) consume [0] = false;
     if (detect !is null) detect [0] = true;
-    POINT pt = new POINT ();
+    POINT pt;
     pt.x = x;
     pt.y = y;
-    OS.ClientToScreen (hwnd, pt);
-    return OS.DragDetect (hwnd, pt);
+    OS.ClientToScreen (hwnd, &pt);
+    return cast(bool) OS.DragDetect (hwnd, pt);
 }
 
 /**
@@ -464,9 +474,8 @@
     return null;
 }
 
-char [] fixMnemonic (String string) {
-    char [] buffer = new char [string.length ()];
-    string.getChars (0, string.length (), buffer, 0);
+char [] fixMnemonic (char[] string) {
+    char [] buffer = string.dup;
     int i = 0, j = 0;
     while (i < buffer.length) {
         if (buffer [i] is '&') {
@@ -507,7 +516,7 @@
  */
 public Object getData () {
     checkWidget();
-    return (state & KEYED_DATA) !is 0 ? ((Object []) data) [0] : data;
+    return (state & KEYED_DATA) !is 0 ? (cast(ArrayWrapperObject) data).array [0] : data;
 }
 
 /**
@@ -534,13 +543,14 @@
  *
  * @see #setData(String, Object)
  */
-public Object getData (String key) {
+public Object getData (char[] key) {
     checkWidget();
     if (key is null) error (DWT.ERROR_NULL_ARGUMENT);
     if ((state & KEYED_DATA) !is 0) {
-        Object [] table = (Object []) data;
+        Object [] table = (cast(ArrayWrapperObject) data).array;
         for (int i=1; i<table.length; i+=2) {
-            if (key.equals (table [i])) return table [i+1];
+            char[] tablekey = (cast(ArrayWrapperString) table[i]).array;
+            if (key ==/*eq*/ tablekey ) return table [i+1];
         }
     }
     return null;
@@ -577,11 +587,11 @@
  *
  * @return the name of the widget
  */
-String getName () {
-    String string = getClass ().getName ();
-    int index = string.lastIndexOf ('.');
-    if (index is -1) return string;
-    return string.substring (index + 1, string.length ());
+char[] getName () {
+    char[] str = this.classinfo.name;
+    int index = str.length;
+    while ((--index > 0) && (str[index] !is '.')) {}
+    return str[index + 1 .. $ ];
 }
 
 /*
@@ -594,7 +604,7 @@
  *
  * @see #toString
  */
-String getNameText () {
+char[] getNameText () {
     return ""; //$NON-NLS-1$
 }
 
@@ -684,7 +694,7 @@
  * @return <code>true</code> when subclassing is allowed and <code>false</code> otherwise
  */
 bool isValidSubclass () {
-    return Display.isValidClass (getClass ());
+    return true;//Display.isValidClass (getClass ());
 }
 
 /*
@@ -698,7 +708,7 @@
     return getDisplay ().isValidThread ();
 }
 
-void mapEvent (int hwnd, Event event) {
+void mapEvent (HWND hwnd, Event event) {
 }
 
 GC new_GC (GCData data) {
@@ -1001,18 +1011,18 @@
     return event.doit;
 }
 
-bool sendMouseEvent (int type, int button, int hwnd, int msg, int wParam, int lParam) {
+bool sendMouseEvent (int type, int button, HWND hwnd, int msg, int wParam, int lParam) {
     return sendMouseEvent (type, button, display.getClickCount (type, button, hwnd, lParam), 0, false, hwnd, msg, wParam, lParam);
 }
 
-bool sendMouseEvent (int type, int button, int count, int detail, bool send, int hwnd, int msg, int wParam, int lParam) {
+bool sendMouseEvent (int type, int button, int count, int detail, bool send, HWND hwnd, int msg, int wParam, int lParam) {
     if (!hooks (type) && !filters (type)) return true;
     Event event = new Event ();
     event.button = button;
     event.detail = detail;
     event.count = count;
-    event.x = (short) (lParam & 0xFFFF);
-    event.y = (short) (lParam >> 16);
+    event.x = cast(short) (lParam & 0xFFFF);
+    event.y = cast(short) (lParam >> 16);
     setInputState (event, type);
     mapEvent (hwnd, event);
     if (send) {
@@ -1049,7 +1059,7 @@
 public void setData (Object data) {
     checkWidget();
     if ((state & KEYED_DATA) !is 0) {
-        ((Object []) this.data) [0] = data;
+        (cast(ArrayWrapperObject) this.data).array [0] = data;
     } else {
         this.data = data;
     }
@@ -1079,15 +1089,16 @@
  *
  * @see #getData(String)
  */
-public void setData (String key, Object value) {
+public void setData (char[] key, Object value) {
     checkWidget();
-    if (key is null) error (DWT.ERROR_NULL_ARGUMENT);
+    if (key.length is 0) error (DWT.ERROR_NULL_ARGUMENT);
     int index = 1;
     Object [] table = null;
     if ((state & KEYED_DATA) !is 0) {
-        table = (Object []) data;
+        table = (cast(ArrayWrapperObject) data).array;
         while (index < table.length) {
-            if (key.equals (table [index])) break;
+            char[] tablekey = (cast(ArrayWrapperString)table[index]).array;
+            if (key ==/*eq*/ tablekey ) break;
             index += 2;
         }
     }
@@ -1096,28 +1107,29 @@
             if (index is table.length) {
                 Object [] newTable = new Object [table.length + 2];
                 System.arraycopy (table, 0, newTable, 0, table.length);
-                data = table = newTable;
+                table = newTable;
+                data = new ArrayWrapperObject( table );
             }
         } else {
             table = new Object [3];
             table [0] = data;
-            data = table;
+            data = new ArrayWrapperObject( table );
             state |= KEYED_DATA;
         }
-        table [index] = key;
+        table [index] = new ArrayWrapperString( key );
         table [index + 1] = value;
     } else {
         if ((state & KEYED_DATA) !is 0) {
             if (index !is table.length) {
-                int length = table.length - 2;
-                if (length is 1) {
+                int len = table.length - 2;
+                if (len is 1) {
                     data = table [0];
                     state &= ~KEYED_DATA;
                 } else {
-                    Object [] newTable = new Object [length];
+                    Object [] newTable = new Object [len];
                     System.arraycopy (table, 0, newTable, 0, index);
-                    System.arraycopy (table, index + 2, newTable, index, length - index);
-                    data = newTable;
+                    System.arraycopy (table, index + 2, newTable, index, len - index);
+                    data = new ArrayWrapperObject( newTable );
                 }
             }
         }
@@ -1224,7 +1236,7 @@
         event.keyCode = display.lastKey;
     }
     if (display.lastAscii !is 0 || display.lastNull) {
-        event.character = Display.mbcsToWcs ((char) display.lastAscii);
+        event.character = Display.mbcsToWcs (cast(char) display.lastAscii);
     }
     if (event.keyCode is 0 && event.character is 0) {
         if (!display.lastNull) return false;
@@ -1232,7 +1244,7 @@
     return setInputState (event, type);
 }
 
-bool SetWindowPos (int hWnd, int hWndInsertAfter, int X, int Y, int cx, int cy, int uFlags) {
+bool SetWindowPos (HWND hWnd, HWND hWndInsertAfter, int X, int Y, int cx, int cy, int uFlags) {
     if (OS.IsWinCE) {
         /*
         * Feature in Windows.  On Windows CE, SetWindowPos() always causes
@@ -1241,8 +1253,8 @@
         * SWP_NOSIZE.
         */
         if ((uFlags & OS.SWP_NOSIZE) is 0) {
-            RECT lpRect = new RECT ();
-            OS.GetWindowRect (hWnd, lpRect);
+            RECT lpRect;
+            OS.GetWindowRect (hWnd, &lpRect);
             if (cy is lpRect.bottom - lpRect.top && cx is lpRect.right - lpRect.left) {
                 /*
                 * Feature in Windows.  On Windows CE, SetWindowPos() when called
@@ -1256,7 +1268,7 @@
             }
         }
     }
-    return OS.SetWindowPos (hWnd, hWndInsertAfter, X, Y, cx, cy, uFlags);
+    return cast(bool) OS.SetWindowPos (hWnd, hWndInsertAfter, X, Y, cx, cy, uFlags);
 }
 
 bool showMenu (int x, int y) {
@@ -1282,18 +1294,18 @@
  *
  * @return a string representation of the receiver
  */
-public String toString () {
-    String string = "*Disposed*"; //$NON-NLS-1$
+public char[] toString () {
+    char[] string = "*Disposed*"; //$NON-NLS-1$
     if (!isDisposed ()) {
         string = "*Wrong Thread*"; //$NON-NLS-1$
         if (isValidThread ()) string = getNameText ();
     }
-    return getName () + " {" + string + "}"; //$NON-NLS-1$ //$NON-NLS-2$
+    return Format( "{} {{{}}", getName (), string ); //$NON-NLS-1$ //$NON-NLS-2$
 }
 
 LRESULT wmCaptureChanged (int hwnd, int wParam, int lParam) {
     display.captureChanged = true;
-    return null;
+    return LRESULT.NULL;
 }
 
 LRESULT wmChar (int hwnd, int wParam, int lParam) {
@@ -1301,8 +1313,8 @@
     * Do not report a lead byte as a key pressed.
     */
     if (!OS.IsUnicode && OS.IsDBLocale) {
-        byte lead = (byte) (wParam & 0xFF);
-        if (OS.IsDBCSLeadByte (lead)) return null;
+        byte lead = cast(byte) (wParam & 0xFF);
+        if (OS.IsDBCSLeadByte (lead)) return LRESULT.NULL;
     }
     display.lastAscii = wParam;
     display.lastNull = wParam is 0;
@@ -1310,11 +1322,11 @@
         return LRESULT.ONE;
     }
     // widget could be disposed at this point
-    return null;
+    return LRESULT.NULL;
 }
 
-LRESULT wmContextMenu (int hwnd, int wParam, int lParam) {
-    if (wParam !is hwnd) return null;
+LRESULT wmContextMenu (HWND hwnd, int wParam, int lParam) {
+    if (wParam !is cast(int)hwnd) return LRESULT.NULL;
 
     /*
     * Feature in Windows.  SHRecognizeGesture() sends an undocumented
@@ -1327,7 +1339,7 @@
     * NOTE: This only happens on WM2003.  Previous WinCE versions did
     * not support WM_CONTEXTMENU.
     */
-    if (OS.IsWinCE) return null;
+    if (OS.IsWinCE) return LRESULT.NULL;
 
     /*
     * Feature in Windows.  When the user presses  WM_NCRBUTTONUP,
@@ -1342,24 +1354,24 @@
     */
     int x = 0, y = 0;
     if (lParam !is -1) {
-        POINT pt = new POINT ();
-        x = pt.x = (short) (lParam & 0xFFFF);
-        y = pt.y = (short) (lParam >> 16);
-        OS.ScreenToClient (hwnd, pt);
-        RECT rect = new RECT ();
-        OS.GetClientRect (hwnd, rect);
-        if (!OS.PtInRect (rect, pt)) return null;
+        POINT pt;
+        x = pt.x = cast(short) (lParam & 0xFFFF);
+        y = pt.y = cast(short) (lParam >> 16);
+        OS.ScreenToClient (hwnd, &pt);
+        RECT rect;
+        OS.GetClientRect (hwnd, &rect);
+        if (!OS.PtInRect (&rect, pt)) return LRESULT.NULL;
     } else {
         int pos = OS.GetMessagePos ();
-        x = (short) (pos & 0xFFFF);
-        y = (short) (pos >> 16);
+        x = cast(short) (pos & 0xFFFF);
+        y = cast(short) (pos >> 16);
     }
 
     /* Show the menu */
-    return showMenu (x, y) ? LRESULT.ZERO : null;
+    return showMenu (x, y) ? LRESULT.ZERO : LRESULT.NULL;
 }
 
-LRESULT wmIMEChar (int hwnd, int wParam, int lParam) {
+LRESULT wmIMEChar (HWND hwnd, int wParam, int lParam) {
     Display display = this.display;
     display.lastKey = 0;
     display.lastAscii = wParam;
@@ -1373,7 +1385,7 @@
     return LRESULT.ONE;
 }
 
-LRESULT wmKeyDown (int hwnd, int wParam, int lParam) {
+LRESULT wmKeyDown (HWND hwnd, int wParam, int lParam) {
 
     /* Ignore repeating modifier keys by testing key down state */
     switch (wParam) {
@@ -1383,7 +1395,7 @@
         case OS.VK_CAPITAL:
         case OS.VK_NUMLOCK:
         case OS.VK_SCROLL:
-            if ((lParam & 0x40000000) !is 0) return null;
+            if ((lParam & 0x40000000) !is 0) return LRESULT.NULL;
     }
 
     /* Clear last key and last ascii because a new key has been typed */
@@ -1394,8 +1406,8 @@
     * Do not report a lead byte as a key pressed.
     */
     if (!OS.IsUnicode && OS.IsDBLocale) {
-        byte lead = (byte) (wParam & 0xFF);
-        if (OS.IsDBCSLeadByte (lead)) return null;
+        byte lead = cast(byte) (wParam & 0xFF);
+        if (OS.IsDBCSLeadByte (lead)) return LRESULT.NULL;
     }
 
     /* Map the virtual key */
@@ -1439,17 +1451,17 @@
     * and avoid issuing the event.
     */
     if (OS.IsWinNT) {
-        if ((mapKey & 0x80000000) !is 0) return null;
+        if ((mapKey & 0x80000000) !is 0) return LRESULT.NULL;
     } else {
-        if ((mapKey & 0x8000) !is 0) return null;
+        if ((mapKey & 0x8000) !is 0) return LRESULT.NULL;
     }
-    MSG msg = new MSG ();
+    MSG msg;
     int flags = OS.PM_NOREMOVE | OS.PM_NOYIELD | OS.PM_QS_INPUT | OS.PM_QS_POSTMESSAGE;
-    if (OS.PeekMessage (msg, hwnd, OS.WM_DEADCHAR, OS.WM_DEADCHAR, flags)) {
+    if (OS.PeekMessage (&msg, hwnd, OS.WM_DEADCHAR, OS.WM_DEADCHAR, flags)) {
         display.lastDead = true;
         display.lastVirtual = mapKey is 0;
         display.lastKey = display.lastVirtual ? wParam : mapKey;
-        return null;
+        return LRESULT.NULL;
     }
 
     /*
@@ -1515,7 +1527,7 @@
             * special Windows keypad sequence when NumLock is down (ie. typing
             * ALT+0231 should gives 'c' with a cedilla when NumLock is down).
             */
-            if (display.asciiKey (display.lastKey) !is 0) return null;
+            if (display.asciiKey (display.lastKey) !is 0) return LRESULT.NULL;
             display.lastAscii = display.numpadKey (display.lastKey);
         }
     } else {
@@ -1525,7 +1537,7 @@
         * upper case values in WM_KEYDOWN despite the fact that the
         * Shift was not pressed.
         */
-        display.lastKey = OS.CharLower ((short) mapKey);
+        display.lastKey = cast(int) OS.CharLower (cast(wchar*) mapKey);
 
         /*
         * Feature in Windows. The virtual key VK_CANCEL is treated
@@ -1544,7 +1556,7 @@
         * WM_CHAR.  If this is the case, issue the key down event from
         * inside WM_CHAR.
         */
-        int asciiKey = display.asciiKey (wParam);
+        dchar asciiKey = display.asciiKey (wParam);
         if (asciiKey !is 0) {
             /*
             * When the user types Ctrl+Space, ToAscii () maps this to
@@ -1553,8 +1565,8 @@
             * To avoid the extra DWT.KeyDown, look for a space and
             * issue the event from WM_CHAR.
             */
-            if (asciiKey is ' ') return null;
-            if (asciiKey !is wParam) return null;
+            if (asciiKey is ' ') return LRESULT.NULL;
+            if (asciiKey !is wParam) return LRESULT.NULL;
             /*
             * Feature in Windows. The virtual key VK_CANCEL is treated
             * as both a virtual key and ASCII key by Windows.  This
@@ -1562,7 +1574,7 @@
             * this key. To avoid the extra DWT.KeyDown, look for
             * VK_CANCEL and issue the event from WM_CHAR.
             */
-            if (wParam is OS.VK_CANCEL) return null;
+            if (wParam is OS.VK_CANCEL) return LRESULT.NULL;
         }
 
         /*
@@ -1571,7 +1583,7 @@
         * key such as 'A' or Shift+A.  In that case, issue the
         * key event from WM_CHAR.
         */
-        if (OS.GetKeyState (OS.VK_CONTROL) >= 0) return null;
+        if (OS.GetKeyState (OS.VK_CONTROL) >= 0) return LRESULT.NULL;
 
         /*
         * Get the shifted state or convert to lower case if necessary.
@@ -1584,21 +1596,21 @@
             display.lastAscii = display.shiftedKey (wParam);
             if (display.lastAscii is 0) display.lastAscii = mapKey;
         } else {
-            display.lastAscii = OS.CharLower ((short) mapKey);
+            display.lastAscii = cast(int)OS.CharLower (cast(wchar*) mapKey);
         }
 
         /* Note that Ctrl+'@' is ASCII NUL and is delivered in WM_CHAR */
-        if (display.lastAscii is '@') return null;
+        if (display.lastAscii is '@') return LRESULT.NULL;
         display.lastAscii = display.controlKey (display.lastAscii);
     }
     if (!sendKeyEvent (DWT.KeyDown, OS.WM_KEYDOWN, wParam, lParam)) {
         return LRESULT.ONE;
     }
     // widget could be disposed at this point
-    return null;
+    return LRESULT.NULL;
 }
 
-LRESULT wmKeyUp (int hwnd, int wParam, int lParam) {
+LRESULT wmKeyUp (HWND hwnd, int wParam, int lParam) {
     Display display = this.display;
 
     /* Check for hardware keys */
@@ -1612,7 +1624,7 @@
             int type = (lParam & 0x40000000) !is 0 ? DWT.HardKeyUp : DWT.HardKeyDown;
             if (setInputState (event, type)) sendEvent (type, event);
             // widget could be disposed at this point
-            return null;
+            return LRESULT.NULL;
         }
     }
 
@@ -1623,7 +1635,7 @@
     if (!hooks (DWT.KeyUp) && !display.filters (DWT.KeyUp)) {
         display.lastKey = display.lastAscii = 0;
         display.lastVirtual = display.lastNull = display.lastDead = false;
-        return null;
+        return LRESULT.NULL;
     }
 
     /* Map the virtual key. */
@@ -1660,11 +1672,11 @@
     * They should both be bit 32.
     */
     if (OS.IsWinNT) {
-        if ((mapKey & 0x80000000) !is 0) return null;
+        if ((mapKey & 0x80000000) !is 0) return LRESULT.NULL;
     } else {
-        if ((mapKey & 0x8000) !is 0) return null;
+        if ((mapKey & 0x8000) !is 0) return LRESULT.NULL;
     }
-    if (display.lastDead) return null;
+    if (display.lastDead) return LRESULT.NULL;
 
     /*
     * NOTE: On Windows 98, keypad keys are virtual despite the
@@ -1687,10 +1699,10 @@
         if (display.lastKey is 0) {
             display.lastAscii = 0;
             display.lastNull = display.lastDead = false;
-            return null;
+            return LRESULT.NULL;
         }
     }
-    LRESULT result = null;
+    LRESULT result = LRESULT.NULL;
     if (!sendKeyEvent (DWT.KeyUp, OS.WM_KEYUP, wParam, lParam)) {
         result = LRESULT.ONE;
     }
@@ -1700,8 +1712,9 @@
     return result;
 }
 
-LRESULT wmKillFocus (int hwnd, int wParam, int lParam) {
+LRESULT wmKillFocus (HWND hwnd, int wParam, int lParam) {
     int code = callWindowProc (hwnd, OS.WM_KILLFOCUS, wParam, lParam);
+    assert( code !is LRESULT.NULL );
     sendFocusEvent (DWT.FocusOut);
     // widget could be disposed at this point
 
@@ -1714,10 +1727,10 @@
     */
     if (isDisposed ()) return LRESULT.ZERO;
     if (code is 0) return LRESULT.ZERO;
-    return new LRESULT (code);
+    return cast(LRESULT) code;
 }
 
-LRESULT wmLButtonDblClk (int hwnd, int wParam, int lParam) {
+LRESULT wmLButtonDblClk (HWND hwnd, int wParam, int lParam) {
     /*
     * Feature in Windows. Windows sends the following
     * messages when the user double clicks the mouse:
@@ -1731,12 +1744,13 @@
     * pairs will not see the second mouse down.  The
     * fix is to send a mouse down event.
     */
-    LRESULT result = null;
+    LRESULT result = LRESULT.NULL;
     Display display = this.display;
     display.captureChanged = false;
     sendMouseEvent (DWT.MouseDown, 1, hwnd, OS.WM_LBUTTONDOWN, wParam, lParam);
     if (sendMouseEvent (DWT.MouseDoubleClick, 1, hwnd, OS.WM_LBUTTONDBLCLK, wParam, lParam)) {
-        result = new LRESULT (callWindowProc (hwnd, OS.WM_LBUTTONDBLCLK, wParam, lParam));
+        result = cast(LRESULT) callWindowProc (hwnd, OS.WM_LBUTTONDBLCLK, wParam, lParam);
+        assert( result !is LRESULT.NULL );
     } else {
         result = LRESULT.ZERO;
     }
@@ -1746,11 +1760,11 @@
     return result;
 }
 
-LRESULT wmLButtonDown (int hwnd, int wParam, int lParam) {
+LRESULT wmLButtonDown (HWND hwnd, int wParam, int lParam) {
     Display display = this.display;
-    LRESULT result = null;
-    int x = (short) (lParam & 0xFFFF);
-    int y = (short) (lParam >> 16);
+    LRESULT result = LRESULT.NULL;
+    int x = cast(short) (lParam & 0xFFFF);
+    int y = cast(short) (lParam >> 16);
     bool [] consume = null, detect = null;
     bool dragging = false, mouseDown = true;
     int count = display.getClickCount (DWT.MouseDown, 1, hwnd, lParam);
@@ -1774,27 +1788,30 @@
     display.captureChanged = false;
     bool dispatch = sendMouseEvent (DWT.MouseDown, 1, count, 0, false, hwnd, OS.WM_LBUTTONDOWN, wParam, lParam);
     if (dispatch && (consume is null || !consume [0])) {
-        result = new LRESULT (callWindowProc (hwnd, OS.WM_LBUTTONDOWN, wParam, lParam));
+        result = cast(LRESULT) callWindowProc (hwnd, OS.WM_LBUTTONDOWN, wParam, lParam);
+        assert( result !is LRESULT.NULL );
     } else {
         result = LRESULT.ZERO;
     }
-    if (OS.IsPPC) {
-        /*
-        * Note: On WinCE PPC, only attempt to recognize the gesture for
-        * a context menu when the control contains a valid menu or there
-        * are listeners for the MenuDetect event.
-        */
-        Menu menu = getMenu ();
-        bool hasMenu = menu !is null && !menu.isDisposed ();
-        if (hasMenu || hooks (DWT.MenuDetect)) {
-            SHRGINFO shrg = new SHRGINFO ();
-            shrg.cbSize = SHRGINFO.sizeof;
-            shrg.hwndClient = hwnd;
-            shrg.ptDown_x = x;
-            shrg.ptDown_y = y;
-            shrg.dwFlags = OS.SHRG_RETURNCMD;
-            int type = OS.SHRecognizeGesture (shrg);
-            if (type is OS.GN_CONTEXTMENU) showMenu (x, y);
+    static if( OS.IsWinCE ){
+        if (OS.IsPPC_) {
+            /*
+            * Note: On WinCE PPC, only attempt to recognize the gesture for
+            * a context menu when the control contains a valid menu or there
+            * are listeners for the MenuDetect event.
+            */
+            Menu menu = getMenu ();
+            bool hasMenu = menu !is null && !menu.isDisposed ();
+            if (hasMenu || hooks (DWT.MenuDetect)) {
+                SHRGINFO shrg;
+                shrg.cbSize = SHRGINFO.sizeof;
+                shrg.hwndClient = hwnd;
+                shrg.ptDown.x = x;
+                shrg.ptDown.y = y;
+                shrg.dwFlags = OS.SHRG_RETURNCMD;
+                int type = OS.SHRecognizeGesture (&shrg);
+                if (type is OS.GN_CONTEXTMENU) showMenu (x, y);
+            }
         }
     }
     if (mouseDown) {
@@ -1834,11 +1851,12 @@
     return result;
 }
 
-LRESULT wmLButtonUp (int hwnd, int wParam, int lParam) {
+LRESULT wmLButtonUp (HWND hwnd, int wParam, int lParam) {
     Display display = this.display;
-    LRESULT result = null;
+    LRESULT result = LRESULT.NULL;
     if (sendMouseEvent (DWT.MouseUp, 1, hwnd, OS.WM_LBUTTONUP, wParam, lParam)) {
-        result = new LRESULT (callWindowProc (hwnd, OS.WM_LBUTTONUP, wParam, lParam));
+        result = cast(LRESULT) callWindowProc (hwnd, OS.WM_LBUTTONUP, wParam, lParam);
+        assert( result !is LRESULT.NULL );
     } else {
         result = LRESULT.ZERO;
     }
@@ -1856,7 +1874,7 @@
     return result;
 }
 
-LRESULT wmMButtonDblClk (int hwnd, int wParam, int lParam) {
+LRESULT wmMButtonDblClk (HWND hwnd, int wParam, int lParam) {
     /*
     * Feature in Windows. Windows sends the following
     * messages when the user double clicks the mouse:
@@ -1870,12 +1888,13 @@
     * pairs will not see the second mouse down.  The
     * fix is to send a mouse down event.
     */
-    LRESULT result = null;
+    LRESULT result = LRESULT.NULL;
     Display display = this.display;
     display.captureChanged = false;
     sendMouseEvent (DWT.MouseDown, 2, hwnd, OS.WM_MBUTTONDOWN, wParam, lParam);
     if (sendMouseEvent (DWT.MouseDoubleClick, 2, hwnd, OS.WM_MBUTTONDBLCLK, wParam, lParam)) {
-        result = new LRESULT (callWindowProc (hwnd, OS.WM_MBUTTONDBLCLK, wParam, lParam));
+        result = cast(LRESULT) callWindowProc (hwnd, OS.WM_MBUTTONDBLCLK, wParam, lParam);
+        assert( result !is LRESULT.NULL );
     } else {
         result = LRESULT.ZERO;
     }
@@ -1885,12 +1904,13 @@
     return result;
 }
 
-LRESULT wmMButtonDown (int hwnd, int wParam, int lParam) {
-    LRESULT result = null;
+LRESULT wmMButtonDown (HWND hwnd, int wParam, int lParam) {
+    LRESULT result = LRESULT.NULL;
     Display display = this.display;
     display.captureChanged = false;
     if (sendMouseEvent (DWT.MouseDown, 2, hwnd, OS.WM_MBUTTONDOWN, wParam, lParam)) {
-        result = new LRESULT (callWindowProc (hwnd, OS.WM_MBUTTONDOWN, wParam, lParam));
+        result = cast(LRESULT) callWindowProc (hwnd, OS.WM_MBUTTONDOWN, wParam, lParam);
+        assert( result !is LRESULT.NULL );
     } else {
         result = LRESULT.ZERO;
     }
@@ -1900,11 +1920,12 @@
     return result;
 }
 
-LRESULT wmMButtonUp (int hwnd, int wParam, int lParam) {
+LRESULT wmMButtonUp (HWND hwnd, int wParam, int lParam) {
     Display display = this.display;
-    LRESULT result = null;
+    LRESULT result = LRESULT.NULL;
     if (sendMouseEvent (DWT.MouseUp, 2, hwnd, OS.WM_MBUTTONUP, wParam, lParam)) {
-        result = new LRESULT (callWindowProc (hwnd, OS.WM_MBUTTONUP, wParam, lParam));
+        result = cast(LRESULT) callWindowProc (hwnd, OS.WM_MBUTTONUP, wParam, lParam);
+        assert( result !is LRESULT.NULL );
     } else {
         result = LRESULT.ZERO;
     }
@@ -1922,29 +1943,29 @@
     return result;
 }
 
-LRESULT wmMouseHover (int hwnd, int wParam, int lParam) {
+LRESULT wmMouseHover (HWND hwnd, int wParam, int lParam) {
     if (!sendMouseEvent (DWT.MouseHover, 0, hwnd, OS.WM_MOUSEHOVER, wParam, lParam)) {
         return LRESULT.ZERO;
     }
-    return null;
+    return LRESULT.NULL;
 }
 
-LRESULT wmMouseLeave (int hwnd, int wParam, int lParam) {
-    if (!hooks (DWT.MouseExit) && !filters (DWT.MouseExit)) return null;
+LRESULT wmMouseLeave (HWND hwnd, int wParam, int lParam) {
+    if (!hooks (DWT.MouseExit) && !filters (DWT.MouseExit)) return LRESULT.NULL;
     int pos = OS.GetMessagePos ();
-    POINT pt = new POINT ();
-    pt.x = (short) (pos & 0xFFFF);
-    pt.y = (short) (pos >> 16);
-    OS.ScreenToClient (hwnd, pt);
+    POINT pt;
+    pt.x = cast(short) (pos & 0xFFFF);
+    pt.y = cast(short) (pos >> 16);
+    OS.ScreenToClient (hwnd, &pt);
     lParam = (pt.x & 0xFFFF) | ((pt.y << 16) & 0xFFFF0000);
     if (!sendMouseEvent (DWT.MouseExit, 0, hwnd, OS.WM_MOUSELEAVE, wParam, lParam)) {
         return LRESULT.ZERO;
     }
-    return null;
+    return LRESULT.NULL;
 }
 
-LRESULT wmMouseMove (int hwnd, int wParam, int lParam) {
-    LRESULT result = null;
+LRESULT wmMouseMove (HWND hwnd, int wParam, int lParam) {
+    LRESULT result = LRESULT.NULL;
     Display display = this.display;
     int pos = OS.GetMessagePos ();
     if (pos !is display.lastMouse || display.captureChanged) {
@@ -1954,15 +1975,15 @@
             bool mouseExit = hooks (DWT.MouseExit) || display.filters (DWT.MouseExit);
             bool mouseHover = hooks (DWT.MouseHover) || display.filters (DWT.MouseHover);
             if (trackMouse || mouseEnter || mouseExit || mouseHover) {
-                TRACKMOUSEEVENT lpEventTrack = new TRACKMOUSEEVENT ();
+                TRACKMOUSEEVENT lpEventTrack;
                 lpEventTrack.cbSize = TRACKMOUSEEVENT.sizeof;
                 lpEventTrack.dwFlags = OS.TME_QUERY;
                 lpEventTrack.hwndTrack = hwnd;
-                OS.TrackMouseEvent (lpEventTrack);
+                OS.TrackMouseEvent (&lpEventTrack);
                 if (lpEventTrack.dwFlags is 0) {
                     lpEventTrack.dwFlags = OS.TME_LEAVE | OS.TME_HOVER;
                     lpEventTrack.hwndTrack = hwnd;
-                    OS.TrackMouseEvent (lpEventTrack);
+                    OS.TrackMouseEvent (&lpEventTrack);
                     if (mouseEnter) {
                         /*
                         * Force all outstanding WM_MOUSELEAVE messages to be dispatched before
@@ -1970,17 +1991,17 @@
                         * before mouse enter events.  Note that WM_MOUSELEAVE is posted to the
                         * event queue by TrackMouseEvent().
                         */
-                        MSG msg = new MSG ();
+                        MSG msg;
                         int flags = OS.PM_REMOVE | OS.PM_NOYIELD | OS.PM_QS_INPUT | OS.PM_QS_POSTMESSAGE;
-                        while (OS.PeekMessage (msg, 0, OS.WM_MOUSELEAVE, OS.WM_MOUSELEAVE, flags)) {
-                            OS.TranslateMessage (msg);
-                            OS.DispatchMessage (msg);
+                        while (OS.PeekMessage (&msg, null, OS.WM_MOUSELEAVE, OS.WM_MOUSELEAVE, flags)) {
+                            OS.TranslateMessage (&msg);
+                            OS.DispatchMessage (&msg);
                         }
                         sendMouseEvent (DWT.MouseEnter, 0, hwnd, OS.WM_MOUSEMOVE, wParam, lParam);
                     }
                 } else {
                     lpEventTrack.dwFlags = OS.TME_HOVER;
-                    OS.TrackMouseEvent (lpEventTrack);
+                    OS.TrackMouseEvent (&lpEventTrack);
                 }
             }
         }
@@ -1995,43 +2016,44 @@
     return result;
 }
 
-LRESULT wmMouseWheel (int hwnd, int wParam, int lParam) {
-    if (!hooks (DWT.MouseWheel) && !filters (DWT.MouseWheel)) return null;
+LRESULT wmMouseWheel (HWND hwnd, int wParam, int lParam) {
+    if (!hooks (DWT.MouseWheel) && !filters (DWT.MouseWheel)) return LRESULT.NULL;
     int delta = wParam >> 16;
-    int [] value = new int [1];
+    int value;
     int count, detail;
-    OS.SystemParametersInfo (OS.SPI_GETWHEELSCROLLLINES, 0, value, 0);
-    if (value [0] is OS.WHEEL_PAGESCROLL) {
+    OS.SystemParametersInfo (OS.SPI_GETWHEELSCROLLLINES, 0, &value, 0);
+    if (value is OS.WHEEL_PAGESCROLL) {
         detail = DWT.SCROLL_PAGE;
         count = delta / OS.WHEEL_DELTA;
     } else {
         detail = DWT.SCROLL_LINE;
-        count = value [0] * delta / OS.WHEEL_DELTA;
+        count = value * delta / OS.WHEEL_DELTA;
     }
-    POINT pt = new POINT ();
-    pt.x = (short) (lParam & 0xFFFF);
-    pt.y = (short) (lParam >> 16);
-    OS.ScreenToClient (hwnd, pt);
+    POINT pt;
+    pt.x = cast(short) (lParam & 0xFFFF);
+    pt.y = cast(short) (lParam >> 16);
+    OS.ScreenToClient (hwnd, &pt);
     lParam = (pt.x & 0xFFFF) | ((pt.y << 16) & 0xFFFF0000);
     if (!sendMouseEvent (DWT.MouseWheel, 0, count, detail, true, hwnd, OS.WM_MOUSEWHEEL, wParam, lParam)) {
         return LRESULT.ZERO;
     }
-    return null;
+    return LRESULT.NULL;
 }
 
-LRESULT wmPaint (int hwnd, int wParam, int lParam) {
+LRESULT wmPaint (HWND hwnd, int wParam, int lParam) {
 
     /* Exit early - don't draw the background */
     if (!hooks (DWT.Paint) && !filters (DWT.Paint)) {
-        return null;
+        return LRESULT.NULL;
     }
 
     /* Issue a paint event */
-    int result = 0;
+    LRESULT result = LRESULT.NULL;
     if (OS.IsWinCE) {
-        RECT rect = new RECT ();
-        OS.GetUpdateRect (hwnd, rect, false);
-        result = callWindowProc (hwnd, OS.WM_PAINT, wParam, lParam);
+        RECT rect;
+        OS.GetUpdateRect (hwnd, &rect, false);
+        result = cast(LRESULT) callWindowProc (hwnd, OS.WM_PAINT, wParam, lParam);
+        assert( result !is LRESULT.NULL );
         /*
         * Bug in Windows.  When InvalidateRgn(), InvalidateRect()
         * or RedrawWindow() with RDW_INVALIDATE is called from
@@ -2041,21 +2063,21 @@
         * caret.
         */
         OS.HideCaret (hwnd);
-        OS.InvalidateRect (hwnd, rect, false);
+        OS.InvalidateRect (hwnd, &rect, false);
         OS.ShowCaret (hwnd);
-        PAINTSTRUCT ps = new PAINTSTRUCT ();
+        PAINTSTRUCT* ps = new PAINTSTRUCT;
         GCData data = new GCData ();
         data.ps = ps;
         data.hwnd = hwnd;
         GC gc = new_GC (data);
         if (gc !is null) {
-            int width = ps.right - ps.left;
-            int height = ps.bottom - ps.top;
+            int width = ps.rcPaint.right - ps.rcPaint.left;
+            int height = ps.rcPaint.bottom - ps.rcPaint.top;
             if (width !is 0 && height !is 0) {
                 Event event = new Event ();
                 event.gc = gc;
-                event.x = ps.left;
-                event.y = ps.top;
+                event.x = ps.rcPaint.left;
+                event.y = ps.rcPaint.top;
                 event.width = width;
                 event.height = height;
                 sendEvent (DWT.Paint, event);
@@ -2065,20 +2087,21 @@
             gc.dispose ();
         }
     } else {
-        int rgn = OS.CreateRectRgn (0, 0, 0, 0);
+        auto rgn = OS.CreateRectRgn (0, 0, 0, 0);
         OS.GetUpdateRgn (hwnd, rgn, false);
-        result = callWindowProc (hwnd, OS.WM_PAINT, wParam, lParam);
+        result = cast(LRESULT) callWindowProc (hwnd, OS.WM_PAINT, wParam, lParam);
+        assert( result !is LRESULT.NULL );
         GCData data = new GCData ();
         data.hwnd = hwnd;
         GC gc = new_GC (data);
         if (gc !is null) {
             OS.HideCaret (hwnd);
-            RECT rect = new RECT();
-            OS.GetRgnBox (rgn, rect);
+            RECT rect;
+            OS.GetRgnBox (rgn, &rect);
             int width = rect.right - rect.left;
             int height = rect.bottom - rect.top;
             if (width !is 0 && height !is 0) {
-                int hDC = gc.handle;
+                auto hDC = gc.handle;
                 OS.SelectClipRgn (hDC, rgn);
                 OS.SetMetaRgn (hDC);
                 Event event = new Event ();
@@ -2097,10 +2120,10 @@
         OS.DeleteObject (rgn);
     }
     if (result is 0) return LRESULT.ZERO;
-    return new LRESULT (result);
+    return result;
 }
 
-LRESULT wmPrint (int hwnd, int wParam, int lParam) {
+LRESULT wmPrint (HWND hwnd, int wParam, int lParam) {
     /*
     * Bug in Windows.  When WM_PRINT is used to print the contents
     * of a control that has WS_EX_CLIENTEDGE, the old 3D border is
@@ -2112,22 +2135,23 @@
             int bits = OS.GetWindowLong (hwnd, OS.GWL_EXSTYLE);
             if ((bits & OS.WS_EX_CLIENTEDGE) !is 0) {
                 int code = callWindowProc (hwnd, OS.WM_PRINT, wParam, lParam);
-                RECT rect = new RECT ();
-                OS.GetWindowRect (hwnd, rect);
+                assert( code !is LRESULT.NULL );
+                RECT rect;
+                OS.GetWindowRect (hwnd, &rect);
                 rect.right -= rect.left;
                 rect.bottom -= rect.top;
                 rect.left = rect.top = 0;
                 int border = OS.GetSystemMetrics (OS.SM_CXEDGE);
-                OS.ExcludeClipRect (wParam, border, border, rect.right - border, rect.bottom - border);
-                OS.DrawThemeBackground (display.hEditTheme (), wParam, OS.EP_EDITTEXT, OS.ETS_NORMAL, rect, null);
-                return new LRESULT (code);
+                OS.ExcludeClipRect ( cast(void*)wParam, border, border, rect.right - border, rect.bottom - border);
+                OS.DrawThemeBackground (display.hEditTheme (), cast(HDC)wParam, OS.EP_EDITTEXT, OS.ETS_NORMAL, &rect, null);
+                return cast(LRESULT)code;
             }
         }
     }
-    return null;
+    return LRESULT.NULL;
 }
 
-LRESULT wmRButtonDblClk (int hwnd, int wParam, int lParam) {
+LRESULT wmRButtonDblClk (HWND hwnd, int wParam, int lParam) {
     /*
     * Feature in Windows. Windows sends the following
     * messages when the user double clicks the mouse:
@@ -2141,12 +2165,13 @@
     * pairs will not see the second mouse down.  The
     * fix is to send a mouse down event.
     */
-    LRESULT result = null;
+    LRESULT result = LRESULT.NULL;
     Display display = this.display;
     display.captureChanged = false;
     sendMouseEvent (DWT.MouseDown, 3, hwnd, OS.WM_RBUTTONDOWN, wParam, lParam);
     if (sendMouseEvent (DWT.MouseDoubleClick, 3, hwnd, OS.WM_RBUTTONDBLCLK, wParam, lParam)) {
-        result = new LRESULT (callWindowProc (hwnd, OS.WM_RBUTTONDBLCLK, wParam, lParam));
+        result = cast(LRESULT) callWindowProc (hwnd, OS.WM_RBUTTONDBLCLK, wParam, lParam);
+        assert( result !is LRESULT.NULL );
     } else {
         result = LRESULT.ZERO;
     }
@@ -2156,12 +2181,13 @@
     return result;
 }
 
-LRESULT wmRButtonDown (int hwnd, int wParam, int lParam) {
-    LRESULT result = null;
+LRESULT wmRButtonDown (HWND hwnd, int wParam, int lParam) {
+    LRESULT result = LRESULT.NULL;
     Display display = this.display;
     display.captureChanged = false;
     if (sendMouseEvent (DWT.MouseDown, 3, hwnd, OS.WM_RBUTTONDOWN, wParam, lParam)) {
-        result = new LRESULT (callWindowProc (hwnd, OS.WM_RBUTTONDOWN, wParam, lParam));
+        result = cast(LRESULT) callWindowProc (hwnd, OS.WM_RBUTTONDOWN, wParam, lParam);
+        assert( result !is LRESULT.NULL );
     } else {
         result = LRESULT.ZERO;
     }
@@ -2171,11 +2197,12 @@
     return result;
 }
 
-LRESULT wmRButtonUp (int hwnd, int wParam, int lParam) {
+LRESULT wmRButtonUp (HWND hwnd, int wParam, int lParam) {
     Display display = this.display;
-    LRESULT result = null;
+    LRESULT result = LRESULT.NULL;
     if (sendMouseEvent (DWT.MouseUp, 3, hwnd, OS.WM_RBUTTONUP, wParam, lParam)) {
-        result = new LRESULT (callWindowProc (hwnd, OS.WM_RBUTTONUP, wParam, lParam));
+        result = cast(LRESULT) callWindowProc (hwnd, OS.WM_RBUTTONUP, wParam, lParam);
+        assert( result !is LRESULT.NULL );
     } else {
         /* Call the DefWindowProc() to support WM_CONTEXTMENU */
         OS.DefWindowProc (hwnd, OS.WM_RBUTTONUP, wParam, lParam);
@@ -2195,8 +2222,9 @@
     return result;
 }
 
-LRESULT wmSetFocus (int hwnd, int wParam, int lParam) {
-    int code = callWindowProc (hwnd, OS.WM_SETFOCUS, wParam, lParam);
+LRESULT wmSetFocus (HWND hwnd, int wParam, int lParam) {
+    LRESULT code = cast(LRESULT) callWindowProc (hwnd, OS.WM_SETFOCUS, wParam, lParam);
+    assert( code !is LRESULT.NULL );
     sendFocusEvent (DWT.FocusIn);
     // widget could be disposed at this point
 
@@ -2209,23 +2237,24 @@
     */
     if (isDisposed ()) return LRESULT.ZERO;
     if (code is 0) return LRESULT.ZERO;
-    return new LRESULT (code);
+    return code;
 }
 
-LRESULT wmSysChar (int hwnd, int wParam, int lParam) {
+LRESULT wmSysChar (HWND hwnd, int wParam, int lParam) {
     Display display = this.display;
     display.lastAscii = wParam;
     display.lastNull = wParam is 0;
 
     /* Do not issue a key down if a menu bar mnemonic was invoked */
     if (!hooks (DWT.KeyDown) && !display.filters (DWT.KeyDown)) {
-        return null;
+        return LRESULT.NULL;
     }
 
     /* Call the window proc to determine whether it is a system key or mnemonic */
     bool oldKeyHit = display.mnemonicKeyHit;
     display.mnemonicKeyHit = true;
-    int result = callWindowProc (hwnd, OS.WM_SYSCHAR, wParam, lParam);
+    LRESULT result = cast(LRESULT) callWindowProc (hwnd, OS.WM_SYSCHAR, wParam, lParam);
+    assert( result !is LRESULT.NULL );
     bool consumed = false;
     if (!display.mnemonicKeyHit) {
         consumed = !sendKeyEvent (DWT.KeyDown, OS.WM_SYSCHAR, wParam, lParam);
@@ -2233,10 +2262,10 @@
     }
     consumed |= display.mnemonicKeyHit;
     display.mnemonicKeyHit = oldKeyHit;
-    return consumed ? LRESULT.ONE : new LRESULT (result);
+    return consumed ? LRESULT.ONE : result;
 }
 
-LRESULT wmSysKeyDown (int hwnd, int wParam, int lParam) {
+LRESULT wmSysKeyDown (HWND hwnd, int wParam, int lParam) {
     /*
     * Feature in Windows.  When WM_SYSKEYDOWN is sent,
     * the user pressed ALT+<key> or F10 to get to the
@@ -2247,19 +2276,19 @@
     */
     if (wParam !is OS.VK_F10) {
         /* Make sure WM_SYSKEYDOWN was sent by ALT-<aKey>. */
-        if ((lParam & 0x20000000) is 0) return null;
+        if ((lParam & 0x20000000) is 0) return LRESULT.NULL;
     }
 
     /* Ignore well known system keys */
     switch (wParam) {
         case OS.VK_F4: {
-            int hwndShell = hwnd;
-            while (OS.GetParent (hwndShell) !is 0) {
-                if (OS.GetWindow (hwndShell, OS.GW_OWNER) !is 0) break;
+            HWND hwndShell = hwnd;
+            while (OS.GetParent (hwndShell) !is null) {
+                if (OS.GetWindow (hwndShell, OS.GW_OWNER) !is null) break;
                 hwndShell = OS.GetParent (hwndShell);
             }
             int bits = OS.GetWindowLong (hwndShell, OS.GWL_STYLE);
-            if ((bits & OS.WS_SYSMENU) !is 0) return null;
+            if ((bits & OS.WS_SYSMENU) !is 0) return LRESULT.NULL;
         }
     }
 
@@ -2271,7 +2300,7 @@
         case OS.VK_CAPITAL:
         case OS.VK_NUMLOCK:
         case OS.VK_SCROLL:
-            if ((lParam & 0x40000000) !is 0) return null;
+            if ((lParam & 0x40000000) !is 0) return LRESULT.NULL;
     }
 
     /* Clear last key and last ascii because a new key has been typed */
@@ -2328,7 +2357,7 @@
                 case OS.VK_ADD:
                 case OS.VK_SUBTRACT:
                 case OS.VK_DECIMAL:
-                case OS.VK_DIVIDE: return null;
+                case OS.VK_DIVIDE: return LRESULT.NULL;
             }
             display.lastAscii = display.numpadKey (display.lastKey);
         }
@@ -2339,7 +2368,7 @@
         * upper case values in WM_SYSKEYDOWN despite the fact that the
         * Shift was not pressed.
         */
-        display.lastKey = OS.CharLower ((short) mapKey);
+        display.lastKey = cast(int) OS.CharLower (cast(wchar*) mapKey);
 
         /*
         * Feature in Windows 98.  MapVirtualKey() indicates that
@@ -2347,8 +2376,8 @@
         * this message never happens.  The fix is to issue the
         * event from WM_SYSKEYDOWN and map VK_RETURN to '\r'.
         */
-        if (OS.IsWinNT) return null;
-        if (wParam !is OS.VK_RETURN) return null;
+        if (OS.IsWinNT) return LRESULT.NULL;
+        if (wParam !is OS.VK_RETURN) return LRESULT.NULL;
         display.lastAscii = '\r';
     }
 
@@ -2356,14 +2385,14 @@
         return LRESULT.ONE;
     }
     // widget could be disposed at this point
-    return null;
+    return LRESULT.NULL;
 }
 
-LRESULT wmSysKeyUp (int hwnd, int wParam, int lParam) {
+LRESULT wmSysKeyUp (HWND hwnd, int wParam, int lParam) {
     return wmKeyUp (hwnd, wParam, lParam);
 }
 
-LRESULT wmXButtonDblClk (int hwnd, int wParam, int lParam) {
+LRESULT wmXButtonDblClk (HWND hwnd, int wParam, int lParam) {
     /*
     * Feature in Windows. Windows sends the following
     * messages when the user double clicks the mouse:
@@ -2377,13 +2406,14 @@
     * pairs will not see the second mouse down.  The
     * fix is to send a mouse down event.
     */
-    LRESULT result = null;
+    LRESULT result = LRESULT.NULL;
     Display display = this.display;
     display.captureChanged = false;
     int button = (wParam >> 16 is OS.XBUTTON1) ? 4 : 5;
     sendMouseEvent (DWT.MouseDown, button, hwnd, OS.WM_XBUTTONDOWN, wParam, lParam);
     if (sendMouseEvent (DWT.MouseDoubleClick, button, hwnd, OS.WM_XBUTTONDBLCLK, wParam, lParam)) {
-        result = new LRESULT (callWindowProc (hwnd, OS.WM_XBUTTONDBLCLK, wParam, lParam));
+        result = cast(LRESULT) callWindowProc (hwnd, OS.WM_XBUTTONDBLCLK, wParam, lParam);
+        assert( result !is LRESULT.NULL );
     } else {
         result = LRESULT.ZERO;
     }
@@ -2393,14 +2423,15 @@
     return result;
 }
 
-LRESULT wmXButtonDown (int hwnd, int wParam, int lParam) {
-    LRESULT result = null;
+LRESULT wmXButtonDown (HWND hwnd, int wParam, int lParam) {
+    LRESULT result = LRESULT.NULL;
     Display display = this.display;
     display.captureChanged = false;
     display.xMouse = true;
     int button = (wParam >> 16 is OS.XBUTTON1) ? 4 : 5;
     if (sendMouseEvent (DWT.MouseDown, button, hwnd, OS.WM_XBUTTONDOWN, wParam, lParam)) {
-        result = new LRESULT (callWindowProc (hwnd, OS.WM_XBUTTONDOWN, wParam, lParam));
+        result = cast(LRESULT) callWindowProc (hwnd, OS.WM_XBUTTONDOWN, wParam, lParam);
+        assert( result !is LRESULT.NULL );
     } else {
         result = LRESULT.ZERO;
     }
@@ -2410,12 +2441,13 @@
     return result;
 }
 
-LRESULT wmXButtonUp (int hwnd, int wParam, int lParam) {
+LRESULT wmXButtonUp (HWND hwnd, int wParam, int lParam) {
     Display display = this.display;
-    LRESULT result = null;
+    LRESULT result = LRESULT.NULL;
     int button = (wParam >> 16 is OS.XBUTTON1) ? 4 : 5;
     if (sendMouseEvent (DWT.MouseUp, button, hwnd, OS.WM_XBUTTONUP, wParam, lParam)) {
-        result = new LRESULT (callWindowProc (hwnd, OS.WM_XBUTTONUP, wParam, lParam));
+        result = cast(LRESULT) callWindowProc (hwnd, OS.WM_XBUTTONUP, wParam, lParam);
+        assert( result !is LRESULT.NULL );
     } else {
         result = LRESULT.ZERO;
     }
@@ -2433,4 +2465,3 @@
     return result;
 }
 }
-++/
\ No newline at end of file