void CSimpleProjectWebSitesPopupButton::RebuildMenu() { for(int i=(int) m_ProjectWebSitesPopUpMenu->GetMenuItemCount()-1; i>=0; --i){ wxMenuItem* item = m_ProjectWebSitesPopUpMenu->FindItemByPosition(i); m_ProjectWebSitesPopUpMenu->Delete(item); } AddMenuItems(); }
void CDrawMenu::AddMenuItems(HMENU hMenu, int& nIndex, int nDepth) { USES_CONVERSION; HTREEITEM hItem = NULL; while (nIndex < m_arrItems.GetSize()) { CMenuItem& item = m_arrItems[nIndex]; int nItemDepth = 0; LPCWSTR p = item.m_bstrText; while (*p++ == '.') nItemDepth++; if (nItemDepth < nDepth) { nIndex--; break; } int nNextItemDepth = nItemDepth; if (nIndex + 1 < m_arrItems.GetSize()) { nNextItemDepth = 0; CMenuItem& itemNext = m_arrItems[nIndex + 1]; LPCWSTR p = itemNext.m_bstrText; while (*p++ == '.') nNextItemDepth++; } if (nNextItemDepth > nItemDepth) { HMENU hNewMenu = CreatePopupMenu(); ATLASSERT(hNewMenu != NULL); AddMenuItems(hNewMenu, ++nIndex, nDepth + 1); AppendMenu(hMenu, MF_POPUP, (UINT)hNewMenu, OLE2T(item.m_bstrText + nItemDepth)); } else { CComBSTR bstrItemText = item.m_bstrText + nItemDepth; if (bstrItemText == L"-") { AppendMenu(hMenu, MF_SEPARATOR, 0, 0); } else { UINT uFlags = MF_STRING; if ((item.m_dwState & MenuStateDisable) != 0) uFlags |= MF_GRAYED; if ((item.m_dwState & MenuStateCheck) != 0) uFlags |= MF_CHECKED; AppendMenu(hMenu, uFlags, nIndex + 1, OLE2T(bstrItemText)); } } nIndex++; } }
CSimpleTaskPopupButton::CSimpleTaskPopupButton(wxWindow* parent, wxWindowID id, const wxString& label, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator, const wxString& name) : wxButton(parent, id, label, pos, size, style, validator, name) { m_TaskSuspendedViaGUI = false; m_TaskCommandPopUpMenu = new wxMenu(); AddMenuItems(); }
STDMETHODIMP CDrawMenu::Popup(/*[in, optional] */VARIANT X, /*[in, optional] */VARIANT Y) { USES_CONVERSION; int nCount = m_arrItems.GetSize(); if (nCount == 0) return S_FALSE; HMENU hMenu = CreatePopupMenu(); if (hMenu == NULL) return E_FAIL; int nIndex = 0; AddMenuItems(hMenu, nIndex, 0); HWND hWndParent = GetClientWindow(); POINT pt; GetCursorPos(&pt); ScreenToClient(hWndParent, &pt); if (X.vt != VT_ERROR) { VariantChangeType(&X, &X, 0, VT_I4); pt.x = X.intVal; } if (Y.vt != VT_ERROR) { VariantChangeType(&Y, &Y, 0, VT_I4); pt.y = Y.intVal; } ClientToScreen(hWndParent, &pt); Fire_Event(2); // 2011.4.25: 鼠标按下时弹出菜单时,释放鼠标捕获 SetCapture(FALSE); int nRet = TrackPopupMenu(hMenu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_NONOTIFY | TPM_RETURNCMD, pt.x, pt.y, 0, hWndParent, 0); if (nRet > 0 && nRet <= m_arrItems.GetSize()) { CMenuItem& item = m_arrItems[nRet - 1]; Fire_MenuClick(nRet, item.m_bstrID); } DestroyMenu(hMenu); Fire_Event(3); return S_OK; }
CSimpleProjectCommandPopupButton::CSimpleProjectCommandPopupButton(wxWindow* parent, wxWindowID id, const wxString& label, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator, const wxString& name) : CTransparentButton(parent, id, label, pos, size, style, validator, name) { m_ProjectCommandsPopUpMenu = new wxMenu(); AddMenuItems(); Connect( id, wxEVT_BUTTON, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) &CSimpleProjectCommandPopupButton::OnProjectCommandsKeyboardNav ); }
void CRunView::ShowPictureComplete(LPCTSTR lpszPicture) { IDispatch* pMenuObject = GetMainMenu(); if (pMenuObject != NULL) { m_arrAccels.RemoveAll(); if (m_menu.m_hMenu != NULL) m_menu.DestroyMenu(); m_menu.CreateMenu(); CComQIPtr<IDrawMenu, &IID_IDrawMenu> spDrawMenu(pMenuObject); long lCount; spDrawMenu->get_ItemCount(&lCount); int nIndex = 0; AddMenuItems(m_menu.m_hMenu, spDrawMenu, nIndex, lCount, 0); if (m_pMenu == NULL) { CMenu* pMenu = AfxGetMainWnd()->GetMenu(); if (pMenu != NULL) m_hAltMenu = pMenu->GetSafeHmenu(); } AfxGetMainWnd()->SetMenu(&m_menu); m_pMenu = spDrawMenu; m_bLockMenu = FALSE; pMenuObject->Release(); if (m_arrAccels.GetSize() > 0) m_hAccelTable = CreateAcceleratorTable(m_arrAccels.GetData(), m_arrAccels.GetSize()); } else { if (m_pMenu != NULL) { ::SetMenu(AfxGetMainWnd()->GetSafeHwnd(), m_hAltMenu); m_hAltMenu = NULL; m_pMenu = NULL; } } }
// weather protocol initialization function // run after the event ME_SYSTEM_MODULESLOADED occurs int WeatherInit(WPARAM, LPARAM) { // initialize netlib NetlibInit(); InitMwin(); // load weather menu items AddMenuItems(); // timer for the first update timerId = SetTimer(NULL, 0, 5000, timerProc2); // first update is 5 sec after load // weather user detail HookEvent(ME_USERINFO_INITIALISE, UserInfoInit); HookEvent(ME_TTB_MODULELOADED, OnToolbarLoaded); return 0; }
void CPopupFrame::AddMenuItems(HMENU hMenu, IDrawMenu* pMenu, int& nIndex, int nCount, int nDepth) { USES_CONVERSION; HTREEITEM hItem = NULL; while (nIndex < nCount) { CComBSTR bstrItemText; pMenu->GetItemText(nIndex + 1, &bstrItemText); int nItemDepth = 0; LPCWSTR p = bstrItemText; while (*p++ == '.') nItemDepth++; if (nItemDepth < nDepth) { nIndex--; break; } int nNextItemDepth = nItemDepth; if (nIndex + 1 < nCount) { nNextItemDepth = 0; CComBSTR bstrNextItemText; pMenu->GetItemText(nIndex + 2, &bstrNextItemText); LPCWSTR p = bstrNextItemText; while (*p++ == '.') nNextItemDepth++; } if (nNextItemDepth > nItemDepth) { HMENU hNewMenu = CreatePopupMenu(); ATLASSERT(hNewMenu != NULL); AddMenuItems(hNewMenu, pMenu, ++nIndex, nCount, nDepth + 1); AppendMenu(hMenu, MF_POPUP, (UINT)hNewMenu, OLE2T(bstrItemText + nItemDepth)); } else { CString strItemText = bstrItemText + nItemDepth; if (bstrItemText == L"-") { AppendMenu(hMenu, MF_SEPARATOR, 0, 0); } else { long lShift = 0; pMenu->GetItemAccelShift(nIndex + 1, &lShift); long lKeyCode = 0; pMenu->GetItemAccelKeyCode(nIndex + 1, &lKeyCode); ACCEL accel; accel.fVirt = FVIRTKEY; if ((lShift & 1) != 0) accel.fVirt |= FSHIFT; if ((lShift & 2) != 0) accel.fVirt |= FCONTROL; if ((lShift & 4) != 0) accel.fVirt |= FALT; accel.key = (USHORT)lKeyCode; accel.cmd = nIndex + 1; m_arrAccels.Add(accel); CString strAccel = GetAccelKeyName(lShift, lKeyCode); if (!strAccel.IsEmpty()) { strItemText += _T("\t"); strItemText += strAccel; } AppendMenu(hMenu, MF_STRING | MF_BYCOMMAND, nIndex + 1, strItemText); } } nIndex++; } }
BOOL CPopupFrame::LoadFrame(UINT nIDResource, DWORD dwDefaultStyle, CWnd* pParentWnd, CCreateContext* pContext) { CFormDoc* pDoc = (CFormDoc *)pContext->m_pCurrentDoc; ASSERT_VALID(pDoc); m_strCaption = pDoc->m_strCaption; m_cx = (int)pDoc->GetWidth(); m_cy = (int)pDoc->GetHeight(); if (pDoc->m_enumStartUpPosition == StartUpPositionWindowsDefault) { m_x = 0; m_y = 0; } else if (pDoc->m_enumStartUpPosition == StartUpPositionManual) { m_x = (int)pDoc->GetHorizontalPosition(); m_y = (int)pDoc->GetVerticalPosition(); } else { CRect rect; if (pDoc->m_enumStartUpPosition == StartUpPositionOwner) { pParentWnd->GetWindowRect(&rect); } else { rect.left = 0; rect.top = 0; rect.right = GetSystemMetrics(SM_CXSCREEN); rect.bottom = GetSystemMetrics(SM_CYSCREEN); } if (rect.Width() > m_cx) m_x = (rect.right + rect.left - m_cx) / 2; if (rect.Height() > m_cy) m_y = (rect.bottom + rect.top - m_cy) / 2; } if (!pDoc->IsMainForm()) { m_bTopMost = TRUE; m_bCaption = pDoc->m_enumBorderStyle != BorderStyleNone; m_bThickframe = pDoc->m_enumBorderStyle == BorderStyleSizable; m_bControlBox = pDoc->m_bControlBox; } BOOL b = CFrameWnd::LoadFrame(nIDResource, dwDefaultStyle, pParentWnd, pContext); if (b) { CDevObj* pObj = pDoc->GetMenuObject(); if (pObj != NULL) { CMenu menu; menu.CreateMenu(); CComQIPtr<IDrawMenu, &IID_IDrawMenu> spDrawMenu(pObj->GetObjectUnknown()); long lCount; spDrawMenu->get_ItemCount(&lCount); int nIndex = 0; AddMenuItems(menu.m_hMenu, spDrawMenu, nIndex, lCount, 0); m_pMenu = spDrawMenu; SetMenu(&menu); menu.Detach(); if (m_arrAccels.GetSize() > 0) m_hAccelTable = CreateAcceleratorTable(m_arrAccels.GetData(), m_arrAccels.GetSize()); } } return b; }