+    wxCHECK_RET(::WinIsWindow(vHabmain, hwnd), wxT("invalid HWND in SubclassWin") );
+    wxAssociateWinWithHandle( hWnd
+                             ,(wxWindow*)this
+                            );
+    if (!wxCheckWindowWndProc( hWnd
+                              ,(WXFARPROC)wxWndProc
+                             ))
+    {
+        m_fnOldWndProc = (WXFARPROC) ::WinSubclassWindow(hwnd, (PFNWP)wxWndProc);
+    }
+    else
+    {
+        m_fnOldWndProc = (WXFARPROC)NULL;
+    }
+} // end of wxWindowOS2::SubclassWin
+
+void wxWindowOS2::UnsubclassWin()
+{
+    //
+    // Restore old Window proc
+    //
+    HWND                            hwnd = GetHWND();
+
+    if (m_hWnd)
+    {
+        wxCHECK_RET( ::WinIsWindow(vHabmain, hwnd), wxT("invalid HWND in UnsubclassWin") );
+
+        PFNWP                       fnProc = (PFNWP)::WinQueryWindowPtr(hwnd, QWP_PFNWP);
+
+        if ( (m_fnOldWndProc != 0) && (fnProc != (PFNWP) m_fnOldWndProc))
+        {
+            WinSubclassWindow(hwnd, (PFNWP)m_fnOldWndProc);
+            m_fnOldWndProc = 0;
+        }
+    }
+} // end of wxWindowOS2::UnsubclassWin
+
+bool wxCheckWindowWndProc(
+  WXHWND                            hWnd
+, WXFARPROC                         fnWndProc
+)
+{
+    static char                     zBuffer[512];
+    CLASSINFO                       vCls;
+
+    ::WinQueryClassName((HWND)hWnd, (LONG)512, (PCH)zBuffer);
+    ::WinQueryClassInfo(wxGetInstance(), (PSZ)zBuffer, &vCls);
+    return(fnWndProc == (WXFARPROC)vCls.pfnWindowProc);
+} // end of WinGuiBase_CheckWindowWndProc
+
+void wxWindowOS2::SetWindowStyleFlag(
+  long                              lFlags
+)
+{
+    long                            lFlagsOld = GetWindowStyleFlag();
+
+    if (lFlags == lFlagsOld)
+        return;
+
+    //
+    // Update the internal variable
+    //
+    wxWindowBase::SetWindowStyleFlag(lFlags);
+
+    //
+    // Now update the Windows style as well if needed - and if the window had
+    // been already created
+    //
+    if (!GetHwnd())
+        return;
+
+    WXDWORD                         dwExstyle;
+    WXDWORD                         dwExstyleOld;
+    long                            lStyle = OS2GetStyle( lFlags
+                                                         ,&dwExstyle
+                                                        );
+    long                            lStyleOld = OS2GetStyle( lFlagsOld
+                                                            ,&dwExstyleOld
+                                                           );
+
+    if (lStyle != lStyleOld)
+    {
+        //
+        // Some flags (e.g. WS_VISIBLE or WS_DISABLED) should not be changed by
+        // this function so instead of simply setting the style to the new
+        // value we clear the bits which were set in styleOld but are set in
+        // the new one and set the ones which were not set before
+        //
+        long                        lStyleReal = ::WinQueryWindowULong(GetHwnd(), QWL_STYLE);
+
+        lStyleReal &= ~lStyleOld;
+        lStyleReal |= lStyle;
+
+        ::WinSetWindowULong(GetHwnd(), QWL_STYLE, lStyleReal);
+    }
+} // end of wxWindowOS2::SetWindowStyleFlag
+
+WXDWORD wxWindowOS2::OS2GetStyle(
+  long                              lFlags
+, WXDWORD*                          pdwExstyle
+) const
+{
+    WXDWORD                         dwStyle = 0L;
+
+    if (lFlags & wxCLIP_CHILDREN )
+        dwStyle |= WS_CLIPCHILDREN;
+
+    if (lFlags & wxCLIP_SIBLINGS )
+        dwStyle |= WS_CLIPSIBLINGS;
+
+    return dwStyle;
+} // end of wxWindowMSW::MSWGetStyle
+
+//
+// Make a Windows extended style from the given wxWindows window style
+//
+WXDWORD wxWindowOS2::MakeExtendedStyle(
+  long                              lStyle
+, bool                              bEliminateBorders
+)
+{
+   //
+   // Simply fill out with wxWindow extended styles.  We'll conjure
+   // something up in OS2Create and all window redrawing pieces later
+   //
+    WXDWORD                         dwStyle = 0;
+
+    if (lStyle & wxTRANSPARENT_WINDOW )
+        dwStyle |= wxTRANSPARENT_WINDOW;
+
+    if (!bEliminateBorders)
+    {
+        if (lStyle & wxSUNKEN_BORDER)
+            dwStyle |= wxSUNKEN_BORDER;
+        if (lStyle & wxDOUBLE_BORDER)
+            dwStyle |= wxDOUBLE_BORDER;
+        if (lStyle & wxRAISED_BORDER )
+            dwStyle |= wxRAISED_BORDER;
+        if (lStyle & wxSTATIC_BORDER)
+            dwStyle |= wxSTATIC_BORDER;
+    }
+    return dwStyle;
+} // end of wxWindowOS2::MakeExtendedStyle
+
+//
+// Determines whether simulated 3D effects or CTL3D should be used,
+// applying a default border style if required, and returning an extended
+// style to pass to OS2Create.
+//
+WXDWORD wxWindowOS2::Determine3DEffects(
+  WXDWORD                           dwDefaultBorderStyle
+, bool*                             pbWant3D
+) const
+{
+    WXDWORD                         dwStyle = 0L;
+
+    //
+    // Native PM does not have any specialize 3D effects like WIN32 does,
+    // so we have to try and invent them.
+    //
+
+    //
+    // If matches certain criteria, then assume no 3D effects
+    // unless specifically requested (dealt with in MakeExtendedStyle)
+    //
+    if (!GetParent()                    ||
+        !IsKindOf(CLASSINFO(wxControl)) ||
+        (m_windowStyle & wxNO_BORDER)
+       )
+    {
+        *pbWant3D = FALSE;
+        return MakeExtendedStyle(m_windowStyle, FALSE);
+    }
+
+    //
+    // 1) App can specify global 3D effects
+    //
+    *pbWant3D = wxTheApp->GetAuto3D();
+
+    //
+    // 2) If the parent is being drawn with user colours, or simple border
+    //    specified, switch effects off.
+    //
+    if (GetParent() &&
+        (GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS) ||
+        (m_windowStyle & wxSIMPLE_BORDER)
+       )
+        *pbWant3D = FALSE;
+
+    //
+    // 3) Control can override this global setting by defining
+    //    a border style, e.g. wxSUNKEN_BORDER
+    //
+    if ((m_windowStyle & wxDOUBLE_BORDER) ||
+        (m_windowStyle & wxRAISED_BORDER) ||
+        (m_windowStyle & wxSTATIC_BORDER) ||
+        (m_windowStyle & wxSUNKEN_BORDER)
+       )
+        *pbWant3D = TRUE;
+
+    dwStyle = MakeExtendedStyle( m_windowStyle
+                                ,FALSE
+                               );
+
+    //
+    // If we want 3D, but haven't specified a border here,
+    // apply the default border style specified.
+    //
+    if (dwDefaultBorderStyle && (*pbWant3D) &&
+        !((m_windowStyle & wxDOUBLE_BORDER) ||
+          (m_windowStyle & wxRAISED_BORDER) ||
+          (m_windowStyle & wxSTATIC_BORDER) ||
+          (m_windowStyle & wxSIMPLE_BORDER)
+         )
+        )
+        dwStyle |= dwDefaultBorderStyle;
+    return dwStyle;
+} // end of wxWindowOS2::Determine3DEffects
+
+#if WXWIN_COMPATIBILITY
+void wxWindowOS2::OnCommand(
+  wxWindow&                         rWin
+, wxCommandEvent&                   rEvent
+)
+{
+    if (GetEventHandler()->ProcessEvent(rEvent))
+        return;
+    if (m_parent)
+        m_parent->GetEventHandler()->OnCommand( rWin
+                                               ,rEvent
+                                              );
+} // end of wxWindowOS2::OnCommand
+
+wxObject* wxWindowOS2::GetChild(
+  int                               nNumber
+) const
+{
+    //
+    // Return a pointer to the Nth object in the Panel
+    //
+    wxNode*                         pNode = GetChildren().First();
+    int                             n = nNumber;
+
+    while (pNode && n--)
+        pNode = pNode->Next();
+    if (pNode)
+    {
+        wxObject*                   pObj = (wxObject*)pNode->Data();
+        return(pObj);
+    }
+    else
+        return NULL;
+} // end of wxWindowOS2::GetChild
+
+#endif // WXWIN_COMPATIBILITY
+
+//
+// Setup background and foreground colours correctly
+//
+void wxWindowOS2::SetupColours()
+{
+    if ( GetParent() )
+        SetBackgroundColour(GetParent()->GetBackgroundColour());
+} // end of wxWindowOS2::SetupColours
+
+void wxWindowOS2::OnIdle(
+  wxIdleEvent&                      WXUNUSED(rEvent)
+)
+{
+    //
+    // Check if we need to send a LEAVE event
+    //
+    if (m_bMouseInWindow)
+    {
+        POINTL                      vPoint;
+
+        ::WinQueryPointerPos(HWND_DESKTOP, &vPoint);
+        if (::WinWindowFromPoint(HWND_DESKTOP, &vPoint, FALSE) != (HWND)GetHwnd())
+        {
+            //
+            // Generate a LEAVE event
+            //
+            m_bMouseInWindow = FALSE;
+
+            //
+            // Unfortunately the mouse button and keyboard state may have changed
+            // by the time the OnIdle function is called, so 'state' may be
+            // meaningless.
+            //
+            int                     nState = 0;
+
+            if (::WinGetKeyState(HWND_DESKTOP, VK_SHIFT) != 0)
+                nState |= VK_SHIFT;
+            if (::WinGetKeyState(HWND_DESKTOP, VK_CTRL) != 0);
+                nState |= VK_CTRL;
+
+            wxMouseEvent            rEvent(wxEVT_LEAVE_WINDOW);
+
+            InitMouseEvent( rEvent
+                           ,vPoint.x
+                           ,vPoint.y
+                           ,nState
+                          );
+            (void)GetEventHandler()->ProcessEvent(rEvent);
+        }
+    }
+    UpdateWindowUI();
+} // end of wxWindowOS2::OnIdle
+
+//
+// Set this window to be the child of 'parent'.
+//
+bool wxWindowOS2::Reparent(
+  wxWindow*                         pParent
+)
+{
+    if (!wxWindowBase::Reparent(pParent))
+        return FALSE;
+
+    HWND                            hWndChild = GetHwnd();
+    HWND                            hWndParent = GetParent() ? GetWinHwnd(GetParent()) : (HWND)0;
+
+    ::WinSetParent(hWndChild, hWndParent, TRUE);
+    return TRUE;
+} // end of wxWindowOS2::Reparent
+
+void wxWindowOS2::Clear()
+{
+    wxClientDC                      vDc((wxWindow*)this);
+    wxBrush                         vBrush( GetBackgroundColour()
+                                           ,wxSOLID
+                                          );
+
+    vDc.SetBackground(vBrush);
+    vDc.Clear();
+} // end of wxWindowOS2::Clear
+
+void wxWindowOS2::Update()
+{
+    ::WinUpdateWindow(GetHwnd());
+} // end of wxWindowOS2::Update
+
+void wxWindowOS2::Freeze()
+{
+   ::WinSendMsg(GetHwnd(), WM_VRNDISABLED, (MPARAM)0, (MPARAM)0);
+} // end of wxWindowOS2::Freeze
+
+void wxWindowOS2::Thaw()
+{
+   ::WinSendMsg(GetHwnd(), WM_VRNENABLED, (MPARAM)TRUE, (MPARAM)0);
+
+    //
+    // We need to refresh everything or otherwise he invalidated area is not
+    // repainted.
+    //
+    Refresh();
+} // end of wxWindowOS2::Thaw
+
+void wxWindowOS2::Refresh(
+  bool                              bEraseBack
+, const wxRect*                     pRect
+)
+{
+    HWND                            hWnd = GetHwnd();
+
+    if (hWnd)
+    {
+        if (pRect)
+        {
+            RECTL                   vOs2Rect;
+
+            vOs2Rect.xLeft   = pRect->x;
+            vOs2Rect.yTop    = pRect->y;
+            vOs2Rect.xRight  = pRect->x + pRect->width;
+            vOs2Rect.yBottom = pRect->y + pRect->height;
+
+            ::WinInvalidateRect(hWnd, &vOs2Rect, bEraseBack);
+        }
+        else
+            ::WinInvalidateRect(hWnd, NULL, bEraseBack);
+        if (m_hWndScrollBarHorz != NULLHANDLE)
+            ::WinInvalidateRect(m_hWndScrollBarHorz, NULL, TRUE);
+        if (m_hWndScrollBarVert != NULLHANDLE)
+            ::WinInvalidateRect(m_hWndScrollBarVert, NULL, TRUE);
+    }
+} // end of wxWindowOS2::Refresh
+
+// ---------------------------------------------------------------------------
+// drag and drop
+// ---------------------------------------------------------------------------
+
+#if wxUSE_DRAG_AND_DROP
+void wxWindowOS2::SetDropTarget(
+  wxDropTarget*                     pDropTarget
+)
+{
+    m_dropTarget = pDropTarget;
+} // end of wxWindowOS2::SetDropTarget
+#endif
+
+//
+// old style file-manager drag&drop support: we retain the old-style
+// DragAcceptFiles in parallel with SetDropTarget.
+//
+void wxWindowOS2::DragAcceptFiles(
+  bool                              bAccept
+)
+{
+    HWND                            hWnd = GetHwnd();
+
+    if (hWnd && bAccept)
+        ::DrgAcceptDroppedFiles(hWnd, NULL, NULL, DO_COPY, 0L);
+} // end of wxWindowOS2::DragAcceptFiles
+
+// ----------------------------------------------------------------------------
+// tooltips
+// ----------------------------------------------------------------------------
+
+#if wxUSE_TOOLTIPS
+
+void wxWindowOS2::DoSetToolTip(
+  wxToolTip*                        pTooltip
+)
+{
+    wxWindowBase::DoSetToolTip(pTooltip);
+
+    if (m_tooltip)
+        m_tooltip->SetWindow(this);
+} // end of wxWindowOS2::DoSetToolTip
+
+#endif // wxUSE_TOOLTIPS
+
+// ---------------------------------------------------------------------------
+// moving and resizing
+// ---------------------------------------------------------------------------
+
+// Get total size
+void wxWindowOS2::DoGetSize(
+  int*                              pWidth
+, int*                              pHeight
+) const
+{
+    HWND                            hWnd;
+    RECTL                           vRect;
+
+    if (IsKindOf(CLASSINFO(wxFrame)))
+    {
+        wxFrame*                    pFrame = wxDynamicCast(this, wxFrame);
+        hWnd = pFrame->GetFrame();
+    }
+    else
+        hWnd = GetHwnd();
+
+    ::WinQueryWindowRect(hWnd, &vRect);
+
+    if (pWidth)
+        *pWidth = vRect.xRight - vRect.xLeft;
+    if (pHeight )
+        // OS/2 PM is backwards from windows
+        *pHeight = vRect.yTop - vRect.yBottom;
+} // end of wxWindowOS2::DoGetSize
+
+void wxWindowOS2::DoGetPosition(
+  int*                              pX
+, int*                              pY
+) const
+{
+    HWND                            hWnd = GetHwnd();
+    SWP                             vSwp;
+    POINTL                          vPoint;
+    wxWindow*                       pParent = GetParent();
+
+    //
+    // It would seem that WinQueryWindowRect would be the correlary to
+    // the WIN32 WinGetRect, but unlike WinGetRect which returns the window
+    // origin position in screen coordinates, WinQueryWindowRect returns it
+    // relative to itself, i.e. (0,0).  To get the same under PM we must
+    // us WinQueryWindowPos.  This call, unlike the WIN32 call, however,
+    // returns a position relative to it's parent, so no parent adujstments
+    // are needed under OS/2.  Also, windows should be created using
+    // wxWindow coordinates, i.e 0,0 is the TOP left so vSwp will already
+    // reflect that.
+    //
+    ::WinQueryWindowPos(hWnd, &vSwp);
+
+    vPoint.x = vSwp.x;
+    vPoint.y = vSwp.y;
+
+    //
+    // We may be faking the client origin. So a window that's really at (0,
+    // 30) may appear (to wxWin apps) to be at (0, 0).
+    //
+    if (pParent)
+    {
+        wxPoint                     vPt(pParent->GetClientAreaOrigin());
+
+        vPoint.x -= vPt.x;
+        vPoint.y -= vPt.y;
+    }
+
+    if (pX)
+        *pX = vPoint.x;
+    if  (pY)
+        *pY = vPoint.y;
+} // end of wxWindowOS2::DoGetPosition
+
+void wxWindowOS2::DoScreenToClient(
+  int*                              pX
+, int*                              pY
+) const
+{
+    HWND                            hWnd = GetHwnd();
+    SWP                             vSwp;
+
+    ::WinQueryWindowPos(hWnd, &vSwp);
+
+    if (pX)
+        *pX += vSwp.x;
+    if (pY)
+        *pY += vSwp.y;
+} // end of wxWindowOS2::DoScreenToClient
+
+void wxWindowOS2::DoClientToScreen(
+  int*                              pX
+, int*                              pY
+) const
+{
+    HWND                            hWnd = GetHwnd();
+    SWP                             vSwp;
+
+    ::WinQueryWindowPos(hWnd, &vSwp);
+
+    if (pX)
+        *pX += vSwp.x;
+    if (pY)
+        *pY += vSwp.y;
+} // end of wxWindowOS2::DoClientToScreen
+
+//
+// Get size *available for subwindows* i.e. excluding menu bar etc.
+// Must be a frame type window
+//
+void wxWindowOS2::DoGetClientSize(
+  int*                              pWidth
+, int*                              pHeight
+) const
+{
+    HWND                            hWnd = GetHwnd();
+    RECTL                           vRect;
+
+   ::WinQueryWindowRect(hWnd, &vRect);
+    if (IsKindOf(CLASSINFO(wxDialog)))
+    {
+        RECTL                       vTitle;
+        HWND                        hWndTitle;
+        //
+        // For a Dialog we have to explicitly request the client portion.
+        // For a Frame the hWnd IS the client window
+        //
+        hWndTitle = ::WinWindowFromID(hWnd, FID_TITLEBAR);
+        if (::WinQueryWindowRect(hWndTitle, &vTitle))
+        {
+            if (vTitle.yTop - vTitle.yBottom == 0)
+            {
+                //
+                // Dialog has not been created yet, use a default
+                //
+                vTitle.yTop = 20;
+            }
+            vRect.yTop -= (vTitle.yTop - vTitle.yBottom);
+        }
+
+        ULONG                       uStyle = ::WinQueryWindowULong(hWnd, QWL_STYLE);
+
+        //
+        // Deal with borders
+        //
+        if (uStyle & FCF_DLGBORDER)
+        {
+            vRect.xLeft += 4;
+            vRect.xRight -= 4;
+            vRect.yTop -= 4;
+            vRect.yBottom += 4;
+        }
+        else if (uStyle & FCF_SIZEBORDER)
+        {
+            vRect.xLeft += 4;
+            vRect.xRight -= 4;
+            vRect.yTop -= 4;
+            vRect.yBottom += 4;
+        }
+        else if (uStyle & FCF_BORDER)
+        {
+            vRect.xLeft += 2;
+            vRect.xRight -= 2;
+            vRect.yTop -= 2;
+            vRect.yBottom += 2;
+        }
+        else // make some kind of adjustment or top sizers ram into the titlebar!
+        {
+            vRect.xLeft += 3;
+            vRect.xRight -= 3;
+            vRect.yTop -= 3;
+            vRect.yBottom += 3;
+        }
+    }
+    if (pWidth)
+        *pWidth  = vRect.xRight - vRect.xLeft;
+    if (pHeight)
+        *pHeight = vRect.yTop - vRect.yBottom;
+} // end of wxWindowOS2::DoGetClientSize
+
+void wxWindowOS2::DoMoveWindow(
+  int                               nX
+, int                               nY
+, int                               nWidth
+, int                               nHeight
+)
+{
+    RECTL                           vRect;
+    HWND                            hParent;
+    wxWindow*                       pParent = GetParent();
+
+    if (pParent && !IsKindOf(CLASSINFO(wxDialog)))
+    {
+        int                         nOS2Height = GetOS2ParentHeight(pParent);
+
+        nY = nOS2Height - (nY + nHeight);
+    }
+    else
+    {
+        RECTL                       vRect;
+
+        ::WinQueryWindowRect(HWND_DESKTOP, &vRect);
+        nY = vRect.yTop - (nY + nHeight);
+    }
+
+    //
+    // In the case of a frame whose client is sized, the client cannot be
+    // large than its parent frame minus its borders! This usually happens
+    // when using an autosizer to size a frame to precisely hold client
+    // controls as in the notebook sample.
+    //
+    // In this case, we may need to resize both a frame and its client so we
+    // need a quick calc of the frame border size, then if the frame
+    // (less its borders) is smaller than the client, size the frame to
+    // encompass the client with the appropriate border size.
+    //
+    if (IsKindOf(CLASSINFO(wxFrame)))
+    {
+        RECTL                       vFRect;
+        HWND                        hWndFrame;
+        int                         nWidthFrameDelta = 0;
+        int                         nHeightFrameDelta = 0;
+        int                         nHeightFrame = 0;
+        int                         nWidthFrame = 0;
+        ULONG                       ulFLag = SWP_MOVE;
+        wxFrame*                    pFrame;
+
+        pFrame = wxDynamicCast(this, wxFrame);
+        hWndFrame = pFrame->GetFrame();
+        ::WinQueryWindowRect(hWndFrame, &vRect);
+        ::WinMapWindowPoints(hWndFrame, HWND_DESKTOP, (PPOINTL)&vRect, 2);
+        vFRect = vRect;
+        ::WinCalcFrameRect(hWndFrame, &vRect, TRUE);
+        nWidthFrameDelta = ((vRect.xLeft - vFRect.xLeft) + (vFRect.xRight - vRect.xRight));
+        nHeightFrameDelta = ((vRect.yBottom - vFRect.yBottom) + (vFRect.yTop - vRect.yTop));
+        nWidthFrame = vFRect.xRight - vFRect.xLeft;
+        nHeightFrame = vFRect.yTop - vFRect.yBottom;
+
+        if (nWidth == vFRect.xRight - vFRect.xLeft &&
+            nHeight == vFRect.yTop - vFRect.yBottom)
+        {
+            //
+            // In this case the caller is not aware of OS/2's need to size both
+            // the frame and it's client and is really only moving the window,
+            // not resizeing it.  So move the frame, and back off the sizes
+            // for a proper client fit.
+            //
+            ::WinSetWindowPos( hWndFrame
+                              ,HWND_TOP
+                              ,(LONG)nX - (vRect.xLeft - vFRect.xLeft)
+                              ,(LONG)nY - (vRect.yBottom - vFRect.yBottom)
+                              ,(LONG)0
+                              ,(LONG)0
+                              ,SWP_MOVE
+                             );
+            nX += (vRect.xLeft - vFRect.xLeft);
+            nY += (vRect.yBottom - vFRect.yBottom);
+            nWidth -= nWidthFrameDelta;
+            nHeight -= nHeightFrameDelta;
+        }
+        else
+        {
+            if (nWidth > nWidthFrame - nHeightFrameDelta ||
+                nHeight > nHeightFrame - nHeightFrameDelta)
+            {
+                ::WinSetWindowPos( hWndFrame
+                                  ,HWND_TOP
+                                  ,(LONG)nX - (vRect.xLeft - vFRect.xLeft)
+                                  ,(LONG)nY - (vRect.yBottom - vFRect.yBottom)
+                                  ,(LONG)nWidth + nWidthFrameDelta
+                                  ,(LONG)nHeight + nHeightFrameDelta
+                                  ,SWP_MOVE | SWP_SIZE
+                                 );
+            }
+        }
+    }
+
+    ::WinSetWindowPos( GetHwnd()
+                      ,HWND_TOP
+                      ,(LONG)nX
+                      ,(LONG)nY
+                      ,(LONG)nWidth
+                      ,(LONG)nHeight
+                      ,SWP_SIZE | SWP_MOVE
+                     );
+    if (m_vWinSwp.cx == 0 && m_vWinSwp.cy == 0 && m_vWinSwp.fl == 0)
+        //
+        // Uninitialized
+        //
+        ::WinQueryWindowPos(GetHwnd(), &m_vWinSwp);
+    else
+    {
+        int                         nYDiff = m_vWinSwp.cy - nHeight;
+
+        //
+        // Handle resizing of scrolled windows.  The target or window to
+        // be scrolled is the owner (gets the scroll notificaitons).  The
+        // parent is usually the parent frame of the scrolled panel window.
+        // In order to show the scrollbars the target window will be shrunk
+        // by the size of the scroll bar widths (20) and moved in the X and Y
+        // directon.  That value will be computed as part of the diff for
+        // moving the children.  Everytime the window is sized the
+        // toplevel OnSize is going to resize the panel to fit the client
+        // or the whole sizer and will need to me resized. This will send
+        // a WM_SIZE out which will be intercepted by the ScrollHelper
+        // which will cause the scrollbars to be displayed via the SetScrollbar
+        // call in CWindow.
+        //
+        if ( IsKindOf(CLASSINFO(wxGenericScrolledWindow)) ||
+             IsKindOf(CLASSINFO(wxScrolledWindow))
+           )
+        {
+            int                     nAdjustWidth  = 0;
+            int                     nAdjustHeight = 0;
+            SWP                     vSwpScroll;
+
+            if (GetScrollBarHorz() == NULLHANDLE ||
+                !WinIsWindowShowing(GetScrollBarHorz()))
+                nAdjustHeight = 0L;
+            else
+                nAdjustHeight = 20L;
+            if (GetScrollBarVert() == NULLHANDLE ||
+                !WinIsWindowShowing(GetScrollBarVert()))
+                nAdjustWidth = 0L;
+            else
+                nAdjustWidth = 20L;
+            ::WinQueryWindowPos(GetHWND(), &vSwpScroll);
+            ::WinSetWindowPos( GetHWND()
+                              ,HWND_TOP
+                              ,vSwpScroll.x
+                              ,vSwpScroll.y + nAdjustHeight
+                              ,vSwpScroll.cx - nAdjustWidth
+                              ,vSwpScroll.cy - nAdjustHeight
+                              ,SWP_MOVE | SWP_SIZE
+                             );
+            nYDiff += nAdjustHeight;
+        }
+        MoveChildren(nYDiff);
+        ::WinQueryWindowPos(GetHwnd(), &m_vWinSwp);
+    }
+} // end of wxWindowOS2::DoMoveWindow
+
+//
+// Set the size of the window: if the dimensions are positive, just use them,
+// but if any of them is equal to -1, it means that we must find the value for
+// it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
+// which case -1 is a valid value for x and y)
+//
+// If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
+// the width/height to best suit our contents, otherwise we reuse the current
+// width/height
+//
+void wxWindowOS2::DoSetSize(
+  int                               nX
+, int                               nY
+, int                               nWidth
+, int                               nHeight
+, int                               nSizeFlags
+)
+{
+    //
+    // Get the current size and position...
+    //
+    int                             nCurrentX;
+    int                             nCurrentY;
+    int                             nCurrentWidth;
+    int                             nCurrentHeight;
+    wxSize                          vSize(-1, -1);
+
+    GetPosition(&nCurrentX, &nCurrentY);
+    GetSize(&nCurrentWidth, &nCurrentHeight);
+
+    //
+    // ... and don't do anything (avoiding flicker) if it's already ok
+    //
+    //
+    // Must convert Y coords to test for equality under OS/2
+    //
+    int                             nY2 = nY;
+    wxWindow*                       pParent = (wxWindow*)GetParent();
+
+    if (nX == nCurrentX && nY2 == nCurrentY &&
+        nWidth == nCurrentWidth && nHeight == nCurrentHeight)
+    {
+        return;
+    }
+
+    if (nX == -1 && !(nSizeFlags & wxSIZE_ALLOW_MINUS_ONE))
+        nX = nCurrentX;
+    if (nY == -1 && !(nSizeFlags & wxSIZE_ALLOW_MINUS_ONE))
+        nY = nCurrentY;
+
+    AdjustForParentClientOrigin(nX, nY, nSizeFlags);
+
+    if (nWidth == -1)
+    {
+        if (nSizeFlags & wxSIZE_AUTO_WIDTH)
+        {
+            vSize  = DoGetBestSize();
+            nWidth = vSize.x;
+        }
+        else
+        {
+            //
+            // Just take the current one
+            //
+            nWidth = nCurrentWidth;
+        }
+    }
+
+    if (nHeight == -1)
+    {
+        if (nSizeFlags & wxSIZE_AUTO_HEIGHT)
+        {
+            if (vSize.x == -1)
+            {
+                vSize = DoGetBestSize();
+            }
+            nHeight = vSize.y;
+        }
+        else
+        {
+            // just take the current one
+            nHeight = nCurrentHeight;
+        }
+    }
+
+    DoMoveWindow( nX
+                 ,nY
+                 ,nWidth
+                 ,nHeight
+                );
+} // end of wxWindowOS2::DoSetSize
+
+void wxWindowOS2::DoSetClientSize(
+  int                               nWidth
+, int                               nHeight
+)
+{
+    POINTL                          vPoint;
+    int                             nActualWidth;
+    int                             nActualHeight;
+    wxWindow*                       pParent = (wxWindow*)GetParent();
+    HWND                            hParentWnd = (HWND)0;
+
+    if (pParent)
+        hParentWnd = (HWND)pParent->GetHWND();
+
+    if (IsKindOf(CLASSINFO(wxFrame)))
+    {
+        wxFrame*                    pFrame = wxDynamicCast(this, wxFrame);
+        HWND                        hFrame = pFrame->GetFrame();
+        RECTL                       vRect;
+        RECTL                       vRect2;
+        RECTL                       vRect3;
+
+        ::WinQueryWindowRect(GetHwnd(), &vRect2);
+        ::WinQueryWindowRect(hFrame, &vRect);
+        ::WinQueryWindowRect(hParentWnd, &vRect3);
+        nActualWidth = vRect2.xRight - vRect2.xLeft - vRect.xRight + nWidth;
+        nActualHeight = vRect2.yTop - vRect2.yBottom - vRect.yTop + nHeight;
+
+        vPoint.x = vRect2.xLeft;
+        vPoint.y = vRect2.yBottom;
+        if (pParent)
+        {
+            vPoint.x -= vRect3.xLeft;
+            vPoint.y -= vRect3.yBottom;
+        }
+    }
+    else
+    {
+        int                         nX;
+        int                         nY;
+
+        GetPosition(&nX, &nY);
+        nActualWidth  = nWidth;
+        nActualHeight = nHeight;
+
+        vPoint.x = nX;
+        vPoint.y = nY;
+    }
+    DoMoveWindow( vPoint.x
+                 ,vPoint.y
+                 ,nActualWidth
+                 ,nActualHeight
+                );
+
+    wxSizeEvent                     vEvent( wxSize( nWidth
+                                                   ,nHeight
+                                                  )
+                                           ,m_windowId
+                                          );
+
+    vEvent.SetEventObject(this);
+    GetEventHandler()->ProcessEvent(vEvent);
+} // end of wxWindowOS2::DoSetClientSize
+
+wxPoint wxWindowOS2::GetClientAreaOrigin() const
+{
+    return wxPoint(0, 0);
+} // end of wxWindowOS2::GetClientAreaOrigin
+
+// ---------------------------------------------------------------------------
+// text metrics
+// ---------------------------------------------------------------------------
+
+int wxWindowOS2::GetCharHeight() const
+{
+    HPS                             hPs;
+    FONTMETRICS                     vFontMetrics;
+
+    hPs = ::WinGetPS(GetHwnd());
+
+    if(!GpiQueryFontMetrics(hPs, sizeof(FONTMETRICS), &vFontMetrics))
+    {
+        ::WinReleasePS(hPs);
+        return (0);
+    }
+    ::WinReleasePS(hPs);
+    return(vFontMetrics.lMaxAscender + vFontMetrics.lMaxDescender);
+} // end of wxWindowOS2::GetCharHeight
+
+int wxWindowOS2::GetCharWidth() const
+{
+    HPS                             hPs;
+    FONTMETRICS                     vFontMetrics;
+
+    hPs = ::WinGetPS(GetHwnd());
+
+    if(!GpiQueryFontMetrics(hPs, sizeof(FONTMETRICS), &vFontMetrics))
+    {
+        ::WinReleasePS(hPs);
+        return (0);
+    }
+    ::WinReleasePS(hPs);
+    return(vFontMetrics.lAveCharWidth);
+} // end of wxWindowOS2::GetCharWidth
+
+void wxWindowOS2::GetTextExtent(
+  const wxString&                   rString
+, int*                              pX
+, int*                              pY
+, int*                              pDescent
+, int*                              pExternalLeading
+, const wxFont*                     pTheFont
+) const
+{
+    POINTL                          avPoint[TXTBOX_COUNT];
+    POINTL                          vPtMin;
+    POINTL                          vPtMax;
+    int                             i;
+    int                             l;
+    FONTMETRICS                     vFM; // metrics structure
+    BOOL                            bRc;
+    char*                           pStr;
+    ERRORID                         vErrorCode; // last error id code
+    HPS                             hPS;
+
+
+    hPS = ::WinGetPS(GetHwnd());
+
+    l = rString.Length();
+    if (l > 0L)
+    {
+        pStr = (PCH)rString.c_str();
+
+        //
+        // In world coordinates.
+        //
+        bRc = ::GpiQueryTextBox( hPS
+                                ,l
+                                ,pStr
+                                ,TXTBOX_COUNT // return maximum information
+                                ,avPoint      // array of coordinates points
+                               );
+        if (bRc)
+        {
+            vPtMin.x = avPoint[0].x;
+            vPtMax.x = avPoint[0].x;
+            vPtMin.y = avPoint[0].y;
+            vPtMax.y = avPoint[0].y;
+            for (i = 1; i < 4; i++)
+            {
+                if(vPtMin.x > avPoint[i].x) vPtMin.x = avPoint[i].x;
+                if(vPtMin.y > avPoint[i].y) vPtMin.y = avPoint[i].y;
+                if(vPtMax.x < avPoint[i].x) vPtMax.x = avPoint[i].x;
+                if(vPtMax.y < avPoint[i].y) vPtMax.y = avPoint[i].y;
+            }
+            bRc = ::GpiQueryFontMetrics( hPS
+                                        ,sizeof(FONTMETRICS)
+                                        ,&vFM
+                                       );
+            if (!bRc)
+            {
+                vPtMin.x = 0;
+                vPtMin.y = 0;
+                vPtMax.x = 0;
+                vPtMax.y = 0;
+            }
+        }
+        else
+        {
+            vPtMin.x = 0;
+            vPtMin.y = 0;
+            vPtMax.x = 0;
+            vPtMax.y = 0;
+        }
+    }
+    else
+    {
+        vPtMin.x = 0;
+        vPtMin.y = 0;
+        vPtMax.x = 0;
+        vPtMax.y = 0;
+    }
+    if (pX)
+        *pX = (vPtMax.x - vPtMin.x + 1);
+    if (pY)
+        *pY = (vPtMax.y - vPtMin.y + 1);
+    if (pDescent)
+    {
+        if (bRc)
+            *pDescent = vFM.lMaxDescender;
+        else
+            *pDescent = 0;
+    }
+    if (pExternalLeading)
+    {
+        if (bRc)
+            *pExternalLeading = vFM.lExternalLeading;
+        else
+            *pExternalLeading = 0;
+    }
+    ::WinReleasePS(hPS);
+} // end of wxWindow::GetTextExtent
+
+bool wxWindowOS2::IsMouseInWindow() const
+{
+    //
+    // Get the mouse position
+    POINTL                          vPt;
+
+    ::WinQueryPointerPos(HWND_DESKTOP, &vPt);
+
+    //
+    // Find the window which currently has the cursor and go up the window
+    // chain until we find this window - or exhaust it
+    //
+    HWND                            hWnd = ::WinWindowFromPoint(HWND_DESKTOP, &vPt, TRUE);
+
+    while (hWnd && (hWnd != GetHwnd()))
+        hWnd = ::WinQueryWindow(hWnd, QW_PARENT);
+
+    return hWnd != NULL;
+} // end of wxWindowOS2::IsMouseInWindow
+
+#if wxUSE_CARET && WXWIN_COMPATIBILITY
+// ---------------------------------------------------------------------------
+// Caret manipulation
+// ---------------------------------------------------------------------------
+
+void wxWindowOS2::CreateCaret(
+  int                               nWidth
+, int                               nHeight
+)
+{
+    SetCaret(new wxCaret( this
+                         ,nWidth
+                         ,nHeight
+                        ));
+} // end of wxWindowOS2::CreateCaret
+
+void wxWindowOS2::CreateCaret(
+  const wxBitmap*                   pBitmap
+)
+{
+    wxFAIL_MSG("not implemented");
+} // end of wxWindowOS2::CreateCaret
+
+void wxWindowOS2::ShowCaret(
+  bool                              bShow
+)
+{
+    wxCHECK_RET( m_caret, "no caret to show" );
+
+    m_caret->Show(bShow);
+} // end of wxWindowOS2::ShowCaret
+
+void wxWindowOS2::DestroyCaret()
+{
+    SetCaret(NULL);
+} // end of wxWindowOS2::DestroyCaret
+
+void wxWindowOS2::SetCaretPos(
+  int                               nX
+, int                               nY)
+{
+    wxCHECK_RET( m_caret, "no caret to move" );
+
+    m_caret->Move( nX
+                  ,nY
+                 );
+} // end of wxWindowOS2::SetCaretPos
+
+void wxWindowOS2::GetCaretPos(
+  int*                              pX
+, int*                              pY
+) const
+{
+    wxCHECK_RET( m_caret, "no caret to get position of" );
+
+    m_caret->GetPosition( pX
+                         ,pY
+                        );
+} // end of wxWindowOS2::GetCaretPos
+
+#endif //wxUSE_CARET
+
+// ---------------------------------------------------------------------------
+// popup menu
+// ---------------------------------------------------------------------------
+//
+#if wxUSE_MENUS_NATIVE
+static void wxYieldForCommandsOnly()
+{
+    //
+    // Peek all WM_COMMANDs (it will always return WM_QUIT too but we don't
+    // want to process it here)
+    //
+    QMSG                            vMsg;
+
+    while (::WinPeekMsg(vHabmain, &vMsg, (HWND)0, WM_COMMAND, WM_COMMAND, PM_REMOVE)
+           && vMsg.msg != WM_QUIT)
+    {
+        wxTheApp->DoMessage((WXMSG*)&vMsg);
+    }
+    if (vMsg.msg == WM_QUIT)
+        ::WinPostMsg(NULL, WM_QUIT, 0, 0);
+}
+#endif // wxUSE_MENUS_NATIVE
+
+#if wxUSE_MENUS_NATIVE
+bool wxWindowOS2::DoPopupMenu(
+  wxMenu*                           pMenu
+, int                               nX
+, int                               nY
+)
+{
+    HWND                            hWndOwner = GetHwnd();
+    HWND                            hWndParent = GetHwnd();
+    HWND                            hMenu = GetHmenuOf(pMenu);
+    bool                            bIsWaiting = TRUE;
+
+    pMenu->SetInvokingWindow(this);
+    pMenu->UpdateUI();
+
+    DoClientToScreen( &nX
+                     ,&nY
+                    );
+    wxCurrentPopupMenu = pMenu;
+
+    ::WinPopupMenu( hWndParent
+                   ,hWndOwner
+                   ,hMenu
+                   ,nX
+                   ,nY
+                   ,0L
+                   ,PU_HCONSTRAIN | PU_VCONSTRAIN | PU_MOUSEBUTTON1 | PU_KEYBOARD
+                  );
+
+    while(bIsWaiting)
+    {
+        QMSG                            vMsg;
+        BOOL                            bRc = ::WinGetMsg(vHabmain, &vMsg, HWND(NULL), 0, 0);
+
+        if (vMsg.msg == WM_MENUEND || vMsg.msg == WM_COMMAND)
+        {
+            bIsWaiting = FALSE;
+        }
+        ::WinDispatchMsg(vHabmain, (PQMSG)&vMsg);
+
+    }
+    wxCurrentPopupMenu = NULL;
+    pMenu->SetInvokingWindow(NULL);
+    return TRUE;
+} // end of wxWindowOS2::DoPopupMenu
+#endif // wxUSE_MENUS_NATIVE
+
+// ===========================================================================
+// pre/post message processing
+// ===========================================================================
+
+MRESULT wxWindowOS2::OS2DefWindowProc(
+  WXUINT                            uMsg
+, WXWPARAM                          wParam
+, WXLPARAM                          lParam
+)
+{
+    if (m_fnOldWndProc)
+        return (MRESULT)m_fnOldWndProc(GetHWND(), uMsg, (MPARAM)wParam, (MPARAM)lParam);
+    else
+        return ::WinDefWindowProc(GetHWND(), uMsg, (MPARAM)wParam, (MPARAM)lParam);
+} // end of wxWindowOS2::OS2DefWindowProc
+
+bool wxWindowOS2::OS2ProcessMessage(
+  WXMSG*                            pMsg
+)
+{
+// wxUniversal implements tab traversal itself
+#ifndef __WXUNIVERSAL__
+    QMSG*                           pQMsg = (QMSG*)pMsg;
+
+    if (m_hWnd != 0 && (GetWindowStyleFlag() & wxTAB_TRAVERSAL))
+    {
+        //
+        // Intercept dialog navigation keys
+        //
+        bool                        bProcess = TRUE;
+        USHORT                      uKeyFlags = SHORT1FROMMP(pQMsg->mp1);
+
+        if (uKeyFlags & KC_KEYUP)
+            bProcess = FALSE;
+
+        if (uKeyFlags & KC_ALT)
+            bProcess = FALSE;
+
+        if (!(uKeyFlags & KC_VIRTUALKEY))
+            bProcess = FALSE;
+
+        if (bProcess)
+        {
+            bool                    bCtrlDown = IsCtrlDown();
+            bool                    bShiftDown = IsShiftDown();
+
+            //
+            // WM_QUERYDLGCODE: ask the control if it wants the key for itself,
+            // don't process it if it's the case (except for Ctrl-Tab/Enter
+            // combinations which are always processed)
+            //
+            ULONG                   ulDlgCode = 0;
+
+            if (!bCtrlDown)
+            {
+                ulDlgCode = (ULONG)::WinSendMsg(pQMsg->hwnd, WM_QUERYDLGCODE, pQMsg, 0);
+            }
+
+            bool                    bForward = TRUE;
+            bool                    bWindowChange = FALSE;
+
+            switch (SHORT2FROMMP(pQMsg->mp2))
+            {
+                //
+                // Going to make certain assumptions about specific types of controls
+                // here, so we may have to alter some things later if they prove invalid
+                //
+                case VK_TAB:
+                    //
+                    // Shift tabl will always be a nav-key but tabs may be wanted
+                    //
+                    if (!bShiftDown)
+                    {
+                        bProcess = FALSE;
+                    }
+                    else
+                    {
+                        //
+                        // Entry Fields want tabs for themselve usually
+                        //
+                        switch (ulDlgCode)
+                        {
+                            case DLGC_ENTRYFIELD:
+                            case DLGC_MLE:
+                                bProcess = TRUE;
+                                break;
+
+                            default:
+                                bProcess = FALSE;
+                        }
+
+                        //
+                        // Ctrl-Tab cycles thru notebook pages
+                        //
+                        bWindowChange = bCtrlDown;
+                        bForward = !bShiftDown;
+                    }
+                    break;
+
+                case VK_UP:
+                case VK_LEFT:
+                    if (bCtrlDown)
+                        bProcess = FALSE;
+                    else
+                        bForward = FALSE;
+                    break;
+
+                case VK_DOWN:
+                case VK_RIGHT:
+                    if (bCtrlDown)
+                        bProcess = FALSE;
+                    break;
+
+                case VK_ENTER:
+                    {
+                        if (bCtrlDown)
+                        {
+                            //
+                            // ctrl-enter is not processed
+                            //
+                            return FALSE;
+                        }
+                        else if (ulDlgCode & DLGC_BUTTON)
+                        {
+                            //
+                            // buttons want process Enter themselevs
+                            //
+                            bProcess = FALSE;
+                        }
+                        else
+                        {
+                            wxButton*   pBtn = wxDynamicCast( GetDefaultItem()
+                                                             ,wxButton
+                                                            );
+
+                            if (pBtn && pBtn->IsEnabled())
+                            {
+                                //
+                                // If we do have a default button, do press it
+                                //
+                                pBtn->OS2Command(BN_CLICKED, 0 /* unused */);
+                                return TRUE;
+                            }
+                            else if (!IsTopLevel())
+                            {
+                                //
+                                // if not a top level window, let parent
+                                // handle it
+                                //
+                                return FALSE;
+                            }
+                            // else: but if it does not it makes sense to make
+                            //       it work like a TAB - and that's what we do.
+                            //       Note that Ctrl-Enter always works this way.
+                        }
+                    }
+                    break;
+
+                default:
+                    bProcess = FALSE;
+            }
+
+            if (bProcess)
+            {
+                wxNavigationKeyEvent    vEvent;
+
+                vEvent.SetDirection(bForward);
+                vEvent.SetWindowChange(bWindowChange);
+                vEvent.SetEventObject(this);
+
+                if (GetEventHandler()->ProcessEvent(vEvent))
+                {
+                    wxButton*       pBtn = wxDynamicCast(FindFocus(), wxButton);
+
+                    if (pBtn)
+                    {
+                        //
+                        // The button which has focus should be default
+                        //
+                        pBtn->SetDefault();
+                    }
+                    return TRUE;
+                }
+            }
+        }
+        //
+        // Let Dialogs process
+        //
+        if (::WinSendMsg(pQMsg->hwnd, WM_QUERYDLGCODE, pQMsg, 0));
+            return TRUE;
+    }
+#else
+    pMsg = pMsg; // just shut up the compiler
+#endif // __WXUNIVERSAL__
+
+    return FALSE;
+} // end of wxWindowOS2::OS2ProcessMessage
+
+bool wxWindowOS2::OS2TranslateMessage(
+  WXMSG*                            pMsg
+)
+{
+#if wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
+  return m_acceleratorTable.Translate(m_hWnd, pMsg);
+#else
+  pMsg = pMsg;
+  return FALSE;
+#endif //wxUSE_ACCEL
+} // end of wxWindowOS2::OS2TranslateMessage
+
+bool wxWindowOS2::OS2ShouldPreProcessMessage(
+  WXMSG*                            pMsg
+)
+{
+    // preprocess all messages by default
+    return TRUE;
+} // end of wxWindowOS2::OS2ShouldPreProcessMessage
+
+// ---------------------------------------------------------------------------
+// message params unpackers
+// ---------------------------------------------------------------------------
+
+void wxWindowOS2::UnpackCommand(
+  WXWPARAM                          wParam
+, WXLPARAM                          lParam
+, WORD*                             pId
+, WXHWND*                           phWnd
+, WORD*                             pCmd
+)
+{
+    *pId = LOWORD(wParam);
+    *phWnd = NULL;  // or may be GetHWND() ?
+    *pCmd = LOWORD(lParam);
+} // end of wxWindowOS2::UnpackCommand
+
+void wxWindowOS2::UnpackActivate(
+  WXWPARAM                          wParam
+, WXLPARAM                          lParam
+, WXWORD*                           pState
+, WXHWND*                           phWnd
+)
+{
+    *pState     = LOWORD(wParam);
+    *phWnd      = (WXHWND)lParam;
+} // end of wxWindowOS2::UnpackActivate
+
+void wxWindowOS2::UnpackScroll(
+  WXWPARAM                          wParam
+, WXLPARAM                          lParam
+, WXWORD*                           pCode
+, WXWORD*                           pPos
+, WXHWND*                           phWnd
+)
+{
+    ULONG                           ulId;
+    HWND                            hWnd;
+
+    ulId    = (ULONG)LONGFROMMP(wParam);
+    hWnd = ::WinWindowFromID(GetHwnd(), ulId);
+    if (hWnd == m_hWndScrollBarHorz || hWnd == m_hWndScrollBarVert)
+        *phWnd = NULLHANDLE;
+    else
+        *phWnd = hWnd;
+
+    *pPos  = SHORT1FROMMP(lParam);
+    *pCode = SHORT2FROMMP(lParam);
+} // end of wxWindowOS2::UnpackScroll
+
+void wxWindowOS2::UnpackMenuSelect(
+  WXWPARAM                          wParam
+, WXLPARAM                          lParam
+, WXWORD*                           pItem
+, WXWORD*                           pFlags
+, WXHMENU*                          phMenu
+)
+{
+    *pItem = (WXWORD)LOWORD(wParam);
+    *pFlags = HIWORD(wParam);
+    *phMenu = (WXHMENU)lParam;
+} // end of wxWindowOS2::UnpackMenuSelect
+
+// ---------------------------------------------------------------------------
+// Main wxWindows window proc and the window proc for wxWindow
+// ---------------------------------------------------------------------------
+
+//
+// Hook for new window just as it's being created, when the window isn't yet
+// associated with the handle
+//
+wxWindowOS2*                         wxWndHook = NULL;
+
+//
+// Main window proc
+//
+MRESULT EXPENTRY wxWndProc(
+  HWND                              hWnd
+, ULONG                             ulMsg
+, MPARAM                            wParam
+, MPARAM                            lParam
+)
+{
+    //
+    // Trace all ulMsgs - useful for the debugging
+    //
+#ifdef __WXDEBUG__
+    wxLogTrace(wxTraceMessages, wxT("Processing %s(wParam=%8lx, lParam=%8lx)"),
+               wxGetMessageName(ulMsg), wParam, lParam);
+#endif // __WXDEBUG__
+
+    wxWindowOS2*                    pWnd = wxFindWinFromHandle((WXHWND)hWnd);
+
+    //
+    // When we get the first message for the HWND we just created, we associate
+    // it with wxWindow stored in wxWndHook
+    //
+    if (!pWnd && wxWndHook)
+    {
+        wxAssociateWinWithHandle(hWnd, wxWndHook);
+        pWnd = wxWndHook;
+        wxWndHook = NULL;
+        pWnd->SetHWND((WXHWND)hWnd);
+    }
+
+    MRESULT                         rc = (MRESULT)0;
+
+
+    //
+    // Stop right here if we don't have a valid handle in our wxWindow object.
+    //
+    if (pWnd && !pWnd->GetHWND())
+    {
+        pWnd->SetHWND((WXHWND) hWnd);
+        rc = pWnd->OS2DefWindowProc(ulMsg, wParam, lParam );
+        pWnd->SetHWND(0);
+    }
+    else
+    {
+        if (pWnd)
+        {
+            rc = pWnd->OS2WindowProc(ulMsg, wParam, lParam);
+            if ( (pWnd->GetScrollBarHorz() != NULLHANDLE ||
+                  pWnd->GetScrollBarVert() != NULLHANDLE) &&
+                  ulMsg == WM_PAINT)
+            {
+                if (pWnd->GetScrollBarHorz() != NULLHANDLE)
+                    ::WinInvalidateRect(pWnd->GetScrollBarHorz(), NULL, TRUE);
+                if (pWnd->GetScrollBarVert() != NULLHANDLE)
+                    ::WinInvalidateRect(pWnd->GetScrollBarVert(), NULL, TRUE);
+            }
+        }
+        else
+            rc = ::WinDefWindowProc(hWnd, ulMsg, wParam, lParam);
+    }
+
+    return rc;
+} // end of wxWndProc
+
+//
+// We will add (or delete) messages we need to handle at this default
+// level as we go
+//
+MRESULT wxWindowOS2::OS2WindowProc(
+  WXUINT                            uMsg
+, WXWPARAM                          wParam
+, WXLPARAM                          lParam
+)
+{
+    //
+    // Did we process the uMsg?
+    //
+    bool                            bProcessed = FALSE;
+    MRESULT                         mResult;
+
+    //
+    // For most messages we should return 0 when we do process the message
+    //
+    mResult = (MRESULT)0;
+
+    switch (uMsg)
+    {
+        case WM_CREATE:
+            {
+                bool                bMayCreate;
+
+                bProcessed = HandleCreate( (WXLPCREATESTRUCT)lParam
+                                          ,&bMayCreate
+                                         );
+                if (bProcessed)
+                {
+                    //
+                    // Return 0 to bAllow window creation
+                    //
+                    mResult = (MRESULT)(bMayCreate ? 0 : -1);
+                }
+            }
+            break;
+
+        case WM_DESTROY:
+             HandleDestroy();
+             bProcessed = TRUE;
+             break;
+
+        case WM_MOVE:
+            bProcessed = HandleMove( LOWORD(lParam)
+                                    ,HIWORD(lParam)
+                                   );
+            break;
+
+        case WM_SIZE:
+            bProcessed = HandleSize( LOWORD(lParam)
+                                    ,HIWORD(lParam)
+                                    ,(WXUINT)wParam
+                                   );
+            break;
+
+        case WM_WINDOWPOSCHANGED:
+
+            //
+            // Dialogs under OS/2 do not get WM_SIZE events at all.
+            // Instead they get this, which can function much like WM_SIZE
+            // PSWP contains the new sizes and positioning, PSWP+1 the old
+            // We use this because ADJUSTWINDOWPOS comes BEFORE the new
+            // position is added and our auto layout does a WinQueryWindowRect
+            // to get the CURRENT client size.  That is the size used to position
+            // child controls, so we need to already be sized
+            // in order to get the child controls positoned properly.
+            //
+            if (IsKindOf(CLASSINFO(wxDialog)) || IsKindOf(CLASSINFO(wxFrame)))
+            {
+                PSWP                pSwp = (PSWP)PVOIDFROMMP(wParam);
+                PSWP                pSwp2 = pSwp++;
+
+                if (!(pSwp->cx == pSwp2->cx &&
+                      pSwp->cy == pSwp2->cy))
+                    bProcessed = HandleSize( pSwp->cx
+                                            ,pSwp->cy
+                                            ,(WXUINT)lParam
+                                           );
+                if (IsKindOf(CLASSINFO(wxFrame)))
+                {
+                    wxFrame*            pFrame = wxDynamicCast(this, wxFrame);
+
+                    if (pFrame)
+                    {
+                        if (pFrame->GetStatusBar())
+                            pFrame->PositionStatusBar();
+                        if (pFrame->GetToolBar())
+                            pFrame->PositionToolBar();
+                    }
+                }
+            }
+            break;
+
+        case WM_ACTIVATE:
+            {
+                WXWORD              wState;
+                WXHWND              hWnd;
+
+                UnpackActivate( wParam
+                               ,lParam
+                               ,&wState
+                               ,&hWnd
+                              );
+
+                bProcessed = HandleActivate( wState
+                                            ,(WXHWND)hWnd
+                                           );
+                bProcessed = FALSE;
+            }
+            break;
+
+        case WM_SETFOCUS:
+            if (SHORT1FROMMP((MPARAM)lParam) == TRUE)
+                bProcessed = HandleSetFocus((WXHWND)(HWND)wParam);
+            else
+                bProcessed = HandleKillFocus((WXHWND)(HWND)wParam);
+            break;
+
+        case WM_PAINT:
+            bProcessed = HandlePaint();
+            break;
+
+        case WM_CLOSE:
+            //
+            // Don't let the DefWindowProc() destroy our window - we'll do it
+            // ourselves in ~wxWindow
+            //
+            bProcessed = TRUE;
+            mResult = (MRESULT)TRUE;
+            break;
+
+        case WM_SHOW:
+            bProcessed = HandleShow(wParam != 0, (int)lParam);
+            break;
+
+        //
+        // Under OS2 PM Joysticks are treated just like mouse events
+        // The "Motion" events will be prevelent in joysticks
+        //
+        case WM_MOUSEMOVE:
+        case WM_BUTTON1DOWN:
+        case WM_BUTTON1UP:
+        case WM_BUTTON1DBLCLK:
+        case WM_BUTTON1MOTIONEND:
+        case WM_BUTTON1MOTIONSTART:
+        case WM_BUTTON2DOWN:
+        case WM_BUTTON2UP:
+        case WM_BUTTON2DBLCLK:
+        case WM_BUTTON2MOTIONEND:
+        case WM_BUTTON2MOTIONSTART:
+        case WM_BUTTON3DOWN:
+        case WM_BUTTON3UP:
+        case WM_BUTTON3DBLCLK:
+        case WM_BUTTON3MOTIONEND:
+        case WM_BUTTON3MOTIONSTART:
+            {
+                if (uMsg == WM_BUTTON1DOWN && AcceptsFocus())
+                    SetFocus();
+
+                short               nX = LOWORD(wParam);
+                short               nY = HIWORD(wParam);
+
+                //
+                // Redirect the event to a static control if necessary
+                //
+                if (this == GetCapture())
+                {
+                    bProcessed = HandleMouseEvent( uMsg
+                                                  ,nX
+                                                  ,nY
+                                                  ,(WXUINT)SHORT1FROMMP(wParam)
+                                                 );
+                }
+                else
+                {
+                    wxWindow*       pWin = FindWindowForMouseEvent( this
+                                                                   ,&nX
+                                                                   ,&nY
+                                                                  );
+                    if (!pWin->IsOfStandardClass())
+                    {
+                        if (uMsg == WM_BUTTON1DOWN && pWin->AcceptsFocus() )
+                            pWin->SetFocus();
+                    }
+                    bProcessed = pWin->HandleMouseEvent( uMsg
+                                                        ,nX
+                                                        ,nY
+                                                        ,(WXUINT)SHORT1FROMMP(wParam)
+                                                       );
+                }
+            }
+            break;
+
+        case WM_SYSCOMMAND:
+            bProcessed = HandleSysCommand(wParam, lParam);
+            break;
+
+        case WM_COMMAND:
+            {
+                WORD id, cmd;
+                WXHWND hwnd;
+                UnpackCommand(wParam, lParam, &id, &hwnd, &cmd);
+
+                bProcessed = HandleCommand(id, cmd, hwnd);
+            }
+            break;
+
+            //
+            // For these messages we must return TRUE if process the message
+            //
+        case WM_DRAWITEM:
+        case WM_MEASUREITEM:
+            {
+                int                 nIdCtrl = (UINT)wParam;
+
+                if ( uMsg == WM_DRAWITEM )
+                {
+                    bProcessed = OS2OnDrawItem(nIdCtrl,
+                                              (WXDRAWITEMSTRUCT *)lParam);
+                }
+                else
+                {
+                    return MRFROMLONG(OS2OnMeasureItem( nIdCtrl
+                                                       ,(WXMEASUREITEMSTRUCT *)lParam
+                                                      ));
+                }
+
+                if ( bProcessed )
+                    mResult = (MRESULT)TRUE;
+            }
+            break;
+
+        case WM_QUERYDLGCODE:
+            if (!IsOfStandardClass())
+            {
+                if ( m_lDlgCode )
+                {
+                    mResult = (MRESULT)m_lDlgCode;
+                    bProcessed = TRUE;
+                }
+            }
+            //
+            //else: get the dlg code from the DefWindowProc()
+            //
+            break;
+
+        //
+        // In OS/2 PM all keyboard events are of the WM_CHAR type.  Virtual key and key-up
+        // and key-down events are obtained from the WM_CHAR params.
+        //
+        case WM_CHAR:
+            {
+                USHORT                  uKeyFlags = SHORT1FROMMP((MPARAM)wParam);
+
+                if (uKeyFlags & KC_KEYUP)
+                {
+                    //TODO: check if the cast to WXWORD isn't causing trouble
+                    bProcessed = HandleKeyUp(wParam, lParam);
+                    break;
+                }
+                else // keydown event
+                {
+                    m_bLastKeydownProcessed = FALSE;
+                    //
+                    // If this has been processed by an event handler,
+                    // return 0 now (we've handled it). DON't RETURN
+                    // we still need to process further
+                    //
+                    m_bLastKeydownProcessed = HandleKeyDown(wParam, lParam);
+                    if (uKeyFlags & KC_VIRTUALKEY)
+                    {
+                        USHORT          uVk = SHORT2FROMMP((MPARAM)lParam);
+
+                        //
+                        // We consider these message "not interesting" to OnChar
+                        //
+                        switch(uVk)
+                        {
+                            case VK_SHIFT:
+                            case VK_CTRL:
+                            case VK_MENU:
+                            case VK_CAPSLOCK:
+                            case VK_NUMLOCK:
+                            case VK_SCRLLOCK:
+                                bProcessed = TRUE;
+                                break;
+
+                            // Avoid duplicate messages to OnChar for these ASCII keys: they
+                            // will be translated by TranslateMessage() and received in WM_CHAR
+                            case VK_ESC:
+                            case VK_ENTER:
+                            case VK_BACKSPACE:
+                            case VK_TAB:
+                                // But set processed to FALSE, not TRUE to still pass them to
+                                // the control's default window proc - otherwise built-in
+                                // keyboard handling won't work
+                                bProcessed = FALSE;
+                                break;
+
+                            default:
+                                bProcessed = HandleChar(wParam, lParam);
+                         }
+                         break;
+                    }
+                    else // WM_CHAR -- Always an ASCII character
+                    {
+                        if (m_bLastKeydownProcessed)
+                        {
+                            //
+                            // The key was handled in the EVT_KEY_DOWN and handling
+                            // a key in an EVT_KEY_DOWN handler is meant, by
+                            // design, to prevent EVT_CHARs from happening
+                            //
+                            m_bLastKeydownProcessed = FALSE;
+                            bProcessed = TRUE;
+                        }
+                        else // do generate a CHAR event
+                        {
+                            bProcessed = HandleChar(wParam, lParam, TRUE);
+                            break;
+                        }
+                    }
+                }
+            }
+
+        case WM_HSCROLL:
+        case WM_VSCROLL:
+            {
+                WXWORD              wCode;
+                WXWORD              wPos;
+                WXHWND              hWnd;
+                UnpackScroll( wParam
+                             ,lParam
+                             ,&wCode
+                             ,&wPos
+                             ,&hWnd
+                            );
+
+                bProcessed = OS2OnScroll( uMsg == WM_HSCROLL ? wxHORIZONTAL
+                                                             : wxVERTICAL
+                                         ,wCode
+                                         ,wPos
+                                         ,hWnd
+                                        );
+            }
+            break;
+
+        case WM_CONTROL:
+            switch(SHORT2FROMMP(wParam))
+            {
+                case BN_PAINT:
+                    {
+                        HWND                hWnd = ::WinWindowFromID((HWND)GetHwnd(), SHORT1FROMMP(wParam));
+                        wxWindowOS2*        pWin = wxFindWinFromHandle(hWnd);
+
+                        if (!pWin)
+                        {
+                            bProcessed = FALSE;
+                            break;
+                        }
+                        if (pWin->IsKindOf(CLASSINFO(wxBitmapButton)))
+                        {
+                            wxBitmapButton*     pBitmapButton = wxDynamicCast(pWin, wxBitmapButton);
+
+                            pBitmapButton->OS2OnDraw((WXDRAWITEMSTRUCT *)lParam);
+                        }
+                        return 0;
+                    }
+                    break;
+
+                case BKN_PAGESELECTEDPENDING:
+                    {
+                        PPAGESELECTNOTIFY  pPage = (PPAGESELECTNOTIFY)lParam;
+
+                        if ((pPage->ulPageIdNew != pPage->ulPageIdCur) &&
+                            (pPage->ulPageIdNew > 0L && pPage->ulPageIdCur > 0L))
+                        {
+                            wxWindowOS2*        pWin = wxFindWinFromHandle(pPage->hwndBook);
+                            wxNotebookEvent     vEvent( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED
+                                                       ,(int)SHORT1FROMMP(wParam)
+                                                       ,(int)pPage->ulPageIdNew
+                                                       ,(int)pPage->ulPageIdCur
+                                                      );
+                            if (!pWin)
+                            {
+                                bProcessed = FALSE;
+                                break;
+                            }
+                            if (pWin->IsKindOf(CLASSINFO(wxNotebook)))
+                            {
+                                wxNotebook*         pNotebook = wxDynamicCast(pWin, wxNotebook);
+
+                                vEvent.SetEventObject(pWin);
+                                pNotebook->OnSelChange(vEvent);
+                                bProcessed = TRUE;
+                            }
+                            else
+                                bProcessed = FALSE;
+                        }
+                        else
+                            bProcessed = FALSE;
+                    }
+                    break;
+
+                case BN_CLICKED: // Dups as LN_SELECT and CBN_LBSELECT
+                    {
+                        HWND                hWnd = ::WinWindowFromID((HWND)GetHwnd(), SHORT1FROMMP(wParam));
+                        wxWindowOS2*        pWin = wxFindWinFromHandle(hWnd);
+
+                        if (!pWin)
+                        {
+                            bProcessed = FALSE;
+                            break;
+                        }
+                        //
+                        // Simulate a WM_COMMAND here, as wxWindows expects all control
+                        // button clicks to generate WM_COMMAND msgs, not WM_CONTROL
+                        //
+                        if (pWin->IsKindOf(CLASSINFO(wxRadioBox)))
+                        {
+                            wxRadioBox*         pRadioBox = wxDynamicCast(pWin, wxRadioBox);
+
+                            pRadioBox->OS2Command( (WXUINT)SHORT2FROMMP(wParam)
+                                                  ,(WXUINT)SHORT1FROMMP(wParam)
+                                                 );
+                        }
+                        if (pWin->IsKindOf(CLASSINFO(wxRadioButton)))
+                        {
+                            wxRadioButton*      pRadioButton = wxDynamicCast(pWin, wxRadioButton);
+
+                            pRadioButton->OS2Command( (WXUINT)SHORT2FROMMP(wParam)
+                                                     ,(WXUINT)SHORT1FROMMP(wParam)
+                                                    );
+                        }
+                        if (pWin->IsKindOf(CLASSINFO(wxCheckBox)))
+                        {
+                            wxCheckBox*         pCheckBox = wxDynamicCast(pWin, wxCheckBox);
+
+                            pCheckBox->OS2Command( (WXUINT)SHORT2FROMMP(wParam)
+                                                  ,(WXUINT)SHORT1FROMMP(wParam)
+                                                 );
+                        }
+                        if (pWin->IsKindOf(CLASSINFO(wxListBox)))
+                        {
+                            wxListBox*          pListBox = wxDynamicCast(pWin, wxListBox);
+
+                            pListBox->OS2Command( (WXUINT)SHORT2FROMMP(wParam)
+                                                 ,(WXUINT)SHORT1FROMMP(wParam)
+                                                );
+                            if (pListBox->GetWindowStyle() & wxLB_OWNERDRAW)
+                                Refresh();
+                        }
+                        if (pWin->IsKindOf(CLASSINFO(wxComboBox)))
+                        {
+                            wxComboBox*          pComboBox = wxDynamicCast(pWin, wxComboBox);
+
+                            pComboBox->OS2Command( (WXUINT)SHORT2FROMMP(wParam)
+                                                  ,(WXUINT)SHORT1FROMMP(wParam)
+                                                 );
+                        }
+                        return 0;
+                    }
+                    break;
+
+                case LN_ENTER:   /* dups as CBN_EFCHANGE */
+                    {
+                        HWND                hWnd = HWNDFROMMP(lParam);
+                        wxWindowOS2*        pWin = wxFindWinFromHandle(hWnd);
+
+                        if (!pWin)
+                        {
+                            bProcessed = FALSE;
+                            break;
+                        }
+                        //
+                        // Simulate a WM_COMMAND here, as wxWindows expects all control
+                        // button clicks to generate WM_COMMAND msgs, not WM_CONTROL
+                        //
+                        if (pWin->IsKindOf(CLASSINFO(wxListBox)))
+                        {
+                            wxListBox*          pListBox = wxDynamicCast(pWin, wxListBox);
+
+                            pListBox->OS2Command( (WXUINT)SHORT2FROMMP(wParam)
+                                                 ,(WXUINT)SHORT1FROMMP(wParam)
+                                                );
+                            if (pListBox->GetWindowStyle() & wxLB_OWNERDRAW)
+                                Refresh();
+
+                        }
+                        if (pWin->IsKindOf(CLASSINFO(wxComboBox)))
+                        {
+                            wxComboBox*          pComboBox = wxDynamicCast(pWin, wxComboBox);
+
+                            pComboBox->OS2Command( (WXUINT)SHORT2FROMMP(wParam)
+                                                  ,(WXUINT)SHORT1FROMMP(wParam)
+                                                 );
+                        }
+                        return 0;
+                    }
+                    break;
+
+                case SPBN_UPARROW:
+                case SPBN_DOWNARROW:
+                case SPBN_CHANGE:
+                    {
+                        char        zVal[10];
+                        long        lVal;
+
+                        ::WinSendMsg( HWNDFROMMP(lParam)
+                                     ,SPBM_QUERYVALUE
+                                     ,&zVal
+                                     ,MPFROM2SHORT( (USHORT)10
+                                                   ,(USHORT)SPBQ_UPDATEIFVALID
+                                                  )
+                                    );
+                        lVal = atol(zVal);
+                        bProcessed = OS2OnScroll( wxVERTICAL
+                                                 ,(int)SHORT2FROMMP(wParam)
+                                                 ,(int)lVal
+                                                 ,HWNDFROMMP(lParam)
+                                                );
+                    }
+                    break;
+
+                case SLN_SLIDERTRACK:
+                    {
+                        HWND                hWnd = ::WinWindowFromID(GetHWND(), SHORT1FROMMP(wParam));
+                        wxWindowOS2*        pChild = wxFindWinFromHandle(hWnd);
+
+                        if (!pChild)
+                        {
+                            bProcessed = FALSE;
+                            break;
+                        }
+                        if (pChild->IsKindOf(CLASSINFO(wxSlider)))
+                            bProcessed = OS2OnScroll( wxVERTICAL
+                                                     ,(int)SHORT2FROMMP(wParam)
+                                                     ,(int)LONGFROMMP(lParam)
+                                                     ,hWnd
+                                                    );
+                    }
+                    break;
+            }
+            break;
+
+#if defined(__VISAGECPP__) && (__IBMCPP__ >= 400)
+        case WM_CTLCOLORCHANGE:
+            {
+                bProcessed = HandleCtlColor(&hBrush);
+            }
+            break;
+#endif
+        case WM_ERASEBACKGROUND:
+            //
+            // Returning TRUE to requestw PM to paint the window background
+            // in SYSCLR_WINDOW. We don't really want that
+            //
+            bProcessed = HandleEraseBkgnd((WXHDC)(HPS)wParam);
+            mResult = (MRESULT)(FALSE);
+            break;
+
+            // the return value for this message is ignored
+        case WM_SYSCOLORCHANGE:
+            bProcessed = HandleSysColorChange();
+            break;
+
+        case WM_REALIZEPALETTE:
+            bProcessed = HandlePaletteChanged();
+            break;
+
+        // move all drag and drops to wxDrg
+        case WM_ENDDRAG:
+            bProcessed = HandleEndDrag(wParam);
+            break;
+
+        case WM_INITDLG:
+            bProcessed = HandleInitDialog((WXHWND)(HWND)wParam);
+
+            if ( bProcessed )
+            {
+                // we never set focus from here
+                mResult = (MRESULT)FALSE;
+            }
+            break;
+
+        // wxFrame specific message
+        case WM_MINMAXFRAME:
+            bProcessed = HandleGetMinMaxInfo((PSWP)wParam);
+            break;
+
+        case WM_SYSVALUECHANGED:
+            // TODO: do something
+            mResult = (MRESULT)TRUE;
+            break;
+
+        //
+        // Comparable to WM_SETPOINTER for windows, only for just controls
+        //
+        case WM_CONTROLPOINTER:
+            bProcessed = HandleSetCursor( SHORT1FROMMP(wParam) // Control ID
+                                         ,(HWND)lParam         // Cursor Handle
+                                        );
+            if (bProcessed )
+            {
+                //
+                // Returning TRUE stops the DefWindowProc() from further
+                // processing this message - exactly what we need because we've
+                // just set the cursor.
+                //
+                mResult = (MRESULT)TRUE;
+            }
+            break;
+    }
+    if (!bProcessed)
+    {
+#ifdef __WXDEBUG__
+        wxLogTrace(wxTraceMessages, wxT("Forwarding %s to DefWindowProc."),
+                   wxGetMessageName(uMsg));
+#endif // __WXDEBUG__
+        if (IsKindOf(CLASSINFO(wxFrame)))
+            mResult = ::WinDefWindowProc(m_hWnd, uMsg, wParam, lParam);
+        else if (IsKindOf(CLASSINFO(wxDialog)))
+            mResult = ::WinDefDlgProc( m_hWnd, uMsg, wParam, lParam);
+        else
+            mResult = OS2DefWindowProc(uMsg, wParam, lParam);
+    }
+    return mResult;
+} // end of wxWindowOS2::OS2WindowProc
+
+#ifndef __EMX__
+// clashes with wxDlgProc in toplevel.cpp?
+//
+// Dialog window proc
+//
+MRESULT wxDlgProc(
+  HWND                              WXUNUSED(hWnd)
+, UINT                              uMsg
+, MPARAM                            WXUNUSED(wParam)
+, MPARAM                            WXUNUSED(lParam))
+{
+    if (uMsg == WM_INITDLG)
+    {
+        //
+        // For this message, returning TRUE tells system to set focus to the
+        // first control in the dialog box
+        //
+        return (MRESULT)TRUE;
+    }
+    else
+    {
+        //
+        // For all the other ones, FALSE means that we didn't process the
+        // message
+        //
+        return (MRESULT)0;
+    }
+} // end of wxDlgProc
+#endif
+
+wxWindow* wxFindWinFromHandle(
+  WXHWND                            hWnd
+)
+{
+    wxNode*                         pNode = wxWinHandleList->Find((long)hWnd);
+
+    if (!pNode)
+        return NULL;
+    return (wxWindow *)pNode->Data();
+} // end of wxFindWinFromHandle
+
+void wxAssociateWinWithHandle(
+  HWND                              hWnd
+, wxWindowOS2*                      pWin
+)
+{
+    //
+    // Adding NULL hWnd is (first) surely a result of an error and
+    // (secondly) breaks menu command processing
+    //
+    wxCHECK_RET( hWnd != (HWND)NULL,
+                 wxT("attempt to add a NULL hWnd to window list ignored") );
+
+
+    wxWindow*                       pOldWin = wxFindWinFromHandle((WXHWND) hWnd);
+
+    if (pOldWin && (pOldWin != pWin))
+    {
+        wxString                    str(pWin->GetClassInfo()->GetClassName());
+        wxLogError( "Bug! Found existing HWND %X for new window of class %s"
+                   ,(int)hWnd
+                   ,(const char*)str
+                  );
+    }
+    else if (!pOldWin)
+    {
+        wxWinHandleList->Append( (long)hWnd
+                                ,pWin
+                               );
+    }
+} // end of wxAssociateWinWithHandle
+
+void wxRemoveHandleAssociation(
+  wxWindowOS2*                      pWin
+)
+{
+    wxWinHandleList->DeleteObject(pWin);
+} // end of wxRemoveHandleAssociation
+
+//
+// Default destroyer - override if you destroy it in some other way
+// (e.g. with MDI child windows)
+//
+void wxWindowOS2::OS2DestroyWindow()
+{
+}
+
+bool wxWindowOS2::OS2GetCreateWindowCoords(
+  const wxPoint&                    rPos
+, const wxSize&                     rSize
+, int&                              rnX
+, int&                              rnY
+, int&                              rnWidth
+, int&                              rnHeight
+) const
+{
+    bool                            bNonDefault = FALSE;
+    static const int                DEFAULT_Y = 200;
+    static const int                DEFAULT_H = 250;
+
+    if (rPos.x == -1)
+    {
+        rnX = rnY = CW_USEDEFAULT;
+    }
+    else
+    {
+        rnX = rPos.x;
+        rnY = rPos.y == -1 ? DEFAULT_Y : rPos.y;
+        bNonDefault = TRUE;
+    }
+    if (rSize.x == -1)
+    {
+        rnWidth = rnHeight = CW_USEDEFAULT;
+    }
+    else
+    {
+        rnWidth  = rSize.x;
+        rnHeight = rSize.y == -1 ? DEFAULT_H : rSize.y;
+        bNonDefault = TRUE;
+    }
+    return bNonDefault;
+} // end of wxWindowOS2::OS2GetCreateWindowCoords
+
+WXHWND wxWindowOS2::OS2GetParent() const
+{
+    return m_parent ? m_parent->GetHWND() : NULL;
+}
+
+bool wxWindowOS2::OS2Create(
+  PSZ                               zClass
+, const char*                       zTitle
+, WXDWORD                           dwStyle
+, const wxPoint&                    rPos
+, const wxSize&                     rSize
+, void*                             pCtlData
+, WXDWORD                           dwExStyle
+, bool                              bIsChild
+)
+{
+    ERRORID                         vError;
+    wxString                        sError;
+    int                             nX      = 0L;
+    int                             nY      = 0L;
+    int                             nWidth  = 0L;
+    int                             nHeight = 0L;
+    wxWindow*                       pParent = GetParent();
+    HWND                            hWnd = NULLHANDLE;
+    HWND                            hParent;
+    long                            lControlId = 0L;
+    wxWindowCreationHook            vHook(this);
+    wxString                        sClassName((wxChar*)zClass);
+
+    OS2GetCreateWindowCoords( rPos
+                             ,rSize
+                             ,nX
+                             ,nY
+                             ,nWidth
+                             ,nHeight
+                            );
+
+    if (bIsChild)
+    {
+        lControlId = GetId();
+        if (GetWindowStyleFlag() & wxCLIP_SIBLINGS)
+        {
+            dwStyle |= WS_CLIPSIBLINGS;
+        }
+    }
+    //
+    // For each class "Foo" we have we also have "FooNR" ("no repaint") class
+    // which is the same but without CS_[HV]REDRAW class styles so using it
+    // ensures that the window is not fully repainted on each resize
+    //
+    if (GetWindowStyleFlag() & wxNO_FULL_REPAINT_ON_RESIZE)
+    {
+        sClassName += wxT("NR");
+    }
+    m_hWnd = (WXHWND)::WinCreateWindow( (HWND)OS2GetParent()
+                                       ,(PSZ)sClassName.c_str()
+                                       ,(PSZ)zTitle ? zTitle : ""
+                                       ,(ULONG)dwStyle
+                                       ,(LONG)0L
+                                       ,(LONG)0L
+                                       ,(LONG)0L
+                                       ,(LONG)0L
+                                       ,NULLHANDLE
+                                       ,HWND_TOP
+                                       ,(ULONG)lControlId
+                                       ,pCtlData
+                                       ,NULL
+                                      );
+    if (!m_hWnd)
+    {
+        vError = ::WinGetLastError(wxGetInstance());
+        sError = wxPMErrorToStr(vError);
+        return FALSE;
+    }
+    SubclassWin(m_hWnd);
+    SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
+
+    m_backgroundColour.Set(wxString("GREY"));
+
+    LONG                            lColor = (LONG)m_backgroundColour.GetPixel();
+
+    if (!::WinSetPresParam( m_hWnd
+                           ,PP_BACKGROUNDCOLOR
+                           ,sizeof(LONG)
+                           ,(PVOID)&lColor
+                          ))
+    {
+        vError = ::WinGetLastError(vHabmain);
+        sError = wxPMErrorToStr(vError);
+        wxLogError("Error creating frame. Error: %s\n", sError);
+        return FALSE;
+    }
+    SetSize( nX
+            ,nY
+            ,nWidth
+            ,nHeight
+           );
+    return TRUE;
+} // end of WinGuiBase_Window::OS2Create
+
+// ===========================================================================
+// OS2 PM message handlers
+// ===========================================================================
+
+// ---------------------------------------------------------------------------
+// window creation/destruction
+// ---------------------------------------------------------------------------
+
+bool wxWindowOS2::HandleCreate(
+  WXLPCREATESTRUCT                  WXUNUSED(vCs)
+, bool*                             pbMayCreate
+)
+{
+    wxWindowCreateEvent             vEvent((wxWindow*)this);
+
+    (void)GetEventHandler()->ProcessEvent(vEvent);
+    *pbMayCreate = TRUE;
+    return TRUE;
+} // end of wxWindowOS2::HandleCreate
+
+bool wxWindowOS2::HandleDestroy()
+{
+    wxWindowDestroyEvent            vEvent((wxWindow*)this);
+    vEvent.SetId(GetId());
+    (void)GetEventHandler()->ProcessEvent(vEvent);
+
+    //
+    // Delete our drop target if we've got one
+    //
+#if wxUSE_DRAG_AND_DROP
+    if (m_dropTarget != NULL)
+    {
+        delete m_dropTarget;
+        m_dropTarget = NULL;
+    }
+#endif // wxUSE_DRAG_AND_DROP
+
+    //
+    // WM_DESTROY handled
+    //
+    return TRUE;
+} // end of wxWindowOS2::HandleDestroy
+
+// ---------------------------------------------------------------------------
+// activation/focus
+// ---------------------------------------------------------------------------
+void wxWindowOS2::OnSetFocus(
+  wxFocusEvent&                     rEvent
+)
+{
+    rEvent.Skip();
+} // end of wxWindowOS2::OnSetFocus
+
+bool wxWindowOS2::HandleActivate(
+  int                               nState
+, WXHWND                            WXUNUSED(hActivate)
+)
+{
+    wxActivateEvent                 vEvent( wxEVT_ACTIVATE
+                                           ,(bool)nState
+                                           ,m_windowId
+                                          );
+    vEvent.SetEventObject(this);
+    return GetEventHandler()->ProcessEvent(vEvent);
+} // end of wxWindowOS2::HandleActivate
+
+bool wxWindowOS2::HandleSetFocus(
+  WXHWND                            WXUNUSED(hWnd)
+)
+{
+    //
+    // Notify the parent keeping track of focus for the kbd navigation
+    // purposes that we got it
+    //
+    wxChildFocusEvent               vEventFocus((wxWindow *)this);
+    (void)GetEventHandler()->ProcessEvent(vEventFocus);
+
+#if wxUSE_CARET
+    //
+    // Deal with caret
+    //
+    if (m_caret)
+    {
+        m_caret->OnSetFocus();
+    }
+#endif // wxUSE_CARET
+
+#if wxUSE_TEXTCTRL
+    // If it's a wxTextCtrl don't send the event as it will be done
+    // after the control gets to process it from EN_FOCUS handler
+    if ( wxDynamicCastThis(wxTextCtrl) )
+    {
+        return FALSE;
+    }
+#endif // wxUSE_TEXTCTRL
+
+    wxFocusEvent                    vEvent(wxEVT_SET_FOCUS, m_windowId);
+
+    vEvent.SetEventObject(this);
+    return GetEventHandler()->ProcessEvent(vEvent);
+} // end of wxWindowOS2::HandleSetFocus
+
+bool wxWindowOS2::HandleKillFocus(
+  WXHWND                            hWnd
+)
+{
+#if wxUSE_CARET
+    //
+    // Deal with caret
+    //
+    if (m_caret)
+    {
+        m_caret->OnKillFocus();
+    }
+#endif // wxUSE_CARET
+
+#if wxUSE_TEXTCTRL
+    //
+    // If it's a wxTextCtrl don't send the event as it will be done
+    // after the control gets to process it.
+    //
+    wxTextCtrl*                     pCtrl = wxDynamicCastThis(wxTextCtrl);
+
+    if (pCtrl)
+    {
+        return FALSE;
+    }
+#endif
+
+    //
+    // Don't send the event when in the process of being deleted.  This can
+    // only cause problems if the event handler tries to access the object.
+    //
+    if ( m_isBeingDeleted )
+    {
+        return FALSE;
+    }
+
+    wxFocusEvent                    vEvent( wxEVT_KILL_FOCUS
+                                           ,m_windowId
+                                          );
+
+    vEvent.SetEventObject(this);
+
+    //
+    // wxFindWinFromHandle() may return NULL, it is ok
+    //
+    vEvent.SetWindow(wxFindWinFromHandle(hWnd));
+    return GetEventHandler()->ProcessEvent(vEvent);
+} // end of wxWindowOS2::HandleKillFocus
+
+// ---------------------------------------------------------------------------
+// miscellaneous
+// ---------------------------------------------------------------------------
+
+bool wxWindowOS2::HandleShow(
+  bool                              bShow
+, int                               WXUNUSED(nStatus)
+)
+{
+    wxShowEvent                     vEvent(GetId(), bShow);
+
+    vEvent.m_eventObject = this;
+    return GetEventHandler()->ProcessEvent(vEvent);
+} // end of wxWindowOS2::HandleShow
+
+bool wxWindowOS2::HandleInitDialog(
+  WXHWND                            WXUNUSED(hWndFocus)
+)
+{
+    wxInitDialogEvent               vEvent(GetId());
+
+    vEvent.m_eventObject = this;
+    return GetEventHandler()->ProcessEvent(vEvent);
+} // end of wxWindowOS2::HandleInitDialog
+
+bool wxWindowOS2::HandleEndDrag(WXWPARAM WXUNUSED(wParam))
+{
+   // TODO: We'll handle drag and drop later
+    return FALSE;
+}
+
+bool wxWindowOS2::HandleSetCursor(
+  USHORT                            WXUNUSED(vId)
+, WXHWND                            hPointer
+)
+{
+    //
+    // Under OS/2 PM this allows the pointer to be changed
+    // as it passes over a control
+    //
+    ::WinSetPointer(HWND_DESKTOP, (HPOINTER)hPointer);
+    return TRUE;
+} // end of wxWindowOS2::HandleSetCursor
+
+// ---------------------------------------------------------------------------
+// owner drawn stuff
+// ---------------------------------------------------------------------------
+bool wxWindowOS2::OS2OnDrawItem(
+  int                               vId
+, WXDRAWITEMSTRUCT*                 pItemStruct
+)
+{
+#if wxUSE_OWNER_DRAWN
+    wxDC                            vDc;
+
+#if wxUSE_MENUS_NATIVE
+    //
+    // Is it a menu item?
+    //
+    if (vId == 0)
+    {
+        ERRORID                     vError;
+        wxString                    sError;
+        POWNERITEM                  pMeasureStruct = (POWNERITEM)pItemStruct;
+        wxFrame*                    pFrame = (wxFrame*)this;
+        wxMenuItem*                 pMenuItem = pFrame->GetMenuBar()->FindItem(pMeasureStruct->idItem, pMeasureStruct->hItem);
+        HDC                         hDC = ::GpiQueryDevice(pMeasureStruct->hps);
+        wxRect                      vRect( pMeasureStruct->rclItem.xLeft
+                                          ,pMeasureStruct->rclItem.yBottom
+                                          ,pMeasureStruct->rclItem.xRight - pMeasureStruct->rclItem.xLeft
+                                          ,pMeasureStruct->rclItem.yTop - pMeasureStruct->rclItem.yBottom
+                                         );
+        vDc.SetHDC( hDC
+                   ,FALSE
+                  );
+        vDc.SetHPS(pMeasureStruct->hps);
+        //
+        // Load the wxWindows Pallete and set to RGB mode
+        //
+        if (!::GpiCreateLogColorTable( pMeasureStruct->hps
+                                      ,0L
+                                      ,LCOLF_CONSECRGB
+                                      ,0L
+                                      ,(LONG)wxTheColourDatabase->m_nSize
+                                      ,(PLONG)wxTheColourDatabase->m_palTable
+                                     ))
+        {
+            vError = ::WinGetLastError(vHabmain);
+            sError = wxPMErrorToStr(vError);
+            wxLogError("Unable to set current color table. Error: %s\n", sError);
+        }
+        //
+        // Set the color table to RGB mode
+        //
+        if (!::GpiCreateLogColorTable( pMeasureStruct->hps
+                                      ,0L
+                                      ,LCOLF_RGB
+                                      ,0L
+                                      ,0L
+                                      ,NULL
+                                     ))
+        {
+            vError = ::WinGetLastError(vHabmain);
+            sError = wxPMErrorToStr(vError);
+            wxLogError("Unable to set current color table. Error: %s\n", sError);
+        }
+
+        wxCHECK( pMenuItem->IsKindOf(CLASSINFO(wxMenuItem)), FALSE );
+
+
+        int                         eAction = 0;
+        int                         eStatus = 0;
+
+        if (pMeasureStruct->fsAttribute == pMeasureStruct->fsAttributeOld)
+        {
+            //
+            // Entire Item needs to be redrawn (either it has reappeared from
+            // behind another window or is being displayed for the first time
+            //
+            eAction = wxOwnerDrawn::wxODDrawAll;
+
+            if (pMeasureStruct->fsAttribute & MIA_HILITED)
+            {
+                //
+                // If it is currently selected we let the system handle it
+                //
+                eStatus |= wxOwnerDrawn::wxODSelected;
+            }
+            if (pMeasureStruct->fsAttribute & MIA_CHECKED)
+            {
+                //
+                // If it is currently checked we draw our own
+                //
+                eStatus |= wxOwnerDrawn::wxODChecked;
+                pMeasureStruct->fsAttributeOld = pMeasureStruct->fsAttribute &= ~MIA_CHECKED;
+            }
+            if (pMeasureStruct->fsAttribute & MIA_DISABLED)
+            {
+                //
+                // If it is currently disabled we let the system handle it
+                //
+                eStatus |= wxOwnerDrawn::wxODDisabled;
+            }
+            //
+            // Don't really care about framed (indicationg focus) or NoDismiss
+            //
+        }
+        else
+        {
+            if (pMeasureStruct->fsAttribute & MIA_HILITED)
+            {
+                eAction = wxOwnerDrawn::wxODDrawAll;
+                eStatus |= wxOwnerDrawn::wxODSelected;
+                //
+                // Keep the system from trying to highlight with its bogus colors
+                //
+                pMeasureStruct->fsAttributeOld = pMeasureStruct->fsAttribute &= ~MIA_HILITED;
+            }
+            else if (!(pMeasureStruct->fsAttribute & MIA_HILITED))
+            {
+                eAction = wxOwnerDrawn::wxODDrawAll;
+                eStatus = 0;
+                //
+                // Keep the system from trying to highlight with its bogus colors
+                //
+                pMeasureStruct->fsAttribute = pMeasureStruct->fsAttributeOld &= ~MIA_HILITED;
+            }
+            else
+            {
+                //
+                // For now we don't care about anything else
+                // just ignore the entire message!
+                //
+                return TRUE;
+            }
+        }
+        //
+        // Now redraw the item
+        //
+        return(pMenuItem->OnDrawItem( vDc
+                                     ,vRect
+                                     ,(wxOwnerDrawn::wxODAction)eAction
+                                     ,(wxOwnerDrawn::wxODStatus)eStatus
+                                    ));
+        //
+        // leave the fsAttribute and fsOldAttribute unchanged.  If different,
+        // the system will do the highlight or fraeming or disabling for us,
+        // otherwise, we'd have to do it ourselves.
+        //
+    }
+#endif // wxUSE_MENUS_NATIVE
+
+    wxWindow*                       pItem = FindItem(vId);
+
+    if (pItem && pItem->IsKindOf(CLASSINFO(wxControl)))
+    {
+        return ((wxControl *)pItem)->OS2OnDraw(pItemStruct);
+    }
+#else
+    vId = vId;
+    pItemStruct = pItemStruct;
+#endif
+    return FALSE;
+} // end of wxWindowOS2::OS2OnDrawItem
+
+long wxWindowOS2::OS2OnMeasureItem(
+  int                               lId
+, WXMEASUREITEMSTRUCT*              pItemStruct
+)
+{
+#if wxUSE_OWNER_DRAWN
+    //
+    // Is it a menu item?
+    //
+    if (lId == 65536) // I really don't like this...has to be a better indicator
+    {
+        if (IsKindOf(CLASSINFO(wxFrame))) // we'll assume if Frame then a menu
+        {
+            size_t                  nWidth;
+            size_t                  nHeight;
+            POWNERITEM              pMeasureStruct = (POWNERITEM)pItemStruct;
+            wxFrame*                pFrame = (wxFrame*)this;
+            wxMenuItem*             pMenuItem = pFrame->GetMenuBar()->FindItem(pMeasureStruct->idItem, pMeasureStruct->hItem);
+
+            wxCHECK( pMenuItem->IsKindOf(CLASSINFO(wxMenuItem)), FALSE );
+            nWidth  = 0L;
+            nHeight = 0L;
+            if (pMenuItem->OnMeasureItem( &nWidth
+                                         ,&nHeight
+                                        ))
+            {
+                MRESULT             mRc;
+
+                pMeasureStruct->rclItem.xRight  = nWidth;
+                pMeasureStruct->rclItem.xLeft   = 0L;
+                pMeasureStruct->rclItem.yTop    = nHeight;
+                pMeasureStruct->rclItem.yBottom = 0L;
+                mRc = MRFROM2SHORT(nHeight, nWidth);
+                return LONGFROMMR(mRc);
+            }
+            return 0L;
+        }
+    }
+    wxWindow*                      pItem = FindItem(lId);
+
+    if (pItem && pItem->IsKindOf(CLASSINFO(wxControl)))
+    {
+        OWNERITEM                   vItem;
+
+        vItem.idItem = (LONG)pItemStruct;
+        return ((wxControl *)pItem)->OS2OnMeasure((WXMEASUREITEMSTRUCT*)&vItem);
+    }
+#else
+    lId = lId;
+    pItemStruct = pItemStruct;
+#endif // wxUSE_OWNER_DRAWN
+    return FALSE;
+}
+
+// ---------------------------------------------------------------------------
+// colours and palettes
+// ---------------------------------------------------------------------------
+
+bool wxWindowOS2::HandleSysColorChange()
+{
+    wxSysColourChangedEvent         vEvent;
+
+    vEvent.SetEventObject(this);
+    return GetEventHandler()->ProcessEvent(vEvent);
+} // end of wxWindowOS2::HandleSysColorChange
+
+bool wxWindowOS2::HandleCtlColor(
+  WXHBRUSH*                         WXUNUSED(phBrush)
+)
+{
+    //
+    // Not much provided with message. So not sure I can do anything with it
+    //
+    return TRUE;
+} // end of wxWindowOS2::HandleCtlColor
+
+
+// Define for each class of dialog and control
+WXHBRUSH wxWindowOS2::OnCtlColor(WXHDC WXUNUSED(hDC),
+                                 WXHWND WXUNUSED(hWnd),
+                                 WXUINT WXUNUSED(nCtlColor),
+                                 WXUINT WXUNUSED(message),
+                                 WXWPARAM WXUNUSED(wParam),
+                                 WXLPARAM WXUNUSED(lParam))
+{
+    return (WXHBRUSH)0;
+}
+
+bool wxWindowOS2::HandlePaletteChanged()
+{
+    // need to set this to something first
+    WXHWND                          hWndPalChange = NULLHANDLE;
+
+    wxPaletteChangedEvent           vEvent(GetId());
+
+    vEvent.SetEventObject(this);
+    vEvent.SetChangedWindow(wxFindWinFromHandle(hWndPalChange));
+
+    return GetEventHandler()->ProcessEvent(vEvent);
+} // end of wxWindowOS2::HandlePaletteChanged
+
+//
+// Responds to colour changes: passes event on to children.
+//
+void wxWindowOS2::OnSysColourChanged(
+  wxSysColourChangedEvent&          rEvent
+)
+{
+    wxNode*                         pNode = GetChildren().First();
+
+    while (pNode)
+    {
+        //
+        // Only propagate to non-top-level windows
+        //
+        wxWindow*                   pWin = (wxWindow *)pNode->Data();
+
+        if (pWin->GetParent())
+        {
+            wxSysColourChangedEvent vEvent;
+
+            rEvent.m_eventObject = pWin;
+            pWin->GetEventHandler()->ProcessEvent(vEvent);
+        }
+        pNode = pNode->Next();
+    }
+} // end of wxWindowOS2::OnSysColourChanged
+
+// ---------------------------------------------------------------------------
+// painting
+// ---------------------------------------------------------------------------
+
+void wxWindow::OnPaint (
+  wxPaintEvent&                     rEvent
+)
+{
+    HDC                             hDC = (HDC)wxPaintDC::FindDCInCache((wxWindow*) rEvent.GetEventObject());
+
+    if (hDC != 0)
+    {
+        OS2DefWindowProc( (WXUINT)WM_PAINT
+                         ,(WXWPARAM)hDC
+                         ,(WXLPARAM)0
+                        );
+    }
+} // end of wxWindow::OnPaint
+
+bool wxWindowOS2::HandlePaint()
+{
+    HRGN                            hRgn;
+    wxPaintEvent                    vEvent(m_windowId);
+    HPS                             hPS;
+    RECTL                           vRect;
+    bool                            bProcessed;
+
+    // Create empty region
+    // TODO: get HPS somewhere else if possible
+    hPS  = ::WinGetPS(GetHwnd());
+    hRgn = ::GpiCreateRegion(hPS, 0, NULL);
+
+    if (::WinQueryUpdateRegion(GetHwnd(), hRgn) == RGN_ERROR)
+    {
+         wxLogLastError("CreateRectRgn");
+         return FALSE;
+    }
+
+    m_updateRegion = wxRegion(hRgn, hPS);
+
+    vEvent.SetEventObject(this);
+    bProcessed = GetEventHandler()->ProcessEvent(vEvent);
+
+    if (!bProcessed &&
+         IsKindOf(CLASSINFO(wxPanel)) &&
+         GetChildren().GetCount() == 0
+       )
+    {
+        //
+        // OS/2 needs to process this right here, not by the default proc
+        // Window's default proc correctly paints everything, OS/2 does not.
+        // For decorative panels that typically have no children, we draw
+        // borders.
+        //
+        HPS                         hPS;
+        RECTL                       vRect;
+        wxFrame*                    pFrame;
+        wxWindow*                   pParent;
+
+        hPS = ::WinBeginPaint( GetHwnd()
+                              ,NULLHANDLE
+                              ,&vRect
+                             );
+        if(hPS)
+        {
+            ::GpiCreateLogColorTable( hPS
+                                     ,0L
+                                     ,LCOLF_CONSECRGB
+                                     ,0L
+                                     ,(LONG)wxTheColourDatabase->m_nSize
+                                     ,(PLONG)wxTheColourDatabase->m_palTable
+                                    );
+            ::GpiCreateLogColorTable( hPS
+                                     ,0L
+                                     ,LCOLF_RGB
+                                     ,0L
+                                     ,0L
+                                     ,NULL
+                                    );
+            if (::WinIsWindowVisible(GetHWND()))
+                ::WinFillRect(hPS, &vRect,  GetBackgroundColour().GetPixel());
+            if (m_dwExStyle)
+            {
+                LINEBUNDLE      vLineBundle;
+
+                vLineBundle.lColor     = 0x00000000; // Black
+                vLineBundle.usMixMode  = FM_OVERPAINT;
+                vLineBundle.fxWidth    = 1;
+                vLineBundle.lGeomWidth = 1;
+                vLineBundle.usType     = LINETYPE_SOLID;
+                vLineBundle.usEnd      = 0;
+                vLineBundle.usJoin     = 0;
+                ::GpiSetAttrs( hPS
+                              ,PRIM_LINE
+                              ,LBB_COLOR | LBB_MIX_MODE | LBB_WIDTH | LBB_GEOM_WIDTH | LBB_TYPE
+                              ,0L
+                              ,&vLineBundle
+                             );
+                ::WinQueryWindowRect(GetHwnd(), &vRect);
+                wxDrawBorder( hPS
+                             ,vRect
+                             ,m_dwExStyle
+                            );
+            }
+        }
+        ::WinEndPaint(hPS);
+        bProcessed = TRUE;
+    }
+    else if (!bProcessed &&
+             IsKindOf(CLASSINFO(wxPanel))
+            )
+    {
+        //
+        // Panel with children, usually fills a frame client so no borders.
+        //
+        HPS                         hPS;
+        RECTL                       vRect;
+        wxFrame*                    pFrame;
+        wxWindow*                   pParent;
+
+        hPS = ::WinBeginPaint( GetHwnd()
+                              ,NULLHANDLE
+                              ,&vRect
+                             );
+        if(hPS)
+        {
+            ::GpiCreateLogColorTable( hPS
+                                     ,0L
+                                     ,LCOLF_CONSECRGB
+                                     ,0L
+                                     ,(LONG)wxTheColourDatabase->m_nSize
+                                     ,(PLONG)wxTheColourDatabase->m_palTable
+                                    );
+            ::GpiCreateLogColorTable( hPS
+                                     ,0L
+                                     ,LCOLF_RGB
+                                     ,0L
+                                     ,0L
+                                     ,NULL
+                                    );
+
+            if (::WinIsWindowVisible(GetHWND()))
+                ::WinFillRect(hPS, &vRect,  GetBackgroundColour().GetPixel());
+        }
+        ::WinEndPaint(hPS);
+        bProcessed = TRUE;
+    }
+    return bProcessed;
+} // end of wxWindowOS2::HandlePaint
+
+bool wxWindowOS2::HandleEraseBkgnd(
+  WXHDC                             hDC
+)
+{
+    SWP                             vSwp;
+    bool                            rc;