Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. ITextDocument::GetSelection

ITextDocument::GetSelection

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorialquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Blade DMS
    wrote on last edited by
    #1

    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]

    B 1 Reply Last reply
    0
    • B 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]

      B Offline
      B Offline
      Blade DMS
      wrote on last edited by
      #2

      Arrgghh... what happened to all my nice tabs??? How do you submit formatted code to the forums?? Blade[DMS]

      T 1 Reply Last reply
      0
      • B Blade DMS

        Arrgghh... what happened to all my nice tabs??? How do you submit formatted code to the forums?? Blade[DMS]

        T Offline
        T Offline
        Tomasz Sowinski
        wrote on last edited by
        #3

        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. **

        B 1 Reply Last reply
        0
        • T Tomasz Sowinski

          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. **

          B Offline
          B Offline
          Blade DMS
          wrote on last edited by
          #4

          Thanks... Blade[DMS]

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups