ITextDocument::GetSelection
-
I'm trying to write a function that will make Visual C++ open a file, and select some text on a particular line. This function is to run in another application (not a macro or Addin)... So far I can cause an existing instance of visual C++ to open the file, but I cannot get the selection object... Heres the code so far... void EditFile( const char *filename, long line, int col, int span ) { try { IXApplication app; if (app.OpenDispatch("MSDev.Application")) { IDocuments docs( app.GetDocuments() ); COleVariant var1(0L,VT_ERROR); var1.scode=DISP_E_PARAMNOTFOUND; COleVariant var2(0L,VT_ERROR); var2.scode=DISP_E_PARAMNOTFOUND; COleVariant var3, var4; _bstr_t ctext; ctext = filename; ITextDocument tdoc( docs.Open(ctext, var1, var2 ) ); if (line >= 0) { ITextSelection tsel( tdoc.GetSelection() ); tsel.Cancel(); if (col < 1) col = 1; tsel.MoveTo( line, col, var1 ); if (span > 0) { var3 = (long)1; var4 = (long)span; tsel.CharRight( var3, var4 ); } } } } catch (...) { } } Unfortunatly, the tdoc.GetSelection() call throws a DISP_E_MEMBERNOTFOUND exception. Does anyone know how to do this... (or where to look for inspiration)? Thanks... BTW... IXApplication is a subclass of IApplication which provides OpenDispatch which finds an existing instance of the application instead of creating a new instance (ala CreateDispatch). Blade[DMS]
-
I'm trying to write a function that will make Visual C++ open a file, and select some text on a particular line. This function is to run in another application (not a macro or Addin)... So far I can cause an existing instance of visual C++ to open the file, but I cannot get the selection object... Heres the code so far... void EditFile( const char *filename, long line, int col, int span ) { try { IXApplication app; if (app.OpenDispatch("MSDev.Application")) { IDocuments docs( app.GetDocuments() ); COleVariant var1(0L,VT_ERROR); var1.scode=DISP_E_PARAMNOTFOUND; COleVariant var2(0L,VT_ERROR); var2.scode=DISP_E_PARAMNOTFOUND; COleVariant var3, var4; _bstr_t ctext; ctext = filename; ITextDocument tdoc( docs.Open(ctext, var1, var2 ) ); if (line >= 0) { ITextSelection tsel( tdoc.GetSelection() ); tsel.Cancel(); if (col < 1) col = 1; tsel.MoveTo( line, col, var1 ); if (span > 0) { var3 = (long)1; var4 = (long)span; tsel.CharRight( var3, var4 ); } } } } catch (...) { } } Unfortunatly, the tdoc.GetSelection() call throws a DISP_E_MEMBERNOTFOUND exception. Does anyone know how to do this... (or where to look for inspiration)? Thanks... BTW... IXApplication is a subclass of IApplication which provides OpenDispatch which finds an existing instance of the application instead of creating a new instance (ala CreateDispatch). Blade[DMS]
-
Arrgghh... what happened to all my nice tabs??? How do you submit formatted code to the forums?? Blade[DMS]
Blade[DMS] wrote: How do you submit formatted code to the forums?? With <pre> and </pre> tags. Tomasz Sowinski -- http://www.shooltz.com
** If you're going to rape, pillage and burn, be sure to do things in that order. ** -
Blade[DMS] wrote: How do you submit formatted code to the forums?? With <pre> and </pre> tags. Tomasz Sowinski -- http://www.shooltz.com
** If you're going to rape, pillage and burn, be sure to do things in that order. **