user32/tests: Check effect of magic font height value 0x7fff in dialog template (try 2)

Koro webmaster at korosoft.net
Mon Mar 23 14:55:06 CDT 2009


This is the second try for my testcase that shows a discrepancy between
Wine and Windows' handling of dialog templates in the specific case
where the font size member is set to 0x7fff.

On Windows NT, setting the font size member to 0x7fff instructs the
dialog manager to skip reading the following font-related members, and
to use the message box font for the dialog to be created instead.

This exact testcase passes on Win 98, ME, NT, XP, Vista, and Win 7. It
also passes on Wine because there's a todo on the crucial line.

Real-world applications affected by this: TDEmu 
(http://www.korosoft.net/projects/tdemu/) which constructs 
MessageBox-like dialog boxes at runtime.

This version of the patch is mostly rewritten to adhere to Wine
coding/testing standards. Thanks to Dan Kegel for suggestions and review.

Patch as attachment.


-------------- next part --------------
>From 7f1783bb53f71a0b8535b513f3c60d41534d5d6d Mon Sep 17 00:00:00 2001
From: Patrick Gauthier <webmaster at korosoft.net>
Date: Fri, 20 Mar 2009 19:23:39 -0400
Subject: user32/tests: Check effect of magic font height value 0x7fff in dialog template (try 2)

---
 dlls/user32/tests/dialog.c |  111 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 111 insertions(+), 0 deletions(-)

diff --git a/dlls/user32/tests/dialog.c b/dlls/user32/tests/dialog.c
index 84929e3..eac3701 100644
--- a/dlls/user32/tests/dialog.c
+++ b/dlls/user32/tests/dialog.c
@@ -36,6 +36,7 @@
 #include "wine/test.h"
 #include "windef.h"
 #include "winbase.h"
+#include "wingdi.h"
 #include "winuser.h"
 
 #define MAXHWNDS 1024
@@ -926,6 +927,115 @@ static void test_DisabledDialogTest(void)
     ok(FALSE == g_terminated, "dialog with disabled ok button has been terminated\n");
 }
 
+static INT_PTR CALLBACK messageBoxFontDlgWinProc (HWND hDlg, UINT uiMsg, WPARAM wParam,
+        LPARAM lParam)
+{
+    return (uiMsg == WM_INITDIALOG);
+}
+
+static void test_MessageBoxFontTest(void)
+{
+    /* This dialog template defines a dialog template which got 0x7fff as its
+     * font size and omits the other font members. On WinNT, passing such a
+     * dialog template to CreateDialogIndirectParamW will result in a dialog
+     * being created which uses the message box font. We test that here.
+     */
+
+    static unsigned char dlgTemplate[] =
+    {
+        /* Dialog header */
+        0x01,0x00,              /* Version */
+        0xff,0xff,              /* Extended template marker */
+        0x00,0x00,0x00,0x00,    /* Context Help ID */
+        0x00,0x00,0x00,0x00,    /* Extended style */
+        0xc0,0x00,0xc8,0x80,    /* Style (WS_SYSMENU|WS_CAPTION|WS_POPUP|DS_SETFONT|DS_MODALFRAME) */
+        0x01,0x00,              /* Control count */
+        0x00,0x00,              /* X */
+        0x00,0x00,              /* Y */
+        0x80,0x00,              /* Width */
+        0x80,0x00,              /* Height */
+        0x00,0x00,              /* Menu name */
+        0x00,0x00,              /* Class name */
+        'T',0x00,'e',0x00,      /* Caption (unicode) */
+        's',0x00,'t',0x00,
+        0x00,0x00,
+        0xff,0x7f,              /* Font height (0x7fff = message box font) */
+
+        /* Control #1 */
+        0x00,0x00,              /* Align to DWORD (header is 42 bytes) */
+        0x00,0x00,0x00,0x00,    /* Context Help ID */
+        0x00,0x00,0x00,0x00,    /* Extended style */
+        0x00,0x00,0x00,0x50,    /* Style (WS_CHILD|WS_VISIBLE) */
+        0x00,0x00,              /* X */
+        0x00,0x00,              /* Y */
+        0x80,0x00,              /* Width */
+        0x80,0x00,              /* Height */
+        0x00,0x01,0x00,0x00,    /* Control ID (256) */
+        0xff,0xff,0x82,0x00,    /* Class (Static) */
+        'W',0x00,'I',0x00,      /* Caption (unicode) */
+        'N',0x00,'E',0x00,
+        ' ',0x00,'d',0x00,
+        'i',0x00,'a',0x00,
+        'l',0x00,'o',0x00,
+        'g',0x00,' ',0x00,
+        't',0x00,'e',0x00,
+        's',0x00,'t',0x00,
+        '.',0x00,0x00,0x00,
+        0x00,0x00,              /* Size of extended data */
+
+        0x00,0x00               /* Align to DWORD */
+    };
+
+    HWND hDlg;
+    HFONT hFont;
+    LOGFONTW lfStaticFont;
+    NONCLIENTMETRICSW ncMetrics;
+
+    /* Check if the dialog can be created from the template. On Win9x, this should fail
+     * because we are calling the W function which is not implemented, but that's what
+     * we want, because passing such a template to CreateDialogIndirectParamA would crash
+     * anyway.
+     */
+    hDlg = CreateDialogIndirectParamW(g_hinst, (LPCDLGTEMPLATE)dlgTemplate, NULL, messageBoxFontDlgWinProc, 0);
+
+    if (!hDlg)
+    {
+        todo_wine win_skip("dialog wasn't created\n");
+        return;
+    }
+
+    /* Next we check if we effectively got the message box font */
+
+    /* Get HFONT for the static control */
+    hFont = (HFONT) SendDlgItemMessageW(hDlg, 256, WM_GETFONT, 0, 0);
+
+    if (!hFont)
+    {
+        skip("dialog uses system font\n");
+        DestroyWindow(hDlg);
+        return;
+    }
+
+    /* Get the LOGFONT structure corresponding to said HFONT */
+    GetObjectW(hFont, sizeof(LOGFONTW), &lfStaticFont);
+
+    /* Get the NONCLIENTMETRICS structure from user32, in order to retrieve the
+     * message box font which is in the lfFaceName member.
+     */
+    ncMetrics.cbSize=sizeof(NONCLIENTMETRICSW);
+    SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, 0, &ncMetrics, 0);
+
+    /* Compare both LOGFONT structs using a binary compare for all members
+     * up to the face name for which we'll use a regular string compare.
+     */
+    ok((!memcmp(&lfStaticFont, &ncMetrics.lfMessageFont, FIELD_OFFSET(LOGFONTW, lfFaceName))) &&
+        (!lstrcmpW(lfStaticFont.lfFaceName, ncMetrics.lfMessageFont.lfFaceName)),
+        "dialog uses message box font as intended\n");
+
+    /* Destroy the dialog */
+    DestroyWindow(hDlg);
+}
+
 START_TEST(dialog)
 {
     g_hinst = GetModuleHandleA (0);
@@ -939,4 +1049,5 @@ START_TEST(dialog)
     test_GetDlgItemText();
     test_DialogBoxParamA();
     test_DisabledDialogTest();
+    test_MessageBoxFontTest();
 }
-- 
1.5.4.3




More information about the wine-patches mailing list