static void IterateThroughItems(HWND WND, HMENU menu, POINT *p) { int count = GetMenuItemCount(menu); RECT rec; MENUITEMINFO info; int i; for (i=0; i<count; i++) { if (GetMenuItemRect(WND, menu, i, &rec) && (rec.left<=p->x) && (p->x<=rec.right) && (rec.top<=p->y) && (p->y<=rec.bottom)) { ZeroMemory(&info, sizeof(info)); info.cbSize = sizeof(info); info.fMask = MIIM_TYPE | MIIM_SUBMENU; info.cch = 256; info.dwTypeData = malloc(256); GetMenuItemInfo(menu, i, TRUE, &info); if (info.cch>0) { if (info.cch > 255) CurParams->WordLen = 255; else CurParams->WordLen = info.cch; CurParams->Unicode = FALSE; CurParams->WordLen = MyCopyMemory(CurParams->MatchedWordA, info.dwTypeData, CurParams->WordLen); CurParams->BeginPos = 0; } free(info.dwTypeData); break; } } }
static void IterateThroughItems(HWND WND, HMENU menu, POINT *p) { int count = GetMenuItemCount(menu); RECT rec; MENUITEMINFO info; int i; TCHAR buf[MATCHED_WORD_BUF_SIZE]; for (i=0; i<count; i++) { if (GetMenuItemRect(WND, menu, i, &rec) && (rec.left<=p->x) && (p->x<=rec.right) && (rec.top<=p->y) && (p->y<=rec.bottom)) { ZeroMemory(&info, sizeof(info)); info.cbSize = sizeof(info); info.fMask = MIIM_TYPE | MIIM_SUBMENU; info.cch = MATCHED_WORD_BUF_SIZE; info.dwTypeData = buf; GetMenuItemInfo(menu, i, TRUE, &info); if (info.cch>0) { if (info.cch >= MATCHED_WORD_BUF_SIZE) CurParams->WordLen = MATCHED_WORD_BUF_SIZE-1; else CurParams->WordLen = info.cch; #ifdef UNICODE CurParams->Unicode = TRUE; CurParams->WordLen = MyCopyMemory(CurParams->MatchedWordW, info.dwTypeData, CurParams->WordLen); #else CurParams->Unicode = FALSE; CurParams->WordLen = MyCopyMemory(CurParams->MatchedWordA, info.dwTypeData, CurParams->WordLen); #endif CurParams->BeginPos = 0; } break; } } }
/************************************************************************* * FileMenu_GetItemExtent [SHELL32.144] * * NOTES * if the menu is too big, entries are getting cut away!! */ DWORD WINAPI FileMenu_GetItemExtent (HMENU hMenu, UINT uPos) { RECT rect; FIXME("%p 0x%08x\n", hMenu, uPos); if (GetMenuItemRect(0, hMenu, uPos, &rect)) { FIXME("0x%04x 0x%04x 0x%04x 0x%04x\n", rect.right, rect.left, rect.top, rect.bottom); return ((rect.right-rect.left)<<16) + (rect.top-rect.bottom); } return 0x00100010; /*FIXME*/ }
//获取菜单栏中非菜单项区域 HRGN CCustomMenu::GetClientMenuRgn() { MENUBARINFO MenuInfo; memset(&MenuInfo,0,sizeof(MENUBARINFO)); MenuInfo.cbSize = sizeof(MENUBARINFO); ::GetMenuBarInfo(AfxGetMainWnd()->m_hWnd,OBJID_MENU,0,&MenuInfo); CRect rc = MenuInfo.rcBar; int MenuCount = GetMenuItemCount(); CRect *pRC = new CRect[MenuCount]; HRGN *pRgn = new HRGN[MenuCount]; CRect winRC; AfxGetMainWnd()->GetWindowRect(winRC); int x = winRC.left; int y = winRC.top; rc.left = rc.left-x; rc.right = rc.right -x; rc.top = rc.top-y; rc.bottom = rc.bottom-y; //创建菜单项的区域 for (int i=0; i<MenuCount; i++) { GetMenuItemRect(AfxGetMainWnd()->m_hWnd,m_hMenu,i,&pRC[i]); pRC[i].left = pRC[i].left-x; pRC[i].right = pRC[i].right-x; pRC[i].top = pRC[i].top-y; pRC[i].bottom = pRC[i].bottom-y; pRgn[i] = CreateRectRgn(pRC[i].left,pRC[i].top,pRC[i].right,pRC[i].bottom); } HRGN MenuRgn = CreateRectRgn(rc.left,rc.top,rc.right,rc.bottom); HRGN retRgn = CreateRectRgn(0,0,0,0); HRGN MenuClientRgn = CreateRectRgn(0,0,0,0); //组合菜单项的区域 for (int j=0; j<MenuCount; j++) { CombineRgn(MenuClientRgn,MenuClientRgn,pRgn[j],RGN_OR); } //去除菜单栏中菜单项的区域,以获取非菜单项区域 CombineRgn(retRgn,MenuRgn,MenuClientRgn,RGN_DIFF); for ( j=0; j<MenuCount; j++) { DeleteObject(pRgn[j]); } DeleteObject(MenuRgn); DeleteObject(MenuClientRgn); delete []pRC; delete []pRgn; return retRgn; }
static void hugsprim_GetMenuItemRect_16(HugsStackPtr hugs_root) { HsPtr arg1; HsPtr arg2; HsWord32 arg3; HsPtr arg4; HsBool res1; arg1 = hugs->getPtr(); arg2 = hugs->getPtr(); arg3 = hugs->getWord32(); arg4 = hugs->getPtr(); res1 = GetMenuItemRect(arg1, arg2, arg3, arg4); hugs->putBool(res1); hugs->returnIO(hugs_root,1); }
int CChildView::GetMenuWidth() { int width = 0; CMenu *menu = GetParentFrame()->GetMenu(); int numItems = menu->GetMenuItemCount(); for (int i = 0; i < numItems; i++) { CRect rect; GetMenuItemRect(*this, *menu, i, rect); width += rect.Width(); } return width + GetSystemMetrics(SM_CXVSCROLL) + 1; }
// Subclass procedure LRESULT APIENTRY MenuSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch(uMsg) { case WM_NCCALCSIZE: { // get calculated size for menu window int width, height; // allow the menu window to calculate it's sizes (possibly it is already done, but i'm not sure) LRESULT callResult = CallWindowProc((WNDPROC)wpOrigEditProc, hwnd, uMsg, wParam, lParam); // get dimensions depending on returned param types if (wParam == TRUE) { NCCALCSIZE_PARAMS *pParams = (NCCALCSIZE_PARAMS *)lParam; width = pParams->lppos->cx; height = pParams->lppos->cy; } else { RECT *pSize = (RECT*)lParam; width = pSize->right - pSize->left; height = pSize->bottom - pSize->top; } // got dimensions, prepare DC and Bitmap hdefaultDC = GetDC(NULL); if (hdefaultDC != NULL) { hDC = CreateCompatibleDC(hdefaultDC); if (hDC != NULL) { hBitmap = CreateCompatibleBitmap(hdefaultDC, width, height); if (hBitmap != NULL) { SelectObject(hDC, hBitmap); } } } // the menu window initialized, allow to make shot calcSizeDone = true; // don't call the default menu window proc again return callResult; } break; case WM_WINDOWPOSCHANGING: if (calcSizeDone) { // move menu window deep out of the screen WINDOWPOS* pPos = (WINDOWPOS*)lParam; pPos->x += 10000; // if initialized successfully then make the window to draw onto our DC if (hDC != NULL && hBitmap != NULL) { PostMessage(hwnd, WM_PRINT, (WPARAM)hDC, PRF_CLIENT | PRF_NONCLIENT | PRF_ERASEBKGND | PRF_CHILDREN); } // Post message to get items dimensions PostMessage(hwnd, WM_GETMENUDIMENSIONS, NULL, NULL); // the menu window is no longer needed PostMessage(hwnd, WM_CLOSE, NULL, NULL); calcSizeDone = false; } break; case WM_GETMENUDIMENSIONS: { // get menu item dimensions int itemCount = GetMenuItemCount(hMenu); // get starting x,y offsets RECT rect1; if (!GetMenuItemRect (hWnd, hMenu, 0, &rect1)) { break; } // get all items dimensions relative to menu (a little overhead is here :)) for (int index = 0; index < itemCount; ++index) { RECT rect2; if (!GetMenuItemRect (hWnd, hMenu, index, &rect2)) { break; } sizes[index * 4 + 0] = rect2.left - rect1.left + 2; sizes[index * 4 + 1] = rect2.top - rect1.top + 2; sizes[index * 4 + 2] = rect2.right - rect2.left; sizes[index * 4 + 3] = rect2.bottom - rect2.top; } } break; } // call default menu window proc return CallWindowProc((WNDPROC)wpOrigEditProc, hwnd, uMsg, wParam, lParam); }