📄 menu.c
字号:
TMII_SMII( {, S, MIIM_BITMAP, -1, -1, -1, -1, -1, -1, -1, -1, -1, hbm, }, OK)
TMII_GMII ( {, S, MIIM_BITMAP|MIIM_FTYPE, -9, -9, -9, -9, -9, -9, -9, string, 80, -9, },
{, S, MIIM_BITMAP|MIIM_FTYPE, MFT_SEPARATOR, -9, -9, 0, -9, -9, -9, string, 80, hbm, },
init, OK, ER )
TMII_DONE
} while( !(ansi = !ansi) );
DeleteObject( hbm);
}
/*
The following tests try to confirm the algorithm used to return the menu items
when there is a collision between a menu item and a popup menu
*/
void test_menu_search_bycommand( void )
{
HMENU hmenu, hmenuSub, hmenuSub2;
MENUITEMINFO info;
BOOL rc;
UINT id;
char strback[0x80];
char strIn[0x80];
/* Case 1: Menu containing a menu item */
hmenu = CreateMenu();
memset( &info, 0, sizeof info );
info.cbSize = sizeof info;
info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
info.fType = MFT_STRING;
strcpy(strIn, "Case 1 MenuItem");
info.dwTypeData = strIn;
info.wID = (UINT) 0x1234;
rc = InsertMenuItem(hmenu, 0, TRUE, &info );
ok (rc, "Inserting the menuitem failed\n");
id = GetMenuItemID(hmenu, 0);
ok (id == 0x1234, "Getting the menuitem id failed(gave %x)\n", id);
/* Confirm the menuitem was given the id supplied (getting by position) */
memset( &info, 0, sizeof info );
strback[0] = 0x00;
info.cbSize = sizeof(MENUITEMINFO);
info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
info.dwTypeData = strback;
info.cch = sizeof(strback);
rc = GetMenuItemInfo(hmenu, 0, TRUE, &info); /* Get by position */
ok (rc, "Getting the menu items info failed\n");
ok (info.wID == 0x1234, "IDs differ for the menuitem\n");
ok (!strcmp(info.dwTypeData, "Case 1 MenuItem"), "Returned item has wrong label\n");
/* Search by id - Should return the item */
memset( &info, 0, sizeof info );
strback[0] = 0x00;
info.cbSize = sizeof(MENUITEMINFO);
info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
info.dwTypeData = strback;
info.cch = sizeof(strback);
rc = GetMenuItemInfo(hmenu, 0x1234, FALSE, &info); /* Get by ID */
ok (rc, "Getting the menu items info failed\n");
ok (info.wID == 0x1234, "IDs differ for the menuitem\n");
ok (!strcmp(info.dwTypeData, "Case 1 MenuItem"), "Returned item has wrong label\n");
DestroyMenu( hmenu );
/* Case 2: Menu containing a popup menu */
hmenu = CreateMenu();
hmenuSub = CreateMenu();
strcpy(strIn, "Case 2 SubMenu");
rc = InsertMenu(hmenu, 0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, strIn);
ok (rc, "Inserting the popup menu into the main menu failed\n");
id = GetMenuItemID(hmenu, 0);
ok (id == -1, "Getting the menuitem id unexpectedly worked (gave %x)\n", id);
/* Confirm the menuitem itself was given an id the same as the HMENU, (getting by position) */
memset( &info, 0, sizeof info );
strback[0] = 0x00;
info.cbSize = sizeof(MENUITEMINFO);
info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
info.dwTypeData = strback;
info.cch = sizeof(strback);
info.wID = 0xdeadbeef;
rc = GetMenuItemInfo(hmenu, 0, TRUE, &info); /* Get by position */
ok (rc, "Getting the menu items info failed\n");
ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the menuitem\n");
ok (!strcmp(info.dwTypeData, "Case 2 SubMenu"), "Returned item has wrong label\n");
/* Search by id - returns the popup menu itself */
memset( &info, 0, sizeof info );
strback[0] = 0x00;
info.cbSize = sizeof(MENUITEMINFO);
info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
info.dwTypeData = strback;
info.cch = sizeof(strback);
rc = GetMenuItemInfo(hmenu, (UINT_PTR)hmenuSub, FALSE, &info); /* Get by ID */
ok (rc, "Getting the menu items info failed\n");
ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the popup menu\n");
ok (!strcmp(info.dwTypeData, "Case 2 SubMenu"), "Returned item has wrong label\n");
/*
Now add an item after it with the same id
*/
memset( &info, 0, sizeof info );
info.cbSize = sizeof info;
info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
info.fType = MFT_STRING;
strcpy(strIn, "Case 2 MenuItem 1");
info.dwTypeData = strIn;
info.wID = (UINT_PTR) hmenuSub;
rc = InsertMenuItem(hmenu, -1, TRUE, &info );
ok (rc, "Inserting the menuitem failed\n");
/* Search by id - returns the item which follows the popup menu */
memset( &info, 0, sizeof info );
strback[0] = 0x00;
info.cbSize = sizeof(MENUITEMINFO);
info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
info.dwTypeData = strback;
info.cch = sizeof(strback);
rc = GetMenuItemInfo(hmenu, (UINT_PTR)hmenuSub, FALSE, &info); /* Get by ID */
ok (rc, "Getting the menu items info failed\n");
ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the popup menu\n");
ok (!strcmp(info.dwTypeData, "Case 2 MenuItem 1"), "Returned item has wrong label (%s)\n", info.dwTypeData);
/*
Now add an item before the popup (with the same id)
*/
memset( &info, 0, sizeof info );
info.cbSize = sizeof info;
info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
info.fType = MFT_STRING;
strcpy(strIn, "Case 2 MenuItem 2");
info.dwTypeData = strIn;
info.wID = (UINT_PTR) hmenuSub;
rc = InsertMenuItem(hmenu, 0, TRUE, &info );
ok (rc, "Inserting the menuitem failed\n");
/* Search by id - returns the item which precedes the popup menu */
memset( &info, 0, sizeof info );
strback[0] = 0x00;
info.cbSize = sizeof(MENUITEMINFO);
info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
info.dwTypeData = strback;
info.cch = sizeof(strback);
rc = GetMenuItemInfo(hmenu, (UINT_PTR)hmenuSub, FALSE, &info); /* Get by ID */
ok (rc, "Getting the menu items info failed\n");
ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the popup menu\n");
ok (!strcmp(info.dwTypeData, "Case 2 MenuItem 2"), "Returned item has wrong label (%s)\n", info.dwTypeData);
DestroyMenu( hmenu );
DestroyMenu( hmenuSub );
/*
Case 3: Menu containing a popup menu which in turn
contains 2 items with the same id as the popup itself
*/
hmenu = CreateMenu();
hmenuSub = CreateMenu();
memset( &info, 0, sizeof info );
info.cbSize = sizeof info;
info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
info.fType = MFT_STRING;
info.dwTypeData = "MenuItem";
info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
rc = InsertMenu(hmenu, 0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, "Submenu");
ok (rc, "Inserting the popup menu into the main menu failed\n");
rc = InsertMenuItem(hmenuSub, 0, TRUE, &info );
ok (rc, "Inserting the sub menu menuitem failed\n");
memset( &info, 0, sizeof info );
info.cbSize = sizeof info;
info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
info.fType = MFT_STRING;
info.dwTypeData = "MenuItem 2";
info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
rc = InsertMenuItem(hmenuSub, 1, TRUE, &info );
ok (rc, "Inserting the sub menu menuitem 2 failed\n");
/* Prove that you can't query the id of a popup directly (By position) */
id = GetMenuItemID(hmenu, 0);
ok (id == -1, "Getting the sub menu id should have failed because its a popup (gave %x)\n", id);
/* Prove getting the item info via ID returns the first item (not the popup or 2nd item)*/
memset( &info, 0, sizeof info );
strback[0] = 0x00;
info.cbSize = sizeof(MENUITEMINFO);
info.fMask = MIIM_STRING | MIIM_ID;
info.dwTypeData = strback;
info.cch = sizeof(strback);
rc = GetMenuItemInfo(hmenu, (UINT_PTR)hmenuSub, FALSE, &info);
ok (rc, "Getting the menus info failed\n");
ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for popup menu\n");
ok (!strcmp(info.dwTypeData, "MenuItem"), "Returned item has wrong label (%s)\n", info.dwTypeData);
DestroyMenu( hmenu );
DestroyMenu( hmenuSub );
/*
Case 4: Menu containing 2 popup menus, the second
contains 2 items with the same id as the first popup menu
*/
hmenu = CreateMenu();
hmenuSub = CreateMenu();
hmenuSub2 = CreateMenu();
rc = InsertMenu(hmenu, 0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, "Submenu");
ok (rc, "Inserting the popup menu into the main menu failed\n");
rc = InsertMenu(hmenu, 1, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub2, "Submenu2");
ok (rc, "Inserting the popup menu into the main menu failed\n");
memset( &info, 0, sizeof info );
info.cbSize = sizeof info;
info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
info.fType = MFT_STRING;
info.dwTypeData = "MenuItem";
info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
rc = InsertMenuItem(hmenuSub2, 0, TRUE, &info );
ok (rc, "Inserting the sub menu menuitem failed\n");
memset( &info, 0, sizeof info );
info.cbSize = sizeof info;
info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
info.fType = MFT_STRING;
info.dwTypeData = "MenuItem 2";
info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
rc = InsertMenuItem(hmenuSub2, 1, TRUE, &info );
ok (rc, "Inserting the sub menu menuitem 2 failed\n");
/* Prove getting the item info via ID returns the first item (not the popup or 2nd item)*/
memset( &info, 0, sizeof info );
strback[0] = 0x00;
info.cbSize = sizeof(MENUITEMINFO);
info.fMask = MIIM_STRING | MIIM_ID;
info.dwTypeData = strback;
info.cch = sizeof(strback);
rc = GetMenuItemInfo(hmenu, (UINT_PTR)hmenuSub, FALSE, &info);
ok (rc, "Getting the menus info failed\n");
ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for popup menu\n");
ok (!strcmp(info.dwTypeData, "MenuItem"), "Returned item has wrong label (%s)\n", info.dwTypeData);
memset( &info, 0, sizeof info );
strback[0] = 0x00;
info.cbSize = sizeof(MENUITEMINFO);
info.fMask = MIIM_STRING | MIIM_ID;
info.dwTypeData = strback;
info.cch = sizeof(strback);
rc = GetMenuItemInfo(hmenu, (UINT_PTR)hmenuSub2, FALSE, &info);
ok (rc, "Getting the menus info failed\n");
ok (info.wID == (UINT)hmenuSub2, "IDs differ for popup menu\n");
ok (!strcmp(info.dwTypeData, "Submenu2"), "Returned item has wrong label (%s)\n", info.dwTypeData);
}
START_TEST(menu)
{
pSetMenuInfo =
(void *)GetProcAddress( GetModuleHandleA("user32.dll"), "SetMenuInfo" );
pGetMenuInfo =
(void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetMenuInfo" );
register_menu_check_class();
test_menu_locked_by_window();
test_menu_ownerdraw();
test_menu_add_string();
test_menu_iteminfo();
test_menu_search_bycommand();
test_menu_bmp_and_string(
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -