📄 menu.c
字号:
pmii->id = pmi->id; } if (pmii->mask & MIIM_STATE) { pmii->state = pmi->mnustate; } if (pmii->mask & MIIM_SUBMENU) { pmii->hsubmenu = (HMENU)(pmi->submenu); } if (pmii->mask & MIIM_TYPE) { pmii->type = pmi->mnutype; if (pmii->type == MFT_STRING) strncpy ((char*)(pmii->typedata), (char*)(pmi->typedata), pmii->cch); else pmii->typedata = pmi->typedata; } return 0;}int GUIAPI SetMenuItemInfo (HMENU hmnu, int item, BOOL flag, PMENUITEMINFO pmii){ PMENUITEM pmi; if (!(pmi = mnuGetMenuItem (hmnu, item, flag))) return ERR_INVALID_HMENU; if (pmii->mask & MIIM_CHECKMARKS) { pmi->hbmpChecked = pmii->hbmpChecked; pmi->hbmpUnchecked = pmii->hbmpUnchecked; } if (pmii->mask & MIIM_DATA) { pmi->itemdata = pmii->itemdata; } if (pmii->mask & MIIM_ID) { pmi->id = pmii->id; } if (pmii->mask & MIIM_STATE) { pmi->mnustate = pmii->state; } if (pmii->mask & MIIM_SUBMENU) { pmi->submenu = (PMENUITEM)(pmii->hsubmenu); } if (pmii->mask & MIIM_TYPE) { if (pmi->mnutype == MFT_STRING) // free string FreeFixStr ((char*) pmi->typedata); pmi->mnutype = pmii->type; if (pmi->mnutype == MFT_STRING) { // allocate memory for string. pmi->typedata = (DWORD)FixStrAlloc (strlen ((char*)pmii->typedata)); strcpy ((char*)pmi->typedata, (char*)pmii->typedata); } else pmi->typedata = pmii->typedata; } return 0;}UINT GUIAPI EnableMenuItem (HMENU hmnu, int item, UINT flags){ PMENUITEM pmi; UINT prevstate = 0xFFFFFFFF; if (!(pmi = mnuGetMenuItem (hmnu, item, flags & MF_BYPOSITION))) return prevstate; prevstate = 0x0000000F & pmi->mnustate; pmi->mnustate = (0xFFFFFFF0 & pmi->mnustate) | flags; return prevstate;}int GUIAPI CheckMenuRadioItem (HMENU hmnu, int first, int last, int checkitem, UINT flags){ PMENUITEM pmi; int index; if (!(pmi = mnuGetMenuItem (hmnu, first, flags & MF_BYPOSITION))) return ERR_INVALID_HMENU; index = first; if (flags & MF_BYPOSITION) { while (pmi) { pmi->mnutype |= MFT_RADIOCHECK; if (index == checkitem) pmi->mnustate = (0xFFFFFFF0 & pmi->mnustate) | MFS_CHECKED; else pmi->mnustate = (0xFFFFFFF0 & pmi->mnustate) | MFS_UNCHECKED; if (index == last) break; index ++; pmi = pmi->next; } } else { while (pmi) { pmi->mnutype |= MFT_RADIOCHECK; if (pmi->id == checkitem) pmi->mnustate = (0xFFFFFFF0 & pmi->mnustate) | MFS_CHECKED; else pmi->mnustate = (0xFFFFFFF0 & pmi->mnustate) | MFS_UNCHECKED; if (pmi->id == last) break; pmi = pmi->next; } } return 0;}int GUIAPI SetMenuItemBitmaps (HMENU hmnu, int item, UINT flags, PBITMAP hBmpUnchecked, PBITMAP hBmpChecked){ PMENUITEM pmi; if (!(pmi = mnuGetMenuItem (hmnu, item, flags & MF_BYPOSITION))) return ERR_INVALID_HMENU; pmi->hbmpChecked = hBmpChecked; pmi->hbmpUnchecked = hBmpUnchecked; return 0;}#ifdef _DEBUGvoid mnuDumpMenuItem (PMENUITEM pmi){ PMENUITEM ptmpmi; printf ("Menu Item (0x%p) Information:\n", pmi); printf ("\tdata class: %d\n", pmi->class); printf ("\tdata type: %d\n", pmi->type); printf ("\tmenu type: %#x\n", pmi->mnutype); printf ("\tmenu state: %#x\n", pmi->mnustate); printf ("\tmenu id: %d\n", pmi->id); printf ("\tchecked bitmap: 0x%p\n", pmi->hbmpChecked); printf ("\tunchecked bitmap: 0x%p\n", pmi->hbmpUnchecked); printf ("\titem data: %lu\n", pmi->itemdata); if (pmi->mnutype == MFT_STRING) printf ("\tstring: %s\n", (char*)pmi->typedata); else printf ("\ttype data: %lu\n", pmi->typedata); printf ("\tnext item: 0x%p\n", pmi->next); printf ("\tfrom heap: %s\n", pmi->fromheap ? "yes" : "no"); if (pmi->submenu) { ptmpmi = pmi->submenu; while (ptmpmi) { mnuDumpMenuItem (ptmpmi); ptmpmi = ptmpmi->next; } } printf ("End of Info of Menu Item: 0x%p\n", pmi);}void DumpMenu (HMENU hmnu){ PMENUBAR pmb; PMENUITEM pmi; pmb = (PMENUBAR) hmnu; if (pmb->class != TYPE_HMENU) { printf ("hmnu is not a valid menu handle.\n"); return; } if (pmb->type == TYPE_MENUBAR) { printf ("hmnu is a menu bar.\n"); pmi = pmb->head; while (pmi) { mnuDumpMenuItem (pmi); pmi = pmi->next; } } else if (pmb->type == TYPE_PPPMENU) { printf ("hmnu is a popup menu.\n"); pmi = (PMENUITEM)hmnu; mnuDumpMenuItem (pmi); } else { printf ("hmnu is a normal menu item.\n"); pmi = (PMENUITEM)hmnu; mnuDumpMenuItem (pmi); }}#endif // _DEBUG/***************************** Menu owner ***********************************/// Global function defined in Desktop module.PMAINWIN MainWindow (HWND hWnd);HMENU GUIAPI SetMenu (HWND hwnd, HMENU hmnu){ PMAINWIN pWin; HMENU hOld; if (!(pWin = MainWindow (hwnd))) return 0; hOld = pWin->hMenu; pWin->hMenu = hmnu; ((PMENUBAR)hmnu)->hwnd = hwnd; return hOld;}HMENU GUIAPI GetMenu (HWND hwnd){ PMAINWIN pWin; if (!(pWin = MainWindow (hwnd))) return 0; return pWin->hMenu;}HMENU GUIAPI GetSystemMenu (HWND hwnd, BOOL flag){ PMAINWIN pWin; if (!(pWin = MainWindow (hwnd))) return 0; return pWin->hSysMenu;}/**************************** Menu drawing support ***************************/void mnuGetMenuBarItemSize (PMENUITEM pmi, SIZE* size){ if (pmi->mnutype & MFT_BITMAP) { size->cx = pmi->hbmpChecked->bmWidth; } else if (pmi->mnutype & MFT_SEPARATOR) { size->cx = GetMainWinMetrics (MWM_MENUSEPARATORX); } else if (pmi->mnutype & MFT_OWNERDRAW) { } else { size->cx = strlen ((char*) pmi->typedata)*GetSysCharWidth(); if (pmi->mnutype & MFT_BMPSTRING) { size->cx += pmi->hbmpChecked->bmWidth; size->cx += GetMainWinMetrics (MWM_INTERMENUITEMX)>>1; } } pmi->h = size->cx; size->cy = GetMainWinMetrics (MWM_MENUBARY); return;}void mnuDrawMenuBarItem (HDC hdc, PMENUITEM pmi, int x, int y, int w, int h){ PBITMAP bmp; int height; int inter; height = GetMainWinMetrics (MWM_MENUBARY); inter = GetMainWinMetrics (MWM_INTERMENUITEMX)>>1; SetBrushColor (hdc, BKC_MENUBAR_NORMAL); FillBox (hdc, x - inter, y - 3, w + (inter<<1), h + 3); if (pmi->mnutype & MFT_BITMAP) { if (pmi->mnustate & MFS_CHECKED) bmp = pmi->hbmpChecked; else bmp = pmi->hbmpUnchecked; FillBoxWithBitmap (hdc, x, y, pmi->h, height, bmp); } else if (pmi->mnutype & MFT_SEPARATOR) { SetPenColor (hdc, FGC_MENUBAR_NORMAL); MoveTo (HDC_SCREEN, x + (pmi->h>>1), y); LineTo (HDC_SCREEN, x + (pmi->h>>1), y + height); } else if (pmi->mnutype & MFT_OWNERDRAW) { } else { if (pmi->mnutype & MFT_BMPSTRING) { if (pmi->mnustate & MFS_CHECKED) bmp = pmi->hbmpChecked; else bmp = pmi->hbmpUnchecked; FillBoxWithBitmap (hdc, x, y, height, height, bmp); x += bmp->bmWidth + inter; } SetTextColor (hdc, FGC_MENUBAR_NORMAL); SetBkColor (hdc, BKC_MENUBAR_NORMAL); TextOut (hdc, x, y, (char *)pmi->typedata); } return;}static int mnuGetNextMenuBarItem (PMENUBAR pmb, int pos){ PMENUITEM pmi; int number; number = 0; pmi = pmb->head; while (pmi) { number ++; pmi = pmi->next; } number--; if (pos == number) return 0; else return pos + 1;}static int mnuGetPrevMenuBarItem (PMENUBAR pmb, int pos){ PMENUITEM pmi; int number; number = 0; pmi = pmb->head; while (pmi) { number ++; pmi = pmi->next; } number--; if (pos == 0) return number; else return pos - 1;}HMENU GUIAPI GetMenuBarItemRect (HWND hwnd, int pos, RECT* prc){ PMAINWIN pWin; PMENUBAR pmb; PMENUITEM pmi; int x, y, inter, h; int count; SIZE size; if (!(pWin = MainWindow (hwnd))) return 0; if (!pWin->hMenu) return 0; pmb = (PMENUBAR) (pWin->hMenu); if (pmb->class != TYPE_HMENU) return 0; if (pmb->type != TYPE_MENUBAR) return 0; x = pWin->cl - pWin->left; x += GetMainWinMetrics (MWM_MENUBAROFFX); y = pWin->ct - pWin->top; h = GetMainWinMetrics (MWM_MENUBARY) + GetMainWinMetrics (MWM_MENUBAROFFY); y -= h; inter = GetMainWinMetrics (MWM_INTERMENUITEMX); count = 0; pmi = pmb->head; while (pmi) { mnuGetMenuBarItemSize (pmi, &size); if (count == pos) break; x = x + inter + size.cx; count ++; pmi = pmi->next; } if (pmi == NULL) return 0; prc->left = x; prc->top = y; prc->bottom = y + h - 1; prc->right = x + size.cx - 1; return (HMENU) pmi;}static BOOL mnuGetMenuBarRect (HWND hwnd, RECT* prc){ PMAINWIN pWin; int w, h; if (!(pWin = MainWindow (hwnd))) return FALSE; prc->left = pWin->cl - pWin->left; w = pWin->cr - pWin->cl + 1; h = GetMainWinMetrics (MWM_MENUBARY) + (GetMainWinMetrics (MWM_MENUBAROFFY)<<1); prc->top = pWin->ct - pWin->top; prc->top -= GetMainWinMetrics (MWM_MENUBARY); prc->top -= GetMainWinMetrics (MWM_MENUBAROFFY)<<1; prc->right = prc->left + w - 1; prc->bottom = prc->top + h - 1; return TRUE;}BOOL GUIAPI HiliteMenuBarItem (HWND hwnd, int pos, UINT flags){ PMENUITEM pmi; RECT rcBar; RECT rc; HDC hdc; int inter; pmi = (PMENUITEM)GetMenuBarItemRect (hwnd, pos, &rc); if (!pmi) return FALSE; inter = GetMainWinMetrics (MWM_INTERMENUITEMX)>>1; hdc = GetDC (hwnd); mnuGetMenuBarRect (hwnd, &rcBar); ClipRectIntersect (hdc, &rcBar); if (flags == HMF_UPITEM) { Draw3DUpThinFrame (hdc, rc.left - inter, rc.top - 3, rc.right + inter, rc.bottom - 1, PIXEL_invalid); } else if (flags == HMF_DOWNITEM) { mnuDrawMenuBarItem (hdc, pmi, rc.left + 1, rc.top + 1, RECTW (rc) - 2, RECTH (rc) - 2); Draw3DDownThinFrame (hdc, rc.left - inter, rc.top - 2, rc.right + inter, rc.bottom - 2, PIXEL_invalid); } else if (flags == HMF_DEFAULT) mnuDrawMenuBarItem (hdc, pmi, rc.left, rc.top, RECTW (rc) + 3, RECTH (rc) + 1); ReleaseDC (hdc); return TRUE;}int MenuBarHitTest (HWND hwnd, int mx, int my){ PMAINWIN pWin; PMENUBAR pmb; PMENUITEM pmi; int x, y, inter, h; RECT rc; int count; SIZE size; if (!(pWin = MainWindow (hwnd))) return -1; if (!pWin->hMenu) return -1; pmb = (PMENUBAR) (pWin->hMenu); if (pmb->class != TYPE_HMENU) return -1; if (pmb->type != TYPE_MENUBAR) return -1; x = pWin->left; x += GetMainWinMetrics (MWM_MENUBAROFFX); y = pWin->ct; y -= GetMainWinMetrics (MWM_MENUBARY); y -= GetMainWinMetrics (MWM_MENUBAROFFY); h = GetMainWinMetrics (MWM_MENUBARY) + GetMainWinMetrics (MWM_MENUBAROFFY); inter = GetMainWinMetrics (MWM_INTERMENUITEMX); rc.top = y; rc.bottom = y + h; count = 0; pmi = pmb->head; while (pmi) { mnuGetMenuBarItemSize (pmi, &size); rc.left = x; rc.right = x + size.cx; if (PtInRect (&rc, mx, my)) return count; x = x + inter + size.cx;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -