//------------------------------------------------------------------------------------------- // This public member function opens file with the given name in the Developer Studio // and highlights the siven line. It also gives focus to the Developer Studio. //------------------------------------------------------------------------------------------- bool CCommands::OpenFileOnLine(CString& file, int line) { ITextDocument* iDocument; IDocuments* iDocuments; ITextSelection* iSelection; // First, check if the given file exists. (Developer Studio will hang for a while // trying to open non-existing file). if(_access(file,04)==-1) return false; // Get document collection from the application object. if(m_pApplication->get_Documents((IDispatch **)&iDocuments)!=S_OK) return false; if(iDocuments==NULL) return false; // Open new document and add it to the documents collection (if not exists). VARIANT varType; varType.vt = VT_BSTR; varType.bstrVal=CString("Auto").AllocSysString(); VARIANT varReadonly; varReadonly.vt = VT_BOOL; varReadonly.boolVal = FALSE; if(iDocuments->Open(file.AllocSysString(),varType,varReadonly,(IDispatch **)&iDocument)!=S_OK) { iDocuments->Release(); return false; } // We do not need documents collection any more iDocuments->Release(); if(iDocument==NULL) return false; // Get text selection from the current document if(iDocument->get_Selection((IDispatch **)&iSelection)!=S_OK) return false; // We do not need document object any more. iDocument->Release(); if(iSelection==NULL) return false; // Move to the first position in the given line VARIANT selAct; selAct.vt = VT_INT; selAct.intVal = dsMove; iSelection->MoveTo(line,1,selAct); // Move to the end of this line in "Shift key pressed" mode. selAct.intVal = dsExtend; iSelection->EndOfLine(selAct); // We do not need text selection object any more iSelection->Release(); // Pop-up MSDEV application. m_pApplication->put_Active(VARIANT_TRUE); return true; }