test: menuc.c File Reference

Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

# menuc.c File Reference

`#include "precomp.h"`

Go to the source code of this file.

## Functions

DWORD | CheckMenuItem (HMENU hMenu, UINT uIDCheckItem, UINT uCheck)
UINT | GetMenuDefaultItem (HMENU hMenu, UINT fByPosition, UINT uFlags)
void | SetMenuItemInfoStruct (HMENU hMenu, UINT wFlags, UINT_PTR wIDNew, LPWSTR pwszNew, LPMENUITEMINFO pmii)
BOOL | SetMenuInfo (HMENU hMenu, LPCMENUINFO lpmi)
BOOL | ChangeMenuW (HMENU hMenu, UINT cmd, LPCWSTR lpNewItem, UINT IdItem, UINT flags)
BOOL | ChangeMenuA (HMENU hMenu, UINT cmd, LPCSTR lpNewItem, UINT IdItem, UINT flags)
LONG | GetMenuCheckMarkDimensions ()
WINUSERAPI DWORD WINAPI | GetMenuContextHelpId (HMENU hMenu)
BOOL | TrackPopupMenu (HMENU hMenu, UINT fuFlags, int x, int y, int nReserved, HWND hwnd, CONST RECT *prcRect)
PMENU | xxxGetSysMenuHandle (PWND pwnd)
BOOL WINAPI | SetMenuItemBitmaps (HMENU hMenu, UINT nPosition, UINT uFlags, HBITMAP hbmpUnchecked, HBITMAP hbmpChecked)
int WINAPI | DrawMenuBarTemp (HWND hwnd, HDC hdc, LPCRECT lprc, HMENU hMenu, HFONT hFont)
BOOL | CheckMenuRadioItem (HMENU hMenu, UINT wIDFirst, UINT wIDLast, UINT wIDCheck, UINT flags)

## Function Documentation

BOOL ChangeMenuA | ( | HMENU | hMenu,
|  | UINT | cmd,
|  | LPCSTR | lpNewItem,
|  | UINT | IdItem,
|  | UINT | flags
| ) |

Definition at line 176 of file menuc.c.

References BOOL, DWORD, MFMWFP_OFFMENU, NtUserDeleteMenu(), NtUserRemoveMenu(), NULL, and UINT.

    00182 {
    00183     /*
    00184      * These next two statements take care of sleazyness needed for
    00185      * compatability with old changemenu.
    00186      */
    00187     if ((flags & MF_SEPARATOR) && cmd == MFMWFP_OFFMENU && !(flags & MF_CHANGE))
    00188         flags |= MF_APPEND;
    00189
    00190     if (lpNewItem == NULL)
    00191         flags |= MF_SEPARATOR;
    00192
    00193
    00194
    00195     /*
    00196      * MUST be MF_BYPOSITION for Win2.x compatability.
    00197      */
    00198     if (flags & MF_REMOVE)
    00199         return(NtUserRemoveMenu(hMenu, cmd,
    00200                 (DWORD)((flags & ~MF_REMOVE) | MF_BYPOSITION)));
    00201
    00202     if (flags & MF_DELETE)
    00203         return(NtUserDeleteMenu(hMenu, cmd, (DWORD)(flags & ~MF_DELETE)));
    00204
    00205     if (flags & MF_CHANGE)
    00206         return(ModifyMenuA(hMenu, cmd, (DWORD)((flags & ~MF_CHANGE) &
    00207                 (0x07F | MF_HELP | MF_BYPOSITION | MF_BYCOMMAND |
    00208                 MF_SEPARATOR)), IdItem, lpNewItem));
    00209
    00210     if (flags & MF_APPEND)
    00211         return(AppendMenuA(hMenu, (UINT)(flags & ~MF_APPEND),
    00212             IdItem, lpNewItem));
    00213
    00214     /*
    00215      * Default is insert
    00216      */
    00217     return(InsertMenuA(hMenu, cmd, (DWORD)(flags & ~MF_INSERT),
    00218             IdItem, lpNewItem));
    00219 }

