用MFC中的CHtmlView建立了一个单文挡程序,想在这个单文挡中显示路径(点击菜单"文件"->"打开"所获得的).我是新手,能给源码更好,谢谢!

解决方案 »

  1.   

    CHtmlView需要显示HTML文件,看你网页是如何设计的了,可以在网页里用脚本代码获取路径:
    <html>
    <head>
      <script ...>
        window.onload = function() {
          document.all.path.innerText = document.URL; // 替换div标签中的内容为当前文档的路径
        }
      </script>
    </head>
    <body>
      <div id=path>路径将显示在这儿</div>
    </body>
    </html>
      

  2.   

    谢谢好友作答,上面的代码的确可以显示路径,但只能显示html的路径.我想要的是在窗体的菜单(点击菜单"文件"->"打开"所获得的路径 或着说ctrl+o获得的路径,打开不同的文件,路径会变化).我考虑用GetModuleFileName,但不知道怎样把获得的地址显示到html中,还请赐教!
      

  3.   

    CHtmlView需要显示HTML文件,看你网页是如何设计的了,可以在网页里用脚本代码获取路径: 
    <html> 
    <head> 
      <script ...> 
        window.onload = function() { 
          document.all.path.innerText = document.URL; // 替换div标签中的内容为当前文档的路径 
        } 
      </script> 
    </head> 
    <body> 
      <div id=path>路径将显示在这儿 </div> 
    </body> 
    </html>
      

  4.   

    上面的大哥们啊,我是不知道怎样把路径(点击菜单"文件"->"打开"所获得的路径)显示在html中啊(也就是把这个路径值传给html啊)
    把路径值放到上面所指的地方,不行啊...
      

  5.   

    TCHAR szpath[MAX_PATH] = _T("");
    GetModuleFileName(NULL, szpath, MAX_PATH);this->GetDocument --> IHTMLDocument2
    IHTMLDocument2::QueryInterface --> IHTMLDocument3
    IHTMLDocument3::getElementById("path") --> IHTMLElement
    IHTMLElement::put_innerText(szpath)
      

  6.   

    jameshooo兄,你好: 
    TCHAR szpath[MAX_PATH] = _T(""); 
    GetModuleFileName(NULL, szpath, MAX_PATH); this->GetDocument --> IHTMLDocument2 
    IHTMLDocument2::QueryInterface --> IHTMLDocument3 
    IHTMLDocument3::getElementById("path") --> IHTMLElement 
    IHTMLElement::put_innerText(szpath) 
    上面的代码应放在哪里呢? 
    我吧他放在view的OnInitialUpdate()里,报错了啊赐教啊 
      

  7.   

    什么错?至少CHtmlView应该打开了某个HTML页面后才能操作
      

  8.   

    是的,已经打开了啊!
    但加入上面的代码就会编译出错:
    E:\TEST\yycHtml\yycHtmlView.cpp(75) : error C2227: left of '->IHTMLDocument2' must point to class/struct/union
    E:\TEST\yycHtml\yycHtmlView.cpp(76) : error C2653: 'IHTMLDocument2' : is not a class or namespace name
    E:\TEST\yycHtml\yycHtmlView.cpp(76) : error C2065: 'QueryInterface' : undeclared identifier
    E:\TEST\yycHtml\yycHtmlView.cpp(76) : error C2065: 'IHTMLDocument3' : undeclared identifier
    E:\TEST\yycHtml\yycHtmlView.cpp(76) : warning C4552: '>' : operator has no effect; expected operator with side-effect
    E:\TEST\yycHtml\yycHtmlView.cpp(77) : error C2653: 'IHTMLDocument3' : is not a class or namespace name
    E:\TEST\yycHtml\yycHtmlView.cpp(77) : error C2065: 'getElementById' : undeclared identifier
    E:\TEST\yycHtml\yycHtmlView.cpp(77) : error C2065: 'IHTMLElement' : undeclared identifier...
      

  9.   

    包含合适的头文件,如果不知道是什么头文件,在MSDN查IHTMLDocument2
      

  10.   

    我实在是搞不定了,恳请各位大师有肯帮忙者把代码发到我邮箱:[email protected]
    分数不够,另开贴奉上,再不够就有情后感,以后补上!先谢过了!
      

  11.   

    VC6也应该有IHTMLDocument2啊,不行就得安装SDK
      

  12.   

    jameshooo兄太客气了,祝身体早日康复!
      

  13.   

    MSDN里面的MFCIE示例非常的好,对我有非常大的帮助,因为通过点击菜单"文件"->"打开" 会弹出 "打开" 对话框,再选择一个exe文件,点击"打开"按钮就可以运行这个exe文件了.非常的好,但我还想把这个 exe文件的路径显示出来(按我的理解就是把这个路径值传给html),还没调试成功,请有时间的朋友继续关注一下,谢谢!