[User32]
[reactos.git] / reactos / dll / win32 / user32 / windows / nonclient.c
index 4388775..5460748 100644 (file)
@@ -5,26 +5,25 @@
  * Copyright (C) 2003 ReactOS Team
  *
  * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
+ * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
+ * version 2.1 of the License, or (at your option) any later version.
  *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Library General Public License for more details.
+ * Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; see the file COPYING.LIB.
- * If not, write to the Free Software Foundation,
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
 /* INCLUDES *******************************************************************/
 
 #include <user32.h>
-#define NDEBUG
-#include <debug.h>
+
+#include <wine/debug.h>
 
 #define HAS_DLGFRAME(Style, ExStyle) \
             (((ExStyle) & WS_EX_DLGMODALFRAME) || \
@@ -54,10 +53,8 @@ VOID
 IntDrawScrollBar(HWND hWnd, HDC hDC, INT nBar);
 DWORD
 IntScrollHitTest(HWND hWnd, INT nBar, POINT pt, BOOL bDragging);
-HPEN STDCALL
-GetSysColorPen(int nIndex);
 
-BOOL STDCALL GdiGradientFill(HDC,PTRIVERTEX,ULONG,PVOID,ULONG,ULONG);
+BOOL WINAPI GdiGradientFill(HDC,PTRIVERTEX,ULONG,PVOID,ULONG,ULONG);
 
 extern ATOM AtomInternalPos;
 
@@ -134,10 +131,10 @@ UserGetWindowIcon(HWND hwnd)
       SendMessageTimeout(hwnd, WM_GETICON, ICON_BIG, 0, SMTO_ABORTIFHUNG, 1000, (LPDWORD)&hIcon);
 
    if (!hIcon)
-      hIcon = (HICON)GetClassLong(hwnd, GCL_HICONSM);
+      hIcon = (HICON)GetClassLongPtr(hwnd, GCL_HICONSM);
 
    if (!hIcon)
-      hIcon = (HICON)GetClassLong(hwnd, GCL_HICON);
+      hIcon = (HICON)GetClassLongPtr(hwnd, GCL_HICON);
 
    return hIcon;
 }
@@ -251,13 +248,20 @@ UserDrawCaptionButtonWnd(HWND hWnd, HDC hDC, BOOL bDown, ULONG Type)
    WindowRect.right -= WindowRect.left;
    WindowRect.bottom -= WindowRect.top;
    WindowRect.left = WindowRect.top = 0;
-   Style = GetWindowLongW(hWnd, GWL_STYLE);
-   ExStyle = GetWindowLongW(hWnd, GWL_EXSTYLE);
+   Style = GetWindowLongPtrW(hWnd, GWL_STYLE);
+   ExStyle = GetWindowLongPtrW(hWnd, GWL_EXSTYLE);
    UserGetWindowBorders(Style, ExStyle, &WindowBorder, FALSE);
    InflateRect(&WindowRect, -WindowBorder.cx, -WindowBorder.cy);
    UserDrawCaptionButton(&WindowRect, Style, ExStyle, hDC, bDown, Type);
 }
 