BOOL ChangeMenuW | ( | HMENU | hMenu,
|  | UINT | cmd,
|  | LPCWSTR | lpNewItem,
|  | UINT | IdItem,
|  | UINT | flags
| ) |

Definition at line 131 of file menuc.c.

References BOOL, DWORD, MFMWFP_OFFMENU, NtUserDeleteMenu(), NtUserRemoveMenu(), NULL, and UINT.

    00137 {
    00138     /*
    00139      * These next two statements take care of sleazyness needed for
    00140      * compatability with old changemenu.
    00141      */
    00142     if ((flags & MF_SEPARATOR) && cmd == MFMWFP_OFFMENU && !(flags & MF_CHANGE))
    00143         flags |= MF_APPEND;
    00144
    00145     if (lpNewItem == NULL)
    00146         flags |= MF_SEPARATOR;
    00147
    00148
    00149
    00150     /*
    00151      * MUST be MF_BYPOSITION for Win2.x compatability.
    00152      */
    00153     if (flags & MF_REMOVE)
    00154         return(NtUserRemoveMenu(hMenu, cmd,
    00155                 (DWORD)((flags & ~MF_REMOVE) | MF_BYPOSITION)));
    00156
    00157     if (flags & MF_DELETE)
    00158         return(NtUserDeleteMenu(hMenu, cmd, (DWORD)(flags & ~MF_DELETE)));
    00159
    00160     if (flags & MF_CHANGE)
    00161         return(ModifyMenuW(hMenu, cmd, (DWORD)((flags & ~MF_CHANGE) &
    00162                 (0x07F | MF_HELP | MF_BYPOSITION | MF_BYCOMMAND |
    00163                 MF_SEPARATOR)), IdItem, lpNewItem));
    00164
    00165     if (flags & MF_APPEND)
    00166         return(AppendMenuW(hMenu, (UINT)(flags & ~MF_APPEND),
    00167             IdItem, lpNewItem));
    00168
    00169     /*
    00170      * Default is insert
    00171      */
    00172     return(InsertMenuW(hMenu, cmd, (DWORD)(flags & ~MF_INSERT),
    00173             IdItem, lpNewItem));
    00174 }

DWORD CheckMenuItem | ( | HMENU | hMenu,
|  | UINT | uIDCheckItem,
|  | UINT | uCheck
| ) |

Definition at line 15 of file menuc.c.

References BOOL, DWORD, tagITEM::fState, MNLookUpItem(), NtUserCheckMenuItem(), NULL, and VALIDATEHMENU.

Referenced by MainWndProc(), MDISetMenu(), SyncMenuChecks(), WndProc(), and xxxMDIActivate().

    00019 {
    00020     PMENU pMenu;
    00021     PITEM pItem;
    00022
    00023     pMenu = VALIDATEHMENU(hMenu);
    00024     if (pMenu == NULL) {
    00025         return (DWORD)-1;
    00026     }
    00027
    00028     /*
    00029      * Get a pointer the the menu item
    00030      */
    00031     if ((pItem = MNLookUpItem(pMenu, uIDCheckItem, (BOOL) (uCheck & MF_BYPOSITION), NULL)) == NULL)
    00032         return (DWORD)-1;
    00033
    00034     /*
    00035      * If the item is already in the state we're
    00036      * trying to set, just return.
    00037      */
    00038     if ((pItem->fState & MFS_CHECKED) == (uCheck & MFS_CHECKED)) {
    00039         return pItem->fState & MF_CHECKED;
    00040     }
    00041
    00042     return NtUserCheckMenuItem(hMenu, uIDCheckItem, uCheck);
    00043 }

BOOL CheckMenuRadioItem | ( | HMENU | hMenu,
|  | UINT | wIDFirst,
|  | UINT | wIDLast,
|  | UINT | wIDCheck,
|  | UINT | flags
| ) |

Definition at line 354 of file menuc.c.

References BOOL, FALSE, tagITEM::fState, tagITEM::fType, min, MNLookUpItem(), NtUserThunkedMenuItemInfo(), NULL, PtoHq, TestMFS, TestMFT, TRUE, UINT, and VALIDATEHMENU.

    00356 {
    00357     BOOL    fByPosition = (BOOL) (flags & MF_BYPOSITION);
    00358     PMENU   pMenu, pMenuItemIsOn;
    00359     PITEM   pItem;
    00360     UINT    wIDCur;
    00361     BOOL    fChecked = FALSE;
    00362     BOOL    fFirst  = TRUE;
    00363     MENUITEMINFO mii;
    00364
    00365     pMenu = VALIDATEHMENU(hMenu);
    00366     if (pMenu == NULL) {
    00367         return FALSE;
    00368     }
    00369
    00370     mii.cbSize = sizeof(mii);
    00371     /*
    00372      * Make sure we won't loop for ever
    00373      */
    00374     wIDLast = min(wIDLast, (UINT)0xFFFFFFFE);
    00375
    00376     for (wIDCur = wIDFirst; wIDCur <= wIDLast; wIDCur++) {
    00377         pItem = MNLookUpItem(pMenu, wIDCur, fByPosition, &pMenuItemIsOn);
    00378         /*
    00379          * Continue searching if it didn't find the item or it's a separator
    00380          */
    00381         if ((pItem == NULL) || TestMFT(pItem, MFT_SEPARATOR)) {
    00382             continue;
    00383         }
    00384         /*
    00385          * If this is the first one, rememeber what menu it's on because
    00386          *  all items are supposed to be in the same menu.
    00387          */
    00388         if (fFirst) {
    00389             pMenu = pMenuItemIsOn;
    00390             hMenu = PtoHq(pMenu);
    00391             fFirst = FALSE;
    00392         }
    00393         /*
    00394          * If this item is on a different menu, don't touch it
    00395          */
    00396         if (pMenu != pMenuItemIsOn) {
    00397             continue;
    00398         }
    00399         /*
    00400          * Set the new check state. Avoid the trip to the kernel if possible
    00401          */
    00402         if (wIDCur == wIDCheck) {
    00403             /*
    00404              * Check it.
    00405              */
    00406             if (!TestMFT(pItem, MFT_RADIOCHECK) || !TestMFS(pItem, MFS_CHECKED)) {
    00407                 mii.fMask = MIIM_FTYPE | MIIM_STATE;
    00408                 mii.fType = (pItem->fType & MFT_MASK) | MFT_RADIOCHECK;
    00409                 mii.fState = (pItem->fState & MFS_MASK) | MFS_CHECKED;
    00410                 NtUserThunkedMenuItemInfo(hMenu, wIDCheck, fByPosition, FALSE, &mii, NULL);
    00411             }
    00412             fChecked = TRUE;
    00413         } else {
    00414             /*
    00415              * Uncheck it
    00416              * NOTE:  don't remove MFT_RADIOCHECK type
    00417              */
    00418             if (TestMFS(pItem, MFS_CHECKED)) {
    00419                 mii.fMask = MIIM_STATE;
    00420                 mii.fState = (pItem->fState & MFS_MASK) & ~MFS_CHECKED;
    00421                 NtUserThunkedMenuItemInfo(hMenu, wIDCur, fByPosition, FALSE, &mii, NULL);
    00422             }
    00423         }
    00424     } /* for */
    00425
    00426     if (fFirst) {
    00427         /*
    00428          * No item was ever found.
    00429          */
    00430         RIPERR0(ERROR_MENU_ITEM_NOT_FOUND, RIP_VERBOSE, "CheckMenuRadioItem, no items found\n");
    00431
    00432     }
    00433     return(fChecked);
    00434 }

int WINAPI DrawMenuBarTemp | ( | HWND | hwnd,
|  | HDC | hdc,
|  | LPCRECT | lprc,
|  | HMENU | hMenu,
|  | HFONT | hFont
| ) |

Definition at line 313 of file menuc.c.

References IsMetaFile(), and NtUserDrawMenuBarTemp().

    00319 {
    00320     HDC hdcr;
    00321
    00322     if (IsMetaFile(hdc))
    00323         return -1;
    00324
    00325     hdcr = GdiConvertAndCheckDC(hdc);
    00326     if (hdcr == (HDC)0)
    00327         return -1;
    00328
    00329     if (!hMenu)
    00330         return -1;
    00331
    00332     return NtUserDrawMenuBarTemp(
    00333             hwnd,
    00334             hdc,
    00335             lprc,
    00336             hMenu,
    00337             hFont);
    00338 }

LONG GetMenuCheckMarkDimensions | ( |  | ) |

Definition at line 221 of file menuc.c.

References DWORD, and SYSMET.

    00222 {
    00223     return((DWORD)MAKELONG(SYSMET(CXMENUCHECK), SYSMET(CYMENUCHECK)));
    00224 }

WINUSERAPI DWORD WINAPI GetMenuContextHelpId | ( | HMENU | hMenu | ) |

Definition at line 233 of file menuc.c.

References tagMENU::dwContextHelpId, DWORD, NULL, and VALIDATEHMENU.

    00235 {
    00236     PMENU pMenu;
    00237
    00238     pMenu = VALIDATEHMENU(hMenu);
    00239
    00240     if (pMenu == NULL)
    00241         return 0;
    00242
    00243     return pMenu->dwContextHelpId;
    00244 }

UINT GetMenuDefaultItem | ( | HMENU | hMenu,
|  | UINT | fByPosition,
|  | UINT | uFlags
| ) |

Definition at line 45 of file menuc.c.

References _GetMenuDefaultItem(), BOOL, DWORD, NULL, UINT, and VALIDATEHMENU.

    00045                                                                     {
    00046     PMENU pMenu;
    00047
    00048     pMenu = VALIDATEHMENU(hMenu);
    00049     if (pMenu == NULL) {
    00050         return (DWORD)-1;
    00051     }
    00052
    00053     return _GetMenuDefaultItem(pMenu, (BOOL)fByPosition, uFlags);
    00054 }

BOOL SetMenuInfo | ( | HMENU | hMenu,
|  | LPCMENUINFO | lpmi
| ) |

Definition at line 115 of file menuc.c.

References BOOL, FALSE, MENUAPI_SET, NtUserThunkedMenuInfo(), and ValidateMENUINFO().

    00116 {
    00117     if (!ValidateMENUINFO(lpmi, MENUAPI_SET)) {
    00118         return FALSE;
    00119     }
    00120
    00121     return NtUserThunkedMenuInfo(hMenu, (LPCMENUINFO)lpmi);
    00122 }

BOOL WINAPI SetMenuItemBitmaps | ( | HMENU | hMenu,
|  | UINT | nPosition,
|  | UINT | uFlags,
|  | HBITMAP | hbmpUnchecked,
|  | HBITMAP | hbmpChecked
| ) |

Definition at line 296 of file menuc.c.

References BOOL, SetMenuItemInfo(), and UINT.

    00303 {
    00304     MENUITEMINFO    mii;
    00305     mii.cbSize          = sizeof(MENUITEMINFO);
    00306     mii.fMask           = MIIM_CHECKMARKS;
    00307     mii.hbmpChecked     = hbmpChecked;
    00308     mii.hbmpUnchecked   = hbmpUnchecked;
    00309
    00310     return(SetMenuItemInfo(hMenu, nPosition, (BOOL) (uFlags & MF_BYPOSITION), &mii));
    00311 }

void SetMenuItemInfoStruct | ( | HMENU | hMenu,
|  | UINT | wFlags,
|  | UINT_PTR | wIDNew,
|  | LPWSTR | pwszNew,
|  | LPMENUITEMINFO | pmii
| ) |

Definition at line 62 of file menuc.c.

References tagMENU::cItems, tagITEM::fType, NULL, REBASEALWAYS, TestMFT, UINT, and VALIDATEHMENU.

    00063 {
    00064     PMENU pMenu;
    00065     PITEM pItem;
    00066
    00067     UserAssert(sizeof(MENUITEMINFOW) == sizeof(MENUITEMINFOA));
    00068
    00069     RtlZeroMemory(pmii, sizeof(*pmii));
    00070
    00071     pmii->fMask = MIIM_STATE | MIIM_ID | MIIM_FTYPE;
    00072
    00073     /*
    00074      * For compatibility, setting the bitmap drops the string and
    00075      *  viceversa; new apps that want to have sting and bitmaps
    00076      *  must use the MENUITEMINFO APIs
    00077      */
    00078     if (wFlags & MFT_BITMAP) {
    00079         pmii->fMask |= MIIM_BITMAP | MIIM_STRING;
    00080         pmii->hbmpItem = (HBITMAP)pwszNew;
    00081         pmii->dwTypeData  = 0;
    00082     } else if (!(wFlags & MFT_NONSTRING)) {
    00083         pmii->fMask |= MIIM_BITMAP | MIIM_STRING;
    00084         pmii->dwTypeData  = pwszNew;
    00085         pmii->hbmpItem = NULL;
    00086     }
    00087
    00088     if (wFlags & MF_POPUP) {
    00089         pmii->fMask |= MIIM_SUBMENU;
    00090         pmii->hSubMenu = (HMENU)wIDNew;
    00091     }
    00092
    00093     if (wFlags & MF_OWNERDRAW) {
    00094         pmii->fMask |= MIIM_DATA;
    00095         pmii->dwItemData = (ULONG_PTR) pwszNew;
    00096     }
    00097
    00098     pmii->fState = wFlags & MFS_OLDAPI_MASK;
    00099     pmii->fType  = wFlags & MFT_OLDAPI_MASK;
    00100     pMenu = VALIDATEHMENU(hMenu);
    00101     if (pMenu && pMenu->cItems) {
    00102         pItem = &((PITEM)REBASEALWAYS(pMenu, rgItems))[0];
    00103         if (pItem && TestMFT(pItem, MFT_RIGHTORDER)) {
    00104             pmii->fType |= MFT_RIGHTORDER;
    00105         }
    00106     }
    00107     pmii->wID    = (UINT)wIDNew;
    00108 }

BOOL TrackPopupMenu | ( | HMENU | hMenu,
|  | UINT | fuFlags,
|  | int | x,
|  | int | y,
|  | int | nReserved,
|  | HWND | hwnd,
|  | CONST RECT * | prcRect
| ) |

Definition at line 246 of file menuc.c.

References BOOL, NtUserTrackPopupMenuEx(), and NULL.

Referenced by HelpMenu().

    00254 {
    00255     UNREFERENCED_PARAMETER(nReserved);
    00256     UNREFERENCED_PARAMETER(prcRect);
    00257
    00258     return NtUserTrackPopupMenuEx(hMenu, fuFlags, x, y, hwnd, NULL);
    00259 }

PMENU xxxGetSysMenuHandle | ( | PWND | pwnd | ) |

Definition at line 270 of file menuc.c.

    00272 {
    00273     PMENU pMenu;
    00274
    00275     if (TestWF(pwnd, WFSYSMENU)) {
    00276         pMenu = pwnd->spmenuSys;
    00277
    00278         /*
    00279          * If the window doesn't have a System Menu, use the default one.
    00280          */
    00281         if (pMenu == NULL) {
    00282
    00283             /*
    00284              * Change owner so this app can access this menu.
    00285              */
    00286             pMenu = (PMENU)NtUserCallHwndLock(HWq(pwnd), SFI_XXXGETSYSMENUHANDLE);
    00287         }
    00288     } else {
    00289         pMenu = NULL;
    00290     }
    00291
    00292     return pMenu;
    00293 }