USER: Neither WS_CAPTION nor WS_EX_APPWINDOW has anything to do how passed in to CreateWindow menu should be handled

Dmitry Timoshkov dmitry at codeweavers.com
Fri Jun 9 09:13:50 CDT 2006


Hello,

this patch should fix the bug #4242.

Changelog:
    USER: Neither WS_CAPTION nor WS_EX_APPWINDOW has anything to do how
    passed in to CreateWindow menu should be handled: as a real menu
    handle or as a child id, only WS_CHILD has a meaningful value. Add
    a basic CreateWindow test to verify what's the correct behaviour is.

diff -up cvs/hq/wine/dlls/user/menu.c wine/dlls/user/menu.c
--- cvs/hq/wine/dlls/user/menu.c	2006-06-06 17:37:59.000000000 +0900
+++ wine/dlls/user/menu.c	2006-06-09 22:55:34.000000000 +0900
@@ -4337,7 +4337,13 @@ HMENU WINAPI LoadMenuIndirectA( LPCVOID 
 BOOL WINAPI IsMenu(HMENU hmenu)
 {
     LPPOPUPMENU menu = MENU_GetMenu(hmenu);
-    return menu != NULL;
+
+    if (!menu)
+    {
+        SetLastError(ERROR_INVALID_MENU_HANDLE);
+        return FALSE;
+    }
+    return TRUE;
 }
 
 /**********************************************************************
diff -up cvs/hq/wine/dlls/user/tests/win.c wine/dlls/user/tests/win.c
--- cvs/hq/wine/dlls/user/tests/win.c	2006-05-24 13:16:28.000000000 +0900
+++ wine/dlls/user/tests/win.c	2006-06-09 22:58:16.000000000 +0900
@@ -3604,6 +3604,138 @@ static void test_IsWindowUnicode(void)
     DestroyWindow(hwnd);
 }
 
+static void test_CreateWindow(void)
+{
+    HWND hwnd, parent;
+    HMENU hmenu;
+
+#define expect_menu(window, menu) \
+    SetLastError(0xdeadbeef); \
+    ok(GetMenu(window) == (HMENU)menu, "GetMenu error %ld\n", GetLastError())
+
+#define expect_style(window, style)\
+    ok(GetWindowLong(window, GWL_STYLE) == (style), "expected style %lx != %lx\n", (long)(style), GetWindowLong(window, GWL_STYLE))
+
+#define expect_ex_style(window, ex_style)\
+    ok(GetWindowLong(window, GWL_EXSTYLE) == (ex_style), "expected ex_style %lx != %lx\n", (long)(ex_style), GetWindowLong(window, GWL_EXSTYLE))
+
+    hmenu = CreateMenu();
+    assert(hmenu != 0);
+    parent = GetDesktopWindow();
+    assert(parent != 0);
+
+    SetLastError(0xdeadbeef);
+    ok(IsMenu(hmenu), "IsMenu error %ld\n", GetLastError());
+
+    SetLastError(0xdeadbeef);
+    hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD,
+                           0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
+    ok(hwnd != 0, "CreateWindowEx error %ld\n", GetLastError());
+    expect_menu(hwnd, 1);
+    expect_style(hwnd, WS_CHILD);
+    expect_ex_style(hwnd, WS_EX_APPWINDOW);
+    DestroyWindow(hwnd);
+
+    SetLastError(0xdeadbeef);
+    hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_CAPTION,
+                           0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
+    ok(hwnd != 0, "CreateWindowEx error %ld\n", GetLastError());
+    expect_menu(hwnd, 1);
+    expect_style(hwnd, WS_CHILD | WS_CAPTION);
+    expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
+    DestroyWindow(hwnd);
+
+    SetLastError(0xdeadbeef);
+    hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD,
+                           0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
+    ok(hwnd != 0, "CreateWindowEx error %ld\n", GetLastError());
+    expect_menu(hwnd, 1);
+    expect_style(hwnd, WS_CHILD);
+    expect_ex_style(hwnd, 0);
+    DestroyWindow(hwnd);
+
+    SetLastError(0xdeadbeef);
+    hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_CAPTION,
+                           0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
+    ok(hwnd != 0, "CreateWindowEx error %ld\n", GetLastError());
+    expect_menu(hwnd, 1);
+    expect_style(hwnd, WS_CHILD | WS_CAPTION);
+    expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
+    DestroyWindow(hwnd);
+
+    SetLastError(0xdeadbeef);
+    hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
+                           0, 0, 100, 100, parent, hmenu, 0, NULL);
+    ok(hwnd != 0, "CreateWindowEx error %ld\n", GetLastError());
+    expect_menu(hwnd, hmenu);
+    expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
+    expect_ex_style(hwnd, WS_EX_APPWINDOW);
+    DestroyWindow(hwnd);
+    SetLastError(0xdeadbeef);
+    ok(!IsMenu(hmenu), "IsMenu should fail\n");
+    ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %ld\n", GetLastError());
+
+    hmenu = CreateMenu();
+    assert(hmenu != 0);
+    SetLastError(0xdeadbeef);
+    hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP | WS_CAPTION,
+                           0, 0, 100, 100, parent, hmenu, 0, NULL);
+    ok(hwnd != 0, "CreateWindowEx error %ld\n", GetLastError());
+    expect_menu(hwnd, hmenu);
+    expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
+    expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
+    DestroyWindow(hwnd);
+    SetLastError(0xdeadbeef);
+    ok(!IsMenu(hmenu), "IsMenu should fail\n");
+    ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %ld\n", GetLastError());
+
+    hmenu = CreateMenu();
+    assert(hmenu != 0);
+    SetLastError(0xdeadbeef);
+    hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
+                           0, 0, 100, 100, parent, hmenu, 0, NULL);
+    ok(hwnd != 0, "CreateWindowEx error %ld\n", GetLastError());
+    expect_menu(hwnd, hmenu);
+    expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
+    expect_ex_style(hwnd, WS_EX_APPWINDOW);
+    DestroyWindow(hwnd);
+    SetLastError(0xdeadbeef);
+    ok(!IsMenu(hmenu), "IsMenu should fail\n");
+    ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %ld\n", GetLastError());
+
+    hmenu = CreateMenu();
+    assert(hmenu != 0);
+    SetLastError(0xdeadbeef);
+    hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP | WS_CAPTION,
+                           0, 0, 100, 100, parent, hmenu, 0, NULL);
+    ok(hwnd != 0, "CreateWindowEx error %ld\n", GetLastError());
+    expect_menu(hwnd, hmenu);
+    expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
+    expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
+    DestroyWindow(hwnd);
+    SetLastError(0xdeadbeef);
+    ok(!IsMenu(hmenu), "IsMenu should fail\n");
+    ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %ld\n", GetLastError());
+
+    hmenu = CreateMenu();
+    assert(hmenu != 0);
+    SetLastError(0xdeadbeef);
+    hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP,
+                           0, 0, 100, 100, parent, hmenu, 0, NULL);
+    ok(hwnd != 0, "CreateWindowEx error %ld\n", GetLastError());
+    expect_menu(hwnd, hmenu);
+    expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
+    expect_ex_style(hwnd, 0);
+    DestroyWindow(hwnd);
+    SetLastError(0xdeadbeef);
+    ok(!IsMenu(hmenu), "IsMenu should fail\n");
+    ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %ld\n", GetLastError());
+
+#undef expect_menu
+#undef expect_style
+#undef expect_ex_style
+}
+
 START_TEST(win)
 {
     pGetAncestor = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetAncestor" );
@@ -3651,6 +3783,7 @@ START_TEST(win)
     test_capture_2();
     test_capture_3(hwndMain, hwndMain2);
 
+    test_CreateWindow();
     test_parent_owner();
     test_SetParent();
     test_shell_window();
diff -up cvs/hq/wine/dlls/user/win.c wine/dlls/user/win.c
--- cvs/hq/wine/dlls/user/win.c	2006-06-06 17:37:59.000000000 +0900
+++ wine/dlls/user/win.c	2006-06-09 22:51:45.000000000 +0900
@@ -1037,8 +1037,7 @@ static HWND WIN_CreateWindowEx( CREATEST
 
     /* Set the window menu */
 
-    if (((wndPtr->dwStyle & (WS_CAPTION|WS_CHILD)) == WS_CAPTION) ||
-        (wndPtr->dwExStyle & WS_EX_APPWINDOW))
+    if (!(wndPtr->dwStyle & WS_CHILD))
     {
         if (cs->hMenu)
         {





More information about the wine-patches mailing list