static AST stmt() { Token *t = &tok; AST a=0; AST a1=0; AST n; AST type; switch (t->sym) { case ID: /* ASN or CALL */ n = vName(); char *s = get_text(n); if (t->sym == ASNOP || t->sym == '[') { int idx = lookup_SYM_all(s); if (idx == 0) parse_error("Undefined symbol"); a1 = asnstmt(n); if (t->sym == ';') gettoken(); } else if (t->sym == '(') { a1 = callstmt(n); AST args = 0; get_sons(a1, 0, 0, &args, 0); if (!checkFuncExistAll(s, args)) parse_error("No defined functions matches types of passed arguments"); if (t->sym == ';') gettoken(); } else if (t->sym == '.'){ gettoken(); type = typeof_AST(n); if (nodetype(type) == tCLASS){ AST function_name = vName(); a1 = callstmt(function_name); AST args = 0; get_sons(a1, 0, 0, &args, 0); /*set_sons(a1, n, function_name, args, 0);*/ if (!checkFuncExistClass(type, get_text(function_name), args)) parse_error("No defined functions of the class matches types of passed arguments"); if (t->sym == ';') gettoken(); } else { parse_error("Symbol must be instance of a class"); skiptoken(';'); } }else { parse_error("expected ASNOP or Funcall"); skiptoken(';'); } break; case tIF: a1 = ifstmt(); break; case tRETURN: a1 = returnstmt(); if (t->sym == ';') gettoken(); break; case '{': a1 = block(); break; default: break; } a = make_AST(nSTMT,a1,0,0,0); return a; }
void assignAttVar(Word av, Word value ARG_LD) { Word a; assert(isAttVar(*av)); assert(!isRef(*value)); assert(gTop+7 <= gMax && tTop+6 <= tMax); DEBUG(1, Sdprintf("assignAttVar(%s)\n", vName(av))); if ( isAttVar(*value) ) { if ( value > av ) { Word tmp = av; av = value; value = tmp; } else if ( av == value ) return; } a = valPAttVar(*av); registerWakeup(a, value PASS_LD); TrailAssignment(av); if ( isAttVar(*value) ) { DEBUG(1, Sdprintf("Unifying two attvars\n")); *av = makeRef(value); } else *av = *value; return; }
void DirLight::SetUniformData(Shader shader, const GLchar *name, GLboolean useShader /* = GL_FALSE */) { if (useShader) { shader.Use(); } std::string vName(name); shader.SetVector3f((vName + ".direction").c_str(), this->Direction); shader.SetVector3f((vName + ".color").c_str(), this->Color * glm::vec3(this->Brightness)); shader.SetVector3f((vName + ".ambient").c_str(), glm::vec3(this->Ambient)); }
GLuint ShaderProgram::getVariablePosition(const char* name) { // A std::string for hasing purposes std::string vName (name); // If we don't know this variable, find out its location if (variableLocations.count(vName)==0) variableLocations[vName] = glGetUniformLocation(ShaderProgramID, name); // Die nicely if we need to //if (variableLocations[vName]==0xFFFFFFFF) // DIE2("Cannot find shader variable",name); // Return the answer return variableLocations[vName]; }
bool lineGraph(Graph g1, Graph& out){ boost::graph_traits<Graph>::edge_iterator e1,e1_end; boost::property_map<Graph, boost::edge_name_t>::type eName = boost::get(boost::edge_name_t(), g1); boost::property_map<Graph, boost::edge_name_t>::type eNameOut = boost::get(boost::edge_name_t(), out); boost::property_map<Graph, boost::vertex_name_t>::type vName = get(boost::vertex_name_t(), g1); boost::property_map<Graph, boost::vertex_name_t>::type vNameOut = get(boost::vertex_name_t(), out); boost::graph_traits<Graph>::vertex_iterator v1,v2,v1_end,v2_end; boost::graph_traits<Graph>::vertex_descriptor s1,t1,s2,t2,v; std::map<std::string, boost::graph_traits<Graph>::edge_descriptor> vertexMap; for (boost::tie(e1, e1_end) = boost::edges(g1); e1 != e1_end; ++e1) { v =boost::add_vertex(out); std::string name = eName[*e1]; vNameOut[v] = name; vertexMap[name]= *e1; } for (boost::tie(v1, v1_end) = boost::vertices(out); v1 != v1_end; ++v1){ for (v2= v1+1; v2 != v1_end; ++v2){ s1 = boost::source(vertexMap[vNameOut[*v2]],out); t1 = boost::target(vertexMap[vNameOut[*v2]],out); s2 = boost::source(vertexMap[vNameOut[*v1]],out); t2 = boost::target(vertexMap[vNameOut[*v1]],out); if (s1 == s2) eNameOut[boost::add_edge(*v1,*v2,out).first] = vName(s1); else if( s1 == t2) eNameOut[boost::add_edge(*v1,*v2,out).first] = vName(s1); else if( t1==s2 ) eNameOut[boost::add_edge(*v1,*v2,out).first] = vName(t1); else if (t1==t2) eNameOut[boost::add_edge(*v1,*v2,out).first] = vName(t1); } } return true; }
void assignAttVar(Word av, Word value, int flags ARG_LD) { Word a; mark m; assert(isAttVar(*av)); assert(!isRef(*value)); assert(gTop+8 <= gMax && tTop+6 <= tMax); DEBUG(CHK_SECURE, assert(on_attvar_chain(av))); DEBUG(1, Sdprintf("assignAttVar(%s)\n", vName(av))); if ( isAttVar(*value) ) { if ( value > av ) { Word tmp = av; av = value; value = tmp; } else if ( av == value ) return; } if( !(flags & ATT_ASSIGNONLY) ) { a = valPAttVar(*av); registerWakeup(av, a, value PASS_LD); } if ( (flags&ATT_WAKEBINDS) ) return; Mark(m); /* must be trailed, even if above last choice */ LD->mark_bar = NO_MARK_BAR; TrailAssignment(av); DiscardMark(m); if ( isAttVar(*value) ) { DEBUG(1, Sdprintf("Unifying two attvars\n")); *av = makeRef(value); } else if ( isVar(*value) ) { DEBUG(1, Sdprintf("Assigning attvar with plain var\n")); *av = makeRef(value); /* JW: Does this happen? */ } else *av = *value; return; }
//********************************************************************************* static void createSnapshotTestSectrion() { CTBSection xCurrentUser; xCurrentUser.Open(&CTBSection::tbRootSection, "CurrentUser"); CTBSection xSnapshotTest; xSnapshotTest.Create(&xCurrentUser, "SnapshotTest", 0); //-------------------------------------------------------------- { CTBSection xSection1; xSection1.Create(&xSnapshotTest, "Section1", 0); } //-------------------------------------------------------------- CMemFile memFile; for(int i = 0; i < 64; ++i) { BYTE buff[1024] = {0}; memset(buff, i, sizeof(buff)); memFile.Write(buff, sizeof(buff)); } //-------------------------------------------------------------- xSnapshotTest.SetLongBinary("Blob1", &memFile); for(int i = 0; i < 200; ++i) { CTBValue vName("Name"); CTBValue vAge(i); CString name, age; name.Format("Name %d", i); age.Format("Age %d", i); xSnapshotTest.SetValue(name, &vName); xSnapshotTest.SetValue(age, &vAge); } //-------------------------------------------------------------- xSnapshotTest.Update(); }
void avtFITSFileFormat::Initialize(avtDatabaseMetaData *md) { const char *mName = "avtFITSFileFormat::Initialize: "; if(fits == 0) { debug4 << mName << "Opening " << filename << endl; int status = 0; if(fits_open_file(&fits, filename, 0, &status)) { PrintError(status); EXCEPTION1(InvalidFilesException, filename); } char card[FLEN_CARD], tmp[100]; std::string fileComment; int hdutype = 0; // Iterate over the HDU's for(int hdu = 1; !(fits_movabs_hdu(fits, hdu, &hdutype, &status)); hdu++) { debug4 << mName << "Looking at HDU " << hdu << endl; // Get no. of keywords int nkeys = 0, keypos = 0; if(fits_get_hdrpos(fits, &nkeys, &keypos, &status)) PrintError(status); if(hdutype == IMAGE_HDU) { debug4 << mName << "HDU " << hdu << " contains an image" << endl; //int status2 = 0; char value[FLEN_VALUE]; std::string objname, bunit, xlabel, ylabel, zlabel; // Try and get the key value for BUNIT if(GetKeywordValue("BUNIT", value)) { bunit = std::string(value); debug4 << "\tBUNIT=" << value << endl; } // Try and get the key value for OBJECT if(GetKeywordValue("OBJECT", value)) { objname = std::string(value); debug4 << "\tOBJECT=" << value << endl; } #if 0 // // Re-enable these someday when we read the mesh coordinates from the file // and use them to construct a sensible mesh. // // Try and get the key value for CTYPE1 if(GetKeywordValue("CTYPE1", value)) { xlabel = std::string(value); debug4 << "\tCTYPE1=" << value << endl; } // Try and get the key value for CTYPE2 if(GetKeywordValue("CTYPE2", value)) { ylabel = std::string(value); debug4 << "\tCTYPE2=" << value << endl; } // Try and get the key value for CTYPE3 if(GetKeywordValue("CTYPE3", value)) { zlabel = std::string(value); debug4 << "\tCTYPE3=" << value << endl; } #endif // Use the keywords to create a comment. SNPRINTF(tmp, 100, "Header listing for HDU #%d:\n", hdu); fileComment += tmp; for(int jj = 1; jj <= nkeys; jj++) { if(fits_read_record(fits, jj, card, &status)) PrintError(status); std::string cs(card); fileComment += cs; if(cs.size() > 0 && cs[cs.size()-1] != '\n') fileComment += "\n"; } fileComment += "\n\n"; // // Get the image's dimensions. // int ndims = 0; if(fits_get_img_dim(fits, &ndims, &status)) PrintError(status); debug4 << mName << "Num dimensions: " << ndims << ", status=" << status << endl; long *dims = new long[ndims]; if(fits_get_img_size(fits, ndims, dims, &status)) PrintError(status); if(ndims == 0) { debug4 << mName << "The image has no dimensions. Skip it." << endl; continue; } // // Create a mesh name for the image. // intVector mdims; std::string meshName("image"); debug4 << mName << "Image dimensions: "; bool dimensionsNonZero = false; for(int i = 0; i < ndims; ++i) { char num[20]; if(i > 0) SNPRINTF(num, 20, "x%d", (int)dims[i]); else SNPRINTF(num, 20, "%d", (int)dims[i]); meshName += num; mdims.push_back((int)dims[i]); dimensionsNonZero |= (dims[i] != 0); debug4 << dims[i] << ", "; } debug4 << endl; if(!dimensionsNonZero) { debug4 << mName << "All dimensions were zero. skip." << endl; continue; } if(ndims == 1 && objname != "") meshName = objname; if(meshDimensions.find(meshName) == meshDimensions.end()) { meshDimensions[meshName] = mdims; // Create metadata if necessary. if(md != 0) { if(ndims == 1) { debug4 << mName << "Adding a curve called " << meshName.c_str() << " for HDU " << hdu << endl; avtCurveMetaData *cmd = new avtCurveMetaData; cmd->name = meshName; if(xlabel != "") cmd->xLabel = xlabel; if(ylabel != "") cmd->yLabel = ylabel; md->Add(cmd); // Do this because we use GetVar to read the data // that we use to create the curve. varToHDU[meshName] = hdu; varToMesh[meshName] = meshName; } else { int sdims, tdims; int nrealdims = (ndims <= 3) ? ndims : 3; #define VECTOR_SUPPORT #ifdef VECTOR_SUPPORT if(nrealdims == 3 && dims[2] == 3) nrealdims = 2; #endif sdims = tdims = nrealdims; debug4 << mName << "Adding a " << sdims << " dimensional mesh called " << meshName.c_str() << " for HDU " << hdu << endl; avtMeshMetaData *mmd = new avtMeshMetaData( meshName, 1, 1, 1, 0, sdims, tdims, AVT_RECTILINEAR_MESH); if(xlabel != "") mmd->xLabel = xlabel; if(ylabel != "") mmd->yLabel = ylabel; if(zlabel != "") mmd->zLabel = zlabel; md->Add(mmd); } } } // // Create a name for the variable at this HDU // if(ndims > 1) { char varname[100]; SNPRINTF(varname, 100, "hdu%d", hdu); std::string vName(varname); if(objname != "") vName = objname; varToHDU[vName] = hdu; varToMesh[vName] = meshName; // Create metadata if necessary if(md != 0) { #ifdef VECTOR_SUPPORT // Limit the dimensions to 3. int ncomps = 1; int nrealdims = (ndims <= 3) ? ndims : 3; if(nrealdims == 3 && dims[2] == 3) ncomps = 3; if(ncomps == 1) { #endif debug4 << mName << "Adding a scalar called " << vName.c_str() << " for HDU " << hdu << endl; // Add the scalar metadata avtScalarMetaData *smd = new avtScalarMetaData( vName, meshName, AVT_ZONECENT); smd->hasUnits = bunit != ""; smd->units = bunit; md->Add(smd); #ifdef VECTOR_SUPPORT } else { debug4 << mName << "Adding a color vector called " << vName.c_str() << " for HDU " << hdu << endl; // Add the vector metadata avtVectorMetaData *vmd = new avtVectorMetaData( vName, meshName, AVT_ZONECENT, 4); // vmd->hasUnits = true; // vmd->units = md->Add(vmd); } #endif } } delete [] dims; } else if(hdutype == ASCII_TBL) { debug4 << mName << "HDU " << hdu << " contains an ascii table" << endl; } else if(hdutype == BINARY_TBL) { debug4 << mName << "HDU " << hdu << " contains a binary table" << endl; // Use the keywords to create a comment. SNPRINTF(tmp, 100, "Header listing for HDU #%d:\n", hdu); debug4 << tmp; for(int jj = 1; jj <= nkeys; jj++) { if(fits_read_record(fits, jj, card, &status)) PrintError(status); std::string cs(card); if(cs.size() > 0 && cs[cs.size()-1] != '\n') cs += "\n"; debug4 << "\t" << cs.c_str(); } } } if(md != 0) md->SetDatabaseComment(fileComment); } }
bool QA::init(void) { // Open the qa-result.nc file, when available or create // it from scratch. Meta data checks are performed. // Initialisation of time and time boundary testing. // Eventually, entry() is called to test the data of fields. notes->init(); // safe qaExp.setParent(this); qaTime.setParent(this); // default for the qaFile setFilename( pIn->file ); // apply parsed command-line args applyOptions(); std::string vName(qaExp.getVarnameFromFilename()); if(isRequiredVariable) pIn->pullMetaData('V', vName); if(isRequiredTime && !isRequiredVariable) pIn->pullMetaData('T'); if(isRequiredGlobal) pIn->pullMetaData('G'); initCheckStatus(); // check for CF Convention. if(isCheckCF) { cF->setDataVarName(vName); cF->setFilename(pIn->file); (void) cF->run(); } // exclude user-defined data variables from any checking pIn->excludeVars(); qaTime.init(optStr); qaExp.init(optStr); // DRS specifications if(isCheckDRS_F || isCheckDRS_P) { drs_cv_table.setParent(this); drs_cv_table.setPath(tablePath); drs_cv_table.applyOptions(optStr); drs_cv_table.read(); } // experiment specific obj: set parent, pass over options // check consistency between sub-sequent files or experiments if(isCheckCNSTY && (fileSequenceState == 's' || fileSequenceState == 'x') ) { // return true for a) no previous check available, // b) deviation from a privous check are found if( checkConsistency(*pIn, optStr, tablePath) ) qaExp.run(); } else qaExp.run(); // check existence of any data at all if( pIn->ncRecBeg == 0 && pIn->ncRecEnd == 0 ) { isCheckData=false; std::string key("6_15"); if( notes->inq( key, fileStr) ) { std::string capt("No records in the file") ; if( notes->operate(capt) ) { notes->setCheckStatus(n_data, n_fail ); setExitState( notes->getExitState() ) ; } } } if( isCheckData ) { if( !checkDataBody() ) { isCheckData = false; notes->setCheckStatus(n_data, n_fail); setExitState(2); // return true; } } if(isCheckTimeValues && !qaTime.isTime) notes->setCheckStatus(n_time, "FIXED"); if(isCheckTimeValues) { if( qaTime.isTime) { if( !checkDataBody(qaTime.name) ) { // time is defined, but there is no data qaTime.isTime = false; notes->setCheckStatus(n_time, n_fail); setExitState(2); } } } if(isCheckData || isCheckTimeValues) { notes->setConstraintFreq( qaExp.getFrequency() ); // enable detection of outlier and replicated records setProcessing(); // open netCDF for creating, continuation or resuming qa_<varname>.nc. // note that this must happen before checkMetaData which uses currQARec openQA_Nc(*pIn); if( isExit() || qaExp.isUseStrict || qaTime.isNoProgress ) { isCheckData=false; return true; } } if( isCheckData || isCheckTimeValues ) { // set pointer to function for operating tests // execPtr = &IObj::entry ; (void) entry(); } return true; // only meta-data check }
HRESULT CConnect::OnConnection(LPDISPATCH Application, ext_ConnectMode ConnectMode, LPDISPATCH AddInInst, SAFEARRAY **custom) { TSAUTO(); Application->QueryInterface(__uuidof(IDispatch), reinterpret_cast<LPVOID*>(&this->m_spApplication)); AddInInst->QueryInterface(__uuidof(IDispatch), reinterpret_cast<LPVOID*>(&this->m_spAddInInstance)); //是否显示按钮 CRegKey key; DWORD dwValue; if(key.Open(HKEY_CURRENT_USER, _T("Software\\WordEncLock")) == ERROR_SUCCESS){ if (key.QueryValue(dwValue, _T("silent")) == ERROR_SUCCESS){ if (dwValue == 1){ g_sIsSilent = TRUE; } } } key.Close(); if (g_sIsSilent){ return S_OK; } CComQIPtr<_Application> spApp(Application); ATLASSERT(spApp); if (!spApp){//获取失败说明是excel //g_sIsSilent = TRUE; return S_OK; } g_Application = spApp; HRESULT hr; CComPtr<Office::_CommandBars> spCmdBars; hr = g_Application->get_CommandBars(&spCmdBars); if(FAILED(hr)) return hr; ATLASSERT(spCmdBars); // now we add a new toolband to Word // to which we''ll add 2 buttons CComVariant vName(""); CComPtr<Office::CommandBar> spNewCmdBar; CComVariant vPos(1); CComVariant vTemp(VARIANT_TRUE); // menu is temporary CComVariant vEmpty(DISP_E_PARAMNOTFOUND, VT_ERROR); spNewCmdBar = spCmdBars->Add(vName, vPos, vEmpty, vTemp); CComPtr < Office::CommandBarControls> spBarControls; spBarControls = spNewCmdBar->GetControls(); ATLASSERT(spBarControls); CComVariant vToolBarType(1); CComVariant vShow(VARIANT_TRUE); CComPtr<Office::CommandBarControl> spNewBar; // add first button spNewBar = spBarControls->Add(vToolBarType,vEmpty,vEmpty,vEmpty,vShow); ATLASSERT(spNewBar); CComQIPtr < Office::_CommandBarButton> spCmdButton(spNewBar); ATLASSERT(spCmdButton); m_spButton = spCmdButton; AppEvents::DispEventAdvise(m_spButton); HBITMAP hBmp =(HBITMAP)::LoadImage(g_hModule, MAKEINTRESOURCE(IDB_BITMAP1),IMAGE_BITMAP,0,0,LR_LOADMAP3DCOLORS); ::OpenClipboard(NULL); ::EmptyClipboard(); ::SetClipboardData(CF_BITMAP, (HANDLE)hBmp); ::CloseClipboard(); ::DeleteObject(hBmp); spCmdButton->PutStyle(Office::msoButtonIconAndWrapCaption); hr = spCmdButton->PasteFace(); if (FAILED(hr)) return hr; spCmdButton->PutVisible(VARIANT_TRUE); spCmdButton->PutCaption(OLESTR("Word安全锁")); spCmdButton->PutEnabled(VARIANT_TRUE); spCmdButton->PutTooltipText(OLESTR("Word安全锁")); spCmdButton->PutTag(OLESTR("给Word文档加密")); spNewCmdBar->PutVisible(VARIANT_TRUE); return S_OK; }
HRESULT CMyAddin::InstallInterface(IExchExtCallback *lpExchangeCallback) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); try { CString csTitle = APP_NAME; // This will be the display-name of the toolbar HBITMAP hBmp; // First we need to get the active Explorer, you could see this as the active window (it's more to it but let's keep it at that for now) Outlook::_ExplorerPtr spExplorer = m_OLAppPtr->ActiveExplorer(); if (spExplorer == NULL) { return S_FALSE; } // Then we need to have a pointer to the commandbars, that is the toolbars in the UI Office::_CommandBarsPtr spCmdBars = spExplorer->CommandBars; if (spCmdBars == NULL) { return S_FALSE; } try { CComVariant vName(csTitle); // This is the caption of the toolbar CComVariant vTemp(TRUE); CComPtr <Office::CommandBar> spToolbar; CComVariant vPos(1); //CComVariant vTemp(VARIANT_TRUE); CComVariant vEmpty(DISP_E_PARAMNOTFOUND, VT_ERROR); /*spToolbar = spCmdBars->Add(vName, // Caption vtMissing, // <ignore this for now> vtMissing, // <ignore this for now> vTemp); // The toolbar should be temporary, // that way we have to add it every time we*/ //spToolbar = spCmdBars->Add(vName, // Caption // vPos, // <ignore this for now> // vEmpty, // <ignore this for now> // vTemp); // The toolbar should be temporary, // that way we have to add it every time we CComPtr <Office::CommandBarControl> pButton = NULL; CComPtr <Office::CommandBarControls> pBarControls = NULL; //pBarControls = spToolbar->GetControls(); /*m_pToolBar = (Office::CommandBarControlPtr)(pBarControls->Add((long)Office::msoBarFloating, //msoControlButton, vtMissing, vtMissing, vtMissing, vTemp));*/ // get the outlok Context Menu. for this enumerate all the command bars for "Context Menu" command bar CComPtr<Office::CommandBar> pTempBar; for(long i = 0; i < spCmdBars->Count ; i++) { CComVariant vItem(i+1); //zero based index pTempBar=NULL; spCmdBars->get_Item(vItem,&pTempBar); if((pTempBar) && (!wcscmp(CString(APP_NAME).AllocSysString(),pTempBar->Name))) { return S_FALSE; } } m_pToolBar = (Office::CommandBarPtr)(spCmdBars->Add(APP_NAME, vPos, /*Office::msoBarFloating,*/ vtMissing, vTemp)); pButton = (Office::CommandBarControlPtr)m_pToolBar->Controls->Add(Office::msoControlButton, vtMissing, vtMissing, vtMissing, vTemp); pButton->Caption = APP_NAME; pButton->OnAction = "MyButtonsAction"; BOOL bSetImage = TRUE; // I've set this to FALSE, but if you want an image to appear on the button, // you will need to have an image in the resources. // The only drawback of this is that there is only one way of // putting an image on the button, and that is by going through the // clipboard. And by doing so, the contents of the clipboard will be // lost, unless you implement some logic to store the clipboard-data // before doing this and then restoring the data once the image is on // the button. if (bSetImage) { UINT uiBitmapId = 0; CComQIPtr <Office::_CommandBarButton> spCmdButton(pButton); // to set a bitmap to a button, load a 32x32 bitmap // and copy it to clipboard. Call CommandBarButton's PasteFace() // to copy the bitmap to the button face. to use // Outlook's set of predefined bitmap, set button's FaceId to // the button whose bitmap you want to use hBmp =(HBITMAP)::LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BITMAP_PHONE), IMAGE_BITMAP, 0, 0, LR_LOADMAP3DCOLORS | LR_LOADTRANSPARENT); if (hBmp) { // put bitmap into Clipboard ::OpenClipboard(NULL); ::EmptyClipboard(); ::SetClipboardData(CF_BITMAP, (HANDLE)hBmp); ::CloseClipboard(); ::DeleteObject(hBmp); // set style before setting bitmap spCmdButton->PutStyle(Office::msoButtonIconAndCaption); if (FAILED(spCmdButton->PasteFace())) { TRACE("Failed to paste face to button\n"); } }/* else { char serr[50]; DWORD err = GetLastError(); ltoa(err, serr, 10); MessageBox(NULL, serr, "error", MB_OK); }*/ } // With the button physically added to the toolbar, we just need to // create an object of COutlookButton to sink it's events. m_pMyButton = new COutlookButton(pButton); m_pMyButton->m_OLAppPtr = m_OLAppPtr; // The only thing left to do is to make the toolbar visible. //spToolbar->PutVisible(VARIANT_TRUE); LoadToolbarSettings(); } catch(...) { } // Add menu item _bstr_t bstrNewMenuText(CString(APP_NAME).AllocSysString()); CComPtr < Office::CommandBarControls> spCmdCtrls; CComPtr < Office::CommandBarControls> spCmdBarCtrls; CComPtr < Office::CommandBarPopup> spCmdPopup; CComPtr < Office::CommandBarControl> spCmdCtrl; CComPtr < Office::CommandBar> spCmdBar; // get CommandBar that is Outlook's main menu HRESULT hr = spCmdBars->get_ActiveMenuBar(&spCmdBar); if (FAILED(hr)) return S_FALSE; //hr; // get menu as CommandBarControls spCmdCtrls = spCmdBar->GetControls(); ATLASSERT(spCmdCtrls); // we want to add a menu entry to Outlook's 6th(Tools) menu //item CComVariant vItem(5); spCmdCtrl= spCmdCtrls->GetItem(vItem); ATLASSERT(spCmdCtrl); IDispatchPtr spDisp; spDisp = spCmdCtrl->GetControl(); // a CommandBarPopup interface is the actual menu item CComQIPtr < Office::CommandBarPopup> ppCmdPopup(spDisp); ATLASSERT(ppCmdPopup); spCmdBarCtrls = ppCmdPopup->GetControls(); ATLASSERT(spCmdBarCtrls); CComVariant vMenuType(1); // type of control - menu CComVariant vMenuPos(6); CComVariant vMenuEmpty(DISP_E_PARAMNOTFOUND, VT_ERROR); CComVariant vMenuShow(VARIANT_TRUE); // menu should be visible CComVariant vMenuTemp(VARIANT_TRUE); // menu is temporary CComPtr < Office::CommandBarControl> spNewMenu; // now create the actual menu item and add it spNewMenu = spCmdBarCtrls->Add(vMenuType, vMenuEmpty, vMenuEmpty, vMenuEmpty, vMenuTemp); ATLASSERT(spNewMenu); spNewMenu->PutCaption(bstrNewMenuText); spNewMenu->PutEnabled(VARIANT_TRUE); spNewMenu->PutVisible(VARIANT_TRUE); spNewMenu->OnAction = "MyButtonsAction"; //we'd like our new menu item to look cool and display // an icon. Get menu item as a CommandBarButton CComQIPtr < Office::_CommandBarButton> spCmdMenuButton(spNewMenu); ATLASSERT(spCmdMenuButton); spCmdMenuButton->PutStyle(Office::msoButtonIconAndCaption); // we want to use the same toolbar bitmap for menuitem too. // we grab the CommandBarButton interface so we can add // a bitmap to it through PasteFace(). spCmdMenuButton->PasteFace(); // Empty whatever we put in the clipboard ::OpenClipboard(NULL); ::EmptyClipboard(); ::CloseClipboard(); // With the button physically added to the toolbar, we just need to // create an object of COutlookButton to sink it's events. m_pMyMenuItem = new COutlookButton(spNewMenu); m_pMyMenuItem->m_OLAppPtr = m_OLAppPtr; // show the menu spNewMenu->PutVisible(VARIANT_TRUE); } catch(...) { } return S_FALSE; }