+// Note from Wine:
+/* MSDN docs are pretty idiotic here, they say app CAN use clipRgn in
+   the call to GetDCEx implying that it is allowed not to use it either.
+   However, the suggested GetDCEx(    , DCX_WINDOW | DCX_INTERSECTRGN)
+   will cause clipRgn to be deleted after ReleaseDC().
+   Now, how is the "system" supposed to tell what happened?
+ */
 /*
  * FIXME:
  * - Drawing of WS_BORDER after scrollbars
@@ -274,16 +278,16 @@ DefWndNCPaint(HWND hWnd, HRGN hRgn, BOOL Active)
    if (!IsWindowVisible(hWnd))
       return 0;
 
-   Style = GetWindowLongW(hWnd, GWL_STYLE);
+   Style = GetWindowLongPtrW(hWnd, GWL_STYLE);
 
-   hDC = GetDCEx(hWnd, hRgn, DCX_WINDOW | DCX_INTERSECTRGN | 0x10000);
+   hDC = GetDCEx(hWnd, hRgn, DCX_WINDOW | DCX_INTERSECTRGN | DCX_USESTYLE | DCX_KEEPCLIPRGN);
    if (hDC == 0)
    {
       return 0;
    }
 
    Parent = GetParent(hWnd);
-   ExStyle = GetWindowLongW(hWnd, GWL_EXSTYLE);
+   ExStyle = GetWindowLongPtrW(hWnd, GWL_EXSTYLE);
    if (Active == -1)
    {
       if (ExStyle & WS_EX_MDICHILD)
@@ -410,7 +414,7 @@ DefWndNCPaint(HWND hWnd, HRGN hRgn, BOOL Active)
          CurrentRect.top += GetSystemMetrics(SM_CYCAPTION);
       }
 
-      DrawCaption(hWnd, hDC, &TempRect, CaptionFlags);
+      NtUserDrawCaption(hWnd, hDC, &TempRect, CaptionFlags);
 
       /* Draw buttons */
       if (Style & WS_SYSMENU)
@@ -425,7 +429,8 @@ DefWndNCPaint(HWND hWnd, HRGN hRgn, BOOL Active)
       if(!(Style & WS_MINIMIZE))
       {
         /* Line under caption */
-        PreviousPen = SelectObject(hDC, GetSysColorPen(
+        PreviousPen = SelectObject(hDC, GetStockObject(DC_PEN));
+        SetDCPenColor(hDC, GetSysColor(
            ((ExStyle & (WS_EX_STATICEDGE | WS_EX_CLIENTEDGE |
                         WS_EX_DLGMODALFRAME)) == WS_EX_STATICEDGE) ?
            COLOR_WINDOWFRAME : COLOR_3DFACE));
@@ -467,7 +472,7 @@ DefWndNCPaint(HWND hWnd, HRGN hRgn, BOOL Active)
         /* FIXME: Correct drawing of size-box with WS_EX_LEFTSCROLLBAR */
         if(Parent)
           GetClientRect(Parent, &ParentClientRect);
-        if (HASSIZEGRIP(Style, ExStyle, GetWindowLongW(Parent, GWL_STYLE), WindowRect, ParentClientRect))
+        if (HASSIZEGRIP(Style, ExStyle, GetWindowLongPtrW(Parent, GWL_STYLE), WindowRect, ParentClientRect))
         {
            DrawFrameControl(hDC, &TempRect, DFC_SCROLL, DFCS_SCROLLSIZEGRIP);
         }
@@ -484,6 +489,7 @@ DefWndNCPaint(HWND hWnd, HRGN hRgn, BOOL Active)
    }
 
    ReleaseDC(hWnd, hDC);
+   DeleteObject(hRgn); // We use DCX_KEEPCLIPRGN
 
    return 0;
 }
@@ -492,10 +498,16 @@ LRESULT
 DefWndNCCalcSize(HWND hWnd, BOOL CalcSizeStruct, RECT *Rect)
 {
    LRESULT Result = 0;
-   DWORD Style = GetClassLongW(hWnd, GCL_STYLE);
+   DWORD Style = GetClassLongPtrW(hWnd, GCL_STYLE);
    DWORD ExStyle;
    SIZE WindowBorders;
-   RECT OrigRect = *Rect;
+   RECT OrigRect;
+
+   if (Rect == NULL)
+   {
+      return Result;
+   }
+   OrigRect = *Rect;
 
    if (CalcSizeStruct)
    {
@@ -510,8 +522,8 @@ DefWndNCCalcSize(HWND hWnd, BOOL CalcSizeStruct, RECT *Rect)
       Result |= WVR_VALIDRECTS;
    }
 
-   Style = GetWindowLongW(hWnd, GWL_STYLE);
-   ExStyle = GetWindowLongW(hWnd, GWL_EXSTYLE);
+   Style = GetWindowLongPtrW(hWnd, GWL_STYLE);
+   ExStyle = GetWindowLongPtrW(hWnd, GWL_EXSTYLE);
 
    if (!(Style & WS_MINIMIZE))
    {
@@ -652,8 +664,8 @@ DefWndNCHitTest(HWND hWnd, POINT Point)
    RECT WindowRect, ClientRect, OrigWndRect;
    POINT ClientPoint;
    SIZE WindowBorders;
-   ULONG Style = GetWindowLongW(hWnd, GWL_STYLE);
-   ULONG ExStyle = GetWindowLongW(hWnd, GWL_EXSTYLE);
+   ULONG Style = GetWindowLongPtrW(hWnd, GWL_STYLE);
+   ULONG ExStyle = GetWindowLongPtrW(hWnd, GWL_EXSTYLE);
 
    GetWindowRect(hWnd, &WindowRect);
    if (!PtInRect(&WindowRect, Point))
@@ -751,11 +763,12 @@ DefWndNCHitTest(HWND hWnd, POINT Point)
             }
             else
             {
-               WindowRect.left += GetSystemMetrics(SM_CXSIZE);
+               if(!(ExStyle & WS_EX_DLGMODALFRAME))
+                  WindowRect.left += GetSystemMetrics(SM_CXSIZE);
                WindowRect.right -= GetSystemMetrics(SM_CXSIZE);
             }
          }
-         if (Point.x <= WindowRect.left)
+         if (Point.x < WindowRect.left)
             return HTSYSMENU;
          if (WindowRect.right <= Point.x)
             return HTCLOSE;
@@ -823,7 +836,7 @@ DefWndNCHitTest(HWND hWnd, POINT Point)
         if(Parent)
           GetClientRect(Parent, &ParentRect);
         if (PtInRect(&TempRect, Point) && HASSIZEGRIP(Style, ExStyle,
-            GetWindowLongW(Parent, GWL_STYLE), OrigWndRect, ParentRect))
+            GetWindowLongPtrW(Parent, GWL_STYLE), OrigWndRect, ParentRect))
         {
            if ((ExStyle & WS_EX_LEFTSCROLLBAR) != 0)
               return HTBOTTOMLEFT;
@@ -866,7 +879,7 @@ DefWndDoButton(HWND hWnd, WPARAM wParam)
    WPARAM SCMsg;
    ULONG ButtonType, Style;
 
-   Style = GetWindowLongW(hWnd, GWL_STYLE);
+   Style = GetWindowLongPtrW(hWnd, GWL_STYLE);
    switch (wParam)
    {
       case HTCLOSE:
@@ -948,7 +961,7 @@ DefWndNCLButtonDown(HWND hWnd, WPARAM wParam, LPARAM lParam)
         }
         case HTSYSMENU:
         {
-         if (GetWindowLongW(hWnd, GWL_STYLE) & WS_SYSMENU)
+         if (GetWindowLongPtrW(hWnd, GWL_STYLE) & WS_SYSMENU)
             {
              SendMessageW(hWnd, WM_SYSCOMMAND, SC_MOUSEMENU + HTSYSMENU,
                           lParam);
@@ -999,7 +1012,7 @@ DefWndNCLButtonDblClk(HWND hWnd, WPARAM wParam, LPARAM lParam)
 {
   ULONG Style;
 
-  Style = GetWindowLongW(hWnd, GWL_STYLE);
+  Style = GetWindowLongPtrW(hWnd, GWL_STYLE);
   switch(wParam)
   {
     case HTCAPTION:
@@ -1045,14 +1058,11 @@ DefWndTrackScrollBar(HWND hWnd, WPARAM wParam, POINT Point)
 
 /* PUBLIC FUNCTIONS ***********************************************************/
 
-/*
- * @implemented
- */
-BOOL STDCALL
-AdjustWindowRectEx(LPRECT lpRect,
-                  DWORD dwStyle,
-                  BOOL bMenu,
-                  DWORD dwExStyle)
+BOOL WINAPI
+RealAdjustWindowRectEx(LPRECT lpRect,
+                       DWORD dwStyle,
+                       BOOL bMenu,
+                       DWORD dwExStyle)
 {
    SIZE BorderSize;
 
@@ -1076,11 +1086,43 @@ AdjustWindowRectEx(LPRECT lpRect,
    return TRUE;
 }
 
+/*
+ * @implemented
+ */
+BOOL WINAPI
+AdjustWindowRectEx(LPRECT lpRect,
+                  DWORD dwStyle,
+                  BOOL bMenu,
+                  DWORD dwExStyle)
+{
+   BOOL Hook, Ret = FALSE;
+
+   LOADUSERAPIHOOK
+
+   Hook = BeginIfHookedUserApiHook();
+
+     /* Bypass SEH and go direct. */
+   if (!Hook) return RealAdjustWindowRectEx(lpRect, dwStyle, bMenu, dwExStyle);
+
+   _SEH2_TRY
+   {
+      Ret = guah.AdjustWindowRectEx(lpRect, dwStyle, bMenu, dwExStyle);
+   }
+   _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
+   {
+   }
+   _SEH2_END;
+
+   EndUserApiHook();
+
+   return Ret;
+}
+
 
 /*
  * @implemented
  */
-BOOL STDCALL
+BOOL WINAPI
 AdjustWindowRect(LPRECT lpRect,
                 DWORD dwStyle,
                 BOOL bMenu)
@@ -1097,239 +1139,37 @@ AdjustWindowRect(LPRECT lpRect,
 BOOL WINAPI
 DrawCaption(HWND hWnd, HDC hDC, LPCRECT lprc, UINT uFlags)
 {
-    NONCLIENTMETRICSW nclm;
-    BOOL result = FALSE;
-    RECT r = *lprc;
-    UINT VCenter = 0, Padding = 0, Height;
-    ULONG Style;
-    WCHAR buffer[256];
-    HFONT hFont = NULL;
-    HFONT hOldFont = NULL;
-    HBRUSH OldBrush = NULL;
-    HDC MemDC = NULL;
-    int ButtonWidth;
-    COLORREF OldTextColor;
-
-#ifdef DOUBLE_BUFFER_CAPTION
-    HBITMAP MemBMP = NULL, OldBMP = NULL;
-
-    MemDC = CreateCompatibleDC(hDC);
-    if (! MemDC) goto cleanup;
-    MemBMP = CreateCompatibleBitmap(hDC, lprc->right - lprc->left, lprc->bottom - lprc->top);
-    if (! MemBMP) goto cleanup;
-    OldBMP = SelectObject(MemDC, MemBMP);
-    if (! OldBMP) goto cleanup;
-#else
-    MemDC = hDC;
+   BOOL Hook, Ret = FALSE;
 
-    OffsetViewportOrgEx(MemDC, lprc->left, lprc->top, NULL);
-#endif
-
-    Style = GetWindowLongW(hWnd, GWL_STYLE);
-
-    /* Windows behaves like this */
-    Height = GetSystemMetrics(SM_CYCAPTION) - 1;
+   LOADUSERAPIHOOK
 
-    VCenter = (lprc->bottom - lprc->top) / 2;
-    Padding = VCenter - (Height / 2);
+   Hook = BeginIfHookedUserApiHook();
 
-    r.left = Padding;
-    r.right = r.left + (lprc->right - lprc->left);
-    r.top = Padding;
-    r.bottom = r.top + (Height / 2);
+   /* Bypass SEH and go direct. */
+   if (!Hook) return NtUserDrawCaption(hWnd, hDC, lprc, uFlags);
 
-    // Draw the caption background
-    if (uFlags & DC_INBUTTON)
-    {
-        OldBrush = SelectObject(MemDC, GetSysColorBrush(uFlags & DC_ACTIVE ? COLOR_BTNFACE : COLOR_BTNSHADOW) );
-        if (! OldBrush) goto cleanup;
-        if (! PatBlt(MemDC, 0, 0, lprc->right - lprc->left, lprc->bottom - lprc->top, PATCOPY )) goto cleanup;
-    }
-    else
-    {
-        if (uFlags & DC_GRADIENT)
-        {
-          static GRADIENT_RECT gcap = {0, 1};
-                 TRIVERTEX vert[2];
-          COLORREF Colors[2];
-          LONG xx;
-
-          r.right = (lprc->right - lprc->left);
-          if (uFlags & DC_SMALLCAP)
-            ButtonWidth = GetSystemMetrics(SM_CXSMSIZE) - 2;
-          else
-            ButtonWidth = GetSystemMetrics(SM_CXSIZE) - 2;
-
-          //if (Style & WS_SYSMENU)
-          //{
-          //  r.right -= 3 + ButtonWidth;
-          //  if (! (uFlags & DC_SMALLCAP))
-          //  {
-          //    if(Style & (WS_MAXIMIZEBOX | WS_MINIMIZEBOX))
-          //      r.right -= 2 + 2 * ButtonWidth;
-          //    else
-          //      r.right -= 2;
-          //    r.right -= 2;
-          //  }
-          //}
-
-          Colors[0] = GetSysColor((uFlags & DC_ACTIVE) ? COLOR_ACTIVECAPTION : COLOR_INACTIVECAPTION);
-          Colors[1] = GetSysColor((uFlags & DC_ACTIVE) ? COLOR_GRADIENTACTIVECAPTION : COLOR_GRADIENTINACTIVECAPTION);
-
-          vert[0].x = r.left;
-          vert[0].y = 0;
-          vert[0].Red = GetRValue(Colors[0]) << 8;
-          vert[0].Green = GetGValue(Colors[0]) << 8;
-          vert[0].Blue = GetBValue(Colors[0]) << 8;
-          vert[0].Alpha = 0;
-
-          vert[1].x = r.right;
-          vert[1].y = lprc->bottom - lprc->top;
-          vert[1].Red = GetRValue(Colors[1]) << 8;
-          vert[1].Green = GetGValue(Colors[1]) << 8;
-          vert[1].Blue = GetBValue(Colors[1]) << 8;
-          vert[1].Alpha = 0;
-
-          GdiGradientFill(MemDC, vert, 2, &gcap, 1, GRADIENT_FILL_RECT_V);
-
-          if ((uFlags & DC_ICON) && (Style & WS_SYSMENU) && !(uFlags & DC_SMALLCAP))
-          {
-            r.top --;
-                       SetBkMode( MemDC, TRANSPARENT );
-                       xx = GetSystemMetrics(SM_CXSIZE) + Padding;
-            if (UserDrawSysMenuButton(hWnd, MemDC, &r, FALSE))
-              r.left += xx;
-            r.top ++;
-          }
-
-          if(OldBrush)
-          {
-            SelectObject(MemDC, OldBrush);
-            OldBrush = NULL;
-          }
-          //xx = lprc->right - lprc->left - r.right;
-          //if(xx > 0)
-          //{
-          //  OldBrush = SelectObject(MemDC, GetSysColorBrush(uFlags & DC_ACTIVE ? COLOR_GRADIENTACTIVECAPTION : COLOR_GRADIENTINACTIVECAPTION));
-          //  if (!OldBrush) goto cleanup;
-          //  PatBlt(MemDC, r.right, 0, xx, lprc->bottom - lprc->top, PATCOPY);
-          //}
-        }
-        else
-        {
-            OldBrush = SelectObject(MemDC, GetSysColorBrush(uFlags & DC_ACTIVE ? COLOR_ACTIVECAPTION : COLOR_INACTIVECAPTION) );
-            if (! OldBrush) goto cleanup;
-            if (! PatBlt(MemDC, 0, 0, lprc->right - lprc->left, lprc->bottom - lprc->top, PATCOPY )) goto cleanup;
-        }
-    }
-
-    if ((uFlags & DC_ICON) && !(uFlags & DC_GRADIENT) && (Style & WS_SYSMENU) && !(uFlags & DC_SMALLCAP))
-    {
-        /* For some reason the icon isn't centered correctly... */
-        r.top --;
-        if (UserDrawSysMenuButton(hWnd, MemDC, &r, FALSE))
-          r.left += GetSystemMetrics(SM_CXSIZE) + Padding;
-        r.top ++;
-    }
-    r.top ++;
-    r.left += 2;
-
-    r.bottom = r.top + Height;
-
-  if ((uFlags & DC_TEXT) && (NtUserInternalGetWindowText( hWnd, buffer, sizeof(buffer)/sizeof(buffer[0]) )))
-  {
-    if(!(uFlags & DC_GRADIENT))
-    {
-    r.right = (lprc->right - lprc->left);
-    if (uFlags & DC_SMALLCAP)
-      ButtonWidth = GetSystemMetrics(SM_CXSMSIZE) - 2;
-    else
-      ButtonWidth = GetSystemMetrics(SM_CXSIZE) - 2;
-
-    if (Style & WS_SYSMENU)
-    {
-      r.right -= 3 + ButtonWidth;
-      if (! (uFlags & DC_SMALLCAP))
-      {
-        if(Style & (WS_MAXIMIZEBOX | WS_MINIMIZEBOX))
-             r.right -= 2 + 2 * ButtonWidth;
-        else
-             r.right -= 2;
-        r.right -= 2;
-      }
-    }
-    }
-
-    nclm.cbSize = sizeof(nclm);
-    if (! SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICSW), &nclm, 0)) goto cleanup;
-
-    SetBkMode( MemDC, TRANSPARENT );
-    if (uFlags & DC_SMALLCAP)
-        hFont = CreateFontIndirectW(&nclm.lfSmCaptionFont);
-    else
-        hFont = CreateFontIndirectW(&nclm.lfCaptionFont);
-
-    if (! hFont) goto cleanup;
-
-    hOldFont = SelectObject(MemDC, hFont);
-    if (! hOldFont) goto cleanup;
-
-    if (uFlags & DC_INBUTTON)
-        OldTextColor = SetTextColor(MemDC, GetSysColor(uFlags & DC_ACTIVE ? COLOR_BTNTEXT : COLOR_GRAYTEXT));
-    else
-        OldTextColor = SetTextColor(MemDC, GetSysColor(uFlags & DC_ACTIVE ? COLOR_CAPTIONTEXT : COLOR_INACTIVECAPTIONTEXT));
-
-    DrawTextW(MemDC, buffer, wcslen(buffer), &r, DT_VCENTER | DT_END_ELLIPSIS);
-
-    SetTextColor(MemDC, OldTextColor);
-  }
-
-#if 0
-    if (uFlags & DC_BUTTONS)
-    {
-        // Windows XP draws the caption buttons with DC_BUTTONS
-//        r.left += GetSystemMetrics(SM_CXSIZE) + 1;
-//        UserDrawCaptionButton( hWnd, hDC, FALSE, DFCS_CAPTIONCLOSE);
-//        r.right -= GetSystemMetrics(SM_CXSMSIZE) + 1;
-//        UserDrawCaptionButton( hWnd, hDC, FALSE, DFCS_CAPTIONMIN);
-//        UserDrawCaptionButton( hWnd, hDC, FALSE, DFCS_CAPTIONMAX);
-    }
-#endif
-
-#ifdef DOUBLE_BUFFER_CAPTION
-    if (! BitBlt(hDC, lprc->left, lprc->top, lprc->right - lprc->left, lprc->bottom - lprc->top,
-            MemDC, 0, 0, SRCCOPY)) goto cleanup;
-#endif
-
-    result = TRUE;
+   _SEH2_TRY
+   {
+      Ret = guah.DrawCaption(hWnd, hDC, lprc, uFlags);
+   }
+   _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
+   {
+   }
+   _SEH2_END;
 
-    cleanup :
-        if (MemDC)
-        {
-            if (OldBrush) SelectObject(MemDC, OldBrush);
-            if (hOldFont) SelectObject(MemDC, hOldFont);
-            if (hFont) DeleteObject(hFont);
-#ifdef DOUBLE_BUFFER_CAPTION
-            if (OldBMP) SelectObject(MemDC, OldBMP);
-            if (MemBMP) DeleteObject(MemBMP);
-            DeleteDC(MemDC);
-#else
-            OffsetViewportOrgEx(MemDC, -lprc->left, -lprc->top, NULL);
-#endif
-        }
+   EndUserApiHook();
 
-        return result;
+   return Ret;
 }
 
-
 /*
- * @unimplemented
+ * @implemented
  */
 BOOL
-STDCALL
+WINAPI
 DrawCaptionTempW(
-                HWND        hwnd,
-                HDC         hdc,
+                HWND        hWnd,
+                HDC         hDC,
                 const RECT *rect,
                 HFONT       hFont,
                 HICON       hIcon,
@@ -1337,15 +1177,16 @@ DrawCaptionTempW(
                 UINT        uFlags
                 )
 {
-  UNIMPLEMENTED;
-  return FALSE;
+   UNICODE_STRING Text = {0};
+   RtlInitUnicodeString(&Text, str);
+   return NtUserDrawCaptionTemp(hWnd, hDC, rect, hFont, hIcon, &Text, uFlags);
 }
 
 /*
- * @unimplemented
+ * @implemented
  */
 BOOL
-STDCALL
+WINAPI
 DrawCaptionTempA(
                 HWND        hwnd,
                 HDC         hdc,
@@ -1356,8 +1197,21 @@ DrawCaptionTempA(
                 UINT        uFlags
                 )
 {
-  UNIMPLEMENTED;
-  return FALSE;
+  LPWSTR strW;
+  INT len;
+  BOOL ret = FALSE;
+
+  if (!(uFlags & DC_TEXT) || !str)
+    return DrawCaptionTempW(hwnd, hdc, rect, hFont, hIcon, NULL, uFlags);
+
+  len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
+  if ((strW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR))))
+  {
+    MultiByteToWideChar(CP_ACP, 0, str, -1, strW, len );
+    ret = DrawCaptionTempW(hwnd, hdc, rect, hFont, hIcon, strW, uFlags);
+    HeapFree(GetProcessHeap(), 0, strW);
+  }
+  return ret;
 }
 
 /***********************************************************************
@@ -1379,14 +1233,14 @@ NcGetInsideRect(HWND Wnd, RECT *Rect)
   Rect->bottom = Rect->bottom - Rect->top;
   Rect->top = 0;
 
-  Style = GetWindowLongW(Wnd, GWL_STYLE);
+  Style = GetWindowLongPtrW(Wnd, GWL_STYLE);
   if (0 != (Style & WS_ICONIC))
     {
       return;
     }
 
   /* Remove frame from rectangle */
-  ExStyle = GetWindowLongW(Wnd, GWL_EXSTYLE);
+  ExStyle = GetWindowLongPtrW(Wnd, GWL_EXSTYLE);
   if (HAS_THICKFRAME(Style, ExStyle))
     {
       InflateRect(Rect, - GetSystemMetrics(SM_CXFRAME), - GetSystemMetrics(SM_CYFRAME));
@@ -1433,7 +1287,7 @@ NcGetSysPopupPos(HWND Wnd, RECT *Rect)
       NcGetInsideRect(Wnd, Rect);
       GetWindowRect(Wnd, &WindowRect);
       OffsetRect(Rect, WindowRect.left, WindowRect.top);
-      if (0 != (GetWindowLongW(Wnd, GWL_STYLE) & WS_CHILD))
+      if (0 != (GetWindowLongPtrW(Wnd, GWL_STYLE) & WS_CHILD))
         {
           ClientToScreen(GetParent(Wnd), (POINT *) Rect);
         }