コード例 #1
0
ファイル: CtrlCoolMenuBar.cpp プロジェクト: ivan386/Shareaza
BOOL CCoolMenuBarCtrl::OpenMenuChar(UINT nChar)
{
	CMenu pMenu;
	pMenu.Attach( m_hMenu );

	for ( UINT nItem = 0 ; nItem < (UINT)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 ) ) != NULL ) PostMessage( WM_TIMER, 5 );
			return TRUE;
		}
	}

	pMenu.Detach();
	return FALSE;
}
コード例 #2
0
LRESULT CMainFrame::OnToolbarContextMenu(WPARAM,LPARAM lp)
{
	CPoint point (AFX_GET_X_LPARAM(lp), AFX_GET_Y_LPARAM(lp));

	CMenu menu;
	VERIFY(menu.LoadMenu (IDR_POPUP_TOOLBAR));

	CMenu* pPopup = menu.GetSubMenu(0);
	ASSERT(pPopup != NULL);

	CMFCPopupMenu* pPopupMenu = new CMFCPopupMenu;
	pPopupMenu->Create (this, point.x, point.y, pPopup->Detach ());

	return 0;
}
コード例 #3
0
ファイル: MainWindow.cpp プロジェクト: Aerodynamic/rhodes
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);
    rect.bottom -= m_menuBarHeight;
	sub.Attach(menu.GetSubMenu(0));
	sub.TrackPopupMenu( TPM_RIGHTALIGN | TPM_BOTTOMALIGN | TPM_LEFTBUTTON | TPM_VERNEGANIMATION, 
						rect.right-1, 
						rect.bottom-1,
						m_hWnd);
	sub.Detach();
}
コード例 #4
0
void DisplayView::PrepareCompatibleFiltersMenu(CMenu &menu, Pin *pin)
{
    /*
    	Enumerate output mediatypes and look for compatible
    	filters.
    */

    compatible_filters.filters.RemoveAll();

    // ignore invalid and connected pins
    if (!pin || !(pin->pin) || (pin->dir == PINDIR_INPUT)) return ;
    if (pin->connected) return ;

    // enumerate media types
    DSUtil::MediaTypes			mtypes;

    DSUtil::EnumMediaTypes(pin->pin, mtypes);
    if (mtypes.GetCount() <= 0) return ;

    // now try to enumerate compatible filters
    int ret = compatible_filters.EnumerateCompatible(mtypes, MERIT_UNLIKELY, false, render_params.exact_match_mode);
    if ((ret == 0) && (compatible_filters.filters.GetCount() > 0)) {

        CMenu		submenu;
        submenu.CreatePopupMenu();
        CMenu		&active_menu = submenu;

        for (int i=0; i<compatible_filters.filters.GetCount(); i++) {
            DSUtil::FilterTemplate	&filt = compatible_filters.filters[i];

            CString		merit;
            merit.Format(_T("%08x)"), filt.merit);
            merit = merit.MakeUpper();

            int idx = active_menu.GetMenuItemCount();

            CString		name = filt.name + _T("\t(0x") + merit;
            active_menu.InsertMenu(idx, MF_BYPOSITION | MF_STRING, ID_COMPATIBLE_FILTER + i, name);
        }

        // do insert the menu
        int		count = menu.GetMenuItemCount();
        menu.InsertMenu(count++, MF_BYPOSITION | MF_SEPARATOR);
        menu.InsertMenu(count, MF_BYPOSITION | MF_STRING, 0, _T("Compatible filters"));
        menu.ModifyMenu(count, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)submenu.m_hMenu, _T("Compatible filters"));
        submenu.Detach();
    }
}
コード例 #5
0
void CMainFrame::OnExitlogin()
{
    // TODO: 在此添加命令处理程序代码
    CMenu menu;
    menu.LoadMenu(IDR_MAINFRAME);
    AfxGetMainWnd()->SetMenu(&menu);
    menu.Detach();
    CStdioFile File;
    File.Open(TEXT("current user.txt"),CFile::modeWrite|CFile::modeCreate);
    char* old_locale=_strdup(setlocale(LC_CTYPE,NULL));
    setlocale( LC_CTYPE,"chs");
    File.WriteString(TEXT("\n"));
    setlocale(LC_CTYPE,old_locale);
    free(old_locale);
    File.Close();
}
コード例 #6
0
void CNetTrafficMonitorDlg::OnRButtonUp(UINT nFlags, CPoint point)
{
	// TODO:  在此添加消息处理程序代码和/或调用默认值
	//if (m_pSlider->IsWindowVisible())
	//{
	//	m_pSlider->ShowWindow(SW_HIDE);
	//}

	CMenu menu;
	menu.CreatePopupMenu();	// 声明一个弹出式菜单
	menu.AppendMenu(MF_STRING, IDC_SELFSTARTING, _T("开机启动"));
	//menu.AppendMenu(MF_STRING, IDC_TOPMOST, _T("置顶"));
	//CString strText;
	//strText.Format(_T("透明度: %d%%"), m_iTransparency);
	//menu.AppendMenu(MF_STRING, IDC_TRANSPARENCY, strText);
	menu.AppendMenu(MF_STRING, IDC_EXIT, _T("退出"));	// 增加菜单项“退出”,点击则发送消息给主窗口将程序结束
	if (m_bSelfStarting)
	{
		menu.SetMenuItemBitmaps(IDC_SELFSTARTING, MF_BYCOMMAND | MF_STRING | MF_ENABLED, &m_cCheckYes, &m_cCheckYes);
	}
	else
	{
		menu.SetMenuItemBitmaps(IDC_SELFSTARTING, MF_BYCOMMAND | MF_STRING | MF_ENABLED, &m_cCheckNo, &m_cCheckNo);
	}
	//if (m_bTopMost)
	//{
	//	menu.SetMenuItemBitmaps(IDC_TOPMOST, MF_BYCOMMAND | MF_STRING | MF_ENABLED, &m_cCheckYes, &m_cCheckYes);
	//}
	//else
	//{
	//	menu.SetMenuItemBitmaps(IDC_TOPMOST, MF_BYCOMMAND | MF_STRING | MF_ENABLED, &m_cCheckNo, &m_cCheckNo);
	//}
	menu.SetMenuItemBitmaps(IDC_EXIT, MF_BYCOMMAND | MF_STRING | MF_ENABLED, &m_cExit, &m_cExit);
	//SetForegroundWindow();

	LPPOINT lpPoint = new tagPOINT();
	GetCursorPos(lpPoint);
	menu.TrackPopupMenu(TPM_LEFTALIGN, lpPoint->x, lpPoint->y, this);	// 确定弹出式菜单的位置

	menu.Detach();	// 资源回收
	menu.DestroyMenu();
	delete lpPoint;

	//CWnd::OnRButtonUp(nFlags, point);	// 屏蔽任务栏自己的右键菜单
}
コード例 #7
0
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);
}
コード例 #8
0
ファイル: ControlEvent.cpp プロジェクト: ltframe/ltplayer0016
void ControlEvent::ShowCMenu(CWnd *pcwnd)
{
	LPPOINT lpoint=new tagPOINT;
	::GetCursorPos(lpoint);//得到鼠标位置
	CMenu menu;
	menu.CreatePopupMenu();//声明一个弹出式菜单
	//增加菜单项“关闭”,点击则发送消息WM_DESTROY给主窗口(已
	//隐藏),将程序结束。
	menu.AppendMenu(MF_STRING,IDR_MYSETTING_MESSAGE,CString("软件设置"));
	menu.AppendMenu(MF_STRING,IDR_MYWEBSITE_MESSAGE,CString("官方网站"));
	menu.AppendMenu(MF_STRING,IDR_MYCLOSE_MESSAGE,CString("关闭退出"));
	//确定弹出式菜单的位置
	menu.TrackPopupMenu(TPM_LEFTALIGN,lpoint->x,lpoint->y,pcwnd);
	//资源回收
	HMENU hmenu=menu.Detach();
	menu.DestroyMenu();
	delete lpoint;
}
コード例 #9
0
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();
}
コード例 #10
0
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;
}
コード例 #11
0
ファイル: SkinBase.cpp プロジェクト: 3rdexp/jezzitest
HMENU CSkinBase::MakeMenuCopy(const HMENU hSrc)
{
	if (!pSrc)
		return NULL;
	
	CMenu menu;
	
	VERIFY (menu.CreatePopupMenu());
	ASSERT (::IsMenu(menu.m_hMenu));
	
	int nNumItems = GetMenuItemCount( hSrc );
	CString sLabel;
	
	MENUITEMINFO mii;
	ZeroMemory(&mii, sizeof(mii));
	mii.cbSize = sizeof(mii); // must fill up this field
	mii.fMask = MIIM_STATE | MIIM_DATA; 			// get the state of the menu item
				
	for (int nItem = 0; nItem < nNumItems; nItem++)
	{
		UINT uIDItem = GetMenuItemID(hSrc, nItem);
		GetMenuString(hSrc, nItem, sLabel, MF_BYPOSITION);
		UINT uFlags = (uIDItem == 0) ? MF_SEPARATOR : (uIDItem == (UINT)-1) ? MF_POPUP : MF_STRING;
		
		// special case: if a popup menu we must copy it too
		if (uFlags == MF_POPUP)
		{
			HMENU hPopup = MakeMenuCopy(GetSubMenu(hSrc, nItem));
			ASSERT (hPopup);
			
			uIDItem = (UINT)hPopup;
		}
		
		menu.AppendMenu(uFlags, uIDItem, sLabel);
		
		// make sure we copy the state too
		::GetMenuItemInfo(hSrc, nItem, TRUE, &mii);
		::SetMenuItemInfo(menu, nItem, TRUE, &mii);
	}
	
	return menu.Detach();
}
コード例 #12
0
ファイル: KillerDlg.cpp プロジェクト: caidongyun/PcGuard
// 处理列表框右键消息 弹出浮动菜单
void CKillerDlg::OnRclickList(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
    if(pNMListView->iItem != -1)
	{
	  DWORD dwPos = GetMessagePos();// 得到鼠标坐标
      CPoint point( LOWORD(dwPos), HIWORD(dwPos) );
      CMenu menu;
      VERIFY( menu.LoadMenu(IDR_MENU1));
      CMenu* popup = menu.GetSubMenu(0);
      ASSERT( popup != NULL );
	  //确定弹出式菜单的位置
      popup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, this);
	  //资源回收
		HMENU hmenu=menu.Detach();
		menu.DestroyMenu();
   }
	*pResult = 0;
	*pResult = 0;
}
コード例 #13
0
ファイル: MainFrm.cpp プロジェクト: zxlooong/bcgexp
LRESULT CMainFrame::OnToolbarContextMenu(WPARAM wp,LPARAM lp)
{
    CBCGPToolBar* pToolBar = DYNAMIC_DOWNCAST (CBCGPToolBar,
                             CWnd::FromHandlePermanent ((HWND) wp));
    m_bMainToolbarMenu = (
                             pToolBar != NULL && pToolBar->GetDlgCtrlID () == AFX_IDW_TOOLBAR);

    CPoint point (BCG_GET_X_LPARAM(lp), BCG_GET_Y_LPARAM(lp));

    CMenu menu;
    VERIFY(menu.LoadMenu (IDR_POPUP_TOOLBAR));

    CMenu* pPopup = menu.GetSubMenu(0);
    ASSERT(pPopup != NULL);

    CBCGPPopupMenu* pPopupMenu = new CBCGPPopupMenu;
    pPopupMenu->Create (this, point.x, point.y, pPopup->Detach ());

    return 0;
}
コード例 #14
0
ファイル: OXSizeCtrlBar.CPP プロジェクト: Spritutu/AiPI-1
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;
}
コード例 #15
0
ファイル: QuickScripts.cpp プロジェクト: OmerMor/SciCompanion
void CQuickScripts::_PrepareViewMenu(int cItems)
{
    if (m_wndButtonViews.m_menu == NULL)
    {
        CMenu menu;
        if (menu.LoadMenu(IDR_MENUVIEWS))
        {
            // We only need to do this once...
            m_wndButtonViews.m_menu.Attach(menu.Detach());
        }
    }
    if (m_wndButtonViews.m_menu)
    {
        UINT nID;
        if (_GetMenuItem("placeholder", &m_wndButtonViews.m_menu, &nID))
        {
            CMenu *pMenuSub = m_wndButtonViews.m_menu.GetSubMenu(nID);

            // Clear the menu out first.
            UINT cItemsInMenu = pMenuSub->GetMenuItemCount();
            while (cItemsInMenu > 0)
            {
                pMenuSub->RemoveMenu(0, MF_BYPOSITION);
                cItemsInMenu--;
            }

            // And rebuild
            for (int iIndex = 0; iIndex < cItems; iIndex++)
            {
                MENUITEMINFO mii = { 0 };
                mii.cbSize = sizeof(mii);
                mii.fMask = MIIM_ID | MIIM_STRING;
                mii.wID = ID_GOTOVIEW1 + iIndex;
                mii.dwTypeData = "foo";
                pMenuSub->InsertMenuItem(ID_GOTOVIEW1 + iIndex, &mii, FALSE);
                //menu.InsertMenuItem(ID_GOTOVIEW1 + iIndex, &mii, FALSE);
            }
        }
    }
    m_wndButtonViews.EnableWindow(cItems > 0);
}
コード例 #16
0
// 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;
}
コード例 #17
0
ファイル: WordsBaseFrame.cpp プロジェクト: zwvista/LollyMFC
void CWordsBaseFrame::AddDict(UINT nID, CUIDict* pUIDict)
{
    int count = m_wndToolBarDicts.GetCount();
    if(count > 0) --count;
    if(auto pUIDictItem = dynamic_cast<CUIDictItem*>(pUIDict))
        m_wndToolBarDicts.InsertButton(CMFCToolBarButton(nID, CMFCToolBar::GetDefaultImage(ID_TB_DICTS_OFFLINEALL + pUIDict->m_ImageIndex)));
    else{
        auto pUIDictCol = dynamic_cast<CUIDictCollection*>(pUIDict);
        if(pUIDictCol->IsPile())
            m_wndToolBarDicts.InsertButton(CMFCToolBarButton(nID, CMFCToolBar::GetDefaultImage(ID_TB_DICTS_OFFLINEALL + pUIDict->m_ImageIndex)));
        else{
            auto pUIDictItem = pUIDictCol->m_vpUIDictItems[0].get();
            CMenu menu;
            menu.LoadMenu(IDR_POPUP_NAVIGATE);
            m_wndToolBarDicts.InsertButton(CMFCToolBarMenuButton(nID, menu.Detach(), CMFCToolBar::GetDefaultImage(ID_TB_DICTS_OFFLINEALL + pUIDictItem->m_ImageIndex)));
        }
    }
	m_wndToolBarDicts.SetToolBarBtnText(count, pUIDict->m_strName);
	m_wndToolBarDicts.EnableCustomizeButton(TRUE, nID, _T(""));
	m_wndToolBarDicts.AdjustSizeImmediate();
}
コード例 #18
0
ファイル: FunctionManager.cpp プロジェクト: axxapp/winxgui
HMENU CFunctionManager::CreateSpecFunctionDropMenu()
{
	bool bDialog = false;
	if (!m_bAllowDlgIdle)
	{
		bDialog = (m_pClass->IsDialog() && !m_pClass->m_DialogID.IsEmpty());
	}
	CMenu Menu;
	Menu.CreatePopupMenu();
	UINT uiFlags = MF_STRING;
	if (IsPreTranslateMessage(m_pClass) || bDialog)
		uiFlags |= MF_DISABLED | MF_GRAYED;
	Menu.AppendMenu(uiFlags, ID_MENU_PRE_TRANSLATE_MESSAGE, _T("PreTranslateMessage"));
	if (IsOnIdle(m_pClass) || bDialog)
		uiFlags = MF_DISABLED | MF_GRAYED;
	else
		uiFlags = MF_ENABLED;
	Menu.AppendMenu(uiFlags, ID_MENU_ON_IDLE, _T("OnIdle"));
	FillSpecFunctionArray();
	CString Parent;
	for (size_t i = 0; i < m_SelectedFunctions.GetCount(); i++)
	{
		if (m_SelectedFunctions[i].Parent != Parent)
		{
			Parent = m_SelectedFunctions[i].Parent;
			Menu.AppendMenu(MF_SEPARATOR, ID_SEPARATOR);
		}
		if (IsSpecFunction(m_pClass, m_SelectedFunctions[i]))
		{
			uiFlags = MF_DISABLED | MF_GRAYED;
		}
		else
		{
			uiFlags = MF_ENABLED;
		}
		Menu.AppendMenu(uiFlags, ID_MENU_ON_IDLE + 1 + i, m_SelectedFunctions[i].FuncName);
	}
	
	return Menu.Detach();
}
コード例 #19
0
ファイル: Mainfrm.cpp プロジェクト: wyrover/win32-framework
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();
    }
}
コード例 #20
0
// 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;
	}
}
コード例 #21
0
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;
}
コード例 #22
0
ファイル: PageToolbars.cpp プロジェクト: ngphloc/agmagic
BOOL CPageToolbars::OnInitDialog() 
{
	CPageBase::OnInitDialog();
	
	CWinApp * pApp = ::AfxGetApp();
	ASSERT( pApp != NULL );
	
	VERIFY(
		g_CmdManager->ProfileSetup(
		_T("PageToolbars"),
		GetSafeHwnd()
		)
		);
	VERIFY(
		g_CmdManager->UpdateFromMenu(
		_T("PageToolbars"),
		IDR_MENU_PAGE_TOOLBARS
		)
		);
	VERIFY(
		g_CmdManager->UpdateFromMenu(
		_T("PageToolbars"),
		IDR_COLOR_MENU
		)
		);
	VERIFY(
		g_CmdManager->UpdateFromToolBar(
		_T("PageToolbars"),
		IDR_PALETTE_TOOLBAR
		)
		);
	VERIFY(
		g_CmdManager->UpdateFromToolBar(
		_T("PageToolbars"),
		IDR_EDIT
		)
		);

	//////////////////////////////////////////////////////////////////////////

	ASSERT( m_wndMenuBar.GetSafeHwnd() != NULL );
	if(	!m_wndMenuBar.LoadMenuBar( IDR_MENU_PAGE_TOOLBARS ) ){
		ASSERT( FALSE );
		return FALSE;
	}
	
	// init combobox in the menubar
	if(	!m_wndComboBoxInMenubar.Create(
		WS_CHILD|WS_VISIBLE|WS_TABSTOP
		|CBS_DROPDOWN|CBS_HASSTRINGS,
		CRect( 0, 0, 150, 100 ),
		&m_wndMenuBar,
		ID_COMBOBOX_IN_MENUBAR
		)
		)
	{
		ASSERT( FALSE );
		return FALSE;
	}
	
	m_wndMenuBar.InsertButton(
		-1,
		ID_COMBOBOX_IN_MENUBAR
		);
	VERIFY(
		m_wndMenuBar.SetButtonCtrl( 
		m_wndMenuBar.CommandToIndex(ID_COMBOBOX_IN_MENUBAR), 
		&m_wndComboBoxInMenubar )
		);
	
	m_wndComboBoxInMenubar.SetFont(
		CFont::FromHandle(
		(HFONT)::GetStockObject(DEFAULT_GUI_FONT)
		)
		);
	m_wndComboBoxInMenubar.AddString( _T("ComboBox in menubar") );
	m_wndComboBoxInMenubar.SetCurSel( 0 );
	
	m_wndMenuBar.InsertButton(
		-1,
		ID_SEPARATOR
		);

	// init editbox in the menubar
	if(	!m_wndEditInMenubar.Create(
		WS_CHILD|WS_VISIBLE|WS_TABSTOP
		|ES_AUTOHSCROLL|ES_LEFT,
		CRect( 0, 0, 100, 18 ),
		&m_wndMenuBar,
		ID_EDIT_IN_MENUBAR
		)
		)
	{
		ASSERT( FALSE );
		return FALSE;
	}
	
	m_wndMenuBar.InsertButton(
		-1,
		ID_EDIT_IN_MENUBAR
		);
	VERIFY(
		m_wndMenuBar.SetButtonCtrl( 
		m_wndMenuBar.CommandToIndex(ID_EDIT_IN_MENUBAR), 
		&m_wndEditInMenubar )
		);
	
	m_wndEditInMenubar.SetFont(
		CFont::FromHandle(
		(HFONT)::GetStockObject(DEFAULT_GUI_FONT)
		)
		);
	m_wndEditInMenubar.SetWindowText( _T("Edit in menubar") );
	
	//////////////////////////////////////////////////////////////////////////

	ASSERT( m_wndToolBar.GetSafeHwnd() != NULL );
	if(	!m_wndToolBar.LoadToolBar( IDR_MAIN_TOOLBAR ) ){
		ASSERT( FALSE );
		return FALSE;
	}

	//////////////////////////////////////////////////////////////////////////
	
	ASSERT( m_wndToolBarControls1.GetSafeHwnd() != NULL );

	CExtCmdItem * pCmdItemSlider =
		g_CmdManager->CmdAllocPtr(
		_T("PageToolbars"),
		ID_MYEXTBTN_SLIDER
		);
 	ASSERT( pCmdItemSlider != NULL );
	pCmdItemSlider->m_sToolbarText = _T("Zoom:");
	pCmdItemSlider->m_sMenuText = _T("Zoom slider");
	pCmdItemSlider->m_sTipTool
		= pCmdItemSlider->m_sTipStatus
		= _T("Zoom slider");
	
	CExtCmdItem * pCmdItemScroller =
		g_CmdManager->CmdAllocPtr(
		_T("PageToolbars"),
		ID_MYEXTBTN_SCROLLER
		);
	ASSERT( pCmdItemScroller != NULL );
	pCmdItemScroller->m_sToolbarText = _T("Seek:");
	pCmdItemScroller->m_sMenuText = _T("Seek slider");
	pCmdItemScroller->m_sTipTool
		= pCmdItemScroller->m_sTipStatus
		= _T("Seek slider");
	

	CZoomBarSliderButton *pZoomSliderTBB =
		new CZoomBarSliderButton(
		/////////////////
		// standard CExtBarButton parms
		/////////////////
		&m_wndToolBarControls1,
		ID_MYEXTBTN_SLIDER,
		0,
		/////////////////
		// CExtBarSliderButton specific parms
		/////////////////
		//
		// scroll total/pos/page
		50, 25, 0,
		// button extent horz(left/right)/vert(up/down) in pixels
		// (if zeros - use slider-like layout instead of scrollbar-like)
		0, 0,
		// total slider control extent horz/vert in pixels
		100, 100
		);
	VERIFY(
		m_wndToolBarControls1.InsertSpecButton(
		-1,
		pZoomSliderTBB,
		FALSE
		)
		);
	
	CSeekBarSliderButton *pSeekScrollerTBB = new CSeekBarSliderButton(
		/////////////////
		// standard CExtBarButton parms
		/////////////////
		&m_wndToolBarControls1,
		ID_MYEXTBTN_SCROLLER,
		0,
		/////////////////
		// CExtBarScrollerButton specific parms
		/////////////////
		//
		// scroll total/pos/page
		100, 50, 0,
		// button extent horz(left/right)/vert(up/down) in pixels
		// (if zeros - use slider-like layout instead of scrollbar-like)
		10, 10,
		// total slider control extent horz/vert in pixels
		210, 210
		);
	VERIFY(
		m_wndToolBarControls1.InsertSpecButton(
		-1,
		pSeekScrollerTBB,
		FALSE
		)
		);

	VERIFY(
		m_wndToolBarControls1.InitContentExpandButton()
		);
	
	
	//////////////////////////////////////////////////////////////////////////
	
	ASSERT( m_wndToolBarControls2.GetSafeHwnd() != NULL );

	// init combobox in the toolbar
	if(	!m_wndComboBoxInToolbar.Create(
		WS_CHILD|WS_VISIBLE|WS_TABSTOP
		|CBS_DROPDOWN|CBS_HASSTRINGS,
		CRect( 0, 0, 150, 100 ),
		&m_wndToolBarControls2,
		ID_COMBOBOX_IN_TOOLBAR
		)
		)
	{
		ASSERT( FALSE );
		return FALSE;
	}

	m_wndToolBarControls2.InsertButton(
		-1,
		ID_COMBOBOX_IN_TOOLBAR
		);
	VERIFY(
		m_wndToolBarControls2.SetButtonCtrl( 
		m_wndToolBarControls2.CommandToIndex(ID_COMBOBOX_IN_TOOLBAR), 
		&m_wndComboBoxInToolbar )
		);
		
	m_wndComboBoxInToolbar.SetFont(
		CFont::FromHandle(
		(HFONT)::GetStockObject(DEFAULT_GUI_FONT)
		)
		);
	m_wndComboBoxInToolbar.AddString( _T("ComboBox in toolbar") );
	m_wndComboBoxInToolbar.SetCurSel( 0 );

	m_wndToolBarControls2.InsertButton(
		-1,
		ID_SEPARATOR
		);

	// init editbox in the toolbar
	if(	!m_wndEditInToolbar.Create(
		WS_CHILD|WS_VISIBLE|WS_TABSTOP
		|ES_AUTOHSCROLL|ES_LEFT,
		CRect( 0, 0, 100, 19 ),
		&m_wndToolBarControls2,
		ID_EDIT_IN_TOOLBAR
		)
		)
	{
		ASSERT( FALSE );
		return FALSE;
	}
	
	m_wndToolBarControls2.InsertButton(
		-1,
		ID_EDIT_IN_TOOLBAR
		);
	VERIFY(
		m_wndToolBarControls2.SetButtonCtrl( 
		m_wndToolBarControls2.CommandToIndex(ID_EDIT_IN_TOOLBAR), 
		&m_wndEditInToolbar )
		);
	
	m_wndEditInToolbar.SetFont(
		CFont::FromHandle(
		(HFONT)::GetStockObject(DEFAULT_GUI_FONT)
		)
		);
	m_wndEditInToolbar.SetWindowText( _T("Edit in toolbar") );

	VERIFY(
		m_wndToolBarControls2.InitContentExpandButton()
		);
	
	//////////////////////////////////////////////////////////////////////////

	ASSERT( m_wndToolBarColor.GetSafeHwnd() != NULL );
	VERIFY(
		m_wndToolBarColor.InsertButton(
		-1,
		ID_COLOR_BTN_HEIGHT,
		FALSE
		)
		);

	CMenu menuWidthCommands;
	VERIFY( menuWidthCommands.LoadMenu(IDR_COLOR_MENU) );
	VERIFY(
		m_wndToolBarColor.SetButtonMenu(
		m_wndToolBarColor.CommandToIndex(ID_COLOR_BTN_HEIGHT),
		menuWidthCommands.Detach(),
		TRUE,
		TRUE,
		FALSE
		)
		);
	VERIFY(
		m_wndToolBarColor.InsertButton( -1, ID_SEPARATOR, FALSE )
		);
	
	const int nLeftToolbarGrayscaleButtonsCount = 8;
	const int nLeftToolbarColorButtonsCount = 18;
	
	for( int nGrayscaleBtn = 0; nGrayscaleBtn < nLeftToolbarGrayscaleButtonsCount; nGrayscaleBtn++ )
	{
		VERIFY(
			m_wndToolBarColor.InsertSpecButton(
			-1,
			new CThinColorButtonInToolBar(
			CExtPaintManager::stat_HLStoRGB(
			0.0,
			double(nLeftToolbarGrayscaleButtonsCount - nGrayscaleBtn - 1)
			/ double(nLeftToolbarGrayscaleButtonsCount-1),
			0.0
			),
			&m_wndToolBarColor
			),
			FALSE
			)
			);
	}
	VERIFY(
		m_wndToolBarColor.InsertButton( -1, ID_SEPARATOR, FALSE )
		);

	for( int nColorBtn = 0; nColorBtn < nLeftToolbarColorButtonsCount; nColorBtn++ )
	{
		VERIFY(
			m_wndToolBarColor.InsertSpecButton(
			-1,
			new	CThinColorButtonInToolBar(
			CExtPaintManager::stat_HLStoRGB(
			double(nColorBtn) / double(nLeftToolbarColorButtonsCount),
			0.5,
			1.0
			),
			&m_wndToolBarColor
			),
			FALSE
			)
			);
	}
	
	VERIFY(
		m_wndToolBarColor.InitContentExpandButton()
		);

	
	//////////////////////////////////////////////////////////////////////////
	
	ASSERT( m_wndToolBarPalette.GetSafeHwnd() != NULL );

	if(	!m_wndToolBarPalette.LoadToolBar( IDR_PALETTE_TOOLBAR ) ){
		ASSERT( FALSE );
		return FALSE;
	}
	m_wndToolBarPalette.m_bPaletteMode = true;
	
	m_wndToolBarPalette.GetButton(3)->SetWrap( CExtBarButton::__EVT_FLOAT );
	m_wndToolBarPalette.GetButton(6)->SetWrap( CExtBarButton::__EVT_FLOAT );
	m_wndToolBarPalette.GetButton(9)->SetWrap( CExtBarButton::__EVT_FLOAT );
	m_wndToolBarPalette.GetButton(12)->SetWrap( CExtBarButton::__EVT_FLOAT );
	
	//////////////////////////////////////////////////////////////////////////
	
	static UINT g_statBasicCommands[] =
	{
			ID_HEIGHT_8PX,
			ID_HEIGHT_10PX,
			ID_HEIGHT_12PX,
			ID_HEIGHT_14PX,
			ID_HEIGHT_16PX,
			ID_HEIGHT_18PX,
			ID_HEIGHT_20PX,
			ID_HEIGHT_22PX,
			ID_HEIGHT_24PX,
			ID_HEIGHT_26PX,
			ID_HEIGHT_28PX,
			ID_HEIGHT_30PX,
			ID_COLOR_BTN_HEIGHT,
			0, // end of list
	};
	
	CExtCmdItem * pCmdItem =
		g_CmdManager->CmdAllocPtr(
		_T("PageToolbars"),
		ID_COLOR_BTN_HEIGHT
		);
	ASSERT( pCmdItem != NULL );
	pCmdItem->m_sToolbarText = pCmdItem->m_sMenuText
		= pCmdItem->m_sTipStatus = pCmdItem->m_sTipTool
		= _T( "Color cell height" );
	
	VERIFY(
		g_CmdManager->SetBasicCommands(
		_T("PageToolbars"),
		g_statBasicCommands
		)
		);

	//////////////////////////////////////////////////////////////////////////
	
	::CheckDlgButton( 
		this->GetSafeHwnd(), 
		IDC_CHECK_SHOW_GRIPPER, 
		BST_CHECKED
		);
	
	CWnd::RepositionBars(0,0xFFFF,0);
	
	m_bInitComplete = true;

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
コード例 #23
0
ファイル: npadBook.cpp プロジェクト: DLive/npadBook
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;
}
コード例 #24
0
ファイル: PanelMenu.cpp プロジェクト: 0vermind/NeoLoader
void CPanel::CreateSystemMenu(HMENU menuSpec,
    const CRecordVector<UInt32> &operatedIndices,
    CMyComPtr<IContextMenu> &systemContextMenu)
{
  systemContextMenu.Release();

  CreateShellContextMenu(operatedIndices, systemContextMenu);

  if (systemContextMenu == 0)
    return;
  
  // Set up a CMINVOKECOMMANDINFO structure.
  CMINVOKECOMMANDINFO ci;
  ZeroMemory(&ci, sizeof(ci));
  ci.cbSize = sizeof(CMINVOKECOMMANDINFO);
  ci.hwnd = GetParent();
  
  /*
  if (Sender == GoBtn)
  {
    // Verbs that can be used are cut, paste,
    // properties, delete, and so on.
    String action;
    if (CutRb->Checked)
      action = "cut";
    else if (CopyRb->Checked)
      action = "copy";
    else if (DeleteRb->Checked)
      action = "delete";
    else if (PropertiesRb->Checked)
      action = "properties";
    
    ci.lpVerb = action.c_str();
    result = cm->InvokeCommand(&ci);
    if (result)
      ShowMessage(
      "Error copying file to clipboard.");
    
  }
  else
  */
  {
    // HMENU hMenu = CreatePopupMenu();
    CMenu popupMenu;
    // CMenuDestroyer menuDestroyer(popupMenu);
    if(!popupMenu.CreatePopup())
      throw 210503;

    HMENU hMenu = popupMenu;

    DWORD Flags = CMF_EXPLORE;
    // Optionally the shell will show the extended
    // context menu on some operating systems when
    // the shift key is held down at the time the
    // context menu is invoked. The following is
    // commented out but you can uncommnent this
    // line to show the extended context menu.
    // Flags |= 0x00000080;
    systemContextMenu->QueryContextMenu(hMenu, 0, kSystemStartMenuID, 0x7FFF, Flags);
    

    {
      CMenu menu;
      menu.Attach(menuSpec);
      CMenuItem menuItem;
      menuItem.fMask = MIIM_SUBMENU | MIIM_TYPE | MIIM_ID;
      menuItem.fType = MFT_STRING;
      menuItem.hSubMenu = popupMenu.Detach();
      // menuDestroyer.Disable();
      menuItem.StringValue = LangString(IDS_SYSTEM, 0x030202A0);
      menu.InsertItem(0, true, menuItem);
    }
    /*
    if (Cmd < 100 && Cmd != 0)
    {
      ci.lpVerb = MAKEINTRESOURCE(Cmd - 1);
      ci.lpParameters = "";
      ci.lpDirectory = "";
      ci.nShow = SW_SHOWNORMAL;
      cm->InvokeCommand(&ci);
    }
    // If Cmd is > 100 then it's one of our
    // inserted menu items.
    else
      // Find the menu item.
      for (int i = 0; i < popupMenu1->Items->Count; i++)
      {
        TMenuItem* menu = popupMenu1->Items->Items[i];
        // Call its OnClick handler.
        if (menu->Command == Cmd - 100)
          menu->OnClick(this);
      }
      // Release the memory allocated for the menu.
      DestroyMenu(hMenu);
    */
  }
}
コード例 #25
0
BOOL CGeneralCRC::OnInitDialog()
{
	CDialog::OnInitDialog();

	settings_.push_back("Dummy");   // Reserve index 0 since we use the index as the menu ID and an ID of zero is not allowed

	// Create the popup menu to attach to the "Select" button
	CMenu mm;
	mm.CreatePopupMenu();

	// Add predefined CRC settings - add names to menu and store corresponding parameters strings in settings_
	mm.AppendMenu(MF_STRING, settings_.size(), "CRC 8");
	settings_.push_back("8|07|0|0|0|0|F4");
	mm.AppendMenu(MF_STRING, settings_.size(), "CRC 10");
	settings_.push_back("10|233|0|0|0|0|199");
	mm.AppendMenu(MF_STRING, settings_.size(), "CRC 12");
	settings_.push_back("12|80F|0|0|0|1|DAF");
	mm.AppendMenu(MF_STRING, settings_.size(), "CRC 16");
	settings_.push_back("16|8005|0|0|1|1|BB3D");
	mm.AppendMenu(MF_STRING, settings_.size(), "CRC 16 USB");
	settings_.push_back("16|8005|FFFF|FFFF|1|1|B4C8");
	mm.AppendMenu(MF_STRING, settings_.size(), "CRC 16 CCITT");
	settings_.push_back("16|1021|0|0|1|1|2189");
	mm.AppendMenu(MF_STRING, settings_.size(), "CRC CCITT F");
	settings_.push_back("16|1021|FFFF|0|0|0|29B1");
	mm.AppendMenu(MF_STRING, settings_.size(), "CRC CCITT AUG");
	settings_.push_back("16|1021|1D0F|0|0|0|E5CC");
	mm.AppendMenu(MF_STRING, settings_.size(), "CRC-A");
	settings_.push_back("16|1021|C6C6|0|1|1|BF05");
	mm.AppendMenu(MF_STRING, settings_.size(), "CRC X-25");
	settings_.push_back("16|1021|FFFF|FFFF|1|1|906E");
	mm.AppendMenu(MF_STRING, settings_.size(), "CRC XModem");
	settings_.push_back("16|1021|0|0|0|0|31C3");
	//mm.AppendMenu(MF_STRING, settings_.size(), "CRC XModem");
	//settings_.push_back("16|8408|0|0|1|1");
	mm.AppendMenu(MF_STRING, settings_.size(), "CRC 32");
	settings_.push_back("32|04C11DB7|FFFFFFFF|FFFFFFFF|1|1|CBF43926");
	mm.AppendMenu(MF_STRING, settings_.size(), "CRC MPEG-2");
	settings_.push_back("32|04C11DB7|FFFFFFFF|0|0|0|0376E6E7");

	mm.AppendMenu(MF_SEPARATOR);
	last_selected_ = -1;
	last_predefined_ = settings_.size();

	// Get any saved settings from the registry
	HKEY hkey;
	if (::RegCreateKey(HKEY_CURRENT_USER, reg_locn, &hkey) == ERROR_SUCCESS)
	{
		LONG err;                        // error return from registry enum function
		char name[80];                   // buffer to hold the name of any registry setting found
		BYTE value[80];                  // buffer to hold the value of any registry setting found
		DWORD name_len = sizeof(name), value_len = sizeof(value);  // corresponding buffer lengths
		DWORD type;                      // the type of registry entry found (we only want strings = REG_SZ)

		for (int ii = 0;
			(err = ::RegEnumValue(hkey, ii, name, &name_len, NULL, &type, value, &value_len)) != ERROR_NO_MORE_ITEMS;
			++ii)
		{
			// If we got a valid string entry
			if (err == ERROR_SUCCESS && type == REG_SZ)
			{
				mm.AppendMenu(MF_STRING, settings_.size(), name);
				settings_.push_back((char*)value);
			}

			// Reset in/out vars that have been modified
			name_len = sizeof(name);
			value_len = sizeof(value);
		}

		::RegCloseKey(hkey);
	}

	// Attach the menu to the button
	select_menu_.m_hMenu = mm.GetSafeHmenu();
	mm.Detach();

	OnChangeName();

	return TRUE;
}
コード例 #26
0
ファイル: ContextMenu.cpp プロジェクト: endlessm/rufus
STDMETHODIMP CZipContextMenu::QueryContextMenu(HMENU hMenu, UINT indexMenu,
      UINT commandIDFirst, UINT commandIDLast, UINT flags)
{
  // OutputDebugStringA("QueryContextMenu");

  LoadLangOneTime();
  if (_fileNames.Size() == 0)
    return E_FAIL;
  UINT currentCommandID = commandIDFirst;
  if ((flags & 0x000F) != CMF_NORMAL  &&
      (flags & CMF_VERBSONLY) == 0 &&
      (flags & CMF_EXPLORE) == 0)
    return MAKE_HRESULT(SEVERITY_SUCCESS, 0, currentCommandID);

  _commandMap.Clear();

  CMenu popupMenu;
  CMenuDestroyer menuDestroyer;

  CContextMenuInfo ci;
  ci.Load();

  _elimDup = ci.ElimDup;

  HBITMAP bitmap = NULL;
  if (ci.MenuIcons.Val)
    bitmap = _bitmap;

  UINT subIndex = indexMenu;
  
  if (ci.Cascaded.Val)
  {
    if (!popupMenu.CreatePopup())
      return E_FAIL;
    menuDestroyer.Attach(popupMenu);

    /* 9.31: we commented the following code. Probably we don't need.
    Check more systems. Maybe it was for old Windows? */
    /*
    AddMapItem_ForSubMenu();
    currentCommandID++;
    */
    subIndex = 0;
  }
  else
  {
    popupMenu.Attach(hMenu);
    CMenuItem mi;
    mi.fType = MFT_SEPARATOR;
    mi.fMask = MIIM_TYPE;
    popupMenu.InsertItem(subIndex++, true, mi);
  }

  UInt32 contextMenuFlags = ci.Flags;

  NFind::CFileInfo fi0;
  FString folderPrefix;
  
  if (_fileNames.Size() > 0)
  {
    const UString &fileName = _fileNames.Front();

    #if defined(_WIN32) && !defined(UNDER_CE)
    if (NName::IsDevicePath(us2fs(fileName)))
    {
      // CFileInfo::Find can be slow for device files. So we don't call it.
      // we need only name here.
      fi0.Name = us2fs(fileName.Ptr(NName::kDevicePathPrefixSize)); // change it 4 - must be constant
      folderPrefix =
        #ifdef UNDER_CE
          FTEXT("\\");
        #else
          FTEXT("C:\\");
        #endif
    }
    else
    #endif
    {
      if (!fi0.Find(us2fs(fileName)))
        return E_FAIL;
      GetOnlyDirPrefix(us2fs(fileName), folderPrefix);
    }
  }

  UString mainString;
  
  if (_fileNames.Size() == 1 && currentCommandID + 14 <= commandIDLast)
  {
    if (!fi0.IsDir() && DoNeedExtract(fi0.Name))
    {
      // Open
      bool thereIsMainOpenItem = ((contextMenuFlags & NContextMenuFlags::kOpen) != 0);
      if (thereIsMainOpenItem)
      {
        CCommandMapItem commandMapItem;
        FillCommand(kOpen, mainString, commandMapItem);
        MyInsertMenu(popupMenu, subIndex++, currentCommandID++, mainString, bitmap);
        _commandMap.Add(commandMapItem);
      }
      if ((contextMenuFlags & NContextMenuFlags::kOpenAs) != 0
          // && (!thereIsMainOpenItem || !FindExt(kNoOpenAsExtensions, fi0.Name))
          )
      {
        CMenu subMenu;
        if (subMenu.CreatePopup())
        {
          CMenuItem mi;
          mi.fType = MFT_STRING;
          mi.fMask = MIIM_SUBMENU | MIIM_TYPE | MIIM_ID;
          if (bitmap)
            mi.fMask |= MIIM_CHECKMARKS;
          mi.wID = currentCommandID++;
          mi.hSubMenu = subMenu;
          mi.hbmpUnchecked = bitmap;

          LangString(IDS_CONTEXT_OPEN, mi.StringValue);
          popupMenu.InsertItem(subIndex++, true, mi);
          AddMapItem_ForSubMenu(kOpenCascadedVerb);
          
          UINT subIndex2 = 0;
          for (unsigned i = (thereIsMainOpenItem ? 1 : 0); i < ARRAY_SIZE(kOpenTypes); i++)
          {
            CCommandMapItem commandMapItem;
            if (i == 0)
              FillCommand(kOpen, mainString, commandMapItem);
            else
            {
              mainString.SetFromAscii(kOpenTypes[i]);
              commandMapItem.CommandInternalID = kOpen;
              commandMapItem.Verb = (UString)kMainVerb + L".Open." + mainString;
              commandMapItem.HelpString = mainString;
              commandMapItem.ArcType = mainString;
            }
            MyInsertMenu(subMenu, subIndex2++, currentCommandID++, mainString, bitmap);
            _commandMap.Add(commandMapItem);
          }

          subMenu.Detach();
        }
      }
    }
  }

  if (_fileNames.Size() > 0 && currentCommandID + 10 <= commandIDLast)
  {
    bool needExtract = (!fi0.IsDir() && DoNeedExtract(fi0.Name));
    
    if (!needExtract)
    {
      for (unsigned i = 1; i < _fileNames.Size(); i++)
      {
        NFind::CFileInfo fi;
        if (!fi.Find(us2fs(_fileNames[i])))
          return E_FAIL;
        if (!fi.IsDir() && DoNeedExtract(fi.Name))
        {
          needExtract = true;
          break;
        }
      }
    }
    
    const UString &fileName = _fileNames.Front();
    
    if (needExtract)
    {
      {
        UString baseFolder = fs2us(folderPrefix);
        if (_dropMode)
          baseFolder = _dropPath;
    
        UString specFolder = L'*';
        if (_fileNames.Size() == 1)
          specFolder = GetSubFolderNameForExtract(fs2us(fi0.Name));
        specFolder.Add_PathSepar();

        if ((contextMenuFlags & NContextMenuFlags::kExtract) != 0)
        {
          // Extract
          CCommandMapItem commandMapItem;
          FillCommand(kExtract, mainString, commandMapItem);
          commandMapItem.Folder = baseFolder + specFolder;
          MyInsertMenu(popupMenu, subIndex++, currentCommandID++, mainString, bitmap);
          _commandMap.Add(commandMapItem);
        }

        if ((contextMenuFlags & NContextMenuFlags::kExtractHere) != 0)
        {
          // Extract Here
          CCommandMapItem commandMapItem;
          FillCommand(kExtractHere, mainString, commandMapItem);
          commandMapItem.Folder = baseFolder;
          MyInsertMenu(popupMenu, subIndex++, currentCommandID++, mainString, bitmap);
          _commandMap.Add(commandMapItem);
        }

        if ((contextMenuFlags & NContextMenuFlags::kExtractTo) != 0)
        {
          // Extract To
          CCommandMapItem commandMapItem;
          UString s;
          FillCommand(kExtractTo, s, commandMapItem);
          commandMapItem.Folder = baseFolder + specFolder;
          MyFormatNew_ReducedName(s, specFolder);
          MyInsertMenu(popupMenu, subIndex++, currentCommandID++, s, bitmap);
          _commandMap.Add(commandMapItem);
        }
      }

      if ((contextMenuFlags & NContextMenuFlags::kTest) != 0)
      {
        // Test
        CCommandMapItem commandMapItem;
        FillCommand(kTest, mainString, commandMapItem);
        MyInsertMenu(popupMenu, subIndex++, currentCommandID++, mainString, bitmap);
        _commandMap.Add(commandMapItem);
      }
    }
    
    UString arcName;
    if (_fileNames.Size() == 1)
      arcName = CreateArchiveName(fi0, false);
    else
      arcName = CreateArchiveName(fileName, _fileNames.Size() > 1, false);
    
    UString arcName7z = arcName + L".7z";
    UString arcNameZip = arcName + L".zip";

    // Compress
    if ((contextMenuFlags & NContextMenuFlags::kCompress) != 0)
    {
      CCommandMapItem commandMapItem;
      if (_dropMode)
        commandMapItem.Folder = _dropPath;
      else
        commandMapItem.Folder = fs2us(folderPrefix);
      commandMapItem.ArcName = arcName;
      FillCommand(kCompress, mainString, commandMapItem);
      MyInsertMenu(popupMenu, subIndex++, currentCommandID++, mainString, bitmap);
      _commandMap.Add(commandMapItem);
    }

    #ifdef EMAIL_SUPPORT
    // CompressEmail
    if ((contextMenuFlags & NContextMenuFlags::kCompressEmail) != 0 && !_dropMode)
    {
      CCommandMapItem commandMapItem;
      commandMapItem.ArcName = arcName;
      FillCommand(kCompressEmail, mainString, commandMapItem);
      MyInsertMenu(popupMenu, subIndex++, currentCommandID++, mainString, bitmap);
      _commandMap.Add(commandMapItem);
    }
    #endif

    // CompressTo7z
    if (contextMenuFlags & NContextMenuFlags::kCompressTo7z &&
        !arcName7z.IsEqualTo_NoCase(fs2us(fi0.Name)))
    {
      CCommandMapItem commandMapItem;
      UString s;
      FillCommand(kCompressTo7z, s, commandMapItem);
      if (_dropMode)
        commandMapItem.Folder = _dropPath;
      else
        commandMapItem.Folder = fs2us(folderPrefix);
      commandMapItem.ArcName = arcName7z;
      commandMapItem.ArcType.SetFromAscii("7z");
      MyFormatNew_ReducedName(s, arcName7z);
      MyInsertMenu(popupMenu, subIndex++, currentCommandID++, s, bitmap);
      _commandMap.Add(commandMapItem);
    }

    #ifdef EMAIL_SUPPORT
    // CompressTo7zEmail
    if ((contextMenuFlags & NContextMenuFlags::kCompressTo7zEmail) != 0  && !_dropMode)
    {
      CCommandMapItem commandMapItem;
      UString s;
      FillCommand(kCompressTo7zEmail, s, commandMapItem);
      commandMapItem.ArcName = arcName7z;
      commandMapItem.ArcType.SetFromAscii("7z");
      MyFormatNew_ReducedName(s, arcName7z);
      MyInsertMenu(popupMenu, subIndex++, currentCommandID++, s, bitmap);
      _commandMap.Add(commandMapItem);
    }
    #endif

    // CompressToZip
    if (contextMenuFlags & NContextMenuFlags::kCompressToZip &&
        !arcNameZip.IsEqualTo_NoCase(fs2us(fi0.Name)))
    {
      CCommandMapItem commandMapItem;
      UString s;
      FillCommand(kCompressToZip, s, commandMapItem);
      if (_dropMode)
        commandMapItem.Folder = _dropPath;
      else
        commandMapItem.Folder = fs2us(folderPrefix);
      commandMapItem.ArcName = arcNameZip;
      commandMapItem.ArcType.SetFromAscii("zip");
      MyFormatNew_ReducedName(s, arcNameZip);
      MyInsertMenu(popupMenu, subIndex++, currentCommandID++, s, bitmap);
      _commandMap.Add(commandMapItem);
    }

    #ifdef EMAIL_SUPPORT
    // CompressToZipEmail
    if ((contextMenuFlags & NContextMenuFlags::kCompressToZipEmail) != 0  && !_dropMode)
    {
      CCommandMapItem commandMapItem;
      UString s;
      FillCommand(kCompressToZipEmail, s, commandMapItem);
      commandMapItem.ArcName = arcNameZip;
      commandMapItem.ArcType.SetFromAscii("zip");
      MyFormatNew_ReducedName(s, arcNameZip);
      MyInsertMenu(popupMenu, subIndex++, currentCommandID++, s, bitmap);
      _commandMap.Add(commandMapItem);
    }
    #endif
  }


  // don't use InsertMenu:  See MSDN:
  // PRB: Duplicate Menu Items In the File Menu For a Shell Context Menu Extension
  // ID: Q214477
  
  if (ci.Cascaded.Val)
  {
    CMenuItem mi;
    mi.fType = MFT_STRING;
    mi.fMask = MIIM_SUBMENU | MIIM_TYPE | MIIM_ID;
    if (bitmap)
      mi.fMask |= MIIM_CHECKMARKS;
    mi.wID = currentCommandID++;
    mi.hSubMenu = popupMenu.Detach();
    mi.StringValue.SetFromAscii("7-Zip"); // LangString(IDS_CONTEXT_POPUP_CAPTION);
    mi.hbmpUnchecked = bitmap;
    
    CMenu menu;
    menu.Attach(hMenu);
    menuDestroyer.Disable();
    menu.InsertItem(indexMenu++, true, mi);
    
    AddMapItem_ForSubMenu(kMainVerb);
  }
  else
  {
    popupMenu.Detach();
    indexMenu = subIndex;
  }

  
  if (!_isMenuForFM &&
      ((contextMenuFlags & NContextMenuFlags::kCRC) != 0
      && currentCommandID + 6 <= commandIDLast))
  {
    CMenu subMenu;
    // CMenuDestroyer menuDestroyer_CRC;
    
    UINT subIndex_CRC = 0;
    
    if (subMenu.CreatePopup())
    {
      // menuDestroyer_CRC.Attach(subMenu);
      CMenuItem mi;
      mi.fType = MFT_STRING;
      mi.fMask = MIIM_SUBMENU | MIIM_TYPE | MIIM_ID;
      if (bitmap)
        mi.fMask |= MIIM_CHECKMARKS;
      mi.wID = currentCommandID++;
      mi.hSubMenu = subMenu;
      mi.StringValue.SetFromAscii("CRC SHA");
      mi.hbmpUnchecked = bitmap;
      
      CMenu menu;
      menu.Attach(hMenu);
      // menuDestroyer_CRC.Disable();
      menu.InsertItem(indexMenu++, true, mi);
      
      AddMapItem_ForSubMenu(kCheckSumCascadedVerb);

      for (unsigned i = 0; i < ARRAY_SIZE(g_HashCommands); i++)
      {
        const CHashCommand &hc = g_HashCommands[i];
        CCommandMapItem commandMapItem;
        commandMapItem.CommandInternalID = hc.CommandInternalID;
        commandMapItem.Verb = (UString)kCheckSumCascadedVerb + (UString)hc.MethodName;
        // commandMapItem.HelpString = hc.Name;
        MyInsertMenu(subMenu, subIndex_CRC++, currentCommandID++, hc.UserName, bitmap);
        _commandMap.Add(commandMapItem);
      }
      
      subMenu.Detach();
    }
  }

  return MAKE_HRESULT(SEVERITY_SUCCESS, 0, currentCommandID - commandIDFirst);
}
コード例 #27
0
ファイル: MainFrm.cpp プロジェクト: tsly2015/VC-
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
		return -1;

	if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
		!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
	{
		TRACE0("Failed to create toolbar\n");
		return -1;      // fail to create
	}

	if (!m_wndStatusBar.Create(this))
	{
		TRACE0("Failed to create status bar\n");
		return -1;      // fail to create
	}
	m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT));

	// TODO: Delete these three lines if you don't want the toolbar to be dockable
	m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
	EnableDocking(CBRS_ALIGN_ANY);
	DockControlBar(&m_wndToolBar);

	SetMenu(NULL);

	CMenu menu;
	menu.LoadMenu(IDR_MAINFRAME);
	SetMenu(&menu);
	menu.Detach();

	//auto format: Ctrl + K + F (selection), Ctrl + K + D (document)
	//GetMenu()->GetSubMenu(0)->CheckMenuItem(0, MF_BYPOSITION | MFS_CHECKED);
	GetMenu()->GetSubMenu(0)->CheckMenuItem(ID_FILE_NEW, MF_BYCOMMAND | MFS_CHECKED);
	//GetMenu()->GetSubMenu(0)->SetDefaultItem(1, TRUE);
	GetMenu()->GetSubMenu(0)->SetDefaultItem(ID_FILE_OPEN, FALSE); //overwritten by next line
	GetMenu()->GetSubMenu(0)->SetDefaultItem(5, TRUE);

	//CString str;
	//str.Format(L"x=%d, y=%d", GetSystemMetrics(SM_CXMENUCHECK), GetSystemMetrics(SM_CXMENUCHECK));
	//MessageBox(str);

	m_bitmap1.LoadBitmap(IDB_BITMAP1);
	m_bitmap2.LoadBitmap(IDB_BITMAP2);
	GetMenu()->GetSubMenu(2)->SetMenuItemBitmaps(0, MF_BYPOSITION, &m_bitmap1, &m_bitmap2);

	//GetMenu()->GetSubMenu(0)->EnableMenuItem(1, MF_BYPOSITION | MF_DISABLED | MF_GRAYED);

	CMenu menu2;
	menu2.CreateMenu();
	//GetMenu()->AppendMenu(MF_POPUP, (UINT)menu2.m_hMenu, L"Test2");
	GetMenu()->InsertMenu(2, MF_POPUP | MF_BYPOSITION, (UINT)menu2.m_hMenu, L"Test3");
	//menu2.AppendMenu(MF_STRING, 111, L"Hello");
	menu2.AppendMenu(MF_STRING, IDM_HELLO, L"Hello");
	menu2.AppendMenu(MF_STRING, 112, L"Bye");
	GetMenu()->GetSubMenu(0)->InsertMenu(ID_FILE_OPEN, MF_BYCOMMAND | MF_STRING, 113, L"VC");
	//GetMenu()->DeleteMenu(1, MF_BYPOSITION);
	GetMenu()->GetSubMenu(0)->DeleteMenu(1, MF_BYPOSITION);

	menu2.Detach();

	return 0;
}
コード例 #28
0
STDMETHODIMP CZipContextMenu::QueryContextMenu(HMENU hMenu, UINT indexMenu,
      UINT commandIDFirst, UINT commandIDLast, UINT flags)
{
  LoadLangOneTime();
  if (_fileNames.Size() == 0)
    return E_FAIL;
  UINT currentCommandID = commandIDFirst;
  if ((flags & 0x000F) != CMF_NORMAL  &&
      (flags & CMF_VERBSONLY) == 0 &&
      (flags & CMF_EXPLORE) == 0)
    return MAKE_HRESULT(SEVERITY_SUCCESS, 0, currentCommandID);

  _commandMap.Clear();

  CMenu popupMenu;
  CMenuDestroyer menuDestroyer;

  CContextMenuInfo ci;
  ci.Load();
  MENUITEMINFO menuItem;
  UINT subIndex = indexMenu;
  if (ci.Cascaded)
  {
    CCommandMapItem commandMapItem;
    if (!popupMenu.CreatePopup())
      return E_FAIL;
    menuDestroyer.Attach(popupMenu);
    commandMapItem.CommandInternalID = kCommandNULL;
    commandMapItem.Verb = kMainVerb;
    commandMapItem.HelpString = LangString(IDS_CONTEXT_CAPTION_HELP, 0x02000102);
    _commandMap.Add(commandMapItem);
    
    menuItem.wID = currentCommandID++;
    subIndex = 0;
  }
  else
  {
    popupMenu.Attach(hMenu);
  }

  UInt32 contextMenuFlags = ci.Flags;

  UString mainString;
  if (_fileNames.Size() == 1 && currentCommandID + 6 <= commandIDLast)
  {
    const UString &fileName = _fileNames.Front();
    UString folderPrefix;
    NFile::NDirectory::GetOnlyDirPrefix(fileName, folderPrefix);
   
    NFile::NFind::CFileInfoW fileInfo;
    if (!fileInfo.Find(fileName))
      return E_FAIL;
    if (!fileInfo.IsDir() && DoNeedExtract(fileInfo.Name))
    {
      // Open
      bool thereIsMainOpenItem = ((contextMenuFlags & NContextMenuFlags::kOpen) != 0);
      if (thereIsMainOpenItem)
      {
        CCommandMapItem commandMapItem;
        FillCommand(kOpen, mainString, commandMapItem);
        MyInsertMenu(popupMenu, subIndex++, currentCommandID++, mainString);
        _commandMap.Add(commandMapItem);
      }
      if ((contextMenuFlags & NContextMenuFlags::kOpenAs) != 0 &&
          (!thereIsMainOpenItem || !FindExt(kNoOpenAsExtensions, fileInfo.Name)))
      {
        CMenu subMenu;
        if (subMenu.CreatePopup())
        {
          CCommandMapItem commandMapItem;
          
          CMenuItem menuItem;
          menuItem.fType = MFT_STRING;
          menuItem.fMask = MIIM_SUBMENU | MIIM_TYPE | MIIM_ID;
          menuItem.wID = currentCommandID++;
          menuItem.hSubMenu = subMenu;
          menuItem.StringValue = LangString(IDS_CONTEXT_OPEN, 0x02000103);
          popupMenu.InsertItem(subIndex++, true, menuItem);
          
          commandMapItem.CommandInternalID = kCommandNULL;
          commandMapItem.Verb = kMainVerb;
          commandMapItem.HelpString = LangString(IDS_CONTEXT_OPEN_HELP, 0x02000104);
          _commandMap.Add(commandMapItem);
          
          UINT subIndex2 = 0;
          const wchar_t *exts[] = { L"", L"*", L"7z", L"zip", L"cab", L"rar" };
          for (int i = (thereIsMainOpenItem ? 1 : 0); i < sizeof(exts) / sizeof(exts[0]); i++)
          {
            CCommandMapItem commandMapItem;
            if (i == 0)
              FillCommand(kOpen, mainString, commandMapItem);
            else
            {
              mainString = exts[i];
              commandMapItem.CommandInternalID = kOpen;
              commandMapItem.Verb = (UString)kMainVerb + L".Open." + mainString;
              commandMapItem.HelpString = mainString;
              commandMapItem.ArcType = mainString;
            }
            MyInsertMenu(subMenu, subIndex2++, currentCommandID++, mainString);
            _commandMap.Add(commandMapItem);
          }
          subMenu.Detach();
        }
      }
    }
  }

  if (_fileNames.Size() > 0 && currentCommandID + 10 <= commandIDLast)
  {
    bool needExtract = false;
    for(int i = 0; i < _fileNames.Size(); i++)
    {
      NFile::NFind::CFileInfoW fileInfo;
      if (!fileInfo.Find(_fileNames[i]))
        return E_FAIL;
      if (!fileInfo.IsDir() && DoNeedExtract(fileInfo.Name))
        needExtract = true;
    }
    const UString &fileName = _fileNames.Front();
    if (needExtract)
    {
      UString folderPrefix;
      NFile::NDirectory::GetOnlyDirPrefix(fileName, folderPrefix);
      NFile::NFind::CFileInfoW fileInfo;
      if (!fileInfo.Find(fileName))
        return E_FAIL;
      // Extract
      if ((contextMenuFlags & NContextMenuFlags::kExtract) != 0)
      {
        CCommandMapItem commandMapItem;
        FillCommand(kExtract, mainString, commandMapItem);
        if (_dropMode)
          commandMapItem.Folder = _dropPath;
        else
          commandMapItem.Folder = folderPrefix;
        commandMapItem.Folder += GetSubFolderNameForExtract(fileInfo.Name) + UString(WCHAR_PATH_SEPARATOR);
        MyInsertMenu(popupMenu, subIndex++, currentCommandID++, mainString);
        _commandMap.Add(commandMapItem);
      }

      // Extract Here
      if ((contextMenuFlags & NContextMenuFlags::kExtractHere) != 0)
      {
        CCommandMapItem commandMapItem;
        FillCommand(kExtractHere, mainString, commandMapItem);
        MyInsertMenu(popupMenu, subIndex++, currentCommandID++, mainString);
        if (_dropMode)
          commandMapItem.Folder = _dropPath;
        else
          commandMapItem.Folder = folderPrefix;
        _commandMap.Add(commandMapItem);
      }

      // Extract To
      if ((contextMenuFlags & NContextMenuFlags::kExtractTo) != 0)
      {
        CCommandMapItem commandMapItem;
        UString s;
        FillCommand(kExtractTo, s, commandMapItem);
        UString folder;
        if (_fileNames.Size() == 1)
          folder = GetSubFolderNameForExtract(fileInfo.Name);
        else
          folder = L'*';
        if (_dropMode)
          commandMapItem.Folder = _dropPath;
        else
          commandMapItem.Folder = folderPrefix;
        commandMapItem.Folder += folder;
        s = MyFormatNew(s, GetQuotedReducedString(folder + UString(WCHAR_PATH_SEPARATOR)));
        MyInsertMenu(popupMenu, subIndex++, currentCommandID++, s);
        _commandMap.Add(commandMapItem);
      }
      // Test
      if ((contextMenuFlags & NContextMenuFlags::kTest) != 0)
      {
        CCommandMapItem commandMapItem;
        FillCommand(kTest, mainString, commandMapItem);
        MyInsertMenu(popupMenu, subIndex++, currentCommandID++, mainString);
        _commandMap.Add(commandMapItem);
      }
    }
    UString archiveName = CreateArchiveName(fileName, _fileNames.Size() > 1, false);
    UString archiveName7z = archiveName + L".7z";
    UString archiveNameZip = archiveName + L".zip";
    UString archivePathPrefix;
    NFile::NDirectory::GetOnlyDirPrefix(fileName, archivePathPrefix);

    // Compress
    if ((contextMenuFlags & NContextMenuFlags::kCompress) != 0)
    {
      CCommandMapItem commandMapItem;
      if (_dropMode)
        commandMapItem.Folder = _dropPath;
      else
        commandMapItem.Folder = archivePathPrefix;
      commandMapItem.ArcName = archiveName;
      FillCommand(kCompress, mainString, commandMapItem);
      MyInsertMenu(popupMenu, subIndex++, currentCommandID++, mainString);
      _commandMap.Add(commandMapItem);
    }

    #ifdef EMAIL_SUPPORT
    // CompressEmail
    if ((contextMenuFlags & NContextMenuFlags::kCompressEmail) != 0 && !_dropMode)
    {
      CCommandMapItem commandMapItem;
      commandMapItem.ArcName = archiveName;
      FillCommand(kCompressEmail, mainString, commandMapItem);
      MyInsertMenu(popupMenu, subIndex++, currentCommandID++, mainString);
      _commandMap.Add(commandMapItem);
    }
    #endif

    // CompressTo7z
    if (contextMenuFlags & NContextMenuFlags::kCompressTo7z)
    {
      CCommandMapItem commandMapItem;
      UString s;
      FillCommand(kCompressTo7z, s, commandMapItem);
      if (_dropMode)
        commandMapItem.Folder = _dropPath;
      else
        commandMapItem.Folder = archivePathPrefix;
      commandMapItem.ArcName = archiveName7z;
      commandMapItem.ArcType = L"7z";
      s = MyFormatNew(s, GetQuotedReducedString(archiveName7z));
      MyInsertMenu(popupMenu, subIndex++, currentCommandID++, s);
      _commandMap.Add(commandMapItem);
    }

    #ifdef EMAIL_SUPPORT
    // CompressTo7zEmail
    if ((contextMenuFlags & NContextMenuFlags::kCompressTo7zEmail) != 0  && !_dropMode)
    {
      CCommandMapItem commandMapItem;
      UString s;
      FillCommand(kCompressTo7zEmail, s, commandMapItem);
      commandMapItem.ArcName = archiveName7z;
      commandMapItem.ArcType = L"7z";
      s = MyFormatNew(s, GetQuotedReducedString(archiveName7z));
      MyInsertMenu(popupMenu, subIndex++, currentCommandID++, s);
      _commandMap.Add(commandMapItem);
    }
    #endif

    // CompressToZip
    if (contextMenuFlags & NContextMenuFlags::kCompressToZip)
    {
      CCommandMapItem commandMapItem;
      UString s;
      FillCommand(kCompressToZip, s, commandMapItem);
      if (_dropMode)
        commandMapItem.Folder = _dropPath;
      else
        commandMapItem.Folder = archivePathPrefix;
      commandMapItem.ArcName = archiveNameZip;
      commandMapItem.ArcType = L"zip";
      s = MyFormatNew(s, GetQuotedReducedString(archiveNameZip));
      MyInsertMenu(popupMenu, subIndex++, currentCommandID++, s);
      _commandMap.Add(commandMapItem);
    }

    #ifdef EMAIL_SUPPORT
    // CompressToZipEmail
    if ((contextMenuFlags & NContextMenuFlags::kCompressToZipEmail) != 0  && !_dropMode)
    {
      CCommandMapItem commandMapItem;
      UString s;
      FillCommand(kCompressToZipEmail, s, commandMapItem);
      commandMapItem.ArcName = archiveNameZip;
      commandMapItem.ArcType = L"zip";
      s = MyFormatNew(s, GetQuotedReducedString(archiveNameZip));
      MyInsertMenu(popupMenu, subIndex++, currentCommandID++, s);
      _commandMap.Add(commandMapItem);
    }
    #endif
  }


  // don't use InsertMenu:  See MSDN:
  // PRB: Duplicate Menu Items In the File Menu For a Shell Context Menu Extension
  // ID: Q214477

  if (ci.Cascaded)
  {
    CMenuItem menuItem;
    menuItem.fType = MFT_STRING;
    menuItem.fMask = MIIM_SUBMENU | MIIM_TYPE | MIIM_ID;
    menuItem.wID = currentCommandID++;
    menuItem.hSubMenu = popupMenu.Detach();
    menuDestroyer.Disable();
    menuItem.StringValue = LangString(IDS_CONTEXT_POPUP_CAPTION, 0x02000101);
    CMenu menu;
    menu.Attach(hMenu);
    menu.InsertItem(indexMenu++, true, menuItem);
  }

  return MAKE_HRESULT(SEVERITY_SUCCESS, 0, currentCommandID - commandIDFirst);
}
コード例 #29
0
int BrowserPanelWnd::AddFavUrlToMenu( int &nStartItemID, int nStartPos, const char* szPath, CMenu* pMenu )
{
	vector<string>	m_arrSubDir;
	CString strPath = szPath;
	int curCnt = 0;

	if(strPath[strPath.GetLength() - 1] != _T('\\'))
		strPath += _T('\\');
	CString strFind = strPath + "*.*";

	WIN32_FIND_DATA	findData;
	HANDLE	hFile = NULL;

	hFile = FindFirstFile(strFind, &findData);
	if (hFile != INVALID_HANDLE_VALUE)
	{
		do 
		{
			if ( strcmp(".", findData.cFileName )==0
				|| strcmp("..", findData.cFileName)==0)
			{
				continue;
			}

			// 略过隐藏文件和系统文件
			if ( (findData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
				|| (findData.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM))
			{
				continue;
			}

			// 目录
			if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
			{
				string strSubDir = strPath;
				strSubDir += findData.cFileName;
				m_arrSubDir.push_back(strSubDir);
			}

			// 文件
			CString strFileName = findData.cFileName;
			strFileName.MakeLower();
			if (strFileName.Right(4) == ".url")
			{
				char szUrl[MAX_PATH] = {0};
				::GetPrivateProfileString(_T("InternetShortcut"), _T("URL"),
					"", szUrl, 400,
					strPath+strFileName);

				strFileName = strFileName.Left(strFileName.GetLength() - 4);

				m_arrFavMenuItemParam.push_back(szUrl);
				pMenu->AppendMenu(MF_STRING|MF_ENABLED, nStartItemID++, strFileName.GetBuffer(0));
				strFileName.ReleaseBuffer();
				curCnt++;
			}

		} while (FindNextFile(hFile, &findData));
	}
	FindClose(hFile);

	vector<string>::iterator it = m_arrSubDir.begin();
	for (; it != m_arrSubDir.end(); it++)
	{
		CMenu *pSubMenu = new CMenu;
		pSubMenu->CreatePopupMenu();

		int n = AddFavUrlToMenu(nStartItemID, 0, it->c_str(), pSubMenu);
		if (n > 0)
		{
			string dir = *it;
			size_t pos = dir.rfind('\\');
			dir = dir.substr(pos+1, dir.length()-pos);
			pMenu->InsertMenu(nStartItemID++, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT)pSubMenu->m_hMenu, dir.c_str());
			pSubMenu->Detach();
			m_arrFavMenuItemParam.push_back(it->c_str());
			curCnt++;
		}
		delete pSubMenu;
	}

	return curCnt;
}
コード例 #30
0
ファイル: MenuBar.cpp プロジェクト: yning/FormerWork
//////////////////
// Track the popup submenu associated with the i'th button in the menu bar.
// This fn actually goes into a loop, tracking different menus until the user
// selects a command or exits the menu.
//
void CMenuBar::TrackPopup(int iButton)
{
	ASSERT_VALID(this);
	ASSERT(m_hmenu);

	g_bRTab = FALSE;
	CMenu menu;
	menu.Attach(m_hmenu);
	int nMenuItems = menu.GetMenuItemCount();
	
	while (iButton >= 0)// while user selects another menu
	{					 
		m_iNewPopup = -1;						 // assume quit after this
		GetToolBarCtrl().PressButton(iButton, TRUE);		 // press the button
		UpdateWindow();						 // and force repaint now

		// post a simulated arrow-down into the message stream
		// so TrackPopupMenu will read it and move to the first item
		AfxGetApp()->m_pMainWnd->PostMessage(WM_KEYDOWN, VK_DOWN, 1);
		AfxGetApp()->m_pMainWnd->PostMessage(WM_KEYUP, VK_DOWN, 1);

		SetTrackingState(TRACK_POPUP, iButton); // enter tracking state

		// Need to install a hook to trap menu input in order to make
		// left/right-arrow keys and "hot" mouse tracking work.
		//
		g_pMenuBar = this;
		g_hMsgHook = SetWindowsHookEx(WH_MSGFILTER,
			MenuInputFilter, NULL, ::GetCurrentThreadId());
		if(g_hMsgHook==NULL)
			g_hMsgHook = SetWindowsHookEx(WH_MSGFILTER,
				MenuInputFilter, NULL, ::GetCurrentThreadId());
		// get submenu and display it beneath button
		TPMPARAMS tpm;
		CRect rcButton;
		GetToolBarCtrl().GetRect(iButton, rcButton);
		ClientToScreen(&rcButton);
		CPoint pt = ComputeMenuTrackPoint(rcButton, tpm);
		HMENU hMenuPopup = ::GetSubMenu(m_hmenu, iButton);
		ASSERT(hMenuPopup);

		//CToolMenu submenu;
		submenu.Detach();
		submenu.m_pImg = &m_ImgList;
		submenu.Attach(hMenuPopup);
		BOOL bRet = submenu.TrackPopupMenu(TPM_LEFTALIGN|TPM_LEFTBUTTON|TPM_VERTICAL,pt.x, pt.y, AfxGetApp()->m_pMainWnd);

		// uninstall hook.
		::UnhookWindowsHookEx(g_hMsgHook);
		g_hMsgHook = NULL;
		g_pMenuBar = NULL;
		
		GetToolBarCtrl().PressButton(iButton, FALSE);	 // un-press button
		UpdateWindow();					 // and force repaint now

		// If the user exited the menu loop by pressing Escape,
		// return to track-button state; otherwise normal non-tracking state.
		SetTrackingState(m_bEscapeWasPressed ?
			TRACK_BUTTON : TRACK_NONE, iButton);

		// If the user moved mouse to a new top-level popup (eg from File to
		// Edit button), I will have posted a WM_CANCELMODE to quit
		// the first popup, and set m_iNewPopup to the new menu to show.
		// Otherwise, m_iNewPopup will be -1 as set above.
		// So just set iButton to the next popup menu and keep looping...
		iButton = m_iNewPopup;
		//submenu.Detach();
	}
	menu.Detach();
}