*** empty log message *** expecco_19_2_0
authorsr
Tue, 26 Nov 2019 15:46:33 +0100
branchexpecco_19_2_0
changeset 8899 fe8d508c7e2f
parent 8895 e8bf0fe9996f
child 8900 666dbd57b00f
*** empty log message ***
WinWorkstation.st
--- a/WinWorkstation.st	Mon Nov 25 14:46:18 2019 +0100
+++ b/WinWorkstation.st	Tue Nov 26 15:46:33 2019 +0100
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
 "
 COPYRIGHT (c) 1996 by Claus Gittinger
 	      All Rights Reserved
@@ -9,6 +11,8 @@
  other person.  No title to or ownership of the software is
  hereby transferred.
 "
+'From Smalltalk/X, Version:7.2.0.0 on 26-11-2019 at 15:46:23'                   !
+
 "{ Package: 'stx:libview' }"
 
 "{ NameSpace: Smalltalk }"
@@ -76,954 +80,12 @@
 !
 
 !WinWorkstation primitiveDefinitions!
-%{
-#define TRACE_ALL_EVENTS      /* */
-
-#define COUNT_RESOURCES       /* */
-#define COUNT_BMP_RESOURCES   /* */
-#define DEBUG_DELETEOBJECT    /* */
-#define DEBUG_DC_REUSE        /* */
-#define xxDEBUG_COLORIZE_WM_PAINT_RECTS1
-#define xxDEBUG_COLORIZE_WM_PAINT_RECTS2
-#define LOCK_DEBUG
-#define xxSTARTUP_DISPATCHTHREAD_DEBUG
-
-#define ADJUSTWINDOW
-#define ALWAYSTRUECOLOR
-#define WIN32THREADS
-
-/* #define DEBUGMASK            /* */
-#define SET_FOCUS_IN_WINTHREAD
-#define SET_CURSOR_IN_WINTHREAD
-#define DELAY_ENTER_LEAVE_WHILE_IN_SIZE_MOVE /* */
-#define xxBEEP_IN_WINTHREAD    /* */
-#define xxKEEP_STD_CURSORS     /* not useful - those are allocated only once, in any case */
-#define xxHANDLE_VIEWGRAVITY   /* not yet working */
-#define HANDLE_DEVICE_EVENTS
-#define COMPRESS_WINDOWPOSCHANGED
-
-#define USE_DRAW_MUTEX
-#define GDIFLUSH_WHEN_CHANGING_CLIP       /* workaround a redraw problem (with dell?) */
-#define LATE_GENERATE_EXPOSE              /* get update region from stx thread */
-#define xxNO_CLEAR_FOR_WM_PAINT           /* do not fill exposed areas with bgColor */
-#define xxLATE_CLEAR_FOR_WM_PAINT         /* fill exposed areas with bgColor in ST/X thread (instead of in event-thread) */
-					  /* seems to be needed to avoid DC conflicts */
-
-#if 0 /* DOES NOT WORK */
-# define CACHE_LAST_PEN                  /* remember last pen in gcData */
-# define CACHE_LAST_BRUSH                /* remember last brush in gcData */
-# define CACHE_LAST_WM_PAINT_BRUSH       /* remember last viewBackground brush */
-# define CACHE_LAST_WM_PAINT_DC          /* remember last viewBackground paints dc */
-# define CACHE_LAST_TMP_FONT             /* */
-#endif
-
-#define CACHE_PEN
-#define CACHE_BRUSH
-#define CACHE_LAST_DC                   /* remember last DC in gcData */
-
-#ifdef CACHE_PEN
-# define xNUM_PEN_CACHED       16        /* that many solid pens are globally remembered */
-# define NUM_PEN_CACHED       64        /* that many solid pens are globally remembered */
-#else
-# define NUM_PEN_CACHED       0
-#endif
-
-#ifdef CACHE_BRUSH
-# define xNUM_BRUSH_CACHED     16         /* that many brushes are globally remembered */
-# define NUM_BRUSH_CACHED     64         /* that many brushes are globally remembered */
-#else
-# define NUM_BRUSH_CACHED     0
-#endif
-
-#if defined(NO_CLEAR_FOR_WM_PAINT)
-# define WM_PAINT_CLEAR_EARLY       0
-# define WM_PAINT_CLEAR_LATE        0
-#else
-# if defined(LATE_CLEAR_FOR_WM_PAINT)
-#  define WM_PAINT_CLEAR_EARLY       0
-#  define WM_PAINT_CLEAR_LATE        1
-# else
-#  define WM_PAINT_CLEAR_EARLY       1
-#  define WM_PAINT_CLEAR_LATE        0
-# endif
-#endif
-
-#undef INT
-#define INT WIN_INT
-#undef Array
-#define Array WIN_Array
-#undef Number
-#define Number WIN_Number
-#undef Method
-#define Method WIN_Method
-#undef Point
-#define Point WIN_Point
-#undef Rectangle
-/* #define Rectangle WIN_Rectangle */
-#undef True
-#define True WIN_True
-#undef False
-#define False WIN_False
-#undef Block
-#define Block WIN_Block
-#undef Context
-#define Context WIN_Context
-#undef Date
-#define Date WIN_Date
-#undef Time
-#define Time WIN_Time
-#undef Delay
-#define Delay WIN_Delay
-#undef Signal
-#define Signal WIN_Signal
-#undef Set
-#define Set WIN_Set
-#undef Process
-#define Process WIN_Process
-#undef Processor
-#define Processor WIN_Processor
-#undef Message
-#define Message WIN_Message
-#undef String
-#define String WIN_String
-#undef Character
-#define Character WIN_Character
-
-#include <stdio.h>
-#include <errno.h>
-/* #include <malloc.h> */
-/* #include <math.h> */
-/* #include <string.h> */
-
-/*#include <stdarg.h>   */
-
-#ifdef __BORLANDC__
-# define NOATOM
-# define NOGDICAPMASKS
-# define NOMETAFILE
-# define NOMINMAX
-# define NOOPENFILE
-# define NOSOUND
-# define NOWH
-# define NOCOMM
-# define NOKANJI
-# define NOCRYPT
-# define NOMCX
-# define WIN32_LEAN_AND_MEAN
-# ifndef _WIN32_WINNT
-#  define _WIN32_WINNT 0x0500    /* need this to get certain defines from winuser.h (WM_NCXBUTTONDOWN) */
-# endif
-# include <windows.h>
-# include <shellapi.h>
-# ifdef HANDLE_DEVICE_EVENTS
-#  include <dbt.h>
-# endif
-# include <sys\timeb.h>
-# include <dir.h>
-
-#else
-
-# define _USERENTRY /**/
-# define NOATOM
-# define NOGDICAPMASKS
-# define NOMETAFILE
-# define NOMINMAX
-# define NOOPENFILE
-# define NOSOUND
-# define NOWH
-# define NOCOMM
-# define NOKANJI
-# define NOCRYPT
-# define NOMCX
-# define WIN32_LEAN_AND_MEAN
-# ifndef _WIN32_WINNT
-#  define _WIN32_WINNT 0x0500    /* need this to get certain defines from winuser.h (WM_NCXBUTTONDOWN) */
-# endif
-# include <windows.h>
-# ifdef HANDLE_DEVICE_EVENTS
-#  include <dbt.h>
-# endif
-# include <shellapi.h>
-# include <sys\timeb.h>
-#endif
-
-#ifndef MAXPATH
-# define MAXPATH 2048   // not defined in MS Visual C 8
-#endif
-
-#include <commdlg.h>
-
-#include <process.h>
-
-#ifdef __DEF_Array
-# undef Array
-# define Array __DEF_Array
-#endif
-#ifdef __DEF_Number
-# undef Number
-# define Number __DEF_Number
-#endif
-#ifdef __DEF_Method
-# undef Method
-# define Method __DEF_Method
-#endif
-#ifdef __DEF_Point
-# undef Point
-# define Point __DEF_Point
-#endif
-#ifdef __DEF_Rectangle
-# undef Rectangle
-# define Rectangle __DEF_Rectangle
-#else
-# undef Rectangle
-#endif
-#ifdef __DEF_Block
-# undef Block
-# define Block __DEF_Block
-#endif
-#ifdef __DEF_Context
-# undef Context
-# define Context __DEF_Context
-#endif
-#ifdef __DEF_Date
-# undef Date
-# define Date __DEF_Date
-#endif
-#ifdef __DEF_Time
-# undef Time
-# define Time __DEF_Time
-#endif
-# ifdef __DEF_Set
-#  undef Set
-#  define Set __DEF_Set
-# endif
-# ifdef __DEF_Signal
-#  undef Signal
-#  define Signal __DEF_Signal
-# endif
-# ifdef __DEF_Delay
-#  undef Delay
-#  define Delay __DEF_Delay
-# endif
-# ifdef __DEF_Process
-#  undef Process
-#  define Process __DEF_Process
-# endif
-# ifdef __DEF_Processor
-#  undef Processor
-#  define Processor __DEF_Processor
-# endif
-# ifdef __DEF_Message
-#  undef Message
-#  define Message __DEF_Message
-# endif
-# ifdef __DEF_String
-#  undef String
-#  define String __DEF_String
-# endif
-# ifdef __DEF_Character
-#  undef Character
-#  define Character __DEF_Character
-# endif
-
-#if 0 /* does not work, anyway */
-#ifndef WM_UNICHAR
-# define WM_UNICHAR                              0x0109
-#endif
-#ifndef UNICODE_NOCHAR
-# define UNICODE_NOCHAR                          0xFFFF
-#endif
-#endif
-
-#undef INT
-#define INT STX_INT
-#undef UINT
-#define UINT STX_UINT
-
-/*
- * some defines - tired of typing ...
- */
-#define _HANDLEVal(o)        (HANDLE)(__MKCP(o))
-#define _HBITMAPVAL(o)       (HBITMAP)(__MKCP(o))
-#define _HWNDVal(o)          (HWND)(__MKCP(o))
-#define _HDCVal(o)           (HDC)(__MKCP(o))
-#define _HPALETTEVal(o)      (HPALETTE)(__MKCP(o))
-#define _HCURSORVal(o)       (HCURSOR)(__MKCP(o))
-#define _HGDIOBJVal(o)       (HGDIOBJ)(__MKCP(o))
-#define _LOGPALETTEVal(o)    (LOGPALETTE *)(__MKCP(o))
-#define _COLORREFVal(o)      (COLORREF)(__MKCP(o))
-
-#define _GCDATA(o)           ((struct gcData *)(__MKCP(o)))
-
-#define WIDECHAR unsigned short
-
-#ifdef LATER
-  /* for multi-WIN display support, we need this as an instance var (as below)
-   * however, there are many more places, where a single static datum is
-   * used currently - therefore don't care for this - at least now.
-   */
-# define __rootDC             (HDC)(__MKCP(__INST(rootDC)))
-#endif
-
-#define ISCONNECTED         1
-
-struct gcData {
-    union {
-	HDC         __hDC;
-	struct gcData *__nextFree;
-    } u;
-    HWND        hWnd;
-    HBITMAP     hBitmap;
-    HBITMAP     save_hBitmap;
-    HBITMAP     hMask;
-    short       clipX;
-    short       clipY;
-    short       clipW;
-    short       clipH;
-    char        clipping;
-    char        clipByChildren;
-    char        bkMode;
-    char        bitmapColorBitCount;
-    short       maskOrgX;
-    short       maskOrgY;
-    short       lineWidth;
-    short       fontAscent;
-    int         lStyle;   /* is lineStyle | joinStyle | capStyle */
-    int         rop2;
-    int         bitbltrop2;
-    COLORREF    fgColor;
-    COLORREF    bgColor;
-    HFONT       hFont;
-    HFONT       save_hFont;
-    HPEN        hPen;
-    HPEN        save_hPen;
-    HBRUSH      hBrush;
-    HBRUSH      save_hBrush;
-    char        doNotCacheOrRelease;
-    char        reserve1;
-    char        reserve2;
-    char        reserve3;
-    char        reserve4;
-    int         reserve5;
-};
-#define _hDC u.__hDC
-
-/*
- * some synthetic values
- */
-/*****************************************************************
- * EVENT DEFINITIONS
- *****************************************************************/
-
-/* Input Event Masks. Used as event-mask window attribute and as arguments
-   to Grab requests.  Not to be confused with event names.  */
-
-#define NoEventMask                     0L
-#define KeyPressMask                    (1L<<0)
-#define KeyReleaseMask                  (1L<<1)
-#define ButtonPressMask                 (1L<<2)
-#define ButtonReleaseMask               (1L<<3)
-#define EnterWindowMask                 (1L<<4)
-#define LeaveWindowMask                 (1L<<5)
-#define PointerMotionMask               (1L<<6)
-#define PointerMotionHintMask           (1L<<7)
-#define Button1MotionMask               (1L<<8)
-#define Button2MotionMask               (1L<<9)
-#define Button3MotionMask               (1L<<10)
-#if 0
-# define Button4MotionMask               (1L<<11)
-# define Button5MotionMask               (1L<<12)
-#endif
-#define ButtonMotionMask                (1L<<13)
-#define KeymapStateMask                 (1L<<14)
-#define ExposureMask                    (1L<<15)
-#define VisibilityChangeMask            (1L<<16)
-#define StructureNotifyMask             (1L<<17)
-#define ResizeRedirectMask              (1L<<18)
-#define SubstructureNotifyMask          (1L<<19)
-#define SubstructureRedirectMask        (1L<<20)
-#define FocusChangeMask                 (1L<<21)
-#define PropertyChangeMask              (1L<<22)
-#define ColormapChangeMask              (1L<<23)
-#define OwnerGrabButtonMask             (1L<<24)
-
-/* Event names.  Used in "type" field in XEvent structures.  Not to be
-confused with event masks above.  They start from 2 because 0 and 1
-are reserved in the protocol for errors and replies. */
-
-#define KeyPress                2
-#define KeyRelease              3
-#define ButtonPress             4
-#define ButtonRelease           5
-#define MotionNotify            6
-#define EnterNotify             7
-#define LeaveNotify             8
-#define FocusIn                 9
-#define FocusOut                10
-#define KeymapNotify            11
-#define Expose                  12
-#define GraphicsExpose          13
-#define NoExpose                14
-#define VisibilityNotify        15
-#define CreateNotify            16
-#define DestroyNotify           17
-#define UnmapNotify             18
-#define MapNotify               19
-#define MapRequest              20
-#define ReparentNotify          21
-#define ConfigureNotify         22
-#define ConfigureRequest        23
-#define GravityNotify           24
-#define ResizeRequest           25
-#define CirculateNotify         26
-#define CirculateRequest        27
-#define PropertyNotify          28
-#define SelectionClear          29
-#define SelectionRequest        30
-#define SelectionNotify         31
-#define ColormapNotify          32
-#define ClientMessage           33
-#define MappingNotify           34
-#define LASTEvent               35      /* must be bigger than any event # */
-
-/* Key masks. Used as modifiers to GrabButton and GrabKey, results of QueryPointer,
-   state in various key-, mouse-, and button-related events. */
-
-/* modifier names.  Used to build a SetModifierMapping request or
-   to read a GetModifierMapping request.  These correspond to the
-   masks defined above. */
-#define ShiftMapIndex           0
-#define LockMapIndex            1
-#define ControlMapIndex         2
-#define Mod1MapIndex            3
-#define Mod2MapIndex            4
-#define Mod3MapIndex            5
-#define Mod4MapIndex            6
-#define Mod5MapIndex            7
-
-#define ShiftMask               (1<<ShiftMapIndex)
-#define LockMask                (1<<LockMapIndex)
-#define ControlMask             (1<<ControlMapIndex)
-#define Mod1Mask                (1<<Mod1MapIndex)
-#define Mod2Mask                (1<<Mod2MapIndex)
-#define Mod3Mask                (1<<Mod3MapIndex)
-#define Mod4Mask                (1<<Mod4MapIndex)
-#define Mod5Mask                (1<<Mod5MapIndex)
-
-
-/* button masks.  Used in same manner as Key masks above. Not to be confused
-   with button names below. */
-
-#define Button1Mask            Button1MotionMask
-#define Button2Mask            Button2MotionMask
-#define Button3Mask            Button3MotionMask
-#if 0
-# define Button4Mask            Button4MotionMask
-# define Button5Mask            Button5MotionMask
-#endif
-#define AnyButtonMask           (Button1Mask|Button2Mask|Button3Mask)
-
-#if 0
-# define AnyModifier             (1<<15)  /* used in GrabButton, GrabKey */
-#endif
-
-/* button names. Used as arguments to GrabButton and as detail in ButtonPress
-   and ButtonRelease events.  Not to be confused with button masks above.
-   Note that 0 is already defined above as "AnyButton".  */
-
-#define Button1                 1
-#define Button2                 2
-#define Button3                 3
-#if 0
-# define Button4                 4
-# define Button5                 5
-#endif
-
-#define CAPTURE_NONE     0
-#define CAPTURE_IMPLICIT 7
-#define CAPTURE_EXPLICIT 8
-
-#define BK_UNDEF         0
-#define BK_TRANSPARENT   1
-#define BK_OPAQUE        2
-
-#define GRAVITY_NONE        0
-#define GRAVITY_S           1
-#define GRAVITY_SW          2
-#define GRAVITY_SE          3
-#define GRAVITY_N           4
-#define GRAVITY_NW          5
-#define GRAVITY_NE          6
-#define GRAVITY_E           7
-#define GRAVITY_W           8
-
-#if 0
-# define ControlMask            8
-# define ShiftMask              16
-#endif
-#define LeftAltMask            Mod1Mask
-#define RightAltMask           Mod2Mask
-#define TRANSLATED_KEY         Mod5Mask
-
-#define WIN32PADDING 32
-
-/*
- * synthetic events
- */
-#define __WM_MOUSEENTER        0x10001
-#define __WM_MOUSELEAVE        0x10002
-#define __WM_GEXPOSE           0x10003
-#define __WM_NOGEXPOSE         0x10004
-#define __WM_ICONIFIED         0x10005
-#define __WM_PAINT             0x10006
-
-static int AltMask = RightAltMask;
-static int MetaMask = LeftAltMask;
-
-#define WhitePixel     RGB(0xFF, 0xFF, 0xFF)
-#define BlackPixel     RGB(0, 0, 0)
-
-/* #undef DEBUG /* */
-
-#ifdef DEBUG
-# define PRINTF(x)              { console_printf x;}
-# define CPRINTF(x)             { if (__debug__ % 1) console_printf x;}
-# define RESPRINTF(x)           /*{ if (__debug__) console_printf x;}*/
-# define RES1PRINTF(x)          /*{ if (__debug__) console_printf x;}*/
-# define RES_BMP_PRINTF(x)      /*{ if (__debug__) console_printf x;}*/
-# define TH_DPRINTF(x)          /*{ if (__debug__) console_printf x;}*/
-# define DPRINTF(x)             { if (__debug__) console_printf x;}
-# define NDPRINTF(x)            { if (__debugNative__) console_printf x;}
-# define NDPRINTF2(x)           { if (__debugNative__ > 1) console_printf x;}
-# define DDPRINTF(x)            { if (__debug__ & 2) console_printf x;}
-# define DDDPRINTF(x)           { if (__debug__ & 4) console_printf x;}
-# define DDDDPRINTF(x)          { if (__debug__ & 16) console_printf x;}
-# define BMDPRINTF(x)           { if (__debug__ & 2) console_printf x;}
-# define EVENT_PRINTF(x)        { if (__debug__ & 8) console_printf x;}
-# define EVENT_PRINTF2(x)       { if (__debug__ & 4) console_printf x;}
-# define EVENT_PRINTF3(x)       /* */
-# define DPRINTFIF(flag, x)                 { if (flag) console_printf x;}
-# define EVENT_PRINTFIF(flag, x)            { if (flag && __debug__) console_printf x;}
-# define UNHANDLED_EVENT_PRINTF(x)          { if (__debug__) { console_printf("unhandled: "); console_printf x; } }
-# define UNHANDLED_EVENT_PRINTFIF(flag, x)  { if (flag && __debug__) { console_printf("unhandled: "); console_printf x; } }
-#else
-# define PRINTF(x)              /* */
-# define CPRINTF(x)             /* */
-# define RES_BMP_PRINTF(x)      /* */
-# define RESPRINTF(x)           /* */
-# define RES1PRINTF(x)          /* */
-# define TH_DPRINTF(x)          /* */
-# define DPRINTF(x)             /* */
-# define NDPRINTF(x)            /* */
-# define NDPRINTF2(x)           /* */
-# define DDPRINTF(x)            /* */
-# define DDDPRINTF(x)           /* */
-# define DDDDPRINTF(x)          /* */
-# define BMDPRINTF(x)           /* */
-# define EVENT_PRINTF(x)        /* */
-# define EVENT_PRINTF2(x)       /* */
-# define EVENT_PRINTF3(x)       /* */
-# define DPRINTFIF(flag, x)             /* */
-# define EVENT_PRINTFIF(flag, x)        /* */
-# define UNHANDLED_EVENT_PRINTF(x)      /* */
-# define UNHANDLED_EVENT_PRINTFIF(flag, x)    /* */
-#endif
-
-extern void __internalError(char *);
-
-/* # define EVENT_PRINTF(x)        { printf x;} */
-
-#define INFOFPRINTF(__x__)                 \
-    if (@global(InfoPrinting) == true) { \
-	console_fprintf __x__;           \
-    }
-
-#define DEBUGFPRINTF(__x__)                 \
-    if (@global(InfoPrinting) == true) { \
-	console_fprintf __x__;           \
-    }
-
-#define BR_SOLID       0
-#define BR_PATTERN     1
-
-#define LINE_SOLID     0
-#define LINE_DASH      1
-#define LINE_DDASH     2
-
-#ifdef KEEP_STD_CURSORS
-# define _C_ARROW       1
-# define _C_CROSS       2
-# define _C_IBEAM       3
-# define _C_ICON        4
-# define _C_NO          5
-# define _C_SIZE        6
-# define _C_SIZEALL     7
-# define _C_SIZENESW    8
-# define _C_SIZENS      9
-# define _C_SIZENWSE    10
-# define _C_UPARROW     11
-# define _C_WAIT        12
-
- static HCURSOR H_C_ARROW = (HCURSOR)0;
- static HCURSOR H_C_CROSS = (HCURSOR)0;
- static HCURSOR H_C_IBEAM = (HCURSOR)0;
- static HCURSOR H_C_ICON = (HCURSOR)0;
- static HCURSOR H_C_NO = (HCURSOR)0;
- static HCURSOR H_C_SIZE = (HCURSOR)0;
- static HCURSOR H_C_SIZEALL = (HCURSOR)0;
- static HCURSOR H_C_SIZENESW = (HCURSOR)0;
- static HCURSOR H_C_SIZENS = (HCURSOR)0;
- static HCURSOR H_C_SIZENWSE = (HCURSOR)0;
- static HCURSOR H_C_UPARROW = (HCURSOR)0;
- static HCURSOR H_C_WAIT = (HCURSOR)0;
- static HCURSOR H_C_APPSTARTING = (HCURSOR)0;
-#endif /* KEEP_STD_CURSORS */
-
-#ifdef EXIT_WITH_3_CTRL_Cs
-static int ctrl_c_count = 0;            /* CTRL-C count */
-#endif
-#ifdef RELEASE_CAPTURE_WITH_3_ESCAPEs
-static int escape_count = 0;            /* ESCAPE count */
-#endif
-
-static int evRootX, evRootY;
-static int multiClickCount = 0;
-static UINT lastMSGTime;
-static UINT lastMouseWheelTime = 0;
-static int lastClickX, lastClickY;
-static int lastMotionX = -9999, lastMotionY = -9999;
-static HWND lastMotionWnd = 0;
-static int deltaDoubleClickX = -999;
-static int deltaDoubleClickY = -999;
-static UINT nextMultiClickTime;
-static OBJ lastButton = 0;
-static int inSizeMove = 0;
-static int inSize = 0;
-static int inMove = 0;
-static HWND needDelayedMouseLeaveWindow = 0;
-static HWND needDelayedMouseEnterWindow = 0;
-static int delayedMouseEnterX, delayedMouseEnterY;
-static int destroyWin;
-static HDC   __tmpDC;
-#ifdef CACHE_LAST_TMP_FONT
-static HFONT __tmpDC_hfont = 0, __tmpDC_prev_hfont = 0;
-#endif
-static int __logPixelSY;
-
-static int __isWinXP = 0;
-static int __isWin2k = 0;
-static int __isWinVista = 0;
-
-#ifdef CACHE_LAST_DC
-static struct gcData *lastGcData = 0;
-static int            lastGcOwnerThreadID = 0;
-static HWND           lastGcHWIN;
-static HBITMAP        lastGcHBITMAP;
-#endif
-
-#ifndef __rootDC
- static HDC __rootDC;
-#endif
-
-#ifdef CACHE_PEN
-static struct __penCache {
-    HPEN            pen;
-    unsigned int    clr;
-} __penCache[NUM_PEN_CACHED];
-#endif
-
-#ifdef CACHE_BRUSH
-static struct __brushCache {
-    HBRUSH          brush;
-    unsigned int    clr;
-} __brushCache[NUM_BRUSH_CACHED];
-#endif
-
-/*
- * globally cached - never released
- */
-static HPEN __blackPen = 0;
-static HPEN __whitePen = 0;
-static HPEN __nullPen = 0;
-static HBRUSH __blackBrush = 0;
-static HBRUSH __whiteBrush = 0;
-
-static HPEN __bgPen = 0;
-static int __bgPenColor = 0;
-
-#define WM_THREAD_CREATEWINDOW     (WM_USER + 0x101)
-#define WM_THREAD_DESTROYWINDOW    (WM_USER + 0x102)
-#define WM_THREAD_SETFOCUS         (WM_USER + 0x103)
-#define WM_THREAD_SETCAPTURE       (WM_USER + 0x104)
-#define WM_THREAD_SETCURSOR        (WM_USER + 0x105)
-#define WM_THREAD_BEEP             (WM_USER + 0x106)
-#define WM_THREAD_REGISTERHOTKEY   (WM_USER + 0x107)
-#define WM_THREAD_UNREGISTERHOTKEY (WM_USER + 0x108)
-
-#define WM_TRAY_MESSAGE          (WM_USER + 0x200)
-
-#define hasEventQueued() (eventQueueHead != NULL)
-#define EVENT_THREAD_STACKSIZE  (4096*10)
-
-typedef int (*intf)(int);
-
-/*
- * keep the windows cursor and others local in the HWND struct.
- */
-#define LI_TOPWIN       0x0001
-#define LI_INPUTWIN     0x0002
-#define LI_NATIVEWIN    0x0004
-
-typedef struct {
-	HCURSOR         hCursor;
-	HBRUSH          viewBgBrush;  /* if that is nil, it has a solid bg color */
-	COLORREF        viewBgColor;
-	int             eventMask;
-	short           flag;         /* LI_ - flags bits */
-	short           minWidth;
-	short           maxWidth;
-	short           minHeight;
-	short           maxHeight;
-	short           currentMonitorWidth;
-	short           currentMonitorHeight;
-	short           bw;
-	unsigned char   iconified;
-	unsigned char   viewGravity;
-	unsigned char   unmapping;
-#if 0
-	short           bgOffsX;      /* bg-pattern offset */
-	short           bgOffsY;      /* bg-pattern offset */
-#endif
-	short           mouseX;       /* last mouseX */
-	short           mouseY;       /* last mouseY */
-	COLORREF        bdColor;
-} localWindowInfo;
-typedef localWindowInfo *plocalWindowInfo;
-
-typedef struct createWindowInfo {
-	localWindowInfo *localWindowInfo;  /* in param */
-	HANDLE          newWinHandle;      /* out param */
-	wchar_t         *windowName;       /* in params */
-	wchar_t         *className;
-	int             winStyleBits;
-	int             winStyleBitsEx;
-	HANDLE          parentHandle;
-	int             x;
-	int             y;
-	int             dx;
-	int             dy;
-	HANDLE          hCreateEvent;
-	short           infoWasRead;
-	unsigned short  sequenceNr;
-	unsigned        errCode;
-} createWindowInfo;
-
-#define INVALIDATED_CWI 0xFFFF             /* seqNr for invalidated CWI */
-
-static createWindowInfo *pendingCREATEWINDOWInfo = 0;
-static unsigned short pendingSequenceNr = INVALIDATED_CWI;
-
-#define N_WINDOW_PRIVATE (sizeof(plocalWindowInfo))
-
-#ifdef _WIN64
-
-# define GWL_LOCALINFO  GWLP_USERDATA
-
-# define SETLOCALWINDOWINFOPTR(__hWnd__,__ptr__) \
-	SetWindowLongPtr(__hWnd__, GWL_LOCALINFO , (LONG_PTR)__ptr__)
-
-# define GETLOCALWINDOWINFOPTR(__hWnd__) \
-	((localWindowInfo *)GetWindowLongPtr(__hWnd__, GWL_LOCALINFO))
-
-#else
-
-# define GWL_LOCALINFO  GWL_USERDATA
-
-# define SETLOCALWINDOWINFOPTR(__hWnd__,__ptr__) \
-	SetWindowLong(__hWnd__, GWL_LOCALINFO , (DWORD)__ptr__)
-
-# define GETLOCALWINDOWINFOPTR(__hWnd__) \
-	((localWindowInfo *)GetWindowLong(__hWnd__, GWL_LOCALINFO))
-
-#endif
-
-#define SetWindow_Cursor(__hWnd__, __hCurs__) \
-	(GETLOCALWINDOWINFOPTR(__hWnd__) ? (GETLOCALWINDOWINFOPTR(__hWnd__)->hCursor = __hCurs__) : 0)
-
-#define GetWindow_Cursor(__hWnd__) \
-	(GETLOCALWINDOWINFOPTR(__hWnd__) ? GETLOCALWINDOWINFOPTR(__hWnd__)->hCursor : 0)
-
-#define SetWindow_viewBgColor(__hWnd__, __viewBgColor__) \
-	(GETLOCALWINDOWINFOPTR(__hWnd__) ? (GETLOCALWINDOWINFOPTR(__hWnd__)->viewBgColor = __viewBgColor__) : 0)
-
-#define GetWindow_viewBgColor(__hWnd__) \
-	(GETLOCALWINDOWINFOPTR(__hWnd__) ? GETLOCALWINDOWINFOPTR(__hWnd__)->viewBgColor : 0)
-
-#define SetWindow_bdColor(__hWnd__, __bdColor__) \
-	(GETLOCALWINDOWINFOPTR(__hWnd__) ? (GETLOCALWINDOWINFOPTR(__hWnd__)->bdColor = __bdColor__) : 0)
-
-#define GetWindow_bdColor(__hWnd__) \
-	(GETLOCALWINDOWINFOPTR(__hWnd__) ? GETLOCALWINDOWINFOPTR(__hWnd__)->bdColor : 0)
-
-#define SetWindow_iconified(__hWnd__, __iconified__) \
-	(GETLOCALWINDOWINFOPTR(__hWnd__) ? (GETLOCALWINDOWINFOPTR(__hWnd__)->iconified = __iconified__) : 0)
-
-#define GetWindow_iconified(__hWnd__) \
-	(GETLOCALWINDOWINFOPTR(__hWnd__) ? GETLOCALWINDOWINFOPTR(__hWnd__)->iconified : 0)
-
-#define SetWindow_unmapping(__hWnd__, __unmapping__) \
-	(GETLOCALWINDOWINFOPTR(__hWnd__) ? (GETLOCALWINDOWINFOPTR(__hWnd__)->unmapping = __unmapping__) : 0)
-
-#define GetWindow_unmapping(__hWnd__) \
-	(GETLOCALWINDOWINFOPTR(__hWnd__) ? GETLOCALWINDOWINFOPTR(__hWnd__)->unmapping : 0)
-
-#define SetWindow_mouseX(__hWnd__, __mouseX__) \
-	(GETLOCALWINDOWINFOPTR(__hWnd__) ? (GETLOCALWINDOWINFOPTR(__hWnd__)->mouseX = __mouseX__) : 0)
-
-#define GetWindow_mouseX(__hWnd__) \
-	(GETLOCALWINDOWINFOPTR(__hWnd__) ? GETLOCALWINDOWINFOPTR(__hWnd__)->mouseX : 0)
-
-#define SetWindow_mouseY(__hWnd__, __mouseY__) \
-	(GETLOCALWINDOWINFOPTR(__hWnd__) ? (GETLOCALWINDOWINFOPTR(__hWnd__)->mouseY = __mouseY__) : 0)
-
-#define GetWindow_mouseY(__hWnd__) \
-	(GETLOCALWINDOWINFOPTR(__hWnd__) ? GETLOCALWINDOWINFOPTR(__hWnd__)->mouseY : 0)
-
-#define SetWindow_mouseXY(__hWnd__, __mouseX__, __mouseY__) \
-	{ SetWindow_mouseX(__hWnd__, __mouseX__); SetWindow_mouseY(__hWnd__, __mouseY__); }
-
-#define SetWindow_viewBgBrush(__hWnd__, __viewBgBrush__) \
-	(GETLOCALWINDOWINFOPTR(__hWnd__) ? (GETLOCALWINDOWINFOPTR(__hWnd__)->viewBgBrush = __viewBgBrush__) : (HBRUSH)0)
-
-#define GetWindow_viewBgBrush(__hWnd__) \
-	(GETLOCALWINDOWINFOPTR(__hWnd__) ? GETLOCALWINDOWINFOPTR(__hWnd__)->viewBgBrush : (HBRUSH)0)
-
-#define SetWindow_bw(__hWnd__, __bw__) \
-	(GETLOCALWINDOWINFOPTR(__hWnd__) ? (GETLOCALWINDOWINFOPTR(__hWnd__)->bw = __bw__) : 0)
-
-#define GetWindow_bw(__hWnd__) \
-	(GETLOCALWINDOWINFOPTR(__hWnd__) ? GETLOCALWINDOWINFOPTR(__hWnd__)->bw : 0)
-
-#define GetWindow_paintInfoPtr(__hWnd__) \
-	(GETLOCALWINDOWINFOPTR(__hWnd__) ? &(GETLOCALWINDOWINFOPTR(__hWnd__)->paintInfo) : 0)
-
-#define SetWindow_flag(__hWnd__, __flag__) \
-	(GETLOCALWINDOWINFOPTR(__hWnd__) ? (GETLOCALWINDOWINFOPTR(__hWnd__)->flag = __flag__) : 0)
-
-#define GetWindow_flag(__hWnd__) \
-	(GETLOCALWINDOWINFOPTR(__hWnd__) ? GETLOCALWINDOWINFOPTR(__hWnd__)->flag : 0)
-
-#define GetWindow_eventMask(__hWnd__) \
-	(GETLOCALWINDOWINFOPTR(__hWnd__) ? (GETLOCALWINDOWINFOPTR(__hWnd__)->eventMask) : 0)
-
-#define SetWindow_currentMonitorWidth(__hWnd__, __width__) \
-	(GETLOCALWINDOWINFOPTR(__hWnd__) ? (GETLOCALWINDOWINFOPTR(__hWnd__)->currentMonitorWidth = __width__) : 0)
-
-#define SetWindow_currentMonitorHeight(__hWnd__, __height__) \
-	(GETLOCALWINDOWINFOPTR(__hWnd__) ? (GETLOCALWINDOWINFOPTR(__hWnd__)->currentMonitorHeight = __height__) : 0)
-
-
-struct queuedEvent {
-	struct queuedEvent     *ev_next;
-	int                     count;
-	int                     ev_flag;
-	HWND                    ev_hWnd;
-	UINT                    ev_message;
-	UINT                    ev_wParam;
-	INT                     ev_arg1;
-	INT                     ev_arg2;
-	INT                     ev_arg3;
-	INT                     ev_arg4;
-	UINT                    ev_time;
-};
-
-#define ev_x    ev_arg1
-#define ev_y    ev_arg2
-#define ev_w    ev_arg3
-#define ev_h    ev_arg4
-
-#define ev_keyCode   ev_wParam
-#define ev_scanCode  ev_arg3
-#define ev_modifiers ev_arg4
-
-#define EV_CHUNK_CNT    10000
-#define xxEV_CHUNK_CNT    1000
-#define EV_CHUNK_SZ     (EV_CHUNK_CNT*sizeof(struct queuedEvent))
-
-#define BITBLT_COPY             SRCCOPY
-#define BITBLT_COPYINVERTED     NOTSRCCOPY
-#define BITBLT_XOR              SRCINVERT
-#define BITBLT_AND              SRCAND
-#define BITBLT_OR               SRCPAINT
-
-typedef struct registerHotKeyInfo {
-	HANDLE       hwnd;          /* in param */
-	int          hotKeyId;      /* in param */
-	unsigned int modifier;      /* in param */
-	unsigned int virtualKey;    /* in params */
-	int          finished;      /* out param */
-	int          errorCode;     /* out param */
-} registerHotKeyInfo;
-
-/*
-    Attention: the following struct has to be the same as in:
-	stx/support/win32/nativeFileDialog/nativeFileDialog.h
-
-    it would be nicer to have this h file as include in WinWorkstation.st
-    but if you do so,
-    stx can not compile at runtime due to using a temp directoy for compile
-*/
-typedef struct fileDialogDataStruct {
-    WCHAR filename[1000 * MAX_PATH]; // big buffer to support multiselect
-    WCHAR directory[MAX_PATH];
-    WCHAR title[MAX_PATH];
-    HWND owningWindow;
-    WCHAR filter[10 * MAX_PATH]; // there could be many filters
-    DWORD filterIndex;
-    BOOL trueForSave;
-    BOOL trueForMultiSelect;
-    BOOL trueForPromptOverwrite;
-
-    DWORD fileDialogThreadId;
-    BOOL fileDialogDidReturn;
-    BOOL fileDialogErrorInInitialize;
-    BOOL didPerformCroppedBaseNameHack; /* the open dialog cropps the default basename https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/644328 */
-} fileDialogData;
-
-BOOL CALLBACK enumWindowsToFindAndDestroyFileDialogProc(HWND hwnd, LPARAM fileDialogThreadId) {
-    if (GetWindowThreadProcessId(hwnd, NULL) == (DWORD)fileDialogThreadId) {
-	PostMessage(hwnd, WM_COMMAND, IDCANCEL, 0);
-    }
-
-    return TRUE;
-};
-
-BOOL CALLBACK enumChildWindowsForCroppedBaseNameHackProc(HWND hwnd, LPARAM lparam) {
-    fileDialogData *pFdd = (fileDialogData*)lparam;
-    char className[5];
-
-    GetClassName(hwnd, className, sizeof(className));
-    if (strcmp("Edit", className) == 0) {
-	if (IsWindowVisible(hwnd)) {
-	    LONG lAlign = GetWindowLong(hwnd, GWL_EXSTYLE);
-
-	    lAlign ^= WS_EX_RTLREADING;
-	    SetWindowLong(hwnd, GWL_EXSTYLE, lAlign);
-	    lAlign ^= WS_EX_RTLREADING;
-	    SetWindowLong(hwnd, GWL_EXSTYLE, lAlign);
-
-	    pFdd->didPerformCroppedBaseNameHack = TRUE;
-	}
-    }
-
-    return TRUE;
-};
-
-BOOL CALLBACK enumWindowsToForCroppedBaseNameHackProc(HWND hwnd, LPARAM lparam) {
-    fileDialogData *pFdd = (fileDialogData*)lparam;
-
-    if (GetWindowThreadProcessId(hwnd, NULL) == (DWORD)pFdd->fileDialogThreadId) {
-	EnumChildWindows(hwnd, enumChildWindowsForCroppedBaseNameHackProc, lparam);
+poolDictionaries:''
+	privateIn:WinWorkstation
+! !
+
+!WinWorkstation primitiveVariables!
+param);
     }
 
     return TRUE;
@@ -1032,4351 +94,14 @@
 %}
 ! !
 
-!WinWorkstation primitiveVariables!
-%{
-
-static int firstInstance = 1;
-static char *app_name = "ST/X";
-static char *app_nameRoot = "ST/X:Root";
-static char *app_namePopup = "ST/X:Popup";
-static char *app_nameDialog = "ST/X:Dialog";
-static wchar_t wapp_name[] = { 'S','T','/','X',0 };
-static wchar_t wapp_nameRoot[] = { 'S','T','/','X',':','R','o','o','t',0 };
-static wchar_t wapp_namePopup[] = { 'S','T','/','X',':','P','o','p','u','p',0 };
-static wchar_t wapp_nameDialog[] = { 'S','T','/','X',':','D','i','a','l','o','g',0 };
-static int __debug__ = 0;
-
-static int __debug_WM_ALL__ = 0;
-static int __debug_WM_MOUSEENTER__ = 0;
-static int __debug_WM_MOUSELEAVE__ = 0;
-static int __debug_WM_MOUSEMOVE__ = 0;
-static int __debug_WM_MOUSEACTIVATE__ = 0;
-static int __debug_WM_CHAR__ = 0;
-static int __debug_WM_KEYUP__ = 0;
-static int __debug_WM_KEYDOWN__ = 0;
-static int __debug_WM_BUTTONUP__ = 0;
-static int __debug_WM_BUTTONDOWN__ = 0;
-static int __debug_WM_PAINT__ = 0;
-static int __debug_WM_MOVING__ = 0;
-static int __debug_WM_ERASEBKGND__ = 0;
-static int __debug_WM_SETTEXT__ = 0;
-static int __debug_WM_CTLCOLORSCROLLBAR__ = 0;
-static int __debug_WM_GETICON__ = 0;
-static int __debug_WM_EXPOSE__ = 0;
-static int __debug_WM_SIZE__ = 0;
-static int __debug_WM_WINDOWPOSCHANGING__ = 0;
-static int __debug_WM_COPYDATA__ = 0;
-static int __debug_WM_DROPFILES__ = 0;
-static int __debug_WM_SHOWWINDOW__ = 0;
-static int __debug_WM_SETCURSOR__ = 0;
-static int __debug_WM_FOCUS__ = 0;
-
-static int __debugNative__ = 0;
-static int __depth;
-static int __realDepth;
-static HWND __rootWin = NULL;
-static HWND __rootWinSpezial = NULL;
-#if 0
-static HDESK __rootDesk;
-#endif
-
-static int __activateOnClick = 1;
-static int __focusFollowsMouse = 0;
-static int __eatingMouseEvents = 0;
-static int __ignoreButtonPressOnActivate = 0;
-static int __rightButtonIsLowerWindow = 1;
-static int __shiftedLeftButtonIsLowerWindow = 1;
-static int __currentCapture = CAPTURE_NONE;
-
-static HANDLE __currentPointerView = (HANDLE)0;
-
-/* MessageDispatchThread */
-
-#ifndef WIN32THREADS
-static HANDLE _masterThread = NULL;
-#endif
-static DWORD _masterThreadId = 0;
-static DWORD _dispatchThreadId = 0;
-static DWORD _dispatchThreadId2 = 0;
-#ifdef LOCK_DEBUG
-static int lockCountEvents = 0;
-#endif
-static HANDLE hEventsMutex = NULL;
-static char *hEventsMutexOwner = NULL;
-
-#ifdef USE_PAINT_MUTEX
-static HANDLE hPaintMutex = NULL;
-# define AQUIRE_PAINT_MUTEX    { WaitForSingleObject(hPaintMutex, 100L); }
-# define RELEASE_PAINT_MUTEX   { ReleaseMutex(hPaintMutex);              }
-#else
-# define AQUIRE_PAINT_MUTEX    { /* nothing */ }
-# define RELEASE_PAINT_MUTEX   { /* nothing */ }
-#endif
-
-#ifdef USE_DRAW_MUTEX
-static HANDLE hDrawMutex = NULL;
-# define AQUIRE_DRAW_MUTEX     { WaitForSingleObject(hDrawMutex, 100L);  }
-# define RELEASE_DRAW_MUTEX    { ReleaseMutex(hDrawMutex);  }
-#else
-# define AQUIRE_DRAW_MUTEX     { /* nothing */ }
-# define RELEASE_DRAW_MUTEX    { /* nothing */ }
-#endif
-
-static HANDLE hCreateEvent = NULL;
-static HANDLE hNeverTriggered = NULL;
-static HANDLE hInputEvent = NULL;
-static HANDLE hDispatchThreadRunningEvent = NULL;
-
-#ifdef COUNT_RESOURCES
- static int __cnt_gcData;
- static int __cnt_createWindows;
- static int __cnt_cur;
- static int __cnt_font;
-#endif
-#ifdef COUNT_BMP_RESOURCES
- static int __cnt_bitmap;
-#endif
-
-static struct queuedEvent *eventFreeList  = (struct queuedEvent *) 0;
-static struct queuedEvent *eventQueueHead = (struct queuedEvent *) 0;
-static struct queuedEvent *eventQueueTail = (struct queuedEvent *) 0;
-static int eventsendcount = 0;
-static int eventempfcount = 0;
-
-/*
- * up to NUM_FREE_GC gc's are kept in a local list
- * (away from free/malloc)
- */
-#define xNUM_FREE_GC     50
-#define NUM_FREE_GC     150
-static struct gcData *gcDataFreeList = (struct gcData *)0;
-static int gcDataNumFree = 0;
-
-/*
- * remember the last background-paint brush
- * will be reused by next bg-paint, if it needs
- * the same color. Otherwise, the next bg-erase
- * will destroy this brush.
- */
-#ifdef CACHE_LAST_WM_PAINT_BRUSH
- static HBRUSH last_wm_paint_brush = (HBRUSH) 0;
- static int    last_wm_paint_brush_clr = (HWND) 0;
-#endif
-#ifdef CACHE_LAST_WM_PAINT_DC
- static HWND last_wm_paint_win = 0;
- static HDC  last_wm_paint_dc = 0;
-#endif
-
-#ifdef COMPRESS_WINDOWPOSCHANGED
- static HWND lastPos_win = 0;
- static int lastPos_w;
- static int lastPos_h;
- static int lastPos_x;
+!WinWorkstation primitiveFunctions!
+_x;
  static int lastPos_y;
 #endif
 
 %}
 ! !
 
-!WinWorkstation primitiveFunctions!
-%{
-
-extern HANDLE __getHInstance();
-
-static void __debugEvent__() {}
-
-#ifdef DEBUGMASK
-static void
-printMask(int mask) {
-        if (mask & KeyPressMask)        console_printf("KeyPressMask\n");
-        if (mask & KeyReleaseMask)      console_printf("KeyReleaseMask\n");
-        if (mask & ButtonPressMask)     console_printf("ButtonPressMask\n");
-        if (mask & ButtonReleaseMask)   console_printf("ButtonReleaseMask\n");
-        if (mask & ButtonMotionMask)    console_printf("ButtonMotionMask\n");
-        if (mask & PointerMotionMask)   console_printf("PointerMotionMask\n");
-        if (mask & ExposureMask)        console_printf("ExposureMask\n");
-        if (mask & FocusChangeMask)     console_printf("FocusChangeMask\n");
-        if (mask & EnterWindowMask)     console_printf("EnterWindowMask\n");
-        if (mask & LeaveWindowMask)     console_printf("LeaveWindowMask\n");
-        if (mask & KeymapStateMask)     console_printf("KeymapStateMask\n");
-        if (mask & VisibilityChangeMask)console_printf("VisibilityChangeMask\n");
-        if (mask & StructureNotifyMask) console_printf("StructureNotifyMask\n");
-        if (mask & ResizeRedirectMask)  console_printf("ResizeRedirectMask\n");
-        if (mask & PropertyChangeMask)  console_printf("PropertyChangeMask\n");
-        if (mask & ColormapChangeMask)  console_printf("ColormapChangeMask\n");
-}
-#endif
-
-static int
-st2RGB(int color, struct gcData *gcData)
-{
-        if (gcData && gcData->bitmapColorBitCount == 1) {
-            return (color ? WhitePixel : BlackPixel);
-        }
-#ifdef ALWAYSTRUECOLOR
-        return (color & 0xffffff);
-#else
-        if (__depth < 15) {
-            return 0;
-        } else {
-            if ((__depth == 16) || (__depth == 15)) {
-                int ib = (color & 0x1f) << 3;
-                int ig = ((color >> 5) & 0x3f) << 2;
-                int ir = ((color >> 11) & 0x1f) << 3;
-                ir |= 7;
-                ig |= 3;
-                ib |= 7;
-                return RGB(ir,ig,ib);
-            }
-            return (color & 0xffffff);
-        }
-#endif
-}
-
-static int
-RGB2st(int r, int g, int b)
-{
-        int ir,ig,ib,id;
-
-#ifdef ALWAYSTRUECOLOR
-        ir = (r >> 8) & 0xff;
-        ig = (g >> 8) & 0xff;
-        ib = (b >> 8) & 0xff;
-
-        id = RGB( ir, ig, ib);
-#else
-        if (__depth < 15) {
-            id = 0;
-        } else {
-            if ((__depth == 16) || (__depth == 15)) {
-                ir = (r >> 11) & 0x1f;
-                ig = (g >> 10) & 0x3f;
-                ib = (b >> 11) & 0x1f;
-
-                id = ( ir << 11 ) | ( ig << 5 ) | ib;
-            } else {
-                ir = (r >> 8) & 0xff;
-                ig = (g >> 8) & 0xff;
-                ib = (b >> 8) & 0xff;
-
-                id = RGB( ir, ig, ib);
-            }
-        }
-#endif
-        return id;
-}
-
-#if 0
-/*
- * return a windows top-window
- */
-static HWND
-GetTopParent(HWND hwnd)
-{
-        HWND lastParent = hWnd;
-        HWND nextParent;
-
-        while (nextParent = GetParent(lastParent)) {
-            lastParent = nextParent;
-        }
-        return lastParent;
-}
-#endif
-
-#ifdef DEBUG_DELETEOBJECT
-
-static int
-_DeleteObject(HANDLE o, int lineNr)
-{
-    int r = DeleteObject(o);
-
-    if (r == 0)
-        console_fprintf(stderr, "WinWorkstation [warning]: ERROR in DeleteObject %x [%d]\n", o, lineNr);
-    return r;
-}
-
-#else
-# define _DeleteObject(o,lnr)  DeleteObject(o)
-#endif
-
-static void
-_DeleteFont(HFONT f, int lineNr)
-{
-#ifdef CACHE_LAST_TMP_FONT
-    if (f == __tmpDC_hfont) {
-        SelectObject(__tmpDC, __tmpDC_prev_hfont);
-        __tmpDC_hfont = NULL;
-    }
-#endif
-    _DeleteObject(f, lineNr);
-}
-
-static int
-_DeleteBrush(HBRUSH br, int lineNr)
-{
-    if ((br != __whiteBrush) && (br != __blackBrush)) {
-        int r = DeleteObject(br);
-
-        if (r == 0)
-            console_fprintf(stderr, "WinWorkstation [warning]: ERROR in DeleteBrush %x [%d]\n", br, lineNr);
-        return r;
-    }
-    return 1;
-}
-
-static int
-_DeletePen(HPEN p, int lineNr)
-{
-    if ((p != __whitePen) && (p != __blackPen)) {
-        int r = DeleteObject(p);
-
-        if (r == 0)
-            console_fprintf(stderr, "WinWorkstation [warning]: ERROR in DeletePen %x [%d]\n", p, lineNr);
-        return r;
-    }
-    return 1;
-}
-
-#ifdef CACHE_PEN
-
-static int
-_DeletePenIfNotInCache(HPEN p, int lineNr)
-{
-    int i, r;
-
-    if ((p == __whitePen) || (p == __blackPen)) {
-        return 1; /* not deleted, but OK */
-    }
-    for (i=0; i<NUM_PEN_CACHED;i++) {
-        if (__penCache[i].pen == p) {
-            return 1; /* not deleted, but OK */
-        }
-    }
-    r = DeleteObject(p);
-
-    if (r == 0)
-        console_fprintf(stderr, "WinWorkstation [warning]: ERROR in DeletePen2 %x [%d]\n", p, lineNr);
-    return r;
-}
-
-#else
-# define _DeletePenIfNotInCache(p, lineNr)   _DeletePen(p, lineNr)
-#endif /* CACHE_PEN */
-
-#ifdef CACHE_BRUSH
-
-static int
-_DeleteBrushIfNotInCache(HBRUSH br, int lineNr)
-{
-    int i, r;
-
-    for (i=0; i<NUM_BRUSH_CACHED;i++) {
-        if (__brushCache[i].brush == br) {
-            return 1; /* not deleted, but OK */
-        }
-    }
-    if ((br == __whiteBrush) || (br == __blackBrush)) {
-        return 1; /* not deleted, but OK */
-    }
-    r = DeleteObject(br);
-
-    if (r == 0)
-        console_fprintf(stderr, "WinWorkstation [warning]: ERROR in DeleteBrush2 %x [%d]\n", br, lineNr);
-    return r;
-}
-
-#else
-# define _DeleteBrushIfNotInCache(br, lineNr)   _DeleteBrush(br, lineNr)
-#endif /* CACHE_BRUSH */
-
-static struct gcData *
-newGcData(void)
-{
-    struct gcData *gcData;
-
-    if (gcDataFreeList) {
-        gcData = gcDataFreeList;
-        gcDataFreeList = gcData->u.__nextFree;
-        gcDataNumFree--;
-    } else {
-        gcData = (struct gcData *) malloc(sizeof(struct gcData));
-        if (! gcData) {
-            console_fprintf(stderr, "WinWorkstat [warning]: failed to allocate gcData\n");
-            return 0;
-        }
-    }
-
-    memset(gcData, 0, sizeof(struct gcData));
-    gcData->fgColor = 0xffffff;
-    /* gcData->bgColor = 0; - not needed - memset does it */
-    gcData->clipping = FALSE;
-    gcData->clipByChildren = TRUE;
-    gcData->bitbltrop2 = BITBLT_COPY;
-    gcData->lineWidth = 1;
-    gcData->lStyle = PS_SOLID | PS_JOIN_MITER | PS_ENDCAP_FLAT;
-    /* gcData->brushOrgX = gcData->brushOrgY = 0; - not needed - memset does it */
-    /* gcData->hPen = 0; - not needed - memset does it */
-    /* gcData->hBrush = 0; - not needed - memset does it */
-    return gcData;
-}
-
-static void
-freeGcData(struct gcData *gcData)
-{
-    if (gcDataNumFree < NUM_FREE_GC) {
-        gcData->u.__nextFree = gcDataFreeList;
-        gcDataFreeList = gcData;
-        gcDataNumFree++;
-    } else {
-        free(gcData);
-    }
-}
-
-#ifdef CACHE_LAST_DC
-# define FLUSH_CACHED_DC(__gcData__) \
-    if (lastGcData == __gcData__) {  \
-        _releaseDC(lastGcData);      \
-    }
-#else
-# define FLUSH_CACHED_DC(x)     /* */
-#endif
-
-#ifdef CACHE_LAST_PEN
-# define FLUSH_CACHED_PEN(__gcData__) \
-    if (__gcData__->hPen) {           \
-        if (__gcData__->save_hPen) {  \
-            SelectObject(__gcData__->_hDC, __gcData__->save_hPen); \
-            __gcData__->save_hPen = 0;   \
-        } \
-        _DeletePenIfNotInCache(__gcData__->hPen, __LINE__); \
-        __gcData__->hPen = 0; \
-    }
-#else
-# define FLUSH_CACHED_PEN(x)    /* */
-#endif
-
-#ifdef CACHE_LAST_BRUSH
-# define FLUSH_CACHED_BRUSH(__gcData__) \
-    if (__gcData__->hBrush) {           \
-        if (__gcData__->save_hBrush) {  \
-            SelectObject(__gcData__->_hDC, __gcData__->save_hBrush); \
-            __gcData__->save_hBrush = 0;   \
-        } \
-        _DeleteBrushIfNotInCache(__gcData__->hBrush, __LINE__); \
-        __gcData__->hBrush = 0; \
-    }
-#else
-# define FLUSH_CACHED_BRUSH(x)    /* */
-#endif
-
-static void
-_releaseDC(struct gcData *gcData)
-{
-    HDC hDC = gcData->_hDC;
-
-    if (gcData->doNotCacheOrRelease ) {
-        return;
-    }
-
-    if (gcData->save_hPen) {
-        SelectObject(hDC, gcData->save_hPen);
-        gcData->save_hPen = 0;
-    }
-    if (gcData->save_hBrush) {
-        SelectObject(hDC, gcData->save_hBrush);
-        gcData->save_hBrush = 0;
-    }
-    if (gcData->save_hFont) {
-        SelectObject(hDC, gcData->save_hFont);
-        gcData->save_hFont = 0;
-    }
-
-    if (gcData->hWnd) {
-        if (hDC) {
-            ReleaseDC(gcData->hWnd, hDC);
-#ifdef CACHE_LAST_WM_PAINT_DC
-            if (hDC == last_wm_paint_dc) {
-                last_wm_paint_dc = last_wm_paint_win = 0;
-# ifdef DEBUG_DC_REUSE
-                console_fprintf(stderr, "WinWorkstation [info]: Oops - releasing bg_paint-dc\n");
-# endif
-            }
-#endif
-        }
-    } else if (gcData->hBitmap) {
-        SelectObject(hDC, gcData->save_hBitmap);
-        DeleteDC(hDC);
-    }
-    gcData->_hDC = 0;
-
-#ifdef CACHE_LAST_DC
-    if (lastGcData == gcData) {
-        lastGcData = 0;
-    }
-#endif
-#ifdef CACHE_LAST_PEN
-    if (gcData->hPen) {
-        _DeletePenIfNotInCache(gcData->hPen, __LINE__);
-        gcData->hPen = 0;
-    }
-#endif
-#ifdef CACHE_LAST_BRUSH
-    if (gcData->hBrush) {
-        _DeleteBrushIfNotInCache(gcData->hBrush, __LINE__);
-        gcData->hBrush = 0;
-    }
-#endif
-}
-
-static HDC
-_getDC(struct gcData *gcData)
-{
-    HDC hDC;
-    int currThreadId;
-
-    if (gcData->doNotCacheOrRelease ) {
-        return gcData->_hDC;
-    }
-
-#ifdef CACHE_LAST_DC
-    currThreadId = GetCurrentThreadId();
-
-    if (lastGcData) {
-        if ((lastGcData == gcData)
-         && (lastGcHWIN == gcData->hWnd)
-         && (lastGcHBITMAP == gcData->hBitmap)
-         && (lastGcOwnerThreadID == currThreadId)
-         && gcData->_hDC
-        ) {
-# ifdef CACHE_LAST_WM_PAINT_DC /* DDD */
-            if (last_wm_paint_dc == gcData->_hDC) {
-#  ifdef DEBUG_DC_REUSE
-                console_fprintf(stderr, "WinWorkstation [info]: Oops wm_paint_dc reuse [%d]\n", __LINE__);
-#  endif
-                last_wm_paint_dc = last_wm_paint_win = 0;
-            }
-# endif
-            return gcData->_hDC;
-        }
-
-        _releaseDC(lastGcData);
-        lastGcData = 0;
-    }
-#endif
-
-    hDC = 0;
-    if (gcData->hWnd != 0) {
-        if (gcData->hWnd == __rootWin) {
-            hDC = gcData->_hDC = GetDCEx(gcData->hWnd, 0, DCX_WINDOW);
-        } else if (gcData->clipByChildren) {
-            //gcData->_hDC = GetDCEx(gcData->hWnd, 0, DCX_CLIPCHILDREN);
-            hDC = gcData->_hDC = GetDC(gcData->hWnd);
-        } else  {
-            hDC = gcData->_hDC = GetDCEx(gcData->hWnd, 0, DCX_PARENTCLIP);
-        }
-    } else if (gcData->hBitmap) {
-        hDC = gcData->_hDC = CreateCompatibleDC(__tmpDC);
-        gcData->save_hBitmap = SelectObject(gcData->_hDC,gcData->hBitmap);
-    }
-    gcData->bkMode = BK_UNDEF;
-
-    if (hDC) {
-        SetTextColor(hDC, gcData->fgColor);
-        SetBkColor(hDC, gcData->bgColor);
-
-        if (gcData->rop2)
-            SetROP2(hDC, gcData->rop2);
-
-        if (gcData->clipping) {
-            HRGN region = CreateRectRgn( gcData->clipX, gcData->clipY,
-                                         gcData->clipX + gcData->clipW,
-                                         gcData->clipY + gcData->clipH);
-            if (region == NULL ) {
-                console_fprintf(stderr, "WinWorkstat [warning]: clipping region creation failed\n");
-            } else {
-                if (SelectClipRgn(hDC, region) == ERROR ) {
-                    DPRINTF(("WinWorkstat [warning]: select clipping region failed\n" ));
-                }
-                _DeleteObject(region, __LINE__);
-            }
-        } else {
-            SelectClipRgn(hDC, NULL);
-        }
-
-        if (gcData->hFont) {
-            HFONT prevFont;
-
-            prevFont = SelectObject(hDC, gcData->hFont);
-            if (! gcData->save_hFont) {
-                gcData->save_hFont = prevFont;
-            }
-        }
-    }
-
-#ifdef CACHE_LAST_DC
-    lastGcData = gcData;
-    lastGcOwnerThreadID = currThreadId;
-    lastGcHWIN = gcData->hWnd;
-    lastGcHBITMAP = gcData->hBitmap;
-
-    gcData->_hDC = hDC;
-
-# ifdef CACHE_LAST_WM_PAINT_DC /* DDD */
-    if (last_wm_paint_dc == hDC) {
-#  ifdef DEBUG_DC_REUSE
-        console_fprintf(stderr, "WinWorkstation [info]: Oops wm_paint_dc reuse [%d]\n", __LINE__);
-#  endif
-        last_wm_paint_dc = last_wm_paint_win = 0;
-    }
-# endif
-#endif
-
-    return hDC;
-}
-
-static HBRUSH
-GcDataGetBrush(HDC hDC, struct gcData *gcData)
-{
-    HBRUSH hBrush = 0;
-    HBRUSH prevBrush;
-
-#ifdef CACHE_LAST_BRUSH
-    if (hBrush = gcData->hBrush) {
-        if (! gcData->save_hBrush) {
-            gcData->save_hBrush = SelectObject(gcData->_hDC, hBrush);
-        }
-        return hBrush;
-    }
-#endif
-    if (gcData->hMask) {
-        hBrush = CreatePatternBrush(gcData->hMask);
-        SetBrushOrgEx(hDC, gcData->maskOrgX, gcData->maskOrgY, 0);
-        RESPRINTF(("CreatePatternBrush %x\n",gcData->hMask));
-    } else {
-        if (gcData->fgColor == BlackPixel) {
-            hBrush = __blackBrush;
-        } else if (gcData->fgColor == WhitePixel) {
-            hBrush = __whiteBrush;
-        } else {
-#ifdef CACHE_BRUSH
-            {
-                int i;
-
-                for (i=0; i<NUM_BRUSH_CACHED; i++) {
-                    if (__brushCache[i].clr == gcData->fgColor) {
-                        hBrush = __brushCache[i].brush;
-                        /*
-                         * move it up in the cache
-                         */
-                        if (i > 0) {
-                            HBRUSH t = __brushCache[i-1].brush;
-                            int c = __brushCache[i-1].clr;
-
-                            __brushCache[i-1].brush = hBrush;
-                            __brushCache[i-1].clr = gcData->fgColor;
-                            __brushCache[i].brush = t;
-                            __brushCache[i].clr = c;
-                        }
-# ifdef CACHE_LAST_BRUSH
-                        prevBrush = SelectObject(gcData->_hDC, hBrush);
-                        if (! gcData->save_hBrush) {
-                            gcData->save_hBrush = prevBrush;
-                        }
-                        gcData->hBrush = hBrush;
-# endif
-                        return hBrush;
-                    }
-                }
-            }
-#endif /* BRUSH_CACHE */
-            hBrush = CreateSolidBrush(gcData->fgColor);
-            RESPRINTF(("CreateSolidBrush %x\n",gcData->fgColor));
-        }
-    }
-    gcData->hBrush = hBrush;
-
-    prevBrush = SelectObject(gcData->_hDC, hBrush);
-    if (! gcData->save_hBrush) {
-        gcData->save_hBrush = prevBrush;
-    }
-    return hBrush;
-}
-
-#ifdef CACHE_LAST_BRUSH
-# define GcDataReleaseBrush(hDC, gcData)  /* nothing*/
-#else
-static void
-GcDataReleaseBrush(HDC hDC, struct gcData *gcData)
-{
-    HBRUSH hBrush = gcData->hBrush;
-
-    if (gcData->save_hBrush) {
-        SelectObject(hDC, gcData->save_hBrush);
-        gcData->save_hBrush = NULL;
-    }
-    _DeleteBrushIfNotInCache(hBrush, __LINE__);
-    gcData->hBrush = 0;
-}
-#endif
-
-static HPEN
-GcDataGetPen(HDC hDC, struct gcData *gcData)
-{
-    HPEN hPen = 0;
-    HPEN prevPen;
-    LOGBRUSH Brush;
-    int lw;
-
-#ifdef CACHE_LAST_PEN
-    if (hPen = gcData->hPen) {
-        if (! gcData->save_hPen) {
-            gcData->save_hPen = SelectObject(gcData->_hDC, hPen);
-        }
-        return hPen;
-    }
-#endif
-
-    if (((gcData->lStyle & PS_STYLE_MASK) == PS_SOLID)
-     && (gcData->hMask == 0)
-     && (gcData->lineWidth <= 1)) {
-        if (gcData->fgColor == BlackPixel) {
-            gcData->hPen = hPen = __blackPen;
-            prevPen = SelectObject(hDC, hPen);
-            if (! gcData->save_hPen) {
-                gcData->save_hPen = prevPen;
-            }
-            return hPen;
-        }
-        if (gcData->fgColor == WhitePixel) {
-            gcData->hPen = hPen = __whitePen;
-            prevPen = SelectObject(hDC, hPen);
-            if (! gcData->save_hPen) {
-                gcData->save_hPen = prevPen;
-            }
-            return hPen;
-        }
-
-#ifdef CACHE_PEN
-        {
-            int i;
-
-            for (i=0; i<NUM_PEN_CACHED; i++) {
-                if (__penCache[i].clr == gcData->fgColor) {
-                    hPen = __penCache[i].pen;
-                    /*
-                     * move it up in the cache
-                     */
-                    if (i > 0) {
-                        HPEN t = __penCache[i-1].pen;
-                        int c = __penCache[i-1].clr;
-
-                        __penCache[i-1].pen = hPen;
-                        __penCache[i-1].clr = gcData->fgColor;
-                        __penCache[i].pen = t;
-                        __penCache[i].clr = c;
-                    }
-
-                    gcData->hPen = hPen;
-                    prevPen = SelectObject(hDC, hPen);
-                    if (! gcData->save_hPen) {
-                        gcData->save_hPen = prevPen;
-                    }
-                    return hPen;
-                }
-            }
-        }
-#endif /* PEN_CACHE */
-    }
-
-    hPen = (HPEN) 0;
-    lw = gcData->lineWidth;
-    if (lw == 0) {
-        lw = 1;
-    }
-
-    /*
-     * NT supports masked drawing with any lineStyle,
-     * and also non-solid lines with any lineWidth.
-     */
-    if (gcData->hMask) {
-        Brush.lbStyle = BS_PATTERN;
-        Brush.lbHatch = (ULONG_PTR)(gcData->hMask);
-        Brush.lbColor = gcData->fgColor;
-    } else {
-        Brush.lbStyle = BS_SOLID;
-        Brush.lbHatch = (ULONG_PTR)0;
-        Brush.lbColor = gcData->fgColor;
-
-        hPen = (HPEN) 0;
-
-#if USE_OLD_CREATE_PEN
-        hPen = CreatePen((gcData->lStyle & PS_STYLE_MASK), lw, gcData->fgColor);
-
-        RESPRINTF(("CreatePen %x %d(%d) %x %x\n",
-                    gcData->lStyle,
-                    lw, gcData->lineWidth,
-                    gcData->fgColor, gcData->hMask));
-#endif
-
-        SetBkMode(hDC, TRANSPARENT);
-        gcData->bkMode = BK_TRANSPARENT;
-
-        if (! hPen) {
-            hPen = ExtCreatePen(PS_GEOMETRIC | gcData->lStyle,
-                            lw, /* gcData->lineWidth, */
-                            &Brush,
-                            0, 0);
-
-            RESPRINTF(("ExtCreatePen1 %x %d(%d) %x %x\n",
-                        gcData->lStyle,
-                        lw, gcData->lineWidth,
-                        gcData->fgColor, gcData->hMask));
-
-            if (gcData->hMask) {
-                SetBrushOrgEx(hDC, gcData->maskOrgX, gcData->maskOrgY, 0);
-            }
-        }
-    }
-
-    gcData->hPen = hPen;
-    prevPen = SelectObject(hDC, hPen);
-    if (! gcData->save_hPen) {
-        gcData->save_hPen = prevPen;
-    }
-
-#ifdef CACHE_PEN
-    /*
-     * remember in penCache
-     */
-    if (((gcData->lStyle & PS_STYLE_MASK) == PS_SOLID)
-     && (gcData->hMask == 0)
-     && (gcData->lineWidth <= 1)) {
-        int i;
-
-        /*
-         * search for an empty slot
-         */
-        for (i=0; i<NUM_PEN_CACHED; i++) {
-            if (__penCache[i].pen == 0) {
-                __penCache[i].clr = gcData->fgColor;
-                __penCache[i].pen = hPen;
-                break;
-            }
-        }
-        if (i == NUM_PEN_CACHED) {
-            /*
-             * replace last in penCache
-             */
-            HPEN t = __penCache[NUM_PEN_CACHED - 1].pen;
-
-            __penCache[NUM_PEN_CACHED - 1].pen = hPen;
-            __penCache[NUM_PEN_CACHED - 1].clr = gcData->fgColor;
-            _DeletePen(t, __LINE__);
-        }
-    }
-#endif
-
-    return hPen;
-}
-
-#ifdef CACHE_LAST_PEN
-# define GcDataReleasePen(HDC hDC, struct gcData *gcData)  /* nothing*/
-#else
-static void
-GcDataReleasePen(HDC hDC, struct gcData *gcData)
-{
-    HPEN hPen;
-
-    if (gcData->save_hPen) {
-        SelectObject(hDC, gcData->save_hPen);
-        gcData->save_hPen = NULL;
-    }
-    hPen = gcData->hPen;
-    _DeletePenIfNotInCache(hPen, __LINE__);
-    gcData->hPen = 0;
-}
-#endif /* CACHE_LAST_PEN */
-
-/* atze */
-
-static int
-lockEvents(char *whoIsLocking)
-{
-    DWORD dwWaitResult = WaitForSingleObject(hEventsMutex, 5000L);
-
-#ifdef LOCK_DEBUG
-    lockCountEvents++;
-    if (lockCountEvents != 1) {
-        console_fprintf(stderr, "WinWorkstation [warning]: lockCountEvents (%d) != 1 in lock\n", lockCountEvents);
-        lockCountEvents = 1;
-    }
-#endif
-
-    switch (dwWaitResult) {
-        case WAIT_OBJECT_0:
-            hEventsMutexOwner = whoIsLocking;
-            return (TRUE);
-
-        case WAIT_ABANDONED:
-            console_fprintf(stderr, "WinWorkstation [warning]: lockEvent abandoned (was owned by %s)\n",
-                        (hEventsMutexOwner ? hEventsMutexOwner : "NONE"));
-            hEventsMutexOwner = whoIsLocking;
-            return (TRUE);
-
-        case WAIT_TIMEOUT:
-            console_fprintf(stderr, "WinWorkstation [warning]: lockEvent timeout (owned by %s)\n",
-                        (hEventsMutexOwner ? hEventsMutexOwner : "NONE") );
-            break;
-
-        default:
-            {
-                unsigned errCode = GetLastError();
-
-                console_fprintf(stderr, "WinWorkstation [error]: lockEvent error (owned by %s) rslt=0x%x err=0x%x\n",
-                            (hEventsMutexOwner ? hEventsMutexOwner : "NONE"),
-                            dwWaitResult, errCode );
-            }
-            break;
-    }
-    return (FALSE);
-}
-
-static int
-unlockEvents(void) {
-#ifdef LOCK_DEBUG
-    lockCountEvents--;
-    if (lockCountEvents != 0) {
-        console_fprintf(stderr, "WinWorkstation [warning]: lockCountEvents (%d) != 0 in unlock\n", lockCountEvents);
-        lockCountEvents = 0;
-    }
-#endif
-    if (! ReleaseMutex(hEventsMutex)) {
-       console_fprintf(stderr, "WinWorkstation [error]: unlockEvent error\n");
-       return (FALSE);
-    }
-    hEventsMutexOwner = NULL;
-
-    return (TRUE);
-}
-
-
-static int
-initEventqueue(void) {
-    struct queuedEvent *bulk;
-    int i;
-
-    bulk = (struct queuedEvent *) malloc(EV_CHUNK_SZ);
-    if (bulk == 0) {
-        console_fprintf(stderr, "WinWorkstation [warning]: no memory for dispatchqueue\n");
-        return 0;
-    }
-    for (i=1; i<EV_CHUNK_CNT; i++) {
-        bulk[i-1].ev_next = &(bulk[i]);
-    }
-    bulk[EV_CHUNK_CNT-1].ev_next = (struct queuedEvent *)0;
-    eventFreeList = bulk;
-
-    return 1;
-}
-
-#define EV_NOTIME       0
-
-#define enqEvent(a1, a2, a3, a4, a5, a6, a7, a8, a9) \
-    __enqEvent(a1, a2, a3, a4, a5, a6, a7, a8, a9)
-
-static void
-__enqEvent(int flag, HWND hWnd, UINT message, UINT wParam, INT arg1, INT arg2, INT arg3, INT arg4, UINT evTime)
-{
-    struct queuedEvent *ev = 0;
-    int repeatCount = 0;
-
-    /* get an event struct
-    */
-    while (! eventFreeList) {
-        if (repeatCount++ >= 5) {
-            /* throw away sorry */
-            console_fprintf(stderr, "WinWorkstation [error]: event throw away (memory problem)\n");
-            return;
-        }
-        console_fprintf(stderr, "WinWorkstation [warning]: wait for event memory (%d)\n", repeatCount);
-        WaitForSingleObject( hNeverTriggered, 100L );
-    }
-    if (! lockEvents("enqEvent")) {
-        console_fprintf(stderr, "WinWorkstation [error]: event throw away (lock problem)\n");
-        return;
-    }
-
-    ev = eventFreeList;
-
-    if (! ev) {
-        console_fprintf(stderr, "WinWorkstation [error]: event throw away (memory problem)\n");
-        unlockEvents();
-        return;
-    }
-    eventFreeList  = ev->ev_next;
-    ev->ev_flag    = flag;
-    ev->ev_hWnd    = hWnd;
-    ev->ev_message = message;
-    ev->ev_wParam  = wParam;
-    ev->ev_arg1    = arg1;
-    ev->ev_arg2    = arg2;
-    ev->ev_arg3    = arg3;
-    ev->ev_arg4    = arg4;
-    ev->ev_time    = evTime /* lastMSGTime */;
-    ev->count      = eventsendcount++;
-    ev->ev_next    = (struct queuedEvent *) 0;
-
-    if (eventQueueTail) {
-        eventQueueTail->ev_next = ev;
-    } else {
-        eventQueueHead = ev;
-    }
-    eventQueueTail = ev;
-
-    unlockEvents();
-
-    if (eventQueueHead == ev) {
-        SetEvent(hInputEvent);
-    }
-
-#if 0
-    SetThreadPriority(_masterThread, THREAD_PRIORITY_HIGHEST);
-#endif
-}
-
-static int
-deqEvent(struct queuedEvent *ret_ev, HWND hWnd, int mask)
-{
-    struct queuedEvent * ev = NULL;
-    char * freeArg2 = NULL;
-
-    if (mask != ~0) {
-        PRINTF(("deqEvent mask:%x\n",mask));
-    }
-    if (hWnd) {
-        PRINTF(("deqEvent hWnd:%x\n",hWnd));
-    }
-
-  again:
-
-    if (! eventQueueHead)
-        return (0);
-
-    if (! lockEvents("deqEvent")) {
-        return (0);
-    }
-
-    TH_DPRINTF(("TDEQ\n"));
-    ev = eventQueueHead;
-
-    if (! ev) {
-        unlockEvents();
-        return (0);
-    }
-    eventQueueHead = ev->ev_next;
-
-    if (! eventQueueHead) {
-        eventQueueTail = (struct queuedEvent *) 0;
-    }
-
-    if (ev->count != -1) {
-        static int anyGoodEventReceived = 1;
-
-        if (eventempfcount != ev->count) {
-            if (anyGoodEventReceived) {
-                console_fprintf(stderr, "WinWorkstation [warning]: lost event (eventcount error %d <-> %d)\n",
-                                 eventempfcount, ev->count);
-            }
-            eventempfcount = ev->count;
-            anyGoodEventReceived = 0;
-        } else {
-            anyGoodEventReceived = 1;
-        }
-        eventempfcount++;
-    }
-
-    if (ev->ev_message == WM_DESTROY) {
-        /*
-         * arg2 is the localInfoPtr
-         * (which is already cleared in the wind-structure)
-         * it must be freed by the stx-process ('cause it was malloc'd by it)
-         */
-        if (ev->ev_arg2) {
-            freeArg2 = (char *) ev->ev_arg2;
-            ev->ev_arg2 = 0;
-        }
-
-#ifdef TOPWINDOWCLASS
-
-FALSCH: nochmals in QUEUE -> (ev_arg2 != 0) arg2 freed !!!
-
-        if (ev->ev_arg1) {
-            if (UnregisterClass((char*)ev->ev_arg1,(HANDLE) __getHInstance())) {
-                /*console_printf("UnregisterClass %s ok.\n",(char*)ev->ev_arg1);*/
-
-            } else {
-                /* noch einmal in die queue
-                */
-                if (ev->ev_arg2++ < 100) {
-                    ev->ev_next = (struct queuedEvent *)0;
-                    ev->count   = eventsendcount++;
-
-                    if (eventQueueTail) {
-                        eventQueueTail->ev_next = ev;
-                    } else {
-                        eventQueueHead = ev;
-                    }
-                    eventQueueTail = ev;
-                    unlockEvents();
-
-                    if (freeArg2) {
-                        free (freeArg2);
-                        freeArg2 = NULL;
-                    }
-
-                    if (ev->ev_arg2 > 98) {
-                        console_fprintf(stderr, "WinWorkstation [info]: UnregisterClass %s failed. Wait 1 sec.\n",(char*)ev->ev_arg1);
-                        sleep(1);
-                    } else {
-                        sleep(0);
-                    }
-                    goto again;
-                }
-                /* fail evtl. später ändern und in st verzögert aufrufen
-                */
-                console_fprintf(stderr, "WinWorkstation [info]: UnregisterClass %s failed.\n",(char*)ev->ev_arg1);
-            }
-            free((char*)ev->ev_arg1);
-            ev->ev_arg1 = 0;
-        }
-#endif
-    }
-
-    *ret_ev = *ev;
-
-    ev->ev_next   = eventFreeList;
-    eventFreeList = ev;
-    unlockEvents();
-
-    if (freeArg2) {
-        free (freeArg2);
-    }
-    return (1);
-}
-
-static void
-__clearRectangles(HWND hWnd, int numRects, RECT *pRect)
-{
-        HDC dc;
-        HBRUSH br;
-        int bgClr;
-        int isPrivateBrush = 0;
-
-# ifdef CACHE_LAST_WM_PAINT_DC
-        AQUIRE_PAINT_MUTEX;
-
-        if (last_wm_paint_dc && (last_wm_paint_win == hWnd)) {
-            dc = last_wm_paint_dc;
-        } else {
-            if (last_wm_paint_dc) {
-#  ifdef CACHE_LAST_DC
-                if (lastGcData && (lastGcData->_hDC == last_wm_paint_dc)) {
-#   ifdef DEBUG_DC_REUSE
-                    console_fprintf(stderr, "WinWorkstation [info]: Oops - release lastGcData [%d]\n", __LINE__);
-#   endif
-                    _releaseDC(lastGcData);
-                } else {
-                    ReleaseDC(last_wm_paint_win, last_wm_paint_dc);
-                }
-#  else
-                ReleaseDC(last_wm_paint_win, last_wm_paint_dc);
-#  endif /* CACHE_LAST_DC */
-            }
-            dc = GetDC(hWnd);
-            last_wm_paint_dc = dc;
-            last_wm_paint_win = hWnd;
-        }
-# else
-        dc = (HDC)GetDC(hWnd);
-# endif /* CACHE_LAST_WM_PAINT_DC */
-
-# ifdef CACHE_LAST_DC
-        if (lastGcData && (lastGcData->_hDC == dc)) {
-#  ifdef DEBUG_DC_REUSE
-            console_fprintf(stderr, "WinWorkstation [info]: Oops wm_paint_dc reuse [%d]\n", __LINE__);
-#  endif
-            if ((lastGcData->rop2 != R2_COPYPEN)
-             || (lastGcData->bitbltrop2 != BITBLT_COPY)) {
-                console_fprintf(stderr, "WinWorkstation [info]: Oops wm_paint_dc not in Copy mode\n");
-            }
-            lastGcData = 0;
-        }
-# endif
-
-        br = GetWindow_viewBgBrush(hWnd);
-        if (! br) {
-            bgClr = GetWindow_viewBgColor(hWnd);
-
-# ifdef CACHE_LAST_WM_PAINT_BRUSH
-            if (last_wm_paint_brush
-             && (last_wm_paint_brush_clr == bgClr)) {
-                br = last_wm_paint_brush;
-            } else {
-                if (bgClr == WhitePixel) {
-                    br = __whiteBrush;
-                } else if (bgClr == BlackPixel) {
-                    br = __blackBrush;
-                } else {
-                    if (last_wm_paint_brush) {
-                        _DeleteBrush(last_wm_paint_brush, __LINE__);
-                    }
-                    last_wm_paint_brush = br = CreateSolidBrush(bgClr);
-                    last_wm_paint_brush_clr = bgClr;
-                    isPrivateBrush = 1;
-                }
-            }
-# else
-            br = CreateSolidBrush(bgClr);
-            isPrivateBrush = 1;
-# endif
-        }
-
-        if (! br) {
-            console_fprintf(stderr, "WinWorkstation [info]: no brush\n");
-        }
-
-        if (br) {
-            int i;
-
-            SelectClipRgn(dc, NULL);
-
-            for (i=0; i<numRects; i++) {
-                /*
-                 * always clear - even if not interested in exposes
-                 */
-                FillRect(dc, &(pRect[i]), br);
-            }
-        }
-
-# ifndef CACHE_LAST_WM_PAINT_BRUSH
-        if (isPrivateBrush) {
-            _DeleteBrush(br, __LINE__);
-        }
-# endif
-
-# ifndef CACHE_LAST_WM_PAINT_DC
-        ReleaseDC(hWnd, dc);
-# endif
-
-# if defined(CACHE_LAST_WM_PAINT_DC)
-        RELEASE_PAINT_MUTEX
-# endif
-}
-
-static void
-__clearWindow(HWND hWnd, int x, int y, int w, int h)
-{
-        RECT rect;
-
-        rect.left = x;
-        rect.top = y;
-        rect.right = x + w;
-        rect.bottom = y + h;
-        __clearRectangles(hWnd, 1, &rect);
-}
-
-
-/*
- * generate expose events from hWnd's update region or the passedIn region.
- * return the number of events (>0), if any was generated.
- * 0, if no event was generated, -1 if none was generated with error.
- * if a region is passed in, it is not destroyed.
- */
-
-static int
-__generateExposes(HWND hWnd, HRGN hRgnInOrNull, int msgType, int doClear)
-{
-        RECT updRect;
-        HRGN updRgn = 0;
-        int numRects, ret, n, i;
-        int wantExpose;
-        RECT *pRect;
-        union {
-            RGNDATA rgnData;
-            char    bytes[512];
-        } data;
-
-        wantExpose = 0;
-
-        if( msgType >= 0 )
-            wantExpose = (GetWindow_eventMask(hWnd) & ExposureMask);
-
-        if (hRgnInOrNull) {
-            updRgn = hRgnInOrNull;
-        } else {
-            PAINTSTRUCT ps;
-
-            /*
-             * fetch the update region, even if ExposureMask is empty.
-             */
-            updRgn = CreateRectRgn(0, 0, 0, 0);
-            ret = GetUpdateRgn(hWnd, updRgn, FALSE);
-
-#if 0
-            BeginPaint(hWnd, &ps);
-            /* store the rectangle required for image bit reversal */
-            /* updateRect = ps.rcPaint;   */
-            EndPaint(hWnd, &ps);
-#endif
-            switch (ret) {
-                case ERROR:
-                    console_fprintf(stderr, "WinWorkstation [info]: errregion\n");
-                    return -1;
-                case NULLREGION:
-                    DDDDPRINTF(("nullregion\n"));
-                    _DeleteObject(updRgn, __LINE__);
-                    return 0;
-                case SIMPLEREGION:
-                case COMPLEXREGION:
-                    break;
-            }
-        }
-        n = GetRegionData(updRgn, sizeof(data), &(data.rgnData));
-
-        /*
-         * the MS-doc states: n==1
-         * but this is not true
-         */
-        if ((n >= sizeof(RGNDATA))
-         && (n <= sizeof(data))
-         && (data.rgnData.rdh.iType == RDH_RECTANGLES))  {
-            /* ok, got the region */
-            numRects = data.rgnData.rdh.nCount;
-            pRect = (RECT *)(data.rgnData.Buffer);
-            DDDDPRINTF(("region numRects=%d\n", numRects));
-        } else {
-            /* a big region ... */
-            GetRgnBox(updRgn, &updRect);
-            numRects = 1;
-            pRect = &updRect;
-            DPRINTF(("very complex region (need:%d have:%d) bounds=%d,%d -> %d,%d\n",
-                     n, sizeof(data),
-                     updRect.left, updRect.top,
-                     updRect.right, updRect.bottom));
-            if (((updRect.right - updRect.left) <= 0)
-             || ((updRect.bottom - updRect.top) <= 0)) {
-                numRects = 0;
-            }
-        }
-
-        if (numRects) {
-            if (doClear) {
-                __clearRectangles(hWnd, numRects, pRect);
-            }
-
-#ifndef PRE_21_NOV
-        for (i=0; i < numRects; i++) {
-            ValidateRect( hWnd, &pRect[i] );
-        }
-#endif
-
-#ifdef DEBUG_COLORIZE_WM_PAINT_RECTS1
-            {
-                HDC hDC;
-                HBRUSH hBrush;
-
-                hBrush = CreateSolidBrush(BlackPixel);
-                hDC = GetWindowDC(hWnd);
-                SelectClipRgn(hDC, NULL);
-                for (i=0; i<numRects; i++) {
-                    FillRect(hDC, &(pRect[i]), hBrush);
-                }
-                _DeleteBrush(hBrush, __LINE__);
-                ReleaseDC(hWnd, hDC);
-            }
-#endif
-
-            if (wantExpose) {
-                for (i=0; i<numRects; i++) {
-                    int final = 0;
-
-                    if ((msgType == __WM_GEXPOSE)
-                     && (i == (numRects - 1))) {
-                        final = 1;
-                    }
-                    enqEvent(ExposureMask, hWnd, msgType, final,
-                             (pRect[i].left), (pRect[i].top),
-                             (pRect[i].right - pRect[i].left),
-                             (pRect[i].bottom - pRect[i].top),
-                             EV_NOTIME);
-                }
-            }
-        }
-
-        if (updRgn && (updRgn != hRgnInOrNull)) {
-            _DeleteObject(updRgn, __LINE__);
-        }
-
-        return numRects;
-}
-
-#ifdef THIS_DOES_NOT_AVOID_DOUBLE_REPAINTS
-
-BOOL CALLBACK
-recursiveExposeGenerator(HWND hChild, LPARAM param)
-{
-        __generateExposes(hChild, NULL, param, 0);
-        return TRUE;
-}
-
-static void
-__generateRecursiveExposes(HWND hWnd, int msgType)
-{
-        EnumChildWindows(hWnd, recursiveExposeGenerator, msgType);
-}
-
-#endif /* sigh */
-
-
-static int
-getModifiers(void)
-{
-    int modifiers = 0;
-
-    if (GetKeyState(VK_SHIFT) & 0x8000)
-        modifiers |= ShiftMask;
-    if (GetKeyState(VK_CONTROL) & 0x8000)
-        modifiers |= ControlMask;
-#if 0
-    if (GetKeyState(VK_RMENU) & 0x8000)
-        modifiers |= RightAltMask;
-    if (GetKeyState(VK_LMENU) & 0x8000)
-        modifiers |= LeftAltMask;
-#else
-    if (GetKeyState(VK_MENU) & 0x8000)
-        modifiers |= LeftAltMask;
-#endif
-    if (GetKeyState(VK_LBUTTON) & 0x8000)
-        modifiers |= Button1Mask;
-    if (GetKeyState(VK_MBUTTON) & 0x8000)
-        modifiers |= Button2Mask;
-    if (GetKeyState(VK_RBUTTON) & 0x8000)
-        modifiers |= Button3Mask;
-
-    if ((modifiers & AnyButtonMask) == 0) {
-        __eatingMouseEvents = 0;
-    }
-    return modifiers;
-}
-
-#ifndef PRE_01_APR_04
-
-/* test whether a button is pressed but we think no button was pressed;
-   in this case 0 (false) is returned otherwise true
-*/
-
-# define MustHandleButtonEvent()\
-    (((__currentCapture == CAPTURE_NONE)       \
-     && (   (GetKeyState(VK_LBUTTON) & 0x8000) \
-         || (GetKeyState(VK_MBUTTON) & 0x8000) \
-         || (GetKeyState(VK_RBUTTON) & 0x8000) \
-        )                                      \
-    ) ? 0 : 1)
-
-#else
-# define MustHandleButtonEvent()   1
-#endif
-
-
-#ifdef HANDLE_VIEWGRAVITY
-
-struct gravityCallBackInfo {
-    HWND parent;
-    int  currW, currH;
-    int  newW, newH;
-    int  parentWinX, parentWinY;
-};
-
-static BOOL CALLBACK
-gravityEnumeratorCallBack(HWND hChild, struct gravityCallBackInfo *iP)
-{
-    localWindowInfo *lI;
-    int gravity;
-
-    if (lI = GETLOCALWINDOWINFOPTR(hChild)) {
-        if ((gravity = lI->viewGravity) != GRAVITY_NONE) {
-            RECT oldChildRct, oldChildWinRct;
-            RECT newChildRct;
-            int deltaW, deltaH;
-            int anyChange = 0;
-
-            /*
-             * get its current bounds ...
-             */
-            GetClientRect(hChild, &oldChildRct);
-            deltaW = iP->newW - iP->currW;
-            deltaH = iP->newH - iP->currH;
-
-            GetWindowRect(hChild, &oldChildWinRct);
-            oldChildRct.left = oldChildWinRct.left - iP->parentWinX;
-            oldChildRct.top =  oldChildWinRct.top - iP->parentWinY;
-
-            newChildRct = oldChildRct;
-            switch (gravity) {
-#if 0
-                case GRAVITY_N:
-                    console_fprintf(stderr, "WinWorkstation [info]: Child %x: North gravity\n", hChild);
-                    /*
-                     * shift to the bottom, for a constant
-                     * distance from the bottom edge;
-                     */
-                    newChildRct.bottom += deltaH;
-                    anyChange = 1;
-                    break;
-
-                case GRAVITY_W:
-                    console_fprintf(stderr, "WinWorkstation [info]: Child %x: West gravity\n", hChild);
-                    /*
-                     * shift to the right, for a constant
-                     * distance from the right edge;
-                     */
-                    newChildRct.right += deltaW;
-                    anyChange = 1;
-                    break;
-#endif
-                case GRAVITY_S:
-                    console_fprintf(stderr, "WinWorkstation [info]: Child %x: South gravity\n", hChild);
-                    /*
-                     * shift to the bottom, for a constant
-                     * distance from the bottom edge;
-                     */
-                    newChildRct.top += deltaH;
-                    newChildRct.bottom  += deltaH;
-                    anyChange = 1;
-                    break;
-
-                case GRAVITY_E:
-                    console_fprintf(stderr, "WinWorkstation [info]: Child %x: East gravity\n", hChild);
-                    /*
-                     * shift to the right, for a constant
-                     * distance from the right edge;
-                     */
-                    newChildRct.right += deltaW;
-                    newChildRct.left  += deltaW;
-                    anyChange = 1;
-                    break;
-
-                case GRAVITY_SE:
-                    console_fprintf(stderr, "WinWorkstation [info]: Child %x: SouthEast gravity\n", hChild);
-                    /*
-                     * shift to the bottom-right, for a constant
-                     * distance from the bottom-right edge;
-                     */
-                    newChildRct.right += deltaW;
-                    newChildRct.left  += deltaW;
-                    newChildRct.top += deltaH;
-                    newChildRct.bottom  += deltaH;
-                    anyChange = 1;
-                    break;
-
-                default:
-                    DPRINTF(("Child %x: other gravity\n", hChild));
-                    break;
-            }
-
-            if (anyChange) {
-                if ((newChildRct.left < 0)
-                 || (newChildRct.top < 0)
-                 || (newChildRct.right >= iP->newW)
-                 || (newChildRct.bottom >= iP->newH)) {
-                    console_fprintf(stderr, "WinWorkstation [info]: dont move child to: %d/%d -> %d/%d\n",
-                                    newChildRct.left, newChildRct.top,
-                                    newChildRct.right, newChildRct.bottom);
-                } else {
-                    console_fprintf(stderr, "WinWorkstation [info]: move child from %d/%d->%d/%d to: %d/%d->%d/%d\n",
-                                    oldChildRct.left, oldChildRct.top,
-                                    oldChildRct.right, oldChildRct.bottom,
-                                    newChildRct.left, newChildRct.top,
-                                    newChildRct.right, newChildRct.bottom);
-
-                    SetWindowPos(hChild, (HWND)0,
-                                 newChildRct.left, newChildRct.top,
-                                 0, 0,
-                                 /* SWP_NOSENDCHANGING | */
-                                 SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER);
-                }
-            }
-        }
-    }
-    return TRUE;
-}
-#endif /* HANDLE_VIEWGRAVITY */
-
-static void
-ch2wch(char *in, wchar_t *out, int nMax)
-{
-    unsigned char *cp = (unsigned char *)in;
-    wchar_t *wcp = out;
-
-    while ((nMax > 1) && cp && *cp) {
-        *wcp++ = *cp++;
-        nMax--;
-    }
-    *wcp = 0;
-}
-
-static int
-winEventProcessing(
-        HWND hWnd,         /* window handle                   */
-        UINT message,      /* type of message                 */
-        UINT wParam,       /* additional information          */
-        INT lParam,        /* additional information          */
-        int *pDefault
-    ) {
-    int curButton;
-    int x, y, w, h;
-    int isNative = 0;
-    UINT evTime;
-
-    /* kludge - info is in msg-struct,
-     * but lost here. (slightly inexact ... but who cares)
-     */
-    evTime = lastMSGTime;
-    lastMSGTime = 0;
-    if (evTime == 0) {
-        lastMSGTime = GetTickCount();
-    }
-
-/*
-    EVENT_PRINTF(("winEvent hWin=0x%x message=0x%x wP=0x%x lP=0x%x\n",
-                        hWnd, message, wParam, lParam));
-*/
-
-    if (hWnd) {
-        if (message != WM_MOUSEMOVE) {
-            lastMotionWnd = 0;
-        }
-
-        isNative = (GetWindow_flag(hWnd) & LI_NATIVEWIN);
-        if (isNative) {
-            NDPRINTF(("event %d (0x%x) for nativeWindow\n", message, message));
-        }
-    }
-
-    /*
-                sr: HACK since a specific Windows 10 Update
-                STX views have been freezed on resize
-                see http://doc.expecco.de/wiki2.x/Probleme_%26_Fehler
-                there is also an expecco ALM defect,
-                but sadly I could not find it ;(
-        */
-    switch (message) {
-            // case WM_PAINT:
-            case WM_NCCALCSIZE:
-            case WM_SIZE:
-            case WM_MOVE:
-            case WM_WINDOWPOSCHANGED:
-                        Sleep(0);
-                break;
-
-            default: break;
-    }
-
-    /*
-     * messages which are enqueued to be handled by the view thread
-     */
-    switch (message) {
-        case WM_THREAD_CREATEWINDOW:
-            EVENT_PRINTF(("*WM_THREAD_CREATEWINDOW\n"));
-
-            {
-                createWindowInfo *cwi = (createWindowInfo *)(lParam);
-
-                if ((cwi->sequenceNr == wParam)
-                 && (cwi->sequenceNr != INVALIDATED_CWI)) {
-                    cwi->sequenceNr = INVALIDATED_CWI;
-                    cwi->infoWasRead = 1;
-                    if (cwi->newWinHandle == NULL) {
-                        HANDLE ev;
-                        HANDLE hwnd;
-
-                        cwi->newWinHandle = hwnd = CreateWindowExW(
-                                            cwi->winStyleBitsEx,
-                                            cwi->className,
-                                            cwi->windowName,
-                                            cwi->winStyleBits,
-                                            cwi->x, cwi->y,
-                                            cwi->dx, cwi->dy,
-                                            cwi->parentHandle,
-                                            NULL,           /* menu */
-                                            (HANDLE) __getHInstance(),
-                                            cwi->localWindowInfo
-                                           );
-
-                        if (hwnd == NULL) {
-                            cwi->errCode = GetLastError();
-                            console_fprintf(stderr, "WinWorkstation [info]: CreateWindow failed: %d (0x%x) [%d]\n",
-                                                cwi->errCode, cwi->errCode, __LINE__);
-                        } else {
-                            SETLOCALWINDOWINFOPTR(hwnd, cwi->localWindowInfo);
-#ifdef DEBUG /* PARANOIA */
-                            if (GETLOCALWINDOWINFOPTR(hwnd) != cwi->localWindowInfo) {
-                               console_fprintf(stderr, "lI-Error\n");
-                            }
-#endif
-                            SetWindowPos(hWnd, HWND_TOP, 0, 0, 0, 0,
-                                        /* SWP_NOOWNERZORDER |*/
-                                        SWP_NOSENDCHANGING | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
-                        }
-
-                        ev = cwi->hCreateEvent;
-                        if (ev) {
-                            SetEvent(ev);
-                        }
-                    }
-                } else {
-                    DPRINTF(("obsolete createWindow message %x ignored\n", cwi->sequenceNr));
-                }
-            }
-            *pDefault = 0;
-            return 0;
-
-        case WM_THREAD_DESTROYWINDOW:
-            {
-                HBRUSH br;
-
-                br = GetWindow_viewBgBrush(hWnd);
-                if (br) {
-                    SetWindow_viewBgBrush(hWnd, 0);
-                    _DeleteBrushIfNotInCache(br, __LINE__);
-                }
-            }
-
-#ifdef CACHE_LAST_DC
-            if (lastGcData && (lastGcHWIN == hWnd)) {
-                _releaseDC(lastGcData);
-            }
-#endif
-#ifdef CACHE_LAST_WM_PAINT_DC
-            if (last_wm_paint_dc && (last_wm_paint_win == hWnd)) {
-                ReleaseDC(hWnd, last_wm_paint_dc);
-                last_wm_paint_win = last_wm_paint_dc = 0;
-            }
-#endif
-            if (! DestroyWindow(hWnd)) {
-                DPRINTF(("DestroyWindow ERROR\n"));
-            } else {
-#ifdef COUNT_RESOURCES
-                __cnt_createWindows--;
-                RESPRINTF(("DestroyWindow -> %d\n", __cnt_createWindows));
-#endif
-            }
-            *pDefault = 0;
-            return 0;
-
-        case WM_CREATE:
-            {
-#ifdef SETLOCALINFO_IN_CREATE /* no longer */
-                localWindowInfo *lI;
-
-                CREATESTRUCT *lpcs = (LPCREATESTRUCT) lParam; // structure with creation data
-
-                lI = lpcs->lpCreateParams;
-                EVENT_PRINTF(("WM_CREATE lI=%x\n", lI));
-
-                SETLOCALWINDOWINFOPTR(hWnd, lI);
-# ifdef SUPERDEBUG
-                if (GETLOCALWINDOWINFOPTR(hWnd) != lpcs->lpCreateParams) {
-                    PRINTF(("SETLOCALWINDOWINFOPTR ERROR\n"));
-                }
-# endif /* SUPERDEBUG */
-#endif
-
-                *pDefault = 0;
-#ifdef COUNT_RESOURCES
-                __cnt_createWindows++;
-                RESPRINTF(("CreateWindows %d\n",__cnt_createWindows));
-#endif
-            }
-            break;
-
-        case WM_CLOSE:
-            EVENT_PRINTF(("WM_CLOSE\n"));
-            if (! destroyWin) {
-                // (flag, hWnd, message, wParam, arg1, arg2, arg3, arg4, evTime)
-                enqEvent(0, hWnd, WM_CLOSE, wParam, 0, 0, 0, 0, EV_NOTIME);
-            } else {
-                destroyWin = 0;
-                {
-                    HBRUSH br;
-
-                    br = GetWindow_viewBgBrush(hWnd);
-                    if (br) {
-                        SetWindow_viewBgBrush(hWnd, 0);
-                        _DeleteBrushIfNotInCache(br, __LINE__);
-                    }
-                }
-#ifdef CACHE_LAST_DC
-                if (lastGcData && (lastGcHWIN == hWnd)) {
-                    _releaseDC(lastGcData);
-                }
-#endif
-#ifdef CACHE_LAST_WM_PAINT_DC
-                if (last_wm_paint_dc && (last_wm_paint_win == hWnd)) {
-                    ReleaseDC(hWnd, last_wm_paint_dc);
-                    last_wm_paint_win = last_wm_paint_dc = 0;
-                }
-#endif
-                if (! DestroyWindow(hWnd)) {
-                    DPRINTF(("DestroyWindow ERROR\n"));
-                } else {
-#ifdef COUNT_RESOURCES
-                    __cnt_createWindows--;
-                    RESPRINTF(("DestroyWindow -> %d\n", __cnt_createWindows));
-#endif
-                }
-            }
-            *pDefault = 0;
-            return 0;
-            break;
-
-        case WM_DESTROY:
-            {
-                char *nm = 0;
-                localWindowInfo *lI;
-
-                lI = GETLOCALWINDOWINFOPTR(hWnd);
-                EVENT_PRINTF(("WM_DESTROY %x li=%x\n", hWnd, lI));
-
-#ifdef TOPWINDOWCLASS
-                if (lI) {
-                    if (lI->flag & LI_TOPWIN) {
-                        nm = (char*) malloc(300);
-                        GetClassName(hWnd, nm, 300);
-                    }
-                    /* freeing now done in other thread */
-                }
-#endif
-                SETLOCALWINDOWINFOPTR(hWnd, 0);
-
-#ifdef FREE_LI_IN_STX_PROCESS
-                enqEvent(0, hWnd, WM_DESTROY, wParam, (INT)nm, lI, 0, 0, EV_NOTIME);
-#else
-                if (lI) {
-                    free(lI);
-                }
-                enqEvent(0, hWnd, WM_DESTROY, wParam, (INT)nm, 0, 0, 0, EV_NOTIME);
-#endif
-                *pDefault = 0;
-                return 0;
-            }
-            break;
-
-        case WM_GETMINMAXINFO:
-
-#ifndef PRE_13_APR_04_POSCHANGED_IN_EXITSIZEMOVE
-            if (inMove) {
-                *pDefault = 0;
-                return 0;
-            }
-#endif
-
-            {
-                int minW, maxW;
-                localWindowInfo *lI;
-                LPMINMAXINFO lpmmi = (LPMINMAXINFO) lParam;
-
-                EVENT_PRINTF2(("WM_GETMINMAXINFO handle=%x got min: %d/%d\n",
-                            hWnd,
-                            lpmmi->ptMinTrackSize.x,
-                            lpmmi->ptMinTrackSize.y));
-
-                lI = GETLOCALWINDOWINFOPTR(hWnd);
-                if (lI && (lI->minWidth) && (lI->maxWidth)) {
-                  lpmmi->ptMaxPosition.x = 0;
-                  lpmmi->ptMaxPosition.y = 0;
-                  lpmmi->ptMaxSize.x = lI->currentMonitorWidth;
-                  lpmmi->ptMaxSize.y = lI->currentMonitorHeight;
-#define MIN(a, b) (a < b ? a : b)
-                  lpmmi->ptMaxSize.x = MIN(GetSystemMetrics(SM_CXMAXIMIZED), lI->maxWidth);
-                  lpmmi->ptMaxSize.y = MIN(GetSystemMetrics(SM_CYMAXIMIZED), lI->maxHeight);
-
-                  lpmmi->ptMaxTrackSize.x = lI->maxWidth == 0 ? GetSystemMetrics(SM_CXMAXTRACK) : lI->maxWidth;
-                  lpmmi->ptMaxTrackSize.y = lI->maxHeight == 0 ? GetSystemMetrics(SM_CYMAXTRACK) : lI->maxHeight;
-                  lpmmi->ptMinTrackSize.x = lI->minWidth;
-                  lpmmi->ptMinTrackSize.y = lI->minHeight;
-
-                  EVENT_PRINTF3(("WM_GETMINMAXINFO handle=%x return min: %d/%d max: %d/%d\n",
-                                  hWnd,
-                                  lI->minWidth, lI->minHeight,
-                                  lI->maxWidth, lI->maxHeight));
-                  *pDefault = 0;
-                }
-            }
-            break;
-
-        case WM_SETCURSOR:
-            {
-                HCURSOR curs;
-                int hitCode;
-
-                hitCode = LOWORD(lParam);
-                if (hitCode != HTCLIENT) {
-                    /*
-                     * not in client area ...
-                     */
-                    return 0;
-                }
-                DPRINTFIF(__debug_WM_SETCURSOR__ , ("WM_SETCURSOR\n"));
-                curs = GetWindow_Cursor(hWnd);
-                if (curs) {
-                    SetCursor(curs);
-                    *pDefault = 0;
-                    return 1;
-                }
-            }
-            return 0;
-
-        case WM_WINDOWPOSCHANGED:
-
-#ifndef PRE_13_APR_04_POSCHANGED_IN_EXITSIZEMOVE
-            if (inMove) {
-                *pDefault = 0;
-                return 0;
-            }
-#endif
-            if (hWnd == __rootWinSpezial) {
-                /* can this happen ? */
-                *pDefault = 1;
-                return 0;
-            }
-
-            if (! inMove && (__currentCapture == CAPTURE_NONE)) {
-                POINT p;
-                HWND hWndChild,hWndTemp;
-
-                p.x = evRootX;
-                p.y = evRootY;
-                ScreenToClient(hWnd, &p);
-                hWndChild = hWnd; //hWndChild = ChildWindowFromPoint(hWnd,p);
-                do {
-                    hWndTemp = hWndChild;
-                    hWndChild = ChildWindowFromPointEx(hWndTemp,p,CWP_SKIPINVISIBLE|CWP_SKIPDISABLED|CWP_SKIPTRANSPARENT);
-                } while ((hWndChild) && (hWndChild != hWndTemp));
-
-                if (hWndChild /*&& (hWndChild != hWnd)*/) {
-                    if (hWndChild != __currentPointerView) {
-                        int modifiers = getModifiers();
-
-                        if (__currentPointerView) {
-                            if (inSizeMove) {
-                                if (needDelayedMouseLeaveWindow == NULL) {
-                                    needDelayedMouseLeaveWindow = __currentPointerView;
-                                }
-                            } else {
-                                if (GetWindow_eventMask(__currentPointerView) & LeaveWindowMask) {
-                                    enqEvent(LeaveWindowMask, __currentPointerView, __WM_MOUSELEAVE, 0, -1, -1, 0, modifiers, EV_NOTIME);
-                                    SetWindow_mouseXY(__currentPointerView, -9999, -9999);
-                                }
-                            }
-                            __currentPointerView = 0;
-                        }
-                        if (inSizeMove) {
-                            needDelayedMouseEnterWindow = hWndChild;
-                            delayedMouseEnterX = evRootX;
-                            delayedMouseEnterY = evRootY;
-                        } else {
-                            if (GetWindow_eventMask(hWndChild) & EnterWindowMask) {
-                                enqEvent(EnterWindowMask, hWndChild, __WM_MOUSEENTER, 0, evRootX, evRootY, 0, modifiers, EV_NOTIME);
-                                SetWindow_mouseXY(hWndChild, evRootX, evRootY);
-                            }
-                            // SetFocus(hWndChild);
-                        }
-                        __currentPointerView = hWndChild;
-                    }
-                }
-            }
-
-            /*
-             * ignore child window messages ...
-             */
-            if (GetParent(hWnd) != NULL) {
-                break;
-            }
-
-            {
-                WINDOWPOS *wp = (WINDOWPOS *)lParam;
-                RECT rct, dRect;
-                int x, y, w, h;
-                int dW, dH;
-
-#if 0
-                dRect.left = 0;
-                dRect.top = 0;
-                dRect.right = 100;
-                dRect.bottom = 100;
-                winStyleBits = GetWindowLong(hWnd, GWL_STYLE);
-                winExStyleBits = GetWindowLong(hWnd, GWL_EXSTYLE);
-                AdjustWindowRectEx(&dRect, winStyleBits, 0, winExStyleBits);
-                dW = dRect.right - dRect.left;
-                dH = dRect.bottom - dRect.top;
-#endif
-                GetClientRect(hWnd, &rct);
-
-                x = rct.left;
-                y = rct.top;
-                w = rct.right - rct.left;
-                h = rct.bottom - rct.top;
-
-                if (__debug__) {
-                    EVENT_PRINTF(("WM_WINDOWPOSCHANGED ["));
-
-                    if (wp->flags & SWP_NOSIZE) {
-                        EVENT_PRINTF(("NOSIZE "));
-                    }
-                    if (wp->flags & SWP_NOMOVE) {
-                        EVENT_PRINTF(("NOMOVE "));
-                    }
-                    if (wp->flags & SWP_NOZORDER) {
-                        EVENT_PRINTF(("NOZORDER "));
-                    }
-                    if (wp->flags & SWP_NOREDRAW) {
-                        EVENT_PRINTF(("NOREDRAW "));
-                    }
-                    if (wp->flags & SWP_NOACTIVATE) {
-                        EVENT_PRINTF(("NOACTIVATE "));
-                    }
-                    if (wp->flags & SWP_FRAMECHANGED) {
-                        EVENT_PRINTF(("FRAMECHANGED "));
-                    }
-                    if (wp->flags & SWP_NOCOPYBITS) {
-                        EVENT_PRINTF(("NOCOPYBITS "));
-                    }
-                    if (wp->flags & SWP_NOOWNERZORDER) {
-                        EVENT_PRINTF(("NOOWNERZORDER "));
-                    }
-                    if (wp->flags & SWP_NOSENDCHANGING) {
-                        EVENT_PRINTF(("NOSENDCHANGING "));
-                    }
-                    if (wp->flags & SWP_DEFERERASE) {
-                        EVENT_PRINTF(("DEFERERASE "));
-                    }
-                    if (wp->flags & SWP_ASYNCWINDOWPOS) {
-                        EVENT_PRINTF(("ASYNCWINDOWPOS "));
-                    }
-                    if (wp->flags & SWP_HIDEWINDOW) {
-                        EVENT_PRINTF(("HIDEWINDOW "));
-                    }
-                    if (wp->flags & SWP_SHOWWINDOW) {
-                        EVENT_PRINTF(("SHOWWINDOW "));
-                    }
-
-                    EVENT_PRINTF(("] %d/%d %d/%d flags:%d (0x%x) ->",
-                                wp->x, wp->y, wp->cx, wp->cy, wp->flags, wp->flags));
-                    EVENT_PRINTF(("  client rect now: %d/%d %d/%d\n",x, y, w, h));
-
-                } /* __debug__ */
-#ifdef THIS_IS_WRONG
-                if (!(wp->flags & SWP_NOSIZE)) {
-                    EVENT_PRINTF(("w,h: %d/%d vs. %d/%d\n", wp->cx, wp->cy, w, h));
-                    w = wp->cx;
-                    h = wp->cy;
-                }
-                if (!(wp->flags & SWP_NOMOVE)) {
-                    EVENT_PRINTF(("x,y: %d/%d vs. %d/%d\n", wp->x, wp->y, x, y));
-                    x = wp->x;
-                    y = wp->y;
-                }
-#endif
-                lastPos_win = 0;
-
-                if ((w == 0) && (h == 0)) {
-                    EVENT_PRINTF(("w,h = 0.\n"));
-                    if (! GetWindow_iconified(hWnd)) {
-                        EVENT_PRINTF(("iconified.\n"));
-                        SetWindow_iconified(hWnd, 1);
-                        DPRINTF(("WM_WINDOWPOSCHANGED to iconified (flags:0x%x)\n", wp->flags));
-                        enqEvent(0, hWnd, __WM_ICONIFIED, 1, 0, 0, 0, 0, EV_NOTIME);
-                    }
-                } else {
-                    if (GetWindow_iconified(hWnd)) {
-                        EVENT_PRINTF(("deiconified.\n"));
-                        SetWindow_iconified(hWnd, 0);
-                        DPRINTF(("WM_WINDOWPOSCHANGED to deiconified (flags:0x%x)\n", wp->flags));
-                        enqEvent(0, hWnd, __WM_ICONIFIED, 0, 0, 0, 0, 0, EV_NOTIME);
-                    }
-                    if (!(wp->flags & SWP_NOSIZE)
-                     || !(wp->flags & SWP_NOMOVE)) {
-                        EVENT_PRINTF(("enq event %x: %d, %d, %d, %d\n", hWnd, x, y, w, h));
-#ifdef COMPRESS_WINDOWPOSCHANGED
-                        /*
-                         * remember the current
-                         * window and size;
-                         * This allows the backend to ignore
-                         * intermediate events.
-                         */
-                        lastPos_w = w;
-                        lastPos_h = h;
-                        lastPos_x = x;
-                        lastPos_y = y;
-                        lastPos_win = hWnd;
-#endif
-                        enqEvent(0, hWnd, WM_WINDOWPOSCHANGED, 0, x, y, w, h, EV_NOTIME);
-                    } else {
-                        EVENT_PRINTF(("no event due to SWP_NOSIZE/SWP_NOMOVE.\n"));
-                    }
-                }
-            }
-            *pDefault = 0;
-            return 0;
-
-        case WM_ERASEBKGND:
-            DPRINTFIF(__debug_WM_ERASEBKGND__ , ("WM_ERASEBKGND\n"));
-            if (isNative) {
-                NDPRINTF(("WM_ERASEBKGND for native - default handling\n"));
-                return 0;
-            }
-
-#ifndef PRE_21_NOV
-            *pDefault = 0;
-            return 0;
-#else
-
-            if (GetWindow_flag(hWnd) & LI_INPUTWIN) {
-                *pDefault = 0;
-                return 0;
-            }
-            if (hWnd == __rootWinSpezial) {
-                *pDefault = 0;
-                return 0;
-            }
-
-            /* THIS_WORKS */
-            *pDefault = 0;
-            return 0;
-
-#endif  /* ! PRE_21_NOV */
-
-        case WM_PAINT:
-            DPRINTFIF(__debug_WM_PAINT__ , ("WM_PAINT ********************* "));
-
-            if (isNative) {
-                NDPRINTF(("WM_PAINT for native - default handling\n"));
-                return 0;
-            }
-
-#ifndef PRE_21_NOV
-            {   int n;
-
-                n = __generateExposes( hWnd, NULL, WM_PAINT, 0 );
-
-                if( n <= 0 ) {
-                    * pDefault = 1;
-                    return 0;
-                }
-                * pDefault = 0;
-                return n;
-            }
-#else
-
-
-
-            if (GetWindow_flag(hWnd) & LI_INPUTWIN) {
-                *pDefault = 0;
-                return 0;
-            }
-
-            if (hWnd == __rootWinSpezial) {
-# ifdef THIS_MAKES_GUI_PAINTER_START_SLOW
-                *pDefault = 0;
-# endif
-                return 0;
-            }
-
-            {
-                int retVal;
-
-# ifdef LATE_GENERATE_EXPOSE
-                enqEvent(0, hWnd, __WM_PAINT, 0, 0, 0, 0, 0, EV_NOTIME);
-# else
-                AQUIRE_DRAW_MUTEX
-                retVal = __generateExposes(hWnd, NULL, WM_PAINT, WM_PAINT_CLEAR_EARLY);
-                RELEASE_DRAW_MUTEX
-# endif
-                switch (retVal) {
-                    case -1:  /* error */
-                        *pDefault = 0;
-                        break;
-                    case 0:   /* nothing generated */
-                    default:  /* generated events */
-                        break;
-                }
-# ifdef THIS_IS_BAD
-                *pDefault = 0;
-                return 1;
-# endif
-            }
-            return 0;
-
-#endif  /* ! PRE_21_NOV */
-
-        case WM_SIZE:
-            DPRINTFIF(__debug_WM_SIZE__ , ("WM_SIZE\n"));
-
-            lastPos_win = 0;
-            /*
-             * ignore child window messages ...
-             */
-            if (GetParent(hWnd) != NULL) {
-                *pDefault = 0;
-                return 0;
-            }
-
-            switch (wParam) {
-                case SIZE_MAXIMIZED:     /* default handling */
-                case SIZE_MINIMIZED:     /* default handling */
-                case SIZE_RESTORED:      /* default handling */
-                    {
-                        RECT rct;
-                        int x, y, w, h;
-
-                        GetClientRect(hWnd, &rct);
-
-                        x = rct.left;
-                        y = rct.top;
-                        w = rct.right - rct.left;
-                        h = rct.bottom - rct.top;
-
-                        EVENT_PRINTF(("WM_MIN/MAX/RESTORED\n"));
-
-                        if ((w == 0) && (h == 0)) {
-                            /*
-                             * iconified ...
-                             */
-                            if (! GetWindow_iconified(hWnd)) {
-                                SetWindow_iconified(hWnd, 1);
-                                enqEvent(0, hWnd, __WM_ICONIFIED, 1, 0, 0, 0, 0, EV_NOTIME);
-                            }
-                        } else {
-                            if (GetWindow_iconified(hWnd)) {
-                                SetWindow_iconified(hWnd, 0);
-                                enqEvent(0, hWnd, __WM_ICONIFIED, 0, 0, 0, 0, 0, EV_NOTIME);
-                            }
-                            EVENT_PRINTF(("enq event2 %x: %d, %d, %d, %d\n", hWnd, x, y, w, h));
-#ifdef COMPRESS_WINDOWPOSCHANGED
-                            /*
-                             * remember the current
-                             * window and size;
-                             * This allows the backend to ignore
-                             * intermediate events.
-                             */
-                            lastPos_w = w;
-                            lastPos_h = h;
-                            lastPos_x = x;
-                            lastPos_y = y;
-                            lastPos_win = hWnd;
-#endif
-                            enqEvent(0, hWnd, WM_WINDOWPOSCHANGED, 0, x, y, w, h, EV_NOTIME);
-                        }
-                   }
-                   break;
-
-                default:                 /* ignore */
-                    *pDefault = 0;
-                    return 0;
-            }
-            break;
-
-        case WM_DROPFILES:
-            DPRINTFIF(__debug_WM_DROPFILES__ , ("WM_DROPFILES\n"));
-            enqEvent(0, hWnd, message, wParam, 0, 0, 0, 0, EV_NOTIME);
-            break;
-
-        case WM_SHOWWINDOW:
-            DPRINTFIF(__debug_WM_SHOWWINDOW__ , ("WM_SHOWWINDOW h=%x\n", hWnd));
-            enqEvent(0, hWnd, message, wParam, 0, 0, 0, 0, EV_NOTIME);
-            if (isNative) {
-                NDPRINTF(("WM_SHOWWINDOW for native - default handling\n"));
-                return 0;
-            }
-            *pDefault = 0;
-            break;
-
-        case WM_MOUSEACTIVATE :
-            DPRINTFIF(__debug_WM_MOUSEACTIVATE__ , ("WM_MOUSEACTIVATE h=%x parent=%x\n", hWnd, GetParent(hWnd)));
-
-            /*
-             * ignore child window messages ...
-             */
-            if (GetParent(hWnd)) {
-                return 0;
-            }
-
-            *pDefault = 0;
-            if ((hWnd == __rootWinSpezial) || (hWnd == GetActiveWindow())) {
-                DDPRINTF(("NOACTIVATE (root or already)\n"));
-                return MA_NOACTIVATE;
-            }
-            if (LOWORD(lParam) != HTCLIENT) {
-                DDPRINTF(("ACTIVATE (not client)\n"));
-                return MA_ACTIVATE;
-            }
-            if (__activateOnClick) {
-                if (__ignoreButtonPressOnActivate) {
-                    DDPRINTF(("ACTIVATE_EAT\n"));
-                    /*
-                     * windows is sooo stupid:
-                     * it will send me a MOTION soon after, with the
-                     * to the click location, with the buttonState down.
-                     * The app will interpret that as a pressed motion and
-                     * do a selection (if in a textview).
-                     * To prevent this, we set a flag here, that the following
-                     * motion is to be suppressed.
-                     * Until the mouse is released.
-                     */
-                    __eatingMouseEvents = 1;
-                    return MA_ACTIVATEANDEAT;
-                }
-                DDPRINTF(("ACTIVATE\n"));
-                return MA_ACTIVATE;
-            }
-            DDPRINTF(("NO_ACTIVATE\n"));
-            return MA_NOACTIVATE;
-
-        case WM_NCHITTEST:
-            EVENT_PRINTF2(("WM_NCHITTEST\n"));
-            if (hWnd == __rootWinSpezial) {
-                *pDefault = 0;
-                return HTCLIENT;
-            }
-            break;
-
-        case WM_NCACTIVATE:
-            EVENT_PRINTF(("WM_NCACTIVATE\n"));
-            break;
-
-        case WM_ACTIVATE:
-            CPRINTF(("WM_ACTIVATE %s h=%x\n", LOWORD(wParam) ? "active" : "inactive", hWnd));
-
-            switch (LOWORD(wParam)) {
-                case WA_INACTIVE:
-                    EVENT_PRINTF2(("WM_ACTIVATE inactive h=%x\n", hWnd));
-                    break;
-
-                case WA_ACTIVE:
-                    EVENT_PRINTF2(("WM_ACTIVATE active h=%x\n", hWnd));
-
-#ifdef THIS_DOES_NOT_AVOID_DOUBLE_REPAINTS
-                    __generateRecursiveExposes(hWnd, WM_PAINT);
-#endif /* sigh */
-                    break;
-
-                case WA_CLICKACTIVE:
-                    EVENT_PRINTF2(("++ WM_ACTIVATE clkactive h=%x\n", hWnd));
-                    break;
-
-                default:
-                    EVENT_PRINTF2(("WM_ACTIVATE ? h=%x\n", hWnd));
-                    break;
-            }
-
-#ifndef PRE_25_NOV_03
-            if (__currentCapture == CAPTURE_NONE) {
-                HWND  newHWnd = 0;
-                POINT newPoint;
-
-                if (LOWORD(wParam) != WA_INACTIVE) {
-                    if (MustHandleButtonEvent()) {
-                        newPoint.x = evRootX;
-                        newPoint.y = evRootY;
-
-                        newHWnd = WindowFromPoint (newPoint);
-
-                        if (newHWnd) {
-                            if ( (newHWnd == hWnd) || IsChild(hWnd, newHWnd) ) {
-                                ScreenToClient (newHWnd, & newPoint);
-
-                                if ((newPoint.x < 0) || (newPoint.y < 0)) {
-                                    newHWnd = 0;
-                                }
-                            } else {
-                                newHWnd = 0;
-                            }
-                        }
-                    }
-                }
-                CPRINTF(( "Old Handle: %x New Handle: %x  x:%d y:%d\n", __currentPointerView, newHWnd, newPoint.x, newPoint.y));
-
-                if (newHWnd != __currentPointerView) {
-                    int modifiers = getModifiers();
-
-                    if (__currentPointerView) {
-                        if (GetWindow_eventMask(__currentPointerView) & LeaveWindowMask) {
-                            enqEvent(LeaveWindowMask, __currentPointerView, __WM_MOUSELEAVE, 0, -1, -1, 0, modifiers, EV_NOTIME);
-                            SetWindow_mouseXY(__currentPointerView, -9999, -9999);
-                        }
-                    }
-                    __currentPointerView = newHWnd;
-
-                    if (GetWindow_eventMask(__currentPointerView) & LeaveWindowMask) {
-                        enqEvent(EnterWindowMask, __currentPointerView, __WM_MOUSEENTER, 0, newPoint.x, newPoint.y, 0, modifiers, EV_NOTIME);
-                        SetWindow_mouseXY(__currentPointerView, newPoint.x, newPoint.y);
-                    }
-                }
-            }
-#endif
-            enqEvent(0, hWnd, WM_ACTIVATE, wParam, 0, 0, 0, 0, EV_NOTIME);
-
-            if (isNative) {
-                return 0;
-            }
-            break;
-
-        case WM_HOTKEY:
-            // console_fprintf(stderr, "winEventProcessing [info]: receive hotkey %x\n",wParam);
-            DPRINTFIF(__debug_WM_KEYUP__ , ("WM_HOTKEY %x\n", wParam));
-            {
-                enqEvent(0, hWnd, WM_HOTKEY, wParam, lParam, 0, 0, 0, evTime);
-            }
-            break;
-
-        case WM_SYSCHAR:
-            EVENT_PRINTF2(("WM_SYSCHAR h=%x %x\n", hWnd, wParam));
-            goto commonChar;
-
-#ifdef WM_UNICHAR
-        /* does not work, anyway */
-        case WM_UNICHAR:
-            DPRINTFIF(__debug_WM_CHAR__ , ("WM_UNICHAR h=%x %x\n", hWnd, wParam));
-            if (wParam == UNICODE_NOCHAR) {
-                /* this is a query from windows to see if I am able to receive unicode... */
-                *pDefault = 0;
-                return 1;
-            }
-            goto commonChar;
-#endif
-
-        case WM_CHAR:
-            DPRINTFIF(__debug_WM_CHAR__ , ("WM_CHAR h=%x %x\n", hWnd, wParam));
-#if 0
-            EVENT_PRINTF2(("WM_CHAR h=%x %x\n", hWnd, wParam));
-#endif
-        commonChar:
-            if (isNative) {
-                NDPRINTF(("WM_CHAR for native - default handling\n"));
-                return 0;
-            }
-
-            {
-                HWND destWindow;
-                int evMask;
-
-                if (__focusFollowsMouse) {
-                    destWindow = __currentPointerView;
-                    if (destWindow == 0) {
-                        destWindow = hWnd;
-                    }
-                } else {
-                    destWindow = hWnd;
-                }
-
-                evMask = GetWindow_eventMask(destWindow);
-                if (evMask & (KeyPressMask | KeyReleaseMask)) {
-                    POINT p;
-                    int modifiers = getModifiers();
-
-                    p.x = evRootX;
-                    p.y = evRootY;
-                    ScreenToClient(destWindow, &p);
-                    x = p.x;
-                    y = p.y;
-
-                    DPRINTFIF(__debug_WM_CHAR__ , ("key:%x modifiers: %x\n", wParam, modifiers));
-                    if (evMask & KeyPressMask)
-                        enqEvent(KeyPressMask, destWindow, WM_KEYDOWN, wParam, x, y, lParam, (modifiers | TRANSLATED_KEY), evTime);
-                    if (evMask & KeyReleaseMask)
-                        enqEvent(KeyReleaseMask, destWindow, WM_KEYUP, wParam, x, y, lParam, (modifiers | TRANSLATED_KEY), evTime);
-                }
-            }
-            *pDefault = 0;
-            return 0;
-
-
-        case WM_KEYUP:
-            DPRINTFIF(__debug_WM_KEYUP__ , ("WM_KEYUP h=%x %x\n", hWnd, wParam));
-            goto commonKeyUp;
-
-        case WM_SYSKEYUP:
-            DPRINTFIF(__debug_WM_KEYUP__ , ("WM_SYSKEYUP %x\n, wParam"));
-        commonKeyUp:
-            if (isNative) {
-                NDPRINTF(("WM_KEYUP/WM_SYSKEYUP for native - default handling\n"));
-                return 0;
-            }
-            {
-                HWND destWindow;
-
-                if (__focusFollowsMouse) {
-                    destWindow = __currentPointerView;
-                    if (destWindow == 0) {
-                        destWindow = hWnd;
-                    }
-                } else {
-                    destWindow = hWnd;
-                }
-
-                if (GetWindow_eventMask(destWindow) & KeyReleaseMask) {
-                    POINT p;
-
-                    p.x = evRootX;
-                    p.y = evRootY;
-                    ScreenToClient(destWindow, &p);
-                    x = p.x;
-                    y = p.y;
-
-                    enqEvent(KeyReleaseMask, destWindow, message, wParam, x, y, lParam, getModifiers(), evTime);
-                }
-            }
-            *pDefault = 0;
-            return 0;
-
-        case WM_SYSKEYDOWN:
-            DPRINTFIF(__debug_WM_KEYDOWN__ , ("WM_SYSKEYDOWN %x\n, wParam"));
-            goto commonKey;
-
-        case WM_KEYDOWN:
-            DPRINTFIF(__debug_WM_KEYDOWN__ , ("WM_KEYDOWN h=%x %x\n", hWnd, wParam));
-        commonKey:
-            if (isNative) {
-                NDPRINTF(("WM_KEYDOWN/WM_SYSKEYDOWN for native - default handling\n"));
-                return 0;
-            }
-
-#ifdef EXIT_WITH_3_CTRL_Cs
-            if ((msg.wParam == 'c')
-             && (GetKeyState(VK_CONTROL) & 0x8000)) {
-                /* CTRL-C */
-                if (ctrl_c_count++ > 3)  /* for debugging */
-                    exit(1);
-            } else {
-                if (msg.wParam != VK_CONTROL)
-                    ctrl_c_count = 0;
-            }
-#endif
-#ifdef RELEASE_CAPTURE_WITH_3_ESCAPEs
-            if (msg.wParam == VK_ESCAPE)) {
-                /* ESCAPE */
-                if (escape_count++ > 3) {
-                    __currentCapture = CAPTURE_NONE;
-                    ReleaseCapture();
-                    CPRINTF(("ReleaseCapture <ESC>\n"));
-                }
-            } else {
-                escape_count = 0;
-            }
-#endif
-            /* FALL INTO */
-
-            {
-                HWND destWindow;
-
-                if (__focusFollowsMouse) {
-                    destWindow = __currentPointerView;
-                    if (destWindow == 0) {
-                        destWindow = hWnd;
-                    }
-                } else {
-                    destWindow = hWnd;
-                }
-
-                if (GetWindow_eventMask(destWindow) & KeyPressMask) {
-                    POINT p;
-
-                    p.x = evRootX;
-                    p.y = evRootY;
-                    ScreenToClient(destWindow, &p);
-                    x = p.x;
-                    y = p.y;
-
-                    enqEvent(KeyPressMask, destWindow, message, wParam, x, y, lParam, getModifiers(), evTime);
-                }
-            }
-            *pDefault = 0;
-            return 0;
-
-#ifdef WM_MOUSEWHEEL
-        case WM_MOUSEWHEEL:
-            {
-                HWND destWindow;
-
-                if (__focusFollowsMouse) {
-                    destWindow = __currentPointerView;
-                    if (destWindow == 0) {
-                        destWindow = hWnd;
-                    }
-                } else {
-                    destWindow = hWnd;
-                }
-
-
-                EVENT_PRINTF(("WM_MOUSEWHEEL h=%x wP=%x lP=%x\n", hWnd, wParam, lParam));
-                if (GetWindow_eventMask(destWindow) & KeyPressMask) {
-                    POINT p;
-                    int delta;
-
-                    p.x = evRootX;
-                    p.y = evRootY;
-                    ScreenToClient(destWindow, &p);
-                    x = p.x;
-                    y = p.y;
-                    delta = evTime - lastMouseWheelTime;
-                    if (evTime < lastMouseWheelTime) {
-                        delta = (0xFFFFFFFF - lastMouseWheelTime) + evTime;
-                    }
-                    enqEvent(0, destWindow, message, wParam, x, y, lParam, getModifiers(), delta);
-                }
-                lastMouseWheelTime = evTime;
-            }
-            *pDefault = 0;
-            return 0;
-#endif
-
-        case WM_MOUSEMOVE:
-            DPRINTFIF(__debug_WM_MOUSEMOVE__ , ("WM_MOUSEMOVE h=%x\n", hWnd));
-            if (isNative) {
-                NDPRINTF(("WM_MOUSEMOVE for native - default handling\n"));
-                return 0;
-            }
-
-            if (hWnd != __currentPointerView) {
-                if (! MustHandleButtonEvent()) {
-                    *pDefault = 0;
-                    return 0;
-                }
-            }
-
-            {
-                short x, y;
-                int modifiers = getModifiers();
-
-                x = (int)(short)LOWORD(lParam);
-                y = (int)(short)HIWORD(lParam);
-
-                if (__currentCapture == CAPTURE_NONE) {
-                    if (hWnd != __currentPointerView) {
-                        HWND prevPointerView;
-
-                        prevPointerView = __currentPointerView;
-                        if (prevPointerView) {
-                            if (inSizeMove) {
-                                if (needDelayedMouseLeaveWindow == NULL) {
-                                    needDelayedMouseLeaveWindow = __currentPointerView;
-                                }
-                            } else {
-                                if (GetWindow_eventMask(__currentPointerView) & LeaveWindowMask) {
-                                    enqEvent(LeaveWindowMask, __currentPointerView, __WM_MOUSELEAVE, 0, -1, -1, 0, modifiers, evTime);
-                                    SetWindow_mouseXY(__currentPointerView, -9999, -9999);
-                                }
-                            }
-                            __currentPointerView = 0;
-                        }
-
-#if 0
-                        if (__activateOnClick) {
-                            /*
-                             * only send mouseEnter if the window belongs to the current
-                             * active window
-                             */
-                            if (GetTopParent(prevPointerView) == GetTopParent(hWnd)) {
-                            }
-                        }
-#endif
-                        if (inSizeMove) {
-                            needDelayedMouseEnterWindow = hWnd;
-                            delayedMouseEnterX = x;
-                            delayedMouseEnterY = y;
-                        } else {
-                            if (GetWindow_eventMask(hWnd) & EnterWindowMask) {
-                                enqEvent(EnterWindowMask, hWnd, __WM_MOUSEENTER, 0, x, y, 0, modifiers, evTime);
-                                SetWindow_mouseXY(hWnd, x, y);
-                            }
-                        }
-                        __currentPointerView = hWnd;
-                    }
-                    DPRINTFIF(__debug_WM_MOUSEMOVE__ , ("MouseMove %x\n", __currentPointerView));
-                } else {
-                    CPRINTF(("MouseMove Capture %x\n", __currentPointerView));
-                }
-
-                if ((GetWindow_eventMask(__currentPointerView) & PointerMotionMask)
-                 || (modifiers & AnyButtonMask)) {
-                    if (! __eatingMouseEvents) {
-                        if ((x == lastMotionX)
-                         && (y == lastMotionY)
-                         && (__currentPointerView == lastMotionWnd)) {
-                            /* ignore */
-                        } else {
-                            lastMotionX = x;
-                            lastMotionY = y;
-                            lastMotionWnd = __currentPointerView;
-
-                            if ((GetWindow_mouseX(__currentPointerView) == x)
-                             && (GetWindow_mouseY(__currentPointerView) == y)) {
-                            } else {
-                                enqEvent(PointerMotionMask, __currentPointerView, WM_MOUSEMOVE, wParam, x, y, 0, modifiers, evTime);
-                                SetWindow_mouseXY(__currentPointerView, x, y);
-                            }
-                        }
-                    }
-                }
-            }
-            *pDefault = 0;
-            return 0;
-
-        case WM_LBUTTONUP:
-            DPRINTFIF(__debug_WM_BUTTONUP__ , ("WM_LBUTTONUP h=%x\n", hWnd));
-            curButton = Button1;
-            goto commonButtonUp;
-        case WM_MBUTTONUP:
-            DPRINTFIF(__debug_WM_BUTTONUP__ , ("WM_MBUTTONUP h=%x\n", hWnd));
-            curButton = Button2;
-            goto commonButtonUp;
-        case WM_RBUTTONUP:
-            DPRINTFIF(__debug_WM_BUTTONUP__ , ("WM_RBUTTONUP h=%x\n", hWnd));
-            curButton = Button3;
-commonButtonUp:
-            if (isNative) {
-                NDPRINTF(("WM_*BUTTONUP for native - default handling\n"));
-                return 0;
-            }
-
-#ifndef PRE_01_APR_04
-            if ((__currentPointerView != hWnd) && (__currentPointerView == (HANDLE)0)) {
-                __currentPointerView = hWnd;
-
-                if (GetWindow_eventMask(hWnd) & EnterWindowMask) {
-                    POINT p;
-
-                    p.x = evRootX;
-                    p.y = evRootY;
-
-                    ScreenToClient (hWnd, & p);
-
-                    if ((p.x >= 0) && (p.y >= 0)) {
-                        enqEvent(EnterWindowMask, hWnd, __WM_MOUSEENTER, 0, p.x, p.y, 0, getModifiers(), EV_NOTIME);
-                        SetWindow_mouseXY(hWnd, p.x, p.y);
-                    } else {
-                        __currentPointerView = (HANDLE) 0;
-                    }
-                }
-            }
-#endif
-
-            if (__currentCapture == curButton /* CAPTURE_IMPLICIT*/) {
-                __currentCapture = CAPTURE_NONE;
-                ReleaseCapture();
-                CPRINTF(("ReleaseCapture <BUTTONUP>\n"));
-            }
-            EVENT_PRINTF3(("WM_BUTTONUP h=%x pos=%d/%d\n",
-                           hWnd, (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam)));
-
-
-            if (GetWindow_eventMask(hWnd) & ButtonReleaseMask) {
-                if (__eatingMouseEvents) {
-                    __eatingMouseEvents = 0;
-                } else {
-                    enqEvent(ButtonReleaseMask, hWnd,
-                             message, wParam, (UINT)(short)LOWORD(lParam), (INT)(short)HIWORD(lParam),
-                             wParam, getModifiers(), evTime);
-                }
-            }
-            *pDefault = 0;
-            break;
-
-        case WM_LBUTTONDBLCLK:
-            DPRINTFIF(__debug_WM_BUTTONDOWN__ , ("WM_LBUTTONDBLCLK h=%x\n", hWnd));
-            curButton = Button1;
-            goto commonButtonDown;
-        case WM_MBUTTONDBLCLK:
-            DPRINTFIF(__debug_WM_BUTTONDOWN__ , ("WM_MBUTTONDBLCLK h=%x\n", hWnd));
-            curButton = Button2;
-            goto commonButtonDown;
-        case WM_RBUTTONDBLCLK:
-            DPRINTFIF(__debug_WM_BUTTONDOWN__ , ("WM_RBUTTONDBLCLK h=%x\n", hWnd));
-            curButton = Button3;
-#ifdef PRE_25_AUG_2010
-            if (isNative) {
-                 NDPRINTF(("WM_*BUTTONDBLCLK for native - default handling\n"));
-                 return 0;
-            }
-            goto commonButton;
-#else
-            goto commonButtonDown;
-#endif /* PRE_25_AUG_2010 */
-
-        case WM_LBUTTONDOWN:
-            DPRINTFIF(__debug_WM_BUTTONDOWN__ , ("WM_LBUTTONDOWN h=%x\n", hWnd));
-            curButton = Button1;
-            goto commonButtonDown;
-        case WM_MBUTTONDOWN:
-            DPRINTFIF(__debug_WM_BUTTONDOWN__ , ("WM_MBUTTONDOWN h=%x\n", hWnd));
-            curButton = Button2;
-            goto commonButtonDown;
-        case WM_RBUTTONDOWN:
-            DPRINTFIF(__debug_WM_BUTTONDOWN__ , ("WM_RBUTTONDOWN h=%x\n", hWnd));
-            curButton = Button3;
-
-        commonButtonDown:
-            if (isNative) {
-                NDPRINTF(("WM_*BUTTONDOWN for native - default handling\n"));
-                return 0;
-            }
-
-        commonButtonWithCapture:
-            if (__currentCapture == CAPTURE_NONE) {
-                __currentCapture = curButton /*CAPTURE_IMPLICIT*/;
-                //SetFocus(hWnd);
-                SetCapture(hWnd);
-                CPRINTF(("SetCapture <BUTTONDOWN>%x\n",hWnd));
-            }
-            goto commonButton;
-
-        commonButton:
-            EVENT_PRINTF3(("WM_BUTTONDOWN h=%x pos=%d/%d\n",
-                           hWnd, LOWORD(lParam), HIWORD(lParam)));
-
-            if (GetWindow_eventMask(hWnd) & ButtonPressMask) {
-                if (__eatingMouseEvents) {
-                    __eatingMouseEvents = 0;
-                } else {
-                    enqEvent(ButtonPressMask, hWnd,
-                             message, wParam, (UINT)(short)LOWORD(lParam), (INT)(short)HIWORD(lParam),
-                             wParam, getModifiers(), evTime);
-                }
-            }
-            *pDefault = 0;
-            break;
-
-        case WM_CAPTURECHANGED:
-            DPRINTFIF(__debug_WM_FOCUS__ , ("WM_CAPTURECHANGED h=%x to %x\n", hWnd, lParam));
-#if 0
-            if ((__currentCapture != CAPTURE_NONE) && (__currentCapture != CAPTURE_EXPLICIT))
-            {
-            }
-#endif
-            break;
-
-        case WM_KILLFOCUS:
-            DPRINTFIF(__debug_WM_FOCUS__ , ("WM_KILLFOCUS h=%x\n", hWnd));
-            // enqEvent(0, hWnd, WM_KILLFOCUS, wParam, 0, 0, 0, 0, EV_NOTIME);
-            if (isNative) {
-                NDPRINTF(("WM_KILLFOCUS for native - default handling\n"));
-                return 0;
-            }
-            *pDefault = 0;
-            break;
-
-        case WM_SETFOCUS:
-            DPRINTFIF(__debug_WM_FOCUS__ , ("WM_SETFOCUS h=%x\n", hWnd));
-#if 0
-            // enqEvent(0,hWnd, WM_SETFOCUS, wParam, 0, 0, 0, 0, EV_NOTIME);
-            {
-                POINT p;
-                HWND hWndChild,hWndTemp;
-
-                p.x = evRootX;
-                p.y = evRootY;
-                ScreenToClient(hWnd, &p);
-                hWndChild = hWnd; //hWndChild = ChildWindowFromPoint(hWnd,p);
-                do {
-                    hWndTemp = hWndChild;
-                    hWndChild = ChildWindowFromPointEx(hWndTemp,p,CWP_SKIPINVISIBLE|CWP_SKIPDISABLED|CWP_SKIPTRANSPARENT);
-                } while ((hWndChild) && (hWndChild != hWndTemp));
-
-                /*console_printf("WM_ACTIVATE active h=%x p=%d.%d in %x\n", hWnd,p.x,p.y,hWndChild);*/
-                if (hWndChild /*&& (hWndChild != hWnd)*/) {
-                    if (hWndChild != __currentPointerView) {
-                        int modifiers = getModifiers();
-
-                        if (__currentPointerView) {
-                            if (GetWindow_eventMask(__currentPointerView) & LeaveWindowMask)
-                                enqEvent(LeaveWindowMask, __currentPointerView, __WM_MOUSELEAVE, 0, -1, -1, 0, modifiers, EV_NOTIME);
-                                SetWindow_mouseXY(__currentPointerView, -9999, -9999);
-
-                            __currentPointerView = 0;
-                        }
-                        if (GetWindow_eventMask(hWndChild) & EnterWindowMask) {
-                            enqEvent(EnterWindowMask, hWndChild, __WM_MOUSEENTER, 0, evRootX, evRootY, 0, modifiers, EV_NOTIME);
-                            SetWindow_mouseXY(hWndChild, evRootX, evRootY);
-                        }
-                        //SetFocus(hWndChild);
-                        __currentPointerView = hWndChild;
-                    }
-                }
-            }
-
-            if (isNative) {
-                NDPRINTF(("WM_SETFOCUS for native - default handling\n"));
-                return 0;
-            }
-            *pDefault = 0;
-#endif
-            break;
-
-        case WM_GETTEXT:
-            /*EVENT_PRINTF(("WM_GETTEXT %x\n", message));*/
-            break;
-
-        case WM_GETTEXTLENGTH:
-            EVENT_PRINTF(("WM_GETTEXTLENGTH %x\n", message));
-            break;
-
-        case WM_NCCREATE:
-            EVENT_PRINTF(("WM_NCCREATE %x\n", message));
-            break;
-
-        case WM_NCMOUSEMOVE:
-            if (__currentCapture == CAPTURE_NONE) {
-                if (__currentPointerView && (hWnd != __currentPointerView)) {
-                    if (inSizeMove) {
-                        if (needDelayedMouseLeaveWindow == NULL) {
-                            needDelayedMouseLeaveWindow = __currentPointerView;
-                        }
-                    } else {
-                        if (GetWindow_eventMask(__currentPointerView) & LeaveWindowMask) {
-                            enqEvent(LeaveWindowMask, __currentPointerView, __WM_MOUSELEAVE, 0, -1, -1, 0, getModifiers(), evTime);
-                            SetWindow_mouseXY(__currentPointerView, -9999, -9999);
-                        }
-                    }
-                    __currentPointerView = 0;
-                }
-            }
-            *pDefault = 0;
-            break;
-
-        case WM_PARENTNOTIFY:
-            EVENT_PRINTF2(("WM_PARENTNOTIFY h=%x hChild=%x %d\n",
-                                hWnd, lParam, LOWORD(wParam)));
-            break;
-
-        case WM_NCLBUTTONDOWN:
-            DPRINTFIF(__debug_WM_BUTTONDOWN__ , ("WM_NCLBUTTONDOWN\n"));
-            if (__shiftedLeftButtonIsLowerWindow) {
-                /*
-                 * with shift, this is a lower-operation
-                 */
-                if (GetKeyState(VK_SHIFT) & 0x8000) {
-                    SetWindowPos(hWnd, HWND_BOTTOM, 0, 0, 0, 0,
-                                 SWP_NOSENDCHANGING |
-                                 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
-                    *pDefault = 0;
-                }
-            }
-            break;
-
-        case WM_NCLBUTTONUP:
-            DPRINTFIF(__debug_WM_BUTTONUP__ , ("WM_NCLBUTTONUP\n"));
-            break;
-
-        case WM_NCRBUTTONDOWN:
-            DPRINTFIF(__debug_WM_BUTTONDOWN__ , ("WM_NCRBUTTONDOWN\n"));
-            if (__rightButtonIsLowerWindow) {
-                /*
-                 * this is a lower-operation
-                 */
-                SetWindowPos(hWnd, HWND_BOTTOM, 0, 0, 0, 0,
-                             SWP_NOSENDCHANGING |
-                             SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
-                *pDefault = 0;
-            }
-            break;
-
-        case WM_NCRBUTTONUP:
-            DPRINTFIF(__debug_WM_BUTTONUP__ , ("WM_NCRBUTTONUP\n"));
-            break;
-
-        case WM_NCMBUTTONDOWN:
-            DPRINTFIF(__debug_WM_BUTTONDOWN__ , ("WM_NCMBUTTONDOWN\n"));
-            break;
-
-        case WM_NCMBUTTONUP:
-            DPRINTFIF(__debug_WM_BUTTONUP__ , ("WM_NCMBUTTONUP\n"));
-            break;
-
-        case WM_NCLBUTTONDBLCLK:
-            EVENT_PRINTF(("WM_NCLBUTTONDBLCLK\n"));
-            break;
-
-        case WM_NCRBUTTONDBLCLK:
-            EVENT_PRINTF(("WM_NCRBUTTONDBLCLK\n"));
-            break;
-
-        case WM_NCMBUTTONDBLCLK:
-            EVENT_PRINTF(("WM_NCMBUTTONDBLCLK\n"));
-            break;
-
-        case WM_SETTEXT:
-            DPRINTFIF(__debug_WM_SETTEXT__ , ("WM_SETTEXT\n"));
-            break;
-
-#ifdef WM_SYNCPAINT
-        case WM_SYNCPAINT:
-            EVENT_PRINTF(("WM_SYNCPAINT\n"));
-            break;
-#else
-        case 0x88:
-            EVENT_PRINTF(("0x88 (undoc)\n"));
-            break;
-#endif
-
-        case WM_NCCALCSIZE:
-            EVENT_PRINTF(("WM_NCCALCSIZE\n"));
-            break;
-
-        case WM_NCPAINT:
-            EVENT_PRINTF3(("WM_NCPAINT\n"));
-
-#ifdef THIS_DOES_NOT_WORK
-            /* mhmh - something is drawn, but clipped wrong
-             * and with wrong colors ....
-             */
-
-            /*
-             * child windows only ...
-             */
-            if (GetParent(hWnd)) {
-                int clr;
-
-                clr = GetWindow_bdColor(hWnd);
-                if (clr != BlackPixel) {
-                    /*
-                     * draw it here
-                     */
-                    HBRUSH br;
-                    RECT rect, lineRect;
-                    HDC hDC;
-
-                    if (clr == WhitePixel) {
-                        br = __whiteBrush;
-                    } else {
-                        br = CreateSolidBrush(clr);
-                    }
-
-                    GetWindowRect(hWnd, &rect);
-                    hDC = GetWindowDC(hWnd);
-                    SelectClipRgn(hDC, NULL);
-
-                    lineRect.left = rect.left;
-                    lineRect.right = rect.right;
-                    lineRect.top = rect.top;
-                    lineRect.bottom = rect.top + 1;
-                    FillRect(hDC, &lineRect, br);
-
-                    lineRect.bottom = rect.bottom - 1;
-                    lineRect.bottom = rect.bottom;
-                    FillRect(hDC, &lineRect, br);
-
-                    lineRect.top = rect.top;
-                    lineRect.bottom = rect.bottom;
-                    lineRect.left = rect.left;
-                    lineRect.right = rect.left + 1;
-                    FillRect(hDC, &lineRect, br);
-
-                    lineRect.left = rect.right - 1;
-                    lineRect.right = rect.right;
-                    FillRect(hDC, &lineRect, br);
-
-                    _DeleteBrush(br, __LINE__);
-                    ReleaseDC(hWnd, hDC);
-                    *pDefault = 0;
-                    return 0;
-                }
-            }
-#endif /* THIS_DOES_NOT_WORK */
-            break;
-
-        case WM_SYSCOMMAND:
-            switch (wParam & ~0x000F) {
-                case SC_CLOSE:
-                    EVENT_PRINTF2(("WM_SYSCOMMAND SC_CLOSE\n"));
-                    break;
-
-                case SC_MOVE:
-                    EVENT_PRINTF2(("WM_SYSCOMMAND SC_MOVE\n"));
-                    break;
-
-                case SC_RESTORE:
-                    EVENT_PRINTF2(("WM_SYSCOMMAND SC_RESTORE\n"));
-                    break;
-
-                case SC_SIZE:
-                    EVENT_PRINTF2(("WM_SYSCOMMAND SC_SIZE\n"));
-                    break;
-
-                default:
-                    EVENT_PRINTF2(("WM_SYSCOMMAND %x\n", wParam));
-                    break;
-            }
-            break;
-
-        case WM_INITMENU:
-            EVENT_PRINTF(("WM_INITMENU\n"));
-            break;
-
-        case WM_INITMENUPOPUP:
-            EVENT_PRINTF(("WM_INITMENUPOPUP\n"));
-            break;
-
-        case WM_ENTERIDLE:
-            EVENT_PRINTF(("WM_ENTERIDLE\n"));
-            break;
-
-        case WM_ENTERMENULOOP:
-            EVENT_PRINTF(("WM_ENTERMENULOOP\n"));
-            break;
-
-        case WM_EXITMENULOOP:
-            EVENT_PRINTF(("WM_EXITMENULOOP\n"));
-            break;
-
-        case WM_MENUSELECT:
-            EVENT_PRINTF(("WM_MENUSELECT\n"));
-            break;
-
-        case WM_QUIT:
-            DPRINTF(("quit message hWnd=0x%x lP=0x%x wP=0x%x\n", hWnd, lParam, wParam));
-            enqEvent(0, 0, WM_QUIT, wParam, lParam, 0, 0, 0, EV_NOTIME);
-            break;
-
-        case WM_NCDESTROY:
-            EVENT_PRINTF(("WM_NCDESTROY\n"));
-            break;
-
-        case WM_QUERYNEWPALETTE:
-            EVENT_PRINTF(("WM_QUERYNEWPALETTE\n"));
-            break;
-
-        case WM_PALETTECHANGED:
-            EVENT_PRINTF(("WM_PALETTECHANGED\n"));
-            break;
-
-        case WM_ACTIVATEAPP:
-            EVENT_PRINTF2(("WM_ACTIVATEAPP %s\n", wParam ? "active" : "inactive"));
-            break;
-
-        case WM_SYSDEADCHAR:
-            EVENT_PRINTF2(("WM_SYSDEADCHAR %x\n, wParam"));
-            break;
-
-        case WM_DEADCHAR:
-            EVENT_PRINTF2(("WM_DEADCHAR %x\n, wParam"));
-            break;
-
-        case WM_PAINTICON:
-            EVENT_PRINTF(("WM_PAINTICON\n"));
-            break;
-
-        case WM_ICONERASEBKGND:
-            EVENT_PRINTF(("WM_ICONERASEBKGND\n"));
-            break;
-
-        case WM_WINDOWPOSCHANGING:
-            DPRINTFIF(__debug_WM_WINDOWPOSCHANGING__ , ("WM_WINDOWPOSCHANGING\n"));
-
-#ifdef HANDLE_VIEWGRAVITY
-            /*
-             * any child with a viewGravity ?
-             * (only care for topViews here;
-             *  child views do it on the smalltalk level ...)
-             */
-            if (GetParent(hWnd) == 0) {
-                if (GetParent(hWnd) == 0) {
-                    struct gravityCallBackInfo i;
-                    RECT rct, dRect;
-                    int dW, dH;
-                    WINDOWPOS *wp = (WINDOWPOS *)lParam;
-                    int winStyleBits, winExStyleBits;
-
-                    if (! (wp->flags & SWP_NOSIZE)) {
-                        dRect.left = 0;
-                        dRect.top = 0;
-                        dRect.right = 100;
-                        dRect.bottom = 100;
-                        winStyleBits = GetWindowLong(hWnd, GWL_STYLE);
-                        winExStyleBits = GetWindowLong(hWnd, GWL_EXSTYLE);
-                        AdjustWindowRectEx(&dRect, winStyleBits, 0, winExStyleBits);
-                        dW = dRect.right - dRect.left;
-                        dH = dRect.bottom - dRect.top;
-
-                        GetClientRect(hWnd, &rct);
-
-                        i.parent = hWnd;
-
-                        i.currW = rct.right - rct.left;
-                        i.currH = rct.bottom - rct.top;
-
-                        /* wp gives us the new outer (frame) bounds */
-                        i.newW = wp->cx - (dW - 100);
-                        i.newH = wp->cy - (dH - 100);
-
-                        if ((i.currW != i.newW)
-                         || (i.currH != i.newH)) {
-                            DPRINTF((stderr, "about to sizeChange old: %d/%d new: %d/%d\n",
-                                    i.currW, i.currH, i.newW, i.newH));
-
-                            GetWindowRect(hWnd, &rct);
-                            i.parentWinX = rct.left - dRect.left;
-                            i.parentWinY = rct.top - dRect.top;
-                            EnumChildWindows(hWnd, gravityEnumeratorCallBack, (int)(&i));
-                        }
-                    }
-                }
-            }
-#endif /* HANDLE_VIEWGRAVITY */
-
-            break;
-
-        case WM_QUERYOPEN:
-            EVENT_PRINTF(("WM_QUERYOPEN\n"));
-            break;
-
-        case WM_QUERYENDSESSION:
-            EVENT_PRINTF(("WM_QUERYENDSESSION\n"));
-            *pDefault = 0;
-            if (@global(CanEndSession) == false) {
-                enqEvent(0, hWnd, WM_QUERYENDSESSION, wParam, 0, 0, 0, 0, EV_NOTIME);
-
-                // TODO: enter new event loop
-                // which is left when an endSessionConfirmation
-                // arrives from smalltalk
-                // (either positive or negative).
-                // for now, do not allow leaving
-                // windows as long as ST/X is open.
-
-                return(0);
-            }
-            return(TRUE);  // allow leaving windows
-            break;
-
-        case WM_ENDSESSION:
-            EVENT_PRINTF(("WM_ENDSESSION\n"));
-            enqEvent(0, hWnd, WM_ENDSESSION, wParam, 0, 0, 0, 0, EV_NOTIME);
-            break;
-
-        case WM_DISPLAYCHANGE:
-            EVENT_PRINTF(("WM_DISPLAYCHANGE\n"));
-            enqEvent(0, hWnd, WM_DISPLAYCHANGE, wParam, 0, 0, 0, 0, EV_NOTIME);
-            break;
-
-        case WM_FONTCHANGE:
-            EVENT_PRINTF(("WM_FONTCHANGE\n"));
-            enqEvent(0, hWnd, WM_FONTCHANGE, wParam, 0, 0, 0, 0, EV_NOTIME);
-            break;
-
-        case WM_WININICHANGE:
-            EVENT_PRINTF(("WM_WININICHANGE\n"));
-            enqEvent(0, hWnd, WM_WININICHANGE, wParam, 0, 0, 0, 0, EV_NOTIME);
-            break;
-
-        case WM_SYSCOLORCHANGE:
-            EVENT_PRINTF(("WM_SYSCOLORCHANGE\n"));
-            enqEvent(0, hWnd, WM_SYSCOLORCHANGE, wParam, 0, 0, 0, 0, EV_NOTIME);
-            break;
-
-        case WM_MOVING:
-            DPRINTFIF(__debug_WM_MOVING__ , ("WM_MOVING\n"));
-#ifdef DELAY_ENTER_LEAVE_WHILE_IN_SIZE_MOVE
-            inMove = 1;
-#endif
-            break;
-
-        case WM_SIZING:
-            EVENT_PRINTF(("WM_SIZING\n"));
-#ifdef DELAY_ENTER_LEAVE_WHILE_IN_SIZE_MOVE
-            inSize = 1;
-#endif
-            break;
-
-        case WM_ENTERSIZEMOVE:
-            EVENT_PRINTF(("WM_ENTERSIZEMOVE\n"));
-#ifdef DELAY_ENTER_LEAVE_WHILE_IN_SIZE_MOVE
-            inSizeMove = 1;
-#endif
-            break;
-
-        case WM_EXITSIZEMOVE:
-            EVENT_PRINTF(("WM_EXITSIZEMOVE\n"));
-
-#ifndef PRE_13_APR_04_POSCHANGED_IN_EXITSIZEMOVE
-            if (inMove) {
-                /* generate WM_WINDOWPOSCHANGED
-                */
-                RECT rct;
-                int x, y, w, h;
-
-                GetClientRect(hWnd, &rct);
-
-                x = rct.left;
-                y = rct.top;
-                w = rct.right - rct.left;
-                h = rct.bottom - rct.top;
-
-                if ((w == 0) && (h == 0)) {
-                    if (! GetWindow_iconified(hWnd)) {
-                        SetWindow_iconified(hWnd, 1);
-                    }
-                    enqEvent(0, hWnd, __WM_ICONIFIED, 1, 0, 0, 0, 0, EV_NOTIME);
-                } else {
-                    if (GetWindow_iconified(hWnd)) {
-                        SetWindow_iconified(hWnd, 0);
-                        enqEvent(0, hWnd, __WM_ICONIFIED, 0, 0, 0, 0, 0, EV_NOTIME);
-                    } else {
-                        enqEvent(0, hWnd, WM_WINDOWPOSCHANGED, 0, x, y, w, h, EV_NOTIME);
-                    }
-                }
-            }
-#endif
-
-            inSizeMove = inMove = inSize = 0;
-
-            if (needDelayedMouseLeaveWindow || needDelayedMouseEnterWindow) {
-                int modifiers = getModifiers();
-
-                if (needDelayedMouseLeaveWindow) {
-                    if (GetWindow_eventMask(needDelayedMouseLeaveWindow) & LeaveWindowMask) {
-                        enqEvent(LeaveWindowMask, needDelayedMouseLeaveWindow, __WM_MOUSELEAVE, 0, -1, -1, 0, modifiers, EV_NOTIME);
-                        SetWindow_mouseXY(needDelayedMouseLeaveWindow, -9999, -9999);
-                    }
-                    needDelayedMouseLeaveWindow = NULL;
-                }
-                if (needDelayedMouseEnterWindow) {
-                    if (GetWindow_eventMask(needDelayedMouseEnterWindow) & EnterWindowMask) {
-                        enqEvent(EnterWindowMask, needDelayedMouseEnterWindow, __WM_MOUSEENTER, 0, delayedMouseEnterX, delayedMouseEnterY, 0, modifiers, EV_NOTIME);
-                        SetWindow_mouseXY(needDelayedMouseEnterWindow, delayedMouseEnterX, delayedMouseEnterY);
-                    }
-                    needDelayedMouseEnterWindow = NULL;
-                }
-            }
-
-            break;
-
-        case WM_MOVE:
-            EVENT_PRINTF(("WM_MOVE\n"));
-            break;
-
-        case WM_POWER:
-            EVENT_PRINTF(("WM_POWER\n"));
-            enqEvent(0, hWnd, WM_POWER, wParam, 0, 0, 0, 0, EV_NOTIME);
-            break;
-
-        /* native widget actions */
-        case WM_COMMAND:
-            if (lParam) {
-                NDPRINTF(("COMMAND for widget\n"));
-                enqEvent(0, (HWND)(lParam), WM_COMMAND, wParam, lParam, 0, 0, 0, EV_NOTIME);
-            } else {
-                NDPRINTF(("COMMAND for owner\n"));
-                enqEvent(0, hWnd, WM_COMMAND, wParam, lParam, 0, 0, 0, EV_NOTIME);
-            }
-            break;
-
-        /* tray action */
-        case WM_TRAY_MESSAGE:
-            DPRINTF(("tray message hWnd=0x%x lP=0x%x wP=0x%x\n", hWnd, lParam, wParam));
-            enqEvent(0, hWnd, WM_TRAY_MESSAGE, wParam, lParam, 0, 0, 0, EV_NOTIME);
-            break;
-
-        case WM_COPYDATA:
-            DPRINTFIF(__debug_WM_COPYDATA__ , ("WM_COPYDATA\n"));
-            {
-                PCOPYDATASTRUCT pCDs = (PCOPYDATASTRUCT) lParam;
-                int dwData = pCDs->dwData;
-                int nBytes = pCDs->cbData;
-                void *pData = pCDs->lpData;
-                void *pCopiedData;
-
-                DPRINTFIF(__debug_WM_COPYDATA__ , ("WM_COPYDATA %d %lx\n", nBytes, pData));
-
-                /*
-                 * because pData is only valid here, copy it out to a malloc'd
-                 * area. This MUST be free'd by someone else !
-                 */
-                if (nBytes) {
-                    pCopiedData = malloc(nBytes);
-                    memcpy(pCopiedData, pData, nBytes);
-                } else {
-                    pCopiedData = NULL;
-                }
-                //     (flag, hWnd, message, wParam, arg1, arg2, arg3, arg4, evTime)
-                enqEvent(0, hWnd, WM_COPYDATA, wParam, (INT)pCopiedData, nBytes, dwData, 0, EV_NOTIME);
-            }
-            *pDefault = 0;
-            break;
-
-        case WM_HSCROLL:
-        case WM_VSCROLL:
-            NDPRINTF(("VM_*SCROLL\n"));
-            enqEvent(0, hWnd, message, wParam, lParam, 0, 0, 0, EV_NOTIME);
-            break;
-
-        case WM_DRAWITEM:
-            EVENT_PRINTF(("WM_DRAWITEM\n"));
-#if 0
-            {
-                DRAWITEMSTRUCT *pItemStruct;
-
-                pItemStruct = (DRAWITEMSTRUCT *)lParam;
-                enqEvent(0, pItemStruct->hwndItem, WM_DRAWITEM, wParam, 0, 0, 0, 0, EV_NOTIME);
-            }
-#endif
-            break;
-
-#ifdef TRACE_ALL_EVENTS
-        case WM_CTLCOLORMSGBOX:
-            UNHANDLED_EVENT_PRINTF(("WM_CTLCOLORMSGBOX\n"));
-            break;
-        case WM_CTLCOLOREDIT:
-            UNHANDLED_EVENT_PRINTF(("WM_CTLCOLOREDIT\n"));
-            break;
-        case WM_CTLCOLORLISTBOX:
-            UNHANDLED_EVENT_PRINTF(("WM_CTLCOLORLISTBOX\n"));
-            break;
-        case WM_CTLCOLORBTN:
-            UNHANDLED_EVENT_PRINTF(("WM_CTLCOLORBTN\n"));
-            break;
-        case WM_CTLCOLORDLG:
-            UNHANDLED_EVENT_PRINTF(("WM_CTLCOLORDLG\n"));
-            break;
-        case WM_CTLCOLORSTATIC:
-            UNHANDLED_EVENT_PRINTF(("WM_CTLCOLORSTATIC\n"));
-            break;
-        case WM_CTLCOLORSCROLLBAR:
-            UNHANDLED_EVENT_PRINTFIF(__debug_WM_CTLCOLORSCROLLBAR__, ("WM_CTLCOLORSCROLLBAR\n"));
-            break;
-
-        case WM_STYLECHANGING:
-            UNHANDLED_EVENT_PRINTF(("WM_STYLECHANGING\n"));
-            break;
-        case WM_STYLECHANGED:
-            UNHANDLED_EVENT_PRINTF(("WM_STYLECHANGED\n"));
-            break;
-
-        case WM_GETICON:
-            UNHANDLED_EVENT_PRINTFIF(__debug_WM_GETICON__, ("WM_GETICON\n"));
-            break;
-        case WM_SETICON:
-            UNHANDLED_EVENT_PRINTF(("WM_SETICON\n"));
-            break;
-
-        case WM_PRINT:
-            UNHANDLED_EVENT_PRINTF(("WM_PRINT(lParam=%d)\n", lParam));
-            break;
-        case WM_PRINTCLIENT:
-            UNHANDLED_EVENT_PRINTF(("WM_PRINTCLIENT(lParam=%d)\n", lParam));
-            break;
-
-        case WM_NULL:
-            UNHANDLED_EVENT_PRINTF(("WM_NULL\n"));
-            break;
-
-        case WM_ENABLE:
-            UNHANDLED_EVENT_PRINTF(("WM_ENABLE\n"));
-            break;
-
-        case WM_SETREDRAW:
-            UNHANDLED_EVENT_PRINTF(("WM_SETREDRAW\n"));
-            break;
-
-        case WM_DEVMODECHANGE:
-            UNHANDLED_EVENT_PRINTF(("WM_DEVMODECHANGE\n"));
-            break;
-
-        case WM_TIMECHANGE:
-            UNHANDLED_EVENT_PRINTF(("WM_TIMECHANGE\n"));
-            break;
-
-        case WM_CANCELMODE:
-            UNHANDLED_EVENT_PRINTF(("WM_CANCELMODE\n"));
-            break;
-
-        case WM_CHILDACTIVATE:
-            UNHANDLED_EVENT_PRINTF(("WM_CHILDACTIVATE\n"));
-            break;
-
-        case WM_QUEUESYNC:
-            UNHANDLED_EVENT_PRINTF(("WM_QUEUESYNC\n"));
-            break;
-
-        case WM_NEXTDLGCTL:
-            UNHANDLED_EVENT_PRINTF(("WM_NEXTDLGCTL\n"));
-            break;
-
-        case WM_SPOOLERSTATUS:
-            UNHANDLED_EVENT_PRINTF(("WM_SPOOLERSTATUS\n"));
-            break;
-
-        case WM_MEASUREITEM:
-            UNHANDLED_EVENT_PRINTF(("WM_MEASUREITEM\n"));
-            break;
-
-        case WM_DELETEITEM:
-            UNHANDLED_EVENT_PRINTF(("WM_DELETEITEM\n"));
-            break;
-
-        case WM_VKEYTOITEM:
-            UNHANDLED_EVENT_PRINTF(("WM_VKEYTOITEM\n"));
-            break;
-
-        case WM_CHARTOITEM:
-            UNHANDLED_EVENT_PRINTF(("WM_CHARTOITEM\n"));
-            break;
-
-        case WM_SETFONT:
-            UNHANDLED_EVENT_PRINTF(("WM_SETFONT\n"));
-            break;
-
-        case WM_GETFONT:
-            UNHANDLED_EVENT_PRINTF(("WM_GETFONT\n"));
-            break;
-
-        case WM_SETHOTKEY:
-            UNHANDLED_EVENT_PRINTF(("WM_SETHOTKEY\n"));
-            break;
-
-        case WM_GETHOTKEY:
-            UNHANDLED_EVENT_PRINTF(("WM_GETHOTKEY\n"));
-            break;
-
-        case WM_QUERYDRAGICON:
-            UNHANDLED_EVENT_PRINTF(("WM_QUERYDRAGICON\n"));
-            break;
-
-        case WM_COMPAREITEM:
-            UNHANDLED_EVENT_PRINTF(("WM_COMPAREITEM\n"));
-            break;
-
-        case WM_GETOBJECT:
-            UNHANDLED_EVENT_PRINTF(("WM_GETOBJECT\n"));
-            break;
-
-        case WM_COMPACTING:
-            UNHANDLED_EVENT_PRINTF(("WM_COMPACTING\n"));
-            break;
-
-        case WM_COMMNOTIFY:
-            UNHANDLED_EVENT_PRINTF(("WM_COMMNOTIFY\n"));
-            break;
-
-        case WM_CANCELJOURNAL:
-            UNHANDLED_EVENT_PRINTF(("WM_CANCELJOURNAL\n"));
-            break;
-
-        case WM_INPUTLANGCHANGEREQUEST:
-            UNHANDLED_EVENT_PRINTF(("WM_INPUTLANGCHANGEREQUEST\n"));
-            break;
-
-        case WM_INPUTLANGCHANGE:
-            UNHANDLED_EVENT_PRINTF(("WM_INPUTLANGCHANGE\n"));
-            break;
-
-        case WM_TCARD:
-            UNHANDLED_EVENT_PRINTF(("WM_TCARD\n"));
-            break;
-
-        case WM_HELP:
-            UNHANDLED_EVENT_PRINTF(("WM_HELP\n"));
-            break;
-
-        case WM_USERCHANGED:
-            UNHANDLED_EVENT_PRINTF(("WM_USERCHANGED\n"));
-            break;
-
-        case WM_NOTIFY:
-            UNHANDLED_EVENT_PRINTF(("WM_NOTIFY\n"));
-            break;
-
-        case WM_NOTIFYFORMAT:
-            UNHANDLED_EVENT_PRINTF(("WM_NOTIFYFORMAT\n"));
-            break;
-
-        case WM_CONTEXTMENU:
-            UNHANDLED_EVENT_PRINTF(("WM_CONTEXTMENU\n"));
-            break;
-
-        case WM_NCXBUTTONDOWN:
-            UNHANDLED_EVENT_PRINTF(("WM_NCXBUTTONDOWN\n"));
-            break;
-
-        case WM_NCXBUTTONUP:
-            UNHANDLED_EVENT_PRINTF(("WM_NCXBUTTONUP\n"));
-            break;
-
-        case WM_NCXBUTTONDBLCLK:
-            UNHANDLED_EVENT_PRINTF(("WM_NCXBUTTONDBLCLK\n"));
-            break;
-
-        case WM_DEVICECHANGE:
-            UNHANDLED_EVENT_PRINTF(("WM_DEVICECHANGE\n"));
-            break;
-
-        case DBT_DEVICEARRIVAL:
-            UNHANDLED_EVENT_PRINTF(("DBT_DEVICEARRIVAL\n"));
-            break;
-
-        case DBT_DEVICEREMOVECOMPLETE:
-            UNHANDLED_EVENT_PRINTF(("DBT_DEVICEREMOVECOMPLETE\n"));
-            break;
-#endif
-
-        default:
-            EVENT_PRINTF(( "WinWorkstat [info] unhandled msg = %d 0x%x [%d]\n", message, message, __LINE__));
-            break;
-    }
-    return 0;
-}
-
-
-static void _USERENTRY
-dispatchThread(void *arg)
-{
-    static int th_calls;
-    RECT rect;
-    MSG msg;
-    localWindowInfo *lI;
-
-    _dispatchThreadId2 = GetCurrentThreadId();
-#ifdef STARTUP_DISPATCHTHREAD_DEBUG
-    console_fprintf(stderr, "WinWorkstation [info]: dispatchThreadID2=%x\n", _dispatchThreadId2);
-#endif
-    TH_DPRINTF(("TS %d\n", th_calls++));
-    PeekMessageW(&msg, NULL, 0, 0, PM_NOREMOVE);   /* must be */
-
-#if 0
-    if (AttachThreadInput(_masterThreadId, _dispatchThreadId2, TRUE) != TRUE) {
-        console_fprintf(stderr, "WinWorkstation [warning]: AttachThreadInput failed\n");
-    };
-#endif
-#ifndef WIN32THREADS
-# if 0
-    SetThreadPriority(_masterThread,THREAD_PRIORITY_HIGHEST);
-    SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_ABOVE_NORMAL);
-# endif
-#endif
-
-    GetWindowRect(GetDesktopWindow(), &rect);
-    /* allocate localMemory for Window */
-    lI = (localWindowInfo *)malloc(sizeof(localWindowInfo));
-    if (lI) {
-        memset(lI, 0, sizeof(*lI));
-    }
-
-    __rootWinSpezial = CreateWindowExW(WS_EX_TOOLWINDOW | WS_EX_TRANSPARENT,
-                                      wapp_nameRoot, wapp_nameRoot,
-                                      WS_POPUP | WS_DISABLED,
-                                      0, 0,
-                                      rect.right - rect.left, rect.bottom - rect.top,
-                                      0, 0, (HANDLE) __getHInstance(), lI);
-
-    //ShowWindow(__rootWinSpezial,SW_SHOWNOACTIVATE);
-    SetWindowPos(__rootWinSpezial, HWND_BOTTOM, 0, 0, 0, 0,
-                 SWP_NOSENDCHANGING |
-                 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
-
-#ifdef STARTUP_DISPATCHTHREAD_DEBUG
-    console_fprintf(stderr, "WinWorkstation [info]: setting ThreadRunningEvent\n");
-#endif
-    SetEvent(hDispatchThreadRunningEvent);
-
-    for (;;) {
-        HANDLE dummy;
-
-        TH_DPRINTF(("TG %d\n", th_calls++));
-
-        /*
-         * if there is no current capture (pointer-grab),
-         * make certain that we do not get stuck in the GetMessage
-         * but instead poll the mouse in 200ms intervals.
-         * This is required to synthesize the MOUSELEAVE message,
-         */
-// DPRINTF(("X1\n"));
-        if (__currentPointerView && (__currentCapture == CAPTURE_NONE)) {
-// DPRINTF(("X2\n"));
-            while (PeekMessageW(&msg, 0, 0, 0, PM_NOREMOVE) == 0) {
-// DPRINTF(("PeekMessage -> 0\n"));
-                /*
-                 * wait for an event; timeout after 200 millis
-                 */
-                if (MsgWaitForMultipleObjects(0,&dummy,FALSE,200,QS_ALLINPUT) == WAIT_TIMEOUT) {
-                    if (! inSizeMove) {
-                        /*
-                         * timeout - see where mouse pointer is
-                         * for synthetic leave events.
-                         */
-                        POINT point;
-
-                        if (GetCursorPos(&point)) {
-                            HWND hWnd = WindowFromPoint(point);
-
-                            if (hWnd) {
-                                if (GetWindowThreadProcessId(hWnd,0) != GetCurrentThreadId()) {
-                                    if (inSizeMove) {
-                                        if (needDelayedMouseLeaveWindow == NULL) {
-                                            needDelayedMouseLeaveWindow = __currentPointerView;
-                                        }
-                                    } else {
-                                        if (GetWindow_eventMask(__currentPointerView) & LeaveWindowMask) {
-                                            enqEvent(LeaveWindowMask, __currentPointerView, __WM_MOUSELEAVE, 0, -1, -1, 0, getModifiers(), EV_NOTIME);
-                                            SetWindow_mouseXY(__currentPointerView, -9999, -9999);
-                                        }
-                                    }
-                                    __currentPointerView = 0;
-                                    break;
-                                }
-                            }
-                        }
-                    }
-                }
-            }
-        }
-
-        GetMessageW(&msg, NULL, 0, 0);
-// DPRINTF(("GetMessage -> %d\n", msg.message));
-        TH_DPRINTF(("TD %d\n", th_calls++));
-        destroyWin = 0;
-
-        switch (msg.message) {
-#if 0
-            case WM_THREAD_DESTROYWINDOW:
-                destroyWin = TRUE;
-                msg.message = WM_CLOSE;
-                EVENT_PRINTF(("thread WM_THREAD_DESTROYWINDOW %x\n",msg.hwnd));
-                break;
-#endif
-
-#ifdef SET_FOCUS_IN_WINTHREAD
-            case WM_THREAD_SETFOCUS:
-                DPRINTFIF(__debug_WM_FOCUS__ , ("WM_THREAD_SETFOCUS h=%x\n", msg.wParam));
-# ifdef xxWIN32THREADS
-                if (msg.lParam) {
-                    if (AttachThreadInput(_dispatchThreadId2,msg.lParam,TRUE) == FALSE)
-                        PRINTF(("SetFocus AttachThreadInput error %d\n", GetLastError()));
-                }
-# endif
-                EVENT_PRINTF(("threadSetfocus %x\n",msg.wParam));
-                if (SetFocus((HWND)msg.wParam) == 0) {
-                    DDPRINTF(("SetFocus to %x failed.\n",msg.wParam));
-                }
-                continue;
-#endif
-
-#ifdef SET_CURSOR_IN_WINTHREAD
-            case WM_THREAD_SETCURSOR:
-                if (msg.lParam) {
-#if 1
-                    SetCursor((HCURSOR)msg.lParam);
-#else
-                    /* this check is done by our sender */
-                    {
-                        POINT p;
-                        GetCursorPos(&p);
-                        if (WindowFromPoint(p) == msg.hwnd) {
-                            EVENT_PRINTF(("threadSetCursor %x\n",msg.lParam));
-                            SetCursor((HCURSOR)msg.lParam);
-                        }
-                    }
-#endif
-                }
-                continue;
-#endif
-
-#ifdef BEEP_IN_WINTHREAD
-            case WM_THREAD_BEEP:
-                MessageBeep( MB_ICONEXCLAMATION);
-                continue;
-#endif
-
-            case WM_THREAD_SETCAPTURE:
-                if (msg.wParam) {
-                    if (__currentPointerView) {
-                        if (inSizeMove) {
-                            if (needDelayedMouseLeaveWindow == NULL) {
-                                needDelayedMouseLeaveWindow = __currentPointerView;
-                            }
-                        } else {
-                            if (GetWindow_eventMask(__currentPointerView) & LeaveWindowMask) {
-                                enqEvent(LeaveWindowMask, __currentPointerView, __WM_MOUSELEAVE, 0, -1, -1, 0, getModifiers(), EV_NOTIME);
-                                SetWindow_mouseXY(__currentPointerView, -9999, -9999);
-                            }
-                        }
-                    }
-
-                    __currentPointerView = (HWND)msg.wParam;
-                    __currentCapture = CAPTURE_EXPLICIT;
-                    EVENT_PRINTF(("threadSetCapture %x\n",msg.wParam));
-                    SetCapture(__currentPointerView);
-                } else {
-                    if (__currentPointerView  == __rootWinSpezial) {
-                        //ShowWindow(__rootWinSpezial, SW_HIDE);
-                        SetWindowPos(__rootWinSpezial, HWND_BOTTOM, 0, 0, 0, 0,
-                                     SWP_NOREDRAW | SWP_NOSENDCHANGING | SWP_NOCOPYBITS
-                                     | SWP_HIDEWINDOW | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE
-                                   /*| SWP_NOZORDER | SWP_NOOWNERZORDER */);
-                    }
-                    __currentPointerView = 0;
-                    __currentCapture = CAPTURE_NONE;
-                    EVENT_PRINTF(("threadReleaseCapture\n"));
-                    ReleaseCapture();
-                }
-                if (msg.lParam) {
-                    DDDDPRINTF(("threadSetCursor %x\n",msg.lParam));
-                    SetCursor((HCURSOR)msg.lParam);
-                }
-                continue;
-
-            case WM_THREAD_CREATEWINDOW:
-                EVENT_PRINTF(("*WM_THREAD_CREATEWINDOW %d\n", th_calls));
-
-                {
-                    createWindowInfo *cwi = (createWindowInfo *)(msg.lParam);
-
-                    if ((cwi->sequenceNr == msg.wParam)
-                     && (cwi->sequenceNr != INVALIDATED_CWI)) {
-                        cwi->sequenceNr = INVALIDATED_CWI;
-                        cwi->infoWasRead = 1;
-                        if (cwi->newWinHandle == NULL) {
-                            HANDLE ev;
-
-                            cwi->newWinHandle = CreateWindowExW(
-                                                cwi->winStyleBitsEx,
-                                                cwi->className,
-                                                cwi->windowName,
-                                                cwi->winStyleBits,
-                                                cwi->x, cwi->y,
-                                                cwi->dx, cwi->dy,
-                                                cwi->parentHandle,
-                                                NULL,           /* menu */
-                                                (HANDLE) __getHInstance(),
-                                                cwi->localWindowInfo
-                                               );
-
-                            if (cwi->newWinHandle == NULL) {
-                                cwi->errCode = GetLastError();
-                                console_fprintf(stderr, "WinWorkstation [info]: CreateWindow %s failed: %d (0x%x) [%d]\n",
-                                                cwi->className, cwi->errCode, cwi->errCode, __LINE__);
-                            } else {
-                                SETLOCALWINDOWINFOPTR(cwi->newWinHandle, cwi->localWindowInfo);
-#ifdef DEBUG /* PARANOIA */
-                                if (GETLOCALWINDOWINFOPTR(cwi->newWinHandle) != cwi->localWindowInfo) {
-                                   console_fprintf(stderr, "lI-Error\n");
-                                }
-#endif
-                            }
-
-                            ev = cwi->hCreateEvent;
-                            if (ev) {
-                                SetEvent(ev);
-                            }
-                        }
-                    } else {
-                        DPRINTF(("obsolete createWindow message %x ignored\n", cwi->sequenceNr));
-                    }
-                }
-                continue;
-
-            case WM_THREAD_REGISTERHOTKEY:
-                EVENT_PRINTF(("*WM_THREAD_REGISTERHOTKEY\n"));
-                {
-                    registerHotKeyInfo *rhki = (registerHotKeyInfo *)(msg.lParam);
-                    rhki->errorCode = 0;
-                    if (!RegisterHotKey(rhki->hwnd,rhki->hotKeyId,rhki->modifier,rhki->virtualKey)){
-                        rhki->errorCode = GetLastError();
-                        console_fprintf(stderr, "WinWorkstation [error]: RegisterHotKey failed: err=%d\n", rhki->errorCode);
-                    }
-                    rhki->finished = 1;
-                }
-                continue;
-
-            case WM_THREAD_UNREGISTERHOTKEY:
-                EVENT_PRINTF(("*WM_THREAD_UNREGISTERHOTKEY\n"));
-                {
-                    registerHotKeyInfo *rhki = (registerHotKeyInfo *)(msg.lParam);
-                    rhki->errorCode = 0;
-                    if (!UnregisterHotKey(rhki->hwnd,rhki->hotKeyId)){
-                        rhki->errorCode = GetLastError();
-                        console_fprintf(stderr, "WinWorkstation [error]: UnregisterHotKey failed: err=%d\n", rhki->errorCode);
-                    }
-                    rhki->finished = 1;
-                }
-                continue;
-
-            case WM_KEYDOWN:
-                DPRINTFIF(__debug_WM_KEYDOWN__ , ("WM_KEYDOWN %x\n", msg.wParam));
-                goto commonKey;
-
-            case WM_KEYUP:
-                DPRINTFIF(__debug_WM_KEYUP__  , ("WM_KEYUP %x\n", msg.wParam));
-                goto commonKey;
-
-            case WM_SYSKEYDOWN:
-                DPRINTFIF(__debug_WM_KEYDOWN__ , ("WM_SYSKEYDOWN %x\n", msg.wParam));
-                goto commonKey;
-
-            case WM_SYSKEYUP:
-                DPRINTFIF(__debug_WM_KEYUP__ , ("WM_SYSKEYUP %x\n", msg.wParam));
-                goto commonKey;
-
-            case WM_HOTKEY:
-                // console_fprintf(stderr, "dispatchThread [info]: receive hotkey %x %x\n", msg.hwnd, msg.wParam);
-                DPRINTFIF(__debug_WM_KEYUP__ , ("WM_HOTKEY %x\n", msg.wParam));
-                break;
-
-            commonKey:
-#if 1
-                if (((msg.wParam >= '0') && (msg.wParam <= 'Z'))
-                 || ((msg.wParam >= VK_MULTIPLY) && (msg.wParam <= VK_DIVIDE))
-                 || (msg.wParam == VK_SPACE)
-                 || (msg.wParam == VK_CAPITAL)
-                 /* || (msg.wParam == VK_SHIFT) */
-                 || (msg.wParam >= 0xB0))
-#endif
-                {
-                    /*
-                     * translate to a WM_CHAR message
-                     */
-                    if (TranslateMessage(&msg))
-                        continue;
-                }
-                break;
-
-            /* short cirquit some messages */
-#if 0
-# ifndef SUPPORT_NATIVE_WINDOWS
-            /*
-             * some can simply be ignored ...
-             */
-            case WM_ERASEBKGND:
-                EVENT_PRINTF(("*WM_ERASEBKGND\n"));
-                continue;
-            case WM_KILLFOCUS:
-                EVENT_PRINTF(("*WM_KILLFOCUS\n"));
-                continue;
-# endif
-#endif
-
-#if 0
-            case WM_SIZE:
-                EVENT_PRINTF(("*WM_SIZE\n"));
-                continue;
-#endif
-        }
-
-        /*
-         * common ...
-         */
-        evRootX = msg.pt.x;
-        evRootY = msg.pt.y;
-#if 1
-        {
-            POINT p;
-
-            if (GetCursorPos(&p)) {
-                evRootX = p.x;
-                evRootY = p.y;
-            }
-        }
-#endif
-        lastMSGTime = msg.time;
-        DispatchMessageW(&msg);   /* Dispatches message to window */
-    }
-}
-
-LONG APIENTRY
-MainWndProc(HWND hWnd, UINT message, UINT wParam, LONG lParam)
-{
-    int wantDefault = 1;
-    int retVal;
-    createWindowInfo *cwi;
-
-    TH_DPRINTF(("TMW %d\n",message));
-    EVENT_PRINTF3(("MainWndProc %d\n",message));
-    /*
-     * kludge while in sizeMove loop, which
-     * is performed directly by DefWindowProc
-     * even more of a kludge: to prevent the message in the PostThreadMessage-queue
-     * from being processed twice, we use a sequenceNr, which is passed as wParam.
-     */
-    cwi = pendingCREATEWINDOWInfo;
-    if (cwi) {
-        int dummyWantDefault;
-        int seqNr = pendingSequenceNr;
-
-        pendingCREATEWINDOWInfo = 0;
-        pendingSequenceNr = INVALIDATED_CWI;
-        DPRINTF(("### THREAD_CREATEWINDOW\n"));
-        winEventProcessing(0, WM_THREAD_CREATEWINDOW, seqNr, (INT)cwi, &dummyWantDefault);
-    }
-
-    retVal = winEventProcessing(hWnd, message, wParam, lParam, &wantDefault);
-    if (wantDefault) {
-        DDDPRINTF((">>DefWindowProc\n"));
-        retVal = DefWindowProcW(hWnd, message, wParam, lParam);
-        DDDPRINTF(("<<DefWindowProc\n"));
-    }
-    return retVal;
-}
-
-static int CALLBACK
-EnumWindowsProc(HWND hwnd, LPARAM lParam)
-{
-        volatile OBJ *refToCollection;
-        OBJ collection;
-        OBJ wHandle;
-
-        if (hwnd) {
-            refToCollection = (OBJ*) lParam;
-            __PROTECT__(*refToCollection);
-            wHandle = __MKEXTERNALADDRESS(hwnd);
-            __UNPROTECT__(*refToCollection);
-            collection = *refToCollection;
-            __SSEND1( collection, @symbol(add:), 0, wHandle );
-        }
-        return TRUE;
-}
-
-#ifdef USE_EnumFontFamiliesEx
-# define LOGFONTTYPE  ENUMLOGFONTEX
-#else
-# define LOGFONTTYPE  LOGFONT
-#endif
-
-static int CALLBACK
-EnumFPTypeFaceProc(
-    const LOGFONTTYPE *lplf,   /* ptr to of logical-font data */
-    const TEXTMETRIC  *lptm,   /* ptr to physical font data */
-    DWORD dwType,              /* font type */
-    LPARAM lpData              /* application supplied data */
-) {
-        OBJ t;
-        volatile OBJ *refToList;
-        OBJ  typeFaceList;
-        char *faceNameString;
-
-        if (lplf) {
-            refToList = (OBJ *) lpData;
-            __PROTECT__(*refToList);
-
-#ifdef USE_EnumFontFamiliesEx
-            faceNameString = lplf->elfLogFont.lfFaceName;
-#else
-            faceNameString = lplf->lfFaceName;
-#endif
-            t = __MKSTRING( faceNameString );
-            __UNPROTECT__(*refToList);
-            typeFaceList = *refToList;
-            __SSEND1( typeFaceList, @symbol(add:), 0, t );
-        }
-        return 1;
-}
-
-/*
- * take a LOGFONT structure and extract relevant data into a smalltalk array.
- *
- * Returned value is:
- *      #(
- *          1   lfHeight
- *          2   lfWidth
- *          3   lfEscapement
- *          4   lfOrientation
- *          5   lfWeight (Integer)
- *          6   lfWeight (String)
- *          7   lfItalic
- *          8   lfUnderline
- *          9   lfStrikeOut
- *         10   lfCharSet (Integer)
- *         11   lfOutPrecision
- *         12   lfClipPrecision
- *         13   lfQuality
- *         14   lfPitchAndFamily
- *         15   face and style name (String i.e. "bold-roman")
- *         16   face name from windows
- *         17   character encoding lfCharSet (as String i.e. "ms_ansi", "ms_oem", "ms_cyrillic")
- *         18
- *         19
- *         20
- *       )
- * CAVEAT: returns an array to avoid knowlege-need about ST-Objects (FontDescripttion) here.
- */
-OBJ
-__charSetSymbolFor(int charSet)
-{
-    OBJ s;
-
-    switch (charSet) {
-        case ANSI_CHARSET:
-            s = @symbol('ms-ansi');
-            break;
-        case DEFAULT_CHARSET:
-            s = @symbol('ms-default');
-            break;
-        case SYMBOL_CHARSET:
-            s = @symbol('ms-symbol');
-            break;
-        case SHIFTJIS_CHARSET:
-            s = @symbol('ms-shiftjis');
-            break;
-        case GB2312_CHARSET:
-            s = @symbol('ms-gb2312');
-            break;
-        case HANGEUL_CHARSET:
-            s = @symbol('ms-hangeul');
-            break;
-# if defined(HANGUL_CHARSET) && (HANGUL_CHARSET != HANGEUL_CHARSET)
-        case HANGUL_CHARSET:
-            s = @symbol('ms-hangul');
-            break;
-# endif
-        case CHINESEBIG5_CHARSET:
-            s = @symbol('ms-chinesebig5');
-            break;
-        case OEM_CHARSET:
-            s = @symbol('ms-oem');
-            break;
-# ifdef JOHAB_CHARSET
-        case JOHAB_CHARSET:
-            s = @symbol('ms-johab');
-            break;
-# endif
-# ifdef HEBREW_CHARSET
-        case HEBREW_CHARSET:
-            s = @symbol('ms-hebrew');
-            break;
-# endif
-# ifdef ARABIC_CHARSET
-        case ARABIC_CHARSET:
-            s = @symbol('ms-arabic');
-            break;
-# endif
-# ifdef GREEK_CHARSET
-        case GREEK_CHARSET:
-            s = @symbol('ms-greek');
-            break;
-# endif
-# ifdef TURKISH_CHARSET
-        case TURKISH_CHARSET:
-            s = @symbol('ms-turkish');
-            break;
-# endif
-# ifdef RUSSIAN_CHARSET
-        case RUSSIAN_CHARSET:
-            s = @symbol('ms-russian');
-            break;
-# endif
-# ifdef EASTEUROPE_CHARSET
-        case EASTEUROPE_CHARSET:
-            s = @symbol('ms-easteurope');
-            break;
-# endif
-# ifdef BALTIC_CHARSET
-        case BALTIC_CHARSET:
-            s = @symbol('ms-baltic');
-            break;
-# endif
-# ifdef VIETNAMESE_CHARSET
-        case VIETNAMESE_CHARSET:
-            s = @symbol('ms-vietnamese');
-            break;
-# endif
-# ifdef THAI_CHARSET
-        case THAI_CHARSET:
-            s = @symbol('ms-thai');
-            break;
-# endif
-# ifdef MAC_CHARSET
-        case MAC_CHARSET:
-            s = @symbol('ms-mac');
-            break;
-# endif
-# ifdef UNICODE_CHARSET
-        case UNICODE_CHARSET:
-            s = @symbol('ms-unicode');
-            break;
-# endif
-        default:
-            s = @symbol(unknown);
-            break;
-    }
-    return s;
-}
-
-OBJ
-__extractLogicalFontParameters(LOGFONT *lplf)
-{
-        OBJ newArray, t;
-        OBJ s;
-
-        DPRINTF((" lfHeight          %d\n", lplf->lfHeight ));
-        DPRINTF((" lfWidth           %d\n", lplf->lfWidth  ));
-        DPRINTF((" lfEscapement      %d\n", lplf->lfEscapement  ));
-        DPRINTF((" lfOrientation     %d\n", lplf->lfOrientation  ));
-        DPRINTF((" lfWeight          %d\n", lplf->lfWeight  ));
-        DPRINTF((" lfItalic          %d\n", lplf->lfItalic  ));
-        DPRINTF((" lfUnderline       %d\n", lplf->lfUnderline  ));
-        DPRINTF((" lfStrikeOut       %d\n", lplf->lfStrikeOut  ));
-        DPRINTF((" lfCharSet         %d\n", lplf->lfCharSet  ));
-        DPRINTF((" lfOutPrecision    %d\n", lplf->lfOutPrecision  ));
-        DPRINTF((" lfClipPrecision   %d\n", lplf->lfClipPrecision  ));
-        DPRINTF((" lfQuality         %d\n", lplf->lfQuality  ));
-        DPRINTF((" lfPitchAndFamily  %d\n", lplf->lfPitchAndFamily  ));
-        DPRINTF((" lfFaceName        %s\n\n", lplf->lfFaceName  ));
-
-        newArray = __ARRAY_NEW_INT(20);
-
-        __ArrayInstPtr(newArray)->a_element[0] = __MKSMALLINT(lplf->lfHeight);
-        __ArrayInstPtr(newArray)->a_element[1] = __MKSMALLINT(lplf->lfWidth);
-        __ArrayInstPtr(newArray)->a_element[2] = __MKSMALLINT(lplf->lfEscapement);
-        __ArrayInstPtr(newArray)->a_element[3] = __MKSMALLINT(lplf->lfOrientation);
-        __ArrayInstPtr(newArray)->a_element[4] = __MKSMALLINT(lplf->lfWeight);
-        switch (lplf->lfWeight) {
-            case FW_HEAVY:
-            case FW_EXTRABOLD:
-            case FW_SEMIBOLD:
-            case FW_BOLD:
-                s = @symbol(bold);
-                break;
-            case FW_NORMAL:
-#if 0
-                s = @symbol(normal);
-                break;
-#endif
-            case FW_MEDIUM:
-                s = @symbol(medium);
-                break;
-            case FW_THIN:
-            case FW_EXTRALIGHT:
-            case FW_LIGHT:
-                s = @symbol(demi);
-                break;
-            default:
-                s = @symbol(other);
-                break;
-        }
-        __ArrayInstPtr(newArray)->a_element[5] = s; __STORE(newArray, s);
-        __ArrayInstPtr(newArray)->a_element[6] = __MKSMALLINT(lplf->lfItalic);
-        __ArrayInstPtr(newArray)->a_element[7] = __MKSMALLINT(lplf->lfUnderline);
-        __ArrayInstPtr(newArray)->a_element[8] = __MKSMALLINT(lplf->lfStrikeOut);
-        __ArrayInstPtr(newArray)->a_element[9] = __MKSMALLINT(lplf->lfCharSet);
-        __ArrayInstPtr(newArray)->a_element[10] = __MKSMALLINT(lplf->lfOutPrecision);
-        __ArrayInstPtr(newArray)->a_element[11] = __MKSMALLINT(lplf->lfClipPrecision);
-        __ArrayInstPtr(newArray)->a_element[12] = __MKSMALLINT(lplf->lfQuality);
-        __ArrayInstPtr(newArray)->a_element[13] = __MKSMALLINT(lplf->lfPitchAndFamily);
-        /* ... */
-
-        if( lplf->lfItalic == TRUE ) {
-            if( lplf->lfUnderline == TRUE ) {
-                if( lplf->lfStrikeOut == TRUE ) {
-                    s = @symbol('italic-underline-strikeOut');
-                } else {
-                    s = @symbol('italic-underline');
-                }
-            } else {
-                if( lplf->lfStrikeOut == TRUE ) {
-                    s = @symbol('italic-strikeOut');
-                } else {
-                    s = @symbol('italic');
-                }
-            }
-        } else {
-            if( lplf->lfUnderline == TRUE ) {
-                if( lplf->lfStrikeOut == TRUE ) {
-                    s = @symbol('roman-underline-strikeOut');
-                } else {
-                    s = @symbol('roman-underline');
-                }
-            } else {
-                if( lplf->lfStrikeOut == TRUE ) {
-                    s = @symbol('roman-strikeOut');
-                } else {
-                    s = @symbol('roman');
-                }
-            }
-        }
-        __ArrayInstPtr(newArray)->a_element[14] = s; __STORE(newArray, s);
-
-        __PROTECT__(newArray);
-        t = __MKSTRING(lplf->lfFaceName);
-        __UNPROTECT__(newArray);
-        __ArrayInstPtr(newArray)->a_element[15] = t; __STORE(newArray, t);
-
-        t = __charSetSymbolFor(lplf->lfCharSet);
-        __ArrayInstPtr(newArray)->a_element[16] = t; __STORE(newArray, t);
-
-        return newArray;
-}
-
-
-static int CALLBACK
-EnumFontsProc(
-    const LOGFONTTYPE *lplf,   // ptr to of logical-font data
-    const TEXTMETRIC *lptm,    // ptr to physical font data
-    DWORD dwType,              // font type
-    LPARAM lpData              // application supplied data
-) {
-        volatile OBJ *refToList;
-        OBJ list;
-        OBJ infoArray;
-        OBJ *fullName;
-
-        DPRINTF(("EnumFontsProc\n"));
-
-        if ( lplf ) {
-            refToList = (OBJ *) lpData;
-
-            __PROTECT__(*refToList);
-#ifdef USE_EnumFontFamiliesEx
-            infoArray = __extractLogicalFontParameters(lplf->elfLogFont);
-            __PROTECT__(infoArray);
-            fullName = __MKSTRING(lplf->elfFullName);
-            __UNPROTECT__(infoArray);
-            __ArrayInstPtr(infoArray)->a_element[17] = fullName; __STORE(infoArray, fullName);
-#else
-            infoArray = __extractLogicalFontParameters(lplf);
-#endif
-
-            __UNPROTECT__(*refToList);
-
-            if ( dwType & TRUETYPE_FONTTYPE ) {
-                /* change height to 0 to mark variable fonts */
-                __ArrayInstPtr(infoArray)->a_element[0] = __MKSMALLINT(0);
-            }
-            list = *refToList;
-            __SSEND1(list, @symbol(add:), 0, infoArray);
-        }
-        return 1;
-}
-
-struct EnumDisplayMonitorsProcData {
-    OBJ hArray;
-    int index;
-};
-
-static int CALLBACK
-EnumDisplayMonitorsProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM lpData)
-{
-    struct EnumDisplayMonitorsProcData *procData = (struct EnumDisplayMonitorsProcData *)lpData;
-    OBJ mHandle;
-
-    __PROTECT__(procData->hArray);
-    mHandle = __MKEXTERNALADDRESS(hMonitor);
-    __UNPROTECT__(procData->hArray);
-
-    __arrayVal(procData->hArray)[procData->index++] = mHandle;
-    __STORE(procData->hArray, mHandle);
-    return (1);
-}
-
-%}
-! !
-
 !WinWorkstation class methodsFor:'documentation'!
 
 copyright
@@ -6843,11 +1568,16 @@
      here we return 1, 1.25 1.5"
 
     "
-        Screen monitorScaleFactorFor:(Display monitorHandleForName:'\\.\DISPLAY1').     
-        Screen monitorScaleFactorFor:(Display monitorHandleForName:'\\.\DISPLAY2').     
-    "
-
-    |scaleFactor|
+        Screen monitorScaleFactorFor:(Display monitorHandleForName:'\\.\DISPLAY1').   
+        Screen monitorScaleFactorFor:(Display monitorHandleForName:'\\.\DISPLAY2').   
+    "
+
+    |sx|
+
+    (aMonitorHandle isNil 
+    or:[aMonitorHandle isExternalAddress not]) ifTrue:[
+        ^ super monitorScaleFactorFor:aMonitorHandle
+    ].
 
 %{
     if (__isExternalAddress(aMonitorHandle)) {
@@ -6855,19 +1585,20 @@
         HINSTANCE hShcore = LoadLibrary("Shcore.dll");
 
         if (hShcore) {
-            static HRESULT (__stdcall *P_GetScaleFactorForMonitor)(HMONITOR, VOID*);
-            P_GetScaleFactorForMonitor = (HRESULT (__stdcall *)(HMONITOR, VOID*))GetProcAddress(hShcore, "GetScaleFactorForMonitor");
-
-            if (P_GetScaleFactorForMonitor) {
-                UINT displayScaleFactor;
-
-                if ((*P_GetScaleFactorForMonitor)(hMonitor, &displayScaleFactor) == S_OK) {
-                    scaleFactor = __MKSMALLINT(displayScaleFactor);
+            static HRESULT (__stdcall *P_GetDpiForMonitor)(HMONITOR, DWORD, UINT*, UINT*);
+            P_GetDpiForMonitor = (HRESULT (__stdcall *)(HMONITOR, DWORD, UINT*, UINT*))GetProcAddress(hShcore, "GetDpiForMonitor");
+
+            if (P_GetDpiForMonitor) {
+                UINT x = 0;
+                UINT y = 0;
+
+                if ((*P_GetDpiForMonitor)(hMonitor, 0, &x, &y) == S_OK) {
+                    sx = __MKSMALLINT(x);
                 } else {
-                    printf("Call \"GetScaleFactorForMonitor()\" failed\n");
+                    printf("Call \"GetDpiForMonitor()\" failed\n");
                 };      
             } else {
-                printf("Loading \"GetScaleFactorForMonitor()\" failed\n");
+                printf("Loading \"GetDpiForMonitor()\" failed\n");
             }
         } else {
             printf("Loading \"Shcore.dll\" failed\n");
@@ -6875,17 +1606,15 @@
     }
 %}.
 
-    scaleFactor isNil ifTrue:[
+    (sx isNil 
+    or:[sx == 0]) ifTrue:[
         ^ super monitorScaleFactorFor:aMonitorHandle
     ].
-    scaleFactor == 0 ifTrue:[
-        ^ super monitorScaleFactorFor:aMonitorHandle
-    ].
-
-    ^ scaleFactor / 100
+
+    ^ sx / 96
 
     "Created: / 25-11-2019 / 11:52:42 / Stefan Reise"
-    "Modified (comment): / 25-11-2019 / 14:26:07 / Stefan Reise"
+    "Modified: / 26-11-2019 / 15:44:28 / Stefan Reise"
 !
 
 thisAppVirtualResolutionByMonitorDeviceName:aMonitorDeviceName
@@ -20539,7 +15268,7 @@
     }
 %}
     "
-     (StandardSystemView new label:'äöü') open
+     (StandardSystemView new label:'äöü') open
     "
 !