开发者

Can CHTMLView be used to display local file?

开发者 https://www.devze.com 2023-04-11 02:59 出处:网络
I would like to display a local file in html format. I can simply do: void CMyhtmlView::OnInitialUpdate()

I would like to display a local file in html format. I can simply do:

void CMyhtmlView::OnInitialUpdate()
{
   CHtmlView::OnInitialUpdate();

   CMyhtml开发者_如何学CDoc * pDoc =  (CMyhtmlDoc *) GetDocument();

   Navigate2 (pDoc->GetPathName() ,NULL,NULL);
}

and this displays an ascii file in the view but my real file is not ascii and it has to be decrepted first, plus obviously I want more control and display data in tables rather than plain text. Can I do that?

Assume a simple case where we multiply 10 numbers by 2 and display the results.

int num[10] = {1,2,3,4,5,6,7,8,9,10};
int multiplyBy = 2;
int result[10] = {0};

for (int i = 0; i < 10; i++)
{
   result[i] = num[i] * multiplyBy;
}

// now display the results in html view
column1(number)     Column2(multiplayBy)   results(result)
1                   2                      2
2                   2                      4
3                   2                      6  
//and so on

Can this be done? Even if your example doesn't use tables, can we display dynamic data like this in htmlview and if so how? I am thinking the data is loaded by document and we can manipulate it already but it is a matter of displaying it. Thanks.


Yes you can. What you need to do:

  1. Go to this article http://www.codeproject.com/KB/MFC/dhtmldialog.aspx
  2. Generate your html table
  3. Use IHTMLElement->put_outerHTML(_bstr_t("<table>.. my table data ..</table>")) to put your html in some element with specified id

All you need its get IHTMLElement than you can do everything with your page.

0

精彩评论

暂无评论...
验证码 换一张
取 消