void LoadFileMenu(HMENU hMenu, int startPos, bool /* forFileMode */, bool programMenu) { { CMenu srcMenu; srcMenu.Attach(::GetSubMenu(::GetMenu(g_HWND), 0)); if ((HMENU)g_FileMenu == 0) { g_FileMenu.CreatePopup(); CopyMenu(srcMenu, g_FileMenu); } } CMenu destMenu; destMenu.Attach(hMenu); for (int i = 0; i < g_FileMenu.GetItemCount(); i++) { CMenuItem item; item.fMask = MIIM_STATE | MIIM_ID | Get_fMaskForFTypeAndString(); item.fType = MFT_STRING; if (g_FileMenu.GetItem(i, true, item)) { if (!programMenu) if (item.wID == IDCLOSE) continue; /* bool createItem = (item.wID == IDM_CREATE_FOLDER || item.wID == IDM_CREATE_FILE); if (forFileMode) { if (createItem) continue; } else { if (!createItem) continue; } */ if (destMenu.InsertItem(startPos, true, item)) startPos++; } } while (destMenu.GetItemCount() > 0) { CMenuItem item; item.fMask = MIIM_TYPE; item.fType = 0; // item.dwTypeData = 0; int lastIndex = destMenu.GetItemCount() - 1; if (!destMenu.GetItem(lastIndex, true, item)) break; if(item.fType != MFT_SEPARATOR) break; if (!destMenu.RemoveItem(lastIndex, MF_BYPOSITION)) break; } }
void CMenuSpawn::RemapMenu(HMENU hMenu) { static int iRecurse = 0; iRecurse ++; CMenu pMenu; pMenu.Attach(hMenu); ASSERT(pMenu); int nItem = pMenu.GetMenuItemCount(); while ((--nItem)>=0) { UINT itemId = pMenu.GetMenuItemID(nItem); if (itemId == (UINT) -1) { CMenu pops(pMenu.GetSubMenu(nItem)); if (pops.GetHandleMenu()) RemapMenu(pops.GetHandleMenu()); if (bIsPopup || iRecurse > 0) { TCHAR cs[128]; memset(cs,0x00,128); pMenu.GetMenuString(nItem, cs, 128,MF_BYPOSITION); if (lstrlen(cs)>0) { SpawnItem * sp = AddSpawnItem(cs, (!bIsPopup && iRecurse == 1) ? -4 : -2); pMenu.ModifyMenu(nItem,MF_BYPOSITION|MF_OWNERDRAW, (UINT) -1, (LPCTSTR)sp); } } } else { if (itemId != 0) { UINT oldState = pMenu.GetMenuState(nItem,MF_BYPOSITION); if (!(oldState&MF_OWNERDRAW) && !(oldState&MF_BITMAP)) { ASSERT(oldState != (UINT)-1); TCHAR cs[128]; memset(cs,0x00,128); pMenu.GetMenuString(nItem, cs, 128, MF_BYPOSITION); SpawnItem * sp = AddSpawnItem(cs, itemId); if (itemId!=SC_CLOSE) pMenu.ModifyMenu(nItem,MF_BYPOSITION|MF_OWNERDRAW|oldState, (LPARAM)itemId, (LPCTSTR)sp); } } else { UINT oldState = pMenu.GetMenuState(nItem,MF_BYPOSITION); if (!(oldState&MF_OWNERDRAW) && !(oldState&MF_BITMAP)) { ASSERT(oldState != (UINT)-1); SpawnItem * sp = AddSpawnItem("--", -3); pMenu.ModifyMenu(nItem,MF_BYPOSITION|MF_OWNERDRAW|oldState, (LPARAM)itemId, (LPCTSTR)sp); } } } } iRecurse --; pMenu.Detach(); }
void CCoolMenuBarCtrl::SetMenu(HMENU hMenu) { m_hMenu = hMenu; Clear(); if ( ! m_hMenu ) return; CMenu pMenu; pMenu.Attach( m_hMenu ); for ( UINT nItem = 0 ; nItem < pMenu.GetMenuItemCount() ; nItem++ ) { CString strMenu; pMenu.GetMenuString( nItem, strMenu, MF_BYPOSITION ); int nAmp = strMenu.Find( '&' ); if ( nAmp >= 0 ) strMenu = strMenu.Left( nAmp ) + strMenu.Mid( nAmp + 1 ); CCoolBarItem* pItem = new CCoolBarItem( this, nItem + 1 ); pItem->SetText( _T(" ") + strMenu + _T(" ") ); m_pItems.AddTail( pItem ); } pMenu.Detach(); }
void CPanel::CreateFileMenu(HMENU menuSpec, CMyComPtr<IContextMenu> &sevenZipContextMenu, CMyComPtr<IContextMenu> &systemContextMenu, bool programMenu) { sevenZipContextMenu.Release(); systemContextMenu.Release(); CRecordVector<UInt32> operatedIndices; GetOperatedItemIndices(operatedIndices); CMenu menu; menu.Attach(menuSpec); CreateSevenZipMenu(menu, operatedIndices, sevenZipContextMenu); if (g_App.ShowSystemMenu) CreateSystemMenu(menu, operatedIndices, systemContextMenu); /* if (menu.GetItemCount() > 0) menu.AppendItem(MF_SEPARATOR, 0, (LPCTSTR)0); */ int i; for (i = 0; i < operatedIndices.Size(); i++) if (IsItemFolder(operatedIndices[i])) break; bool allAreFiles = (i == operatedIndices.Size()); LoadFileMenu(menu, menu.GetItemCount(), programMenu, IsFSFolder(), operatedIndices.Size(), allAreFiles); }
BOOL COXShellNamespaceNavigator::InvokeDefaultCommand(const LPSHELLFOLDER lpParentFolder, const LPITEMIDLIST lpRelativeIDL) const { // retrieve the default command ID HMENU hMenu=GetObjectContextMenu(lpParentFolder,lpRelativeIDL,CMF_DEFAULTONLY); if(hMenu==NULL) { TRACE(_T("COXShellNamespaceNavigator::InvokeDefaultCommand: GetObjectContextMenu() failed\n")); return FALSE; } CMenu menuPopup; VERIFY(menuPopup.Attach(hMenu)); if(menuPopup.GetMenuItemCount()==0) { TRACE(_T("COXShellNamespaceNavigator::InvokeDefaultCommand: there is no context menu for the specified object\n")); return FALSE; } int nDefaultCmdID=-1; #if _MFC_VER > 0x0421 nDefaultCmdID=menuPopup.GetDefaultItem(GMDI_GOINTOPOPUPS,FALSE); #else nDefaultCmdID=::GetMenuDefaultItem(menuPopup.GetSafeHmenu(), FALSE,GMDI_GOINTOPOPUPS); #endif if(nDefaultCmdID==-1) { TRACE(_T("COXShellNamespaceNavigator::InvokeDefaultCommand: there is no default menu item for the specified object\n")); return FALSE; } VERIFY(menuPopup.DestroyMenu()); return InvokeCommand(lpParentFolder,lpRelativeIDL,nDefaultCmdID,CMF_DEFAULTONLY); }
void COutputsPage::OnPMixSelect( UINT nID ) ///////////////////////////////////////////////////////////////////////////// { CMenu Menu; CMenu PopupMenu; CPoint Point; int nDst, nSrc; ULONG ulValue; m_nPlaySelectID = nID; // remember which control launced the popup menu nDst = (m_nPlaySelectID - IDC_OUT1_PMIXA_SELECT) / (IDC_OUT2_PMIXA_SELECT - IDC_OUT1_PMIXA_SELECT); nSrc = ((m_nPlaySelectID - IDC_OUT1_PMIXA_SELECT) - (nDst * (IDC_OUT2_PMIXA_SELECT - IDC_OUT1_PMIXA_SELECT))) / ((IDC_OUT1_PMIXD_SELECT - IDC_OUT1_PMIXA_SELECT) / 2); m_pHalMixer->GetControl( LINE_OUT_1 + nDst, LINE_PLAY_MIXA + nSrc, CONTROL_SOURCE, 0, &ulValue ); Menu.LoadMenu( IDR_OUTPUT_SOURCE ); PopupMenu.Attach( Menu.GetSubMenu( 0 )->m_hMenu ); GetCursorPos( &Point ); PopupMenu.CheckMenuItem( IDM_SOURCE_RECORD1LEFT + ulValue, MF_BYCOMMAND | MF_CHECKED ); PopupMenu.TrackPopupMenu( TPM_LEFTALIGN, Point.x, Point.y, this, NULL ); }
void CMainWindow::createCustomMenu() { CMenu menu; CMenu sub; CMenu popup; if (!m_pBrowserEng->GetHTMLWND()) return; VERIFY(menu.CreateMenu()); VERIFY(popup.CreatePopupMenu()); menu.AppendMenu(MF_POPUP, (UINT) popup.m_hMenu, _T("")); RHODESAPP().getAppMenu().copyMenuItems(m_arAppMenuItems); #ifdef ENABLE_DYNAMIC_RHOBUNDLE String strIndexPage = CFilePath::join(RHODESAPP().getStartUrl(),"index"RHO_ERB_EXT); if ( RHODESAPP().getCurrentUrl().compare(RHODESAPP().getStartUrl()) == 0 || RHODESAPP().getCurrentUrl().compare(strIndexPage) == 0 ) m_arAppMenuItems.addElement(CAppMenuItem("Reload RhoBundle","reload_rhobundle")); #endif //ENABLE_DYNAMIC_RHOBUNDLE //update UI with custom menu items USES_CONVERSION; for ( int i = m_arAppMenuItems.size() - 1; i >= 0; i--) { CAppMenuItem& oItem = m_arAppMenuItems.elementAt(i); if (oItem.m_eType == CAppMenuItem::emtSeparator) popup.InsertMenu(0, MF_BYPOSITION | MF_SEPARATOR, (UINT_PTR)0, (LPCTSTR)0); else { StringW strLabelW = convertToStringW(oItem.m_strLabel); popup.InsertMenu(0, MF_BYPOSITION, ID_CUSTOM_MENU_ITEM_FIRST + i, oItem.m_eType == CAppMenuItem::emtClose ? _T("Exit") : strLabelW.c_str() ); } } RECT rect; GetWindowRect(&rect); #if defined( OS_PLATFORM_MOTCE ) rect.right = 1; rect.bottom = m_menuBarHeight+1; #else rect.bottom -= m_menuBarHeight; #endif sub.Attach(menu.GetSubMenu(0)); sub.TrackPopupMenu( #if defined( OS_PLATFORM_MOTCE ) TPM_LEFTALIGN, #else TPM_RIGHTALIGN | TPM_BOTTOMALIGN | TPM_LEFTBUTTON | TPM_VERNEGANIMATION, #endif rect.right-1, rect.bottom-1, m_hWnd); sub.Detach(); }
static void CopyMenu(HMENU srcMenuSpec, HMENU destMenuSpec) { CMenu srcMenu; srcMenu.Attach(srcMenuSpec); CMenu destMenu; destMenu.Attach(destMenuSpec); int startPos = 0; for (int i = 0; i < srcMenu.GetItemCount(); i++) { CMenuItem item; item.fMask = MIIM_STATE | MIIM_ID | Get_fMaskForFTypeAndString(); item.fType = MFT_STRING; if (srcMenu.GetItem(i, true, item)) if (destMenu.InsertItem(startPos, true, item)) startPos++; } }
static void MyChangeMenu(HMENU menuLoc, int level, int menuIndex) { CMenu menu; menu.Attach(menuLoc); for (int i = 0;; i++) { CMenuItem item; item.fMask = Get_fMask_for_String() | MIIM_SUBMENU | MIIM_ID; item.fType = MFT_STRING; if (!menu.GetItem(i, true, item)) break; { UString newString; if (item.hSubMenu) { UInt32 langID = 0; if (level == 1 && menuIndex == kMenuIndex_Bookmarks) langID = kAddToFavoritesLangID; else { MyChangeMenu(item.hSubMenu, level + 1, i); if (level == 1 && menuIndex == kMenuIndex_View) langID = kToolbarsLangID; else if (level == 0 && i < ARRAY_SIZE(kTopMenuLangIDs)) langID = kTopMenuLangIDs[i]; else continue; } LangString_OnlyFromLangFile(langID, newString); if (newString.IsEmpty()) continue; } else { if (item.IsSeparator()) continue; int langPos = FindLangItem(item.wID); // we don't need lang change for CRC items!!! LangString_OnlyFromLangFile(langPos >= 0 ? kIDLangPairs[langPos].LangID : item.wID, newString); if (newString.IsEmpty()) continue; int tabPos = item.StringValue.ReverseFind(L'\t'); if (tabPos >= 0) newString += item.StringValue.Ptr(tabPos); } { item.StringValue = newString; item.fMask = Get_fMask_for_String(); item.fType = MFT_STRING; menu.SetItem(i, true, item); } } } }
BOOL CSkinWin::PopupSysMenu(CPoint point) { CWnd * pWnd = CWnd::FromHandle(m_hWnd); CMenu SysMenu; HMENU HTest; HTest = GetSystemMenu(m_hWnd, FALSE) ; if ( ! HTest ) { return FALSE; } SysMenu.Attach( GetSystemMenu(m_hWnd, FALSE) ); // when gray menuitem, a strange line appears!! try { #if 0 SysMenu.EnableMenuItem( SC_SIZE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED ); if ( m_winstate == 0 ) { SysMenu.EnableMenuItem( SC_MINIMIZE, MF_BYCOMMAND|MF_ENABLED ); SysMenu.EnableMenuItem( SC_MAXIMIZE, MF_BYCOMMAND|MF_ENABLED ); SysMenu.EnableMenuItem( SC_RESTORE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED ); } else if ( m_winstate == 1 ) { SysMenu.EnableMenuItem( SC_MAXIMIZE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED ); SysMenu.EnableMenuItem( SC_RESTORE, MF_BYCOMMAND|MF_ENABLED ); } else if ( m_winstate == 2 ) { SysMenu.EnableMenuItem( SC_MINIMIZE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED ); SysMenu.EnableMenuItem( SC_RESTORE, MF_BYCOMMAND|MF_ENABLED ); } if (!m_minable) { SysMenu.EnableMenuItem( SC_MINIMIZE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED); } if (!m_maxable) { SysMenu.EnableMenuItem( SC_MAXIMIZE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED); } #endif SysMenu.TrackPopupMenu( 0, point.x, point.y, pWnd ); SysMenu.Detach(); } catch (...) { } OnNcPaint(0); return TRUE; }
BOOL CDHtmlMainDialog::OnCommand(WPARAM wParam, LPARAM lParam) { // Select Theme if(WM_THEME_ID <= wParam && wParam < WM_THEME_ID + (UINT)m_MenuArrayTheme.GetSize()) { CMenu menu; CMenu subMenu; menu.Attach(GetMenu()->GetSafeHmenu()); subMenu.Attach(menu.GetSubMenu(m_ThemeIndex)->GetSafeHmenu()); m_CurrentTheme = m_MenuArrayTheme.GetAt(wParam - WM_THEME_ID); ChangeTheme(m_MenuArrayTheme.GetAt(wParam - WM_THEME_ID)); subMenu.CheckMenuRadioItem(WM_THEME_ID, WM_THEME_ID + (UINT)m_MenuArrayTheme.GetSize(), (UINT)wParam, MF_BYCOMMAND); subMenu.Detach(); menu.Detach(); } return CDHtmlDialogEx::OnCommand(wParam, lParam); }
static void MyChangeMenu(HMENU menuLoc, int level, int menuIndex) { CMenu menu; menu.Attach(menuLoc); for (int i = 0;; i++) { CMenuItem item; item.fMask = Get_fMaskForString() | MIIM_SUBMENU | MIIM_ID; item.fType = MFT_STRING; if (!menu.GetItem(i, true, item)) break; { UString newString; if (item.hSubMenu) { UInt32 langID = 0; if (level == 1 && menuIndex == kMenuIndex_Bookmarks) langID = kAddToFavoritesLangID; else { MyChangeMenu(item.hSubMenu, level + 1, i); if (level == 1 && menuIndex == kMenuIndex_View) langID = kToolbarsLangID; else if (level == 0 && i < sizeof(kTopMenuLangIDs) / sizeof(kTopMenuLangIDs[0])) langID = kTopMenuLangIDs[i]; else continue; } newString = LangString(langID); if (newString.IsEmpty()) continue; } else { int langPos = FindLangItem(item.wID); if (langPos < 0) continue; newString = LangString(kIDLangPairs[langPos].LangID); if (newString.IsEmpty()) continue; UString shorcutString = item.StringValue; int tabPos = shorcutString.ReverseFind(wchar_t('\t')); if (tabPos >= 0) newString += shorcutString.Mid(tabPos); } { item.StringValue = newString; item.fMask = Get_fMaskForString(); item.fType = MFT_STRING; menu.SetItem(i, true, item); } } } }
static void CopyMenu(HMENU srcMenuSpec, HMENU destMenuSpec) { CMenu srcMenu; srcMenu.Attach(srcMenuSpec); CMenu destMenu; destMenu.Attach(destMenuSpec); int startPos = 0; for (int i = 0;; i++) { CMenuItem item; item.fMask = MIIM_SUBMENU | MIIM_STATE | MIIM_ID | Get_fMask_for_FType_and_String(); item.fType = MFT_STRING; if (!srcMenu.GetItem(i, true, item)) break; CopyPopMenu_IfRequired(item); if (destMenu.InsertItem(startPos, true, item)) startPos++; } }
BOOL CPmwMDIChild::LoadFrame(UINT nIDResource, DWORD dwDefaultStyle, CWnd* pParentWnd, CCreateContext* pContext) { if (!CMDIChildWnd::LoadFrame(nIDResource, dwDefaultStyle, pParentWnd, pContext)) { return FALSE; } CMenu menu; menu.Attach(m_hMenuShared); RemoveUnneededMenus(&menu); menu.Detach(); return TRUE; }
//----------------------------------------------------------------------------- // Purpose: // Input : pView - // point - // Output : //----------------------------------------------------------------------------- bool Marker3D::OnContextMenu2D(CMapView2D *pView, CPoint point) { if (!IsEmpty()) { CMapDoc *pDoc = pView->GetDocument(); if (pDoc == NULL) { return true; } // FIXME: functionalize this or fix it! pView->ScreenToClient(&point); CRect rect; pView->GetClientRect(&rect); if (!rect.PtInRect(point)) { return true; } CPoint ptScreen(point); CPoint ptMapScreen(point); pView->ClientToScreen(&ptScreen); pView->ClientToWorld(point); ptMapScreen.x += pView->GetScrollPos(SB_HORZ); ptMapScreen.y += pView->GetScrollPos(SB_VERT); if (HitTest(ptMapScreen, FALSE) != -1) { static CMenu menu, menuCreate; static bool bInit = false; if (!bInit) { bInit = true; menu.LoadMenu(IDR_POPUPS); menuCreate.Attach(::GetSubMenu(menu.m_hMenu, 1)); } menuCreate.TrackPopupMenu(TPM_LEFTBUTTON | TPM_RIGHTBUTTON | TPM_LEFTALIGN, ptScreen.x, ptScreen.y, pView); } } return true; }
void CPanel::CreateSevenZipMenu(HMENU menuSpec, const CRecordVector<UInt32> &operatedIndices, CMyComPtr<IContextMenu> &sevenZipContextMenu) { sevenZipContextMenu.Release(); CMenu menu; menu.Attach(menuSpec); // CMenuDestroyer menuDestroyer(menu); // menu.CreatePopup(); bool sevenZipMenuCreated = false; CZipContextMenu *contextMenuSpec = new CZipContextMenu; CMyComPtr<IContextMenu> contextMenu = contextMenuSpec; // if (contextMenu.CoCreateInstance(CLSID_CZipContextMenu, IID_IContextMenu) == S_OK) { /* CMyComPtr<IInitContextMenu> initContextMenu; if (contextMenu.QueryInterface(IID_IInitContextMenu, &initContextMenu) != S_OK) return; */ UString currentFolderUnicode = _currentFolderPrefix; UStringVector names; int i; for(i = 0; i < operatedIndices.Size(); i++) names.Add(currentFolderUnicode + GetItemRelPath(operatedIndices[i])); CRecordVector<const wchar_t *> namePointers; for(i = 0; i < operatedIndices.Size(); i++) namePointers.Add(names[i]); // NFile::NDirectory::MySetCurrentDirectory(currentFolderUnicode); if (contextMenuSpec->InitContextMenu(currentFolderUnicode, &namePointers.Front(), operatedIndices.Size()) == S_OK) { HRESULT res = contextMenu->QueryContextMenu(menu, 0, kSevenZipStartMenuID, kSystemStartMenuID - 1, 0); sevenZipMenuCreated = (HRESULT_SEVERITY(res) == SEVERITY_SUCCESS); if (sevenZipMenuCreated) sevenZipContextMenu = contextMenu; // int code = HRESULT_CODE(res); // int nextItemID = code; } } }
void CGeneralCRC::OnSave() { if (!UpdateData()) return; // Get the name to save the settings under and check its valid CString strName; GetDlgItemText(IDC_CRC_NAME, strName); if (strName.IsEmpty()) { TaskMessageBox("Invalid Name", "The CRC name cannot be empty"); return; } else if (find_name(strName) != -1) { CString ss; ss.Format("The name \"%s\" is already being used. " "Please choose another name.", strName); TaskMessageBox("Name in Use", ss); return; } // Get the current settings to be associated with the name CString params = SaveParams(); // Add the name to the end of the Select menu CMenu menu; menu.Attach(select_menu_.m_hMenu); menu.AppendMenu(MF_STRING, settings_.size(), strName); menu.Detach(); // Add corresponding parameters to the end of settings_ settings_.push_back(params); // Add to the registry (for next time the dialog is opened) HKEY hkey; if (::RegCreateKey(HKEY_CURRENT_USER, reg_locn, &hkey) == ERROR_SUCCESS) { ::RegSetValueEx(hkey, strName, 0, REG_SZ, (BYTE *)params.GetBuffer(), params.GetLength()+1); ::RegCloseKey(hkey); } // Disable Save button as we can't save again with the same name GetDlgItem(IDC_CRC_SAVE)->EnableWindow(FALSE); }
void LoadFileMenu(HMENU hMenu, int startPos, bool programMenu, bool isFsFolder, int numItems, bool allAreFiles) { CMenu destMenu; destMenu.Attach(hMenu); UString diffPath; ReadRegDiff(diffPath); int numRealItems = startPos; for (int i = 0;; i++) { CMenuItem item; item.fMask = MIIM_STATE | MIIM_ID | Get_fMaskForFTypeAndString(); item.fType = MFT_STRING; if (!g_FileMenu.GetItem(i, true, item)) break; { if (!programMenu && item.wID == IDCLOSE) continue; if (item.wID == IDM_FILE_DIFF && diffPath.IsEmpty()) continue; bool isOneFsFile = (isFsFolder && numItems == 1 && allAreFiles); bool disable = ((item.wID == IDM_FILE_SPLIT || item.wID == IDM_FILE_COMBINE) && !isOneFsFile); bool isBigScreen = NControl::IsDialogSizeOK(40, 200); if (!isBigScreen && (disable || item.IsSeparator())) continue; if (destMenu.InsertItem(startPos, true, item)) startPos++; if (disable) destMenu.EnableItem(startPos - 1, MF_BYPOSITION | MF_GRAYED); if (!item.IsSeparator()) numRealItems = startPos; } } destMenu.RemoveAllItemsFrom(numRealItems); }
void CLogView::OnPopupMenuCommand() { CMenu menu; CMenu sub; POINT point; ::GetCursorPos(&point); //where is the mouse? RECT rect; GetWindowRect(&rect); VERIFY(menu.LoadMenu(IDR_LOGVIEW_MENU)); sub.Attach(menu.GetSubMenu(0)); sub.TrackPopupMenu( TPM_RIGHTALIGN | TPM_TOPALIGN | TPM_LEFTBUTTON | TPM_VERNEGANIMATION, point.x, point.y, m_hWnd); sub.Detach(); }
STDMETHODIMP ExplorerBar::QueryContextMenu(HMENU hShellContextMenu, UINT iContextMenuFirstItem, UINT idCmdFirst, UINT idCmdLast, UINT uFlags) { DEBUG_UNUSED( idCmdLast ); DEBUG_UNUSED( uFlags ); CMenu menubar; menubar.LoadMenu(IDR_CONTEXT_MENU); CMenu * menu = menubar.GetSubMenu(0); CMenu shellmenu; shellmenu.Attach(hShellContextMenu); UINT iShellItem = iContextMenuFirstItem; //! remove plus one UINT idShellCmd = idCmdFirst; int n = menu->GetMenuItemCount(); for (int i=0; i<n; ++i) { MENUITEMINFO mii; TCHAR sz[128] = {0}; ZeroMemory(&mii, sizeof(mii)); mii.fMask = MIIM_TYPE | MIIM_ID; mii.fType = MFT_STRING; mii.cbSize = sizeof(mii); mii.cch = LENGTHOF(sz); mii.dwTypeData = sz; menu->GetMenuItemInfo(i, &mii, TRUE); mii.wID = idShellCmd++; shellmenu.InsertMenuItem(iShellItem++, &mii, TRUE); } shellmenu.Detach(); return n; }
LONG COXSizeControlBar::OnAddContextMenuItems(WPARAM /* wParam */, LPARAM lParam) { HMENU hMenu = (HMENU)lParam; // handle of menu. CMenu Menu; Menu.Attach(hMenu); DWORD dwDockStyle = m_dwDockStyle & CBRS_ALIGN_ANY; DWORD style; CString strMenu; BOOL bMDIFloating = FALSE; CFrameWnd* pParentFrame = GetParentFrame(); if (IsFloating()) { if (pParentFrame != NULL && pParentFrame->IsKindOf(RUNTIME_CLASS(COXMDIFloatWnd))) { bMDIFloating = TRUE; } } style = (bMDIFloating ? MF_STRING | MF_CHECKED : MF_STRING); // if allowed - add the float as MDI floating window if ((m_Style&SZBARF_ALLOW_MDI_FLOAT)!=0 && m_pDockContext!=NULL) { VERIFY(strMenu.LoadString(ID_OX_MRC_MDIFLOAT)); Menu.AppendMenu(style, ID_OX_MRC_MDIFLOAT, strMenu); } if (!bMDIFloating && (dwDockStyle != 0 || m_dwAllowDockingState != 0)) // ie docking is actually allowed ... { DWORD style = (dwDockStyle != 0 ? MF_STRING | MF_CHECKED : MF_STRING); VERIFY(strMenu.LoadString(ID_OX_MRC_ALLOWDOCKING)); Menu.AppendMenu(style, ID_OX_MRC_ALLOWDOCKING, strMenu); } VERIFY(strMenu.LoadString(ID_OX_MRC_HIDE)); Menu.AppendMenu(MF_STRING, ID_OX_MRC_HIDE, strMenu); Menu.Detach(); // detatch MFC object return TRUE; }
// Search the "Select" menu to see if a CRC setting name is in use. // Returns the ID (index into settings_) if found or -1 if not int CGeneralCRC::find_name(LPCTSTR name) { int retval = -1; CMenu menu; menu.Attach(select_menu_.m_hMenu); int lst = menu.GetMenuItemCount(); for (int ii = 0; ii < lst; ++ii) { CString ss; menu.GetMenuString(ii, ss, MF_BYPOSITION); if (ss.CompareNoCase(name) == 0) { retval = menu.GetMenuItemID(ii); break; } } menu.Detach(); return retval; }
void CGeneralCRC::OnDelete() { // First check that we selected from the list (using Select menu) // else we don't know what to delete if (last_selected_ < last_predefined_ || last_selected_ >= settings_.size()) { assert(0); // Code should prevent this from happening return; } // Delete from the Select menu CMenu menu; menu.Attach(select_menu_.m_hMenu); CString strName = get_menu_text(&menu, last_selected_); // save mneu item name - used to delete reg value by name CString mess; mess.Format("Are you sure you want to delete the settings for %s", strName); if (TaskMessageBox("Delete CRC Settings", mess, MB_YESNO) != IDYES) { menu.Detach(); return; } menu.DeleteMenu(last_selected_, MF_BYCOMMAND); // Delete menu item with selected ID menu.Detach(); // Delete from settings_ (where ID == last_selected_ is the index into the array) settings_[last_selected_] = CString(""); // clear but don't delete unused entries (else menu item ID's won't mathc array indices) // Remove the setting from the registry HKEY hkey; if (::RegCreateKey(HKEY_CURRENT_USER, reg_locn, &hkey) == ERROR_SUCCESS) { ::RegDeleteValue(hkey, strName); ::RegCloseKey(hkey); } // Disable Delete button now as we just deleted it GetDlgItem(IDC_CRC_DELETE)->EnableWindow(FALSE); }
//动态添加菜单,根据应用的需要进行添加,不是必须的操 extern"C" _declspec(dllexport) BOOL InstallExtMenu(CWnd* pChild, HWND Parent, UINT* NextMenuID) { AFX_MANAGE_STATE(AfxGetAppModuleState()); BOOL bReturn = FALSE; if (!pChild) //dll 中的wnd为空,无法添加 return FALSE; if (!Parent) return FALSE; HMENU hMenu = ::GetMenu(Parent); //获取父窗口的菜单 if (!hMenu) return FALSE; CMenu ParentMenu; ParentMenu.Attach(hMenu); CMenu Menu; if (!Menu.CreateMenu()) //创建菜单 return FALSE; theApp.m_CommandToMessage.InitHashTable(3); //预定3项,可修改 NextMenuID = new UINT[3]; NextMenuID[0] = theApp.ID_MENU_SHOWHINT; NextMenuID[1] = theApp.ID_MENU_HIDEHINT; NextMenuID[2] = theApp.ID_MENU_SETTASK; Menu.AppendMenu(MF_STRING, (UINT_PTR)(*NextMenuID), L"显示提示符"); theApp.m_CommandToMessage.SetAt(*(NextMenuID)++, theApp.ID_MENU_SHOWHINT); //设置映射 Menu.AppendMenu(MF_STRING, (UINT_PTR)(*NextMenuID), L"隐藏提示符"); theApp.m_CommandToMessage.SetAt(*(NextMenuID)++, theApp.ID_MENU_HIDEHINT); Menu.AppendMenu(MF_STRING, (UINT_PTR)(*NextMenuID), L"设置任务"); theApp.m_CommandToMessage.SetAt(*(NextMenuID)++, theApp.ID_MENU_SETTASK); HMENU hsubMenu = Menu.Detach(); ParentMenu.InsertMenuW(ParentMenu.GetMenuItemCount(), MF_BYPOSITION | MF_STRING | MF_POPUP, (UINT_PTR)hsubMenu, _T("数字应用设置")); ParentMenu.Detach(); CWnd::FromHandle(Parent)->DrawMenuBar(); //强制重绘菜单 return TRUE; }
// Selection was made from the Select menu button of a predefined CRC settings void CGeneralCRC::OnSelect() { int id = select_menu_.m_nMenuResult; // slected menu ID (= index into settings_) if (id > 0 && id < settings_.size()) { // Get the param string associated with the select menu item and load it into member vars LoadParams(settings_[id]); // Update dlg controls from members variables UpdateData(FALSE); // Get the menu item text and load it into the name field CMenu menu; menu.Attach(select_menu_.m_hMenu); CString ss = get_menu_text(&menu, id); menu.Detach(); SetDlgItemText(IDC_CRC_NAME, ss); // Enable the Delete button if this is a user defined setting GetDlgItem(IDC_CRC_DELETE)->EnableWindow(id >= last_predefined_); last_selected_ = id; } }
void CRecordPage::OnRecordSelect( UINT nID ) ///////////////////////////////////////////////////////////////////////////// { CMenu Menu; CMenu PopupMenu; CPoint Point; ULONG ulValue; int nLineCtls = IDC_RECORD2L_SELECT - IDC_RECORD1L_SELECT; int nDst = (nID - IDC_RECORD1L_SELECT) / nLineCtls; int nCh = nID - (IDC_RECORD1L_SELECT + (nDst * nLineCtls)); m_nRecordSelectID = nID; // remember which control launced the popup menu if( !nCh ) m_pHalMixer->GetControl( LINE_RECORD_0 + nDst, LINE_NO_SOURCE, CONTROL_SOURCE_LEFT, 0, &ulValue ); else m_pHalMixer->GetControl( LINE_RECORD_0 + nDst, LINE_NO_SOURCE, CONTROL_SOURCE_RIGHT, 0, &ulValue ); Menu.LoadMenu( IDR_INPUT_SOURCE ); PopupMenu.Attach( Menu.GetSubMenu( 0 )->m_hMenu ); GetCursorPos( &Point ); PopupMenu.CheckMenuItem( IDM_SOURCE_ANALOGIN1 + ulValue, MF_BYCOMMAND | MF_CHECKED ); PopupMenu.TrackPopupMenu( TPM_LEFTALIGN, Point.x, Point.y, this, NULL ); }
void CMainFrame::OnMenuUpdate(UINT nID) // Called when menu items are about to be displayed { // Only for the Menu IDs we wish to modify if (nID >= IDM_EDIT_UNDO && nID <= IDM_EDIT_DELETE) { CWnd* pWnd = 0; CMenu Menu; Menu.Attach(GetFrameMenu()); CMenu* pEditMenu = Menu.GetSubMenu(1); if (m_pLastActiveDocker) { if (m_pLastActiveDocker == &m_DockTabbedMDI) pWnd = m_DockTabbedMDI.GetTabbedMDI()->GetActiveMDIChild(); else if (m_pLastActiveDocker->IsDocked()) pWnd = m_pLastActiveDocker->GetContainer()->GetActiveView(); } // Enable the Edit menu items for CViewText windows, disable them otherwise UINT Flags = (dynamic_cast<CViewText*>(pWnd)) ? MF_ENABLED : MF_GRAYED; pEditMenu->EnableMenuItem(nID, MF_BYCOMMAND | Flags); Menu.Detach(); } }
BOOL CSkinWin::HandleSysCommand(WPARAM wp, LPARAM lp) { int i; if ( lp == 0 ) { CMenu SysMenu; BOOL bBack = SysMenu.Attach( GetSystemMenu(m_hWnd, FALSE) ); if (!bBack) { return FALSE; } int count = SysMenu.GetMenuItemCount(); for( i = 0; i < count ; i++ ) if ( SysMenu.GetMenuItemID(i) == wp ) break; SysMenu.Detach(); if ( i >= count ) return FALSE; if ( wp == SC_MAXIMIZE ) Maximize(); else if ( wp == SC_MINIMIZE ) Minimize(); else if ( wp == SC_RESTORE && m_winstate == 1 ) Restore(); else if ( wp == SC_RESTORE && m_winstate == 2 ) { ShowWindow( m_hWnd, SW_RESTORE ); m_winstate = m_oldwinstate; } else SendMessage( m_hWnd, WM_SYSCOMMAND, wp, lp ); OnNcPaint(0); return TRUE; } return FALSE; }
BOOL CCoolMenuBarCtrl::OpenMenuChar(UINT nChar) { CMenu pMenu; pMenu.Attach( m_hMenu ); for ( UINT nItem = 0 ; nItem < pMenu.GetMenuItemCount() ; nItem++ ) { CString strMenu; pMenu.GetMenuString( nItem, strMenu, MF_BYPOSITION ); LPCTSTR pszChar = _tcschr( strMenu, '&' ); if ( ! pszChar++ ) continue; if ( toupper( *pszChar ) == toupper( nChar ) ) { pMenu.Detach(); if ( m_pSelect = GetIndex( nItem ) ) PostMessage( WM_TIMER, 5 ); return TRUE; } } pMenu.Detach(); return FALSE; }
BOOL CnpadBookApp::showDlg(int isInitNPP){ if(funcItem[0]._cmdID){ HMENU hMenu; hMenu=(HMENU)::SendMessage(nppData._nppHandle, NPPM_GETMENUHANDLE, NPPPLUGINMENU, 0); CMenu menu; menu.Attach(hMenu); BOOL isNeedShow=FALSE; if(isInitNPP){ isNeedShow=(MF_CHECKED &(menu.GetMenuState(funcItem[0]._cmdID,MF_BYCOMMAND))); } else{ isNeedShow=!(MF_CHECKED &(menu.GetMenuState(funcItem[0]._cmdID,MF_BYCOMMAND))); } menu.Detach(); if(isInitNPP){ CConndb add; CString sqlcmd=_T("select * from config where key='show'"); add.search(sqlcmd); if(!add.m_query->eof()) { CString tmp; _variant_t var; var=add.m_query->getStringField(_T("value")); if(var.vt!=VT_NULL){ tmp=(LPCSTR)_bstr_t(var); if(tmp==_T("1")) isNeedShow=TRUE; else isNeedShow=FALSE; } } } if(!CnpadBookApp::isInitDock && isNeedShow){ mydlg.dlgID=1; mydlg.hClient=pBookDlg->m_hWnd; mydlg.hIconTab=NULL; mydlg.uMask=DWS_DF_CONT_LEFT; mydlg.pszModuleName=TEXT("npadBook.dll"); mydlg.pszName=TEXT("ITBook笔记管理"); mydlg.pszAddInfo=TEXT("npadBook"); CnpadBookApp::isInitDock=::SendMessage(nppData._nppHandle,NPPM_DMMREGASDCKDLG, 0, (LPARAM)&mydlg); ::SendMessage(nppData._nppHandle,NPPM_SETMENUITEMCHECK,funcItem[0]._cmdID, (LPARAM)TRUE); }else if(isNeedShow){ ::SendMessage(nppData._nppHandle,NPPM_DMMSHOW, 0, (LPARAM)mydlg.hClient); ::SendMessage(nppData._nppHandle,NPPM_SETMENUITEMCHECK,funcItem[0]._cmdID, (LPARAM)TRUE); }else if(!isNeedShow){ ::SendMessage(nppData._nppHandle,NPPM_DMMHIDE, 0, (LPARAM)mydlg.hClient); ::SendMessage(nppData._nppHandle,NPPM_SETMENUITEMCHECK,funcItem[0]._cmdID, (LPARAM)FALSE); } CConndb add; CString sql; if(isNeedShow) sql=_T("update config set value='1'"); else{ sql=_T("update config set value='0'"); } add.excuteSql(sql); } return TRUE; }