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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to modify inserted table in CHtmlEditView

How to modify inserted table in CHtmlEditView

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialdatabase
4 Posts 4 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.
  • U Offline
    U Offline
    User 51754
    wrote on last edited by
    #1

    Eureka! After some input from TCP folks, I finally arrived at the solution to getting, and modifying a table inserted into an CHtmlEditView: STEP 1: Get the DHTML document to a IDISPATCH STEP 2: Query interface for IID_IHTMLDocument2 STEP 3: get all elements -> IHTMLDocument2::get_all into IHTMLElementCollection STEP 4: Get the item (in this case a table) based on the table id ( _variant_t varID = _bstr_t(L"view"); _variant_t varIdx(0); IDispatch *pDocDisp=NULL; pCollect->item(varID,varIdx, &pDocDisp ); STEP 5: Now query the table item pDocDisp->QueryInterface(IID_IHTMLTable, (void**)&pTable); STEP 6: Now do an insertrow with a IDispatch pointer and -1 for append to end of table Then query the IHTMLTableRow interface IDispatch *pdispRow=NULL; IHTMLTableRow *pRow=NULL; pTable->insertRow ( -1, &pdispRow ); pdispRow->QueryInterface(IID_IHTMLTableRow, (void**)&pRow); STEP 7: Next do an IHTMLTableRow::insertCell with an IDispatch pointer Then query the IHTMLElement interface to get pointer tp IHTMLElement insert a space into the cell do this for the # of columns you have. in my example below i am inserting a row in a 3 column table. IDispatch *pDispCell=NULL; IHTMLElement *pCell=NULL; // col1 pRow->insertCell( -1, &pDispCell ); pDispCell->QueryInterface(IID_IHTMLElement, (void**)&pCell); pCell->put_innerText(L"  "); I'm sure there's a better way - this solution isn't elegant but it works! [ entire code ] IHTMLTable* pTable = NULL; IHTMLElementCollection *pCollect=NULL; _variant_t varID = _bstr_t(L"view"); _variant_t varIdx(0); BSTR tag = SysAllocString(L"0"); long cols = 1; IHTMLDocument2 *pDoc; IDispatch * pDocDisp = NULL; IHTMLTableCaption *pCaption=NULL; pDocDisp = GetHtmlDocument(); HRESULT h = pDocDisp->QueryInterface( IID_IHTMLDocument2, (void**)&pDoc ); pDoc->get_all(&pCollect); pCollect->item(varID,varIdx, &pDocDisp ); pDocDisp->QueryInterface(IID_IHTMLTable, (void**)&pTable); // now insert row and get an IHTMLTableRow pointer IDispatch *pdispRow=NULL; IHTMLTableRow *pRow=NULL; pTable->insertRow ( -1, &pdispRow ); pdispRow->QueryInterface(IID_IHTMLTableRow, (void**)&pRow); pRow->put_align(L"Center"); // Now insert the cell for 3 columns that exist in table already // and get IHTMLElement pointer IDispatch *pDispCell=NULL; IHTMLElement *pCell=NULL; // col1 pRow->insertCell( -

    C M 2 Replies Last reply
    0
    • U User 51754

      Eureka! After some input from TCP folks, I finally arrived at the solution to getting, and modifying a table inserted into an CHtmlEditView: STEP 1: Get the DHTML document to a IDISPATCH STEP 2: Query interface for IID_IHTMLDocument2 STEP 3: get all elements -> IHTMLDocument2::get_all into IHTMLElementCollection STEP 4: Get the item (in this case a table) based on the table id ( _variant_t varID = _bstr_t(L"view"); _variant_t varIdx(0); IDispatch *pDocDisp=NULL; pCollect->item(varID,varIdx, &pDocDisp ); STEP 5: Now query the table item pDocDisp->QueryInterface(IID_IHTMLTable, (void**)&pTable); STEP 6: Now do an insertrow with a IDispatch pointer and -1 for append to end of table Then query the IHTMLTableRow interface IDispatch *pdispRow=NULL; IHTMLTableRow *pRow=NULL; pTable->insertRow ( -1, &pdispRow ); pdispRow->QueryInterface(IID_IHTMLTableRow, (void**)&pRow); STEP 7: Next do an IHTMLTableRow::insertCell with an IDispatch pointer Then query the IHTMLElement interface to get pointer tp IHTMLElement insert a space into the cell do this for the # of columns you have. in my example below i am inserting a row in a 3 column table. IDispatch *pDispCell=NULL; IHTMLElement *pCell=NULL; // col1 pRow->insertCell( -1, &pDispCell ); pDispCell->QueryInterface(IID_IHTMLElement, (void**)&pCell); pCell->put_innerText(L"  "); I'm sure there's a better way - this solution isn't elegant but it works! [ entire code ] IHTMLTable* pTable = NULL; IHTMLElementCollection *pCollect=NULL; _variant_t varID = _bstr_t(L"view"); _variant_t varIdx(0); BSTR tag = SysAllocString(L"0"); long cols = 1; IHTMLDocument2 *pDoc; IDispatch * pDocDisp = NULL; IHTMLTableCaption *pCaption=NULL; pDocDisp = GetHtmlDocument(); HRESULT h = pDocDisp->QueryInterface( IID_IHTMLDocument2, (void**)&pDoc ); pDoc->get_all(&pCollect); pCollect->item(varID,varIdx, &pDocDisp ); pDocDisp->QueryInterface(IID_IHTMLTable, (void**)&pTable); // now insert row and get an IHTMLTableRow pointer IDispatch *pdispRow=NULL; IHTMLTableRow *pRow=NULL; pTable->insertRow ( -1, &pdispRow ); pdispRow->QueryInterface(IID_IHTMLTableRow, (void**)&pRow); pRow->put_align(L"Center"); // Now insert the cell for 3 columns that exist in table already // and get IHTMLElement pointer IDispatch *pDispCell=NULL; IHTMLElement *pCell=NULL; // col1 pRow->insertCell( -

      C Offline
      C Offline
      ColinDavies
      wrote on last edited by
      #2

      Some notes. 1. For some reason two piece BSTR creation & allocation is advised. 2. If your QueryInterfaces ever return "FAILED" you could have a nasty crash on your next call I guess. So you should be testing them with your HRESULT 3. When doing this stuff I think it makes sense to add a check that the document is truly loaded !! Ouch !! :-) PS: I have never used CHTMLEditView So I'm just assuming it's the same as the good ol mshtml.dll :-) Regardz Colin J Davies

      Sonork ID 100.9197:Colin

      You are the intrepid one, always willing to leap into the fray! A serious character flaw, I might add, but entertaining. Said by Roger Wright about me.

      S 1 Reply Last reply
      0
      • U User 51754

        Eureka! After some input from TCP folks, I finally arrived at the solution to getting, and modifying a table inserted into an CHtmlEditView: STEP 1: Get the DHTML document to a IDISPATCH STEP 2: Query interface for IID_IHTMLDocument2 STEP 3: get all elements -> IHTMLDocument2::get_all into IHTMLElementCollection STEP 4: Get the item (in this case a table) based on the table id ( _variant_t varID = _bstr_t(L"view"); _variant_t varIdx(0); IDispatch *pDocDisp=NULL; pCollect->item(varID,varIdx, &pDocDisp ); STEP 5: Now query the table item pDocDisp->QueryInterface(IID_IHTMLTable, (void**)&pTable); STEP 6: Now do an insertrow with a IDispatch pointer and -1 for append to end of table Then query the IHTMLTableRow interface IDispatch *pdispRow=NULL; IHTMLTableRow *pRow=NULL; pTable->insertRow ( -1, &pdispRow ); pdispRow->QueryInterface(IID_IHTMLTableRow, (void**)&pRow); STEP 7: Next do an IHTMLTableRow::insertCell with an IDispatch pointer Then query the IHTMLElement interface to get pointer tp IHTMLElement insert a space into the cell do this for the # of columns you have. in my example below i am inserting a row in a 3 column table. IDispatch *pDispCell=NULL; IHTMLElement *pCell=NULL; // col1 pRow->insertCell( -1, &pDispCell ); pDispCell->QueryInterface(IID_IHTMLElement, (void**)&pCell); pCell->put_innerText(L"  "); I'm sure there's a better way - this solution isn't elegant but it works! [ entire code ] IHTMLTable* pTable = NULL; IHTMLElementCollection *pCollect=NULL; _variant_t varID = _bstr_t(L"view"); _variant_t varIdx(0); BSTR tag = SysAllocString(L"0"); long cols = 1; IHTMLDocument2 *pDoc; IDispatch * pDocDisp = NULL; IHTMLTableCaption *pCaption=NULL; pDocDisp = GetHtmlDocument(); HRESULT h = pDocDisp->QueryInterface( IID_IHTMLDocument2, (void**)&pDoc ); pDoc->get_all(&pCollect); pCollect->item(varID,varIdx, &pDocDisp ); pDocDisp->QueryInterface(IID_IHTMLTable, (void**)&pTable); // now insert row and get an IHTMLTableRow pointer IDispatch *pdispRow=NULL; IHTMLTableRow *pRow=NULL; pTable->insertRow ( -1, &pdispRow ); pdispRow->QueryInterface(IID_IHTMLTableRow, (void**)&pRow); pRow->put_align(L"Center"); // Now insert the cell for 3 columns that exist in table already // and get IHTMLElement pointer IDispatch *pDispCell=NULL; IHTMLElement *pCell=NULL; // col1 pRow->insertCell( -

        M Offline
        M Offline
        Michael Dunn
        wrote on last edited by
        #3

        That's pretty much how you have to do it, although you can make your code way more readable and stable by using either CComPtr<> or #import'ing mshtml.tlb to get the HTML DOM wrapper classes. Check out An Advanced Windows Hotfix Manager[^], one of the things I do there is generate a report in a <table> using the DOM interfaces. --Mike-- "I'd rather you just give me a fish today, because even if you teach me how to fish, I won't do it. I'm lazy." -- Nish Just released - 1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click! My really out-of-date homepage Sonork-100.19012 Acid_Helm

        1 Reply Last reply
        0
        • C ColinDavies

          Some notes. 1. For some reason two piece BSTR creation & allocation is advised. 2. If your QueryInterfaces ever return "FAILED" you could have a nasty crash on your next call I guess. So you should be testing them with your HRESULT 3. When doing this stuff I think it makes sense to add a check that the document is truly loaded !! Ouch !! :-) PS: I have never used CHTMLEditView So I'm just assuming it's the same as the good ol mshtml.dll :-) Regardz Colin J Davies

          Sonork ID 100.9197:Colin

          You are the intrepid one, always willing to leap into the fray! A serious character flaw, I might add, but entertaining. Said by Roger Wright about me.

          S Offline
          S Offline
          Stephane Rodriguez
          wrote on last edited by
          #4

          Colin Davies wrote: PS: I have never used CHTMLEditView So I'm just assuming it's the same as the good ol mshtml.dll The insertion code has nothing to do with the CHtmlEditView. It's just the author of the posts who managed to put a reference to this class in the post header whenever he posted ! :-D CHtmlEditView is just a MFC CHtmlView-derived class (a simple web browser control wrapper), using one of the latest methods exposed by IE5.5+ (which were earlier available as a separate SDK (the DHTML edit component SDK, now legacy)). mshtml.dll is the DOM.


          How low can you go ?
          (MS rant)

          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