示例#1
0
void CAddCADFrameMenu::ClearMenu(IAcadPopupMenus *mnus,LPCTSTR menuname)
{
	long cnt = 0l;
	HRESULT hr = mnus->get_Count(&cnt);

	//now get Tools menu
	IAcadPopupMenu *toolsMenu = NULL;
	BSTR   tempName;
	VARIANT vtName;
	VariantInit(&vtName);

	bool found = false;
	for (long i=0; i < cnt; i++){
		vtName.vt = VT_I4;
		vtName.lVal = i;
		hr = mnus->Item(vtName, &toolsMenu);
		if (FAILED(hr))
			return ;

		hr = toolsMenu->get_NameNoMnemonic(&tempName);
		CString mnuName(tempName);
		SysFreeString(tempName);
		if(mnuName.CompareNoCase(menuname)==0)
		{
			found = true;
			break;
		}
	}

	if (!found)
	{
		acutPrintf(_T("没有找到菜单 : %s "),menuname);
		return;
	}

	hr = toolsMenu->get_Count(&cnt);
	VARIANT vIndex;
	vIndex.vt = VT_I4;
	vIndex.lVal = cnt;
	IAcadPopupMenuItem *cmd1 = NULL;
	while(cnt--)
	{
		vIndex.lVal=cnt;
		hr=toolsMenu->Item(vIndex,&cmd1);
		hr=cmd1->Delete();
		cmd1->Release();
	}

	toolsMenu->RemoveFromMenuBar();
	toolsMenu->Release();

	mnus->RemoveMenuFromMenuBar(vtName);

	return;

}
示例#2
0
void CleanUpMenus()
{
    IAcadMenuGroup *mnuGrp = NULL;
    if (!getAcadMenuGroup(&mnuGrp))
        return ;

    //now get all the popup menus
    IAcadPopupMenus  *mnus = NULL;
    HRESULT hr = S_OK;
    hr = mnuGrp->get_Menus(&mnus);
    long cnt = 0l;
    hr = mnus->get_Count(&cnt);
    mnuGrp->Release();

    //now get Tools menu
    IAcadPopupMenu *toolsMenu = NULL;
    BSTR   tempName;
    VARIANT vtName;
    bool found = false;
    for (long i=0; i < cnt; i++)
    {
        vtName.vt = VT_I4;
        vtName.lVal = i;
        hr = mnus->Item(vtName, &toolsMenu);
        if (FAILED(hr))
            return ;

        hr = toolsMenu->get_NameNoMnemonic(&tempName);
        CString mnuName(tempName);
        SysFreeString(tempName);
        if(mnuName.CompareNoCase("Tools")==0)
        {
            found = true;
            break;
        }
    }
    mnus->Release();

    if (!found)
    {
        acutPrintf("Could not found tools menu\n");
        return;
    }

    hr = toolsMenu->get_Count(&cnt);
    VARIANT vIndex;
    vIndex.vt = VT_I4;
    vIndex.lVal = cnt;
    IAcadPopupMenu  *polySampCmds = NULL;
    IAcadPopupMenuItem *cmd1 = NULL;
    long index = 0l;
    for ( i=0; i < cnt; i++)
    {
        vtName.vt = VT_I4;
        vtName.lVal = i;
        hr = toolsMenu->Item(vtName, &cmd1);
        hr = cmd1->get_Label(&tempName);
        CString mnuName(tempName);
        SysFreeString(tempName);
        if(mnuName.CompareNoCase("PolySamp Application")==0)
        {   index = i-1;
            break;
        }
    }

    vIndex.vt = VT_I4;
    vIndex.lVal = index;
    //Remove all the menus loaded by this program
    IAcadPopupMenuItem *tempItem = NULL;
    hr = toolsMenu->Item(vIndex, &tempItem);
    hr = tempItem->Delete();
    tempItem->Release();
    hr = toolsMenu->Item(vIndex, &tempItem);
    hr = tempItem->Delete();
    tempItem->Release();
    toolsMenu->Release();


    return;
}
示例#3
0
void CreateMenus()
{

    IAcadMenuGroup *mnuGrp = NULL;
    if (!getAcadMenuGroup(&mnuGrp))
        return ;

    //now get all the popup menus
    IAcadPopupMenus  *mnus = NULL;
    HRESULT hr = S_OK;
    hr = mnuGrp->get_Menus(&mnus);
    long cnt = 0l;
    hr = mnus->get_Count(&cnt);
    mnuGrp->Release();

    //now get Tools menu
    IAcadPopupMenu *toolsMenu = NULL;
    BSTR   tempName;
    VARIANT vtName;
    bool found = false;
    for (long i=0; i < cnt; i++)
    {
        vtName.vt = VT_I4;
        vtName.lVal = i;
        hr = mnus->Item(vtName, &toolsMenu);
        if (FAILED(hr))
            return ;

        hr = toolsMenu->get_NameNoMnemonic(&tempName);
        CString mnuName(tempName);

        if(mnuName.CompareNoCase("Tools")==0)
        {
            found = true;
            break;
        }
    }
    mnus->Release();
    if (!found)
    {
        acutPrintf("Could not found tools menu\n");
        return;
    }

    hr = toolsMenu->get_Count(&cnt);
    VARIANT  vtIndex;
    vtIndex.vt = VT_I4;
    vtIndex.lVal = cnt + 1;
    IAcadPopupMenuItem  *item1 = NULL;
    hr = toolsMenu->AddSeparator(vtIndex, &item1);
    item1->Release();
    vtIndex.lVal = cnt + 2;
    IAcadPopupMenu *polyMnu = NULL;
    hr = toolsMenu->AddSubMenu(vtIndex, L"Polysamp Application", &polyMnu);
    toolsMenu->Release();


    IAcadPopupMenuItem *polycmds = NULL;
    vtIndex.lVal = 0;
    hr = polyMnu->AddMenuItem(vtIndex, L"POLY", L"_poly ", &polycmds);

    vtIndex.lVal = 1;
    hr = polyMnu->AddMenuItem(vtIndex, L"POLYEDIT", L"_polyedit ", &polycmds);
    vtIndex.lVal = 2;
    hr = polyMnu->AddMenuItem(vtIndex, L"TRANSACT", L"_TRANSACT ", &polycmds);
    vtIndex.lVal = 3;
    hr = polyMnu->AddMenuItem(vtIndex, L"HILITPOLY", L"_HILITPOLY ", &polycmds);
    vtIndex.lVal = 4;
    hr = polyMnu->AddMenuItem(vtIndex, L"CREATEINSERT", L"_CREATEINSERT ", &polycmds);
    vtIndex.lVal = 5;
    hr = polyMnu->AddMenuItem(vtIndex, L"HILITINSERT", L"_HILITINSERT ", &polycmds);
    vtIndex.lVal = 6;
    hr = polyMnu->AddMenuItem(vtIndex, L"USEDRAGDATA", L"_USEDRAGDATA ", &polycmds);
    vtIndex.lVal = 7;
    hr = polyMnu->AddMenuItem(vtIndex, L"HILITINSERT", L"_HILITINSERT ", &polycmds);
    vtIndex.lVal = 8;
    hr = polyMnu->AddMenuItem(vtIndex, L"HILITINSERT", L"_HILITINSERT ", &polycmds);
//	polycmds->Release();
    polyMnu->Release();

    return;
}