如何在WEBBROWSER中用,选择菜单中的源文件后,记事本弹出来
读网页源文件

解决方案 »

  1.   

    文本是
      HtmlText := IHtmlDocument2(self.WebBrowser.Document).Body.OuterHtml ;procedure TMDIChild.ZZViewSourceCode;
    var
      hwndNotepad,hwndEdit : THandle;
      HtmlText : Widestring ;
    begin
      HtmlText := IHtmlDocument2(self.WebBrowser.Document).Body.OuterHtml ;
       WinExec('NOTEPAD.EXE',1);
      hwndNotepad := FindWindow('notepad',nil);
      hwndEdit := FindWindowEx(hwndNotepad, 0, 'Edit', nil);
      shellexecute(0,'open','notepad.exe',pchar(HtmlText),nil,sw_normal);
    end;
    这个只显示一个字符
      

  2.   

    取得完整源文件应该是 
    IHtmlDocument3(WebBrowser.Document).documentElement.outerHtml ;
    你可以把这个字符串内容存储到本地文本文件,然后调用notepad打开。即使如此,你可能发现这样子取出的内容与IE中“察看源文件”所得到的内容有些不同
    要真正模拟IE的功能,你可以使用
    IPersistFile(WebBrowser.Document).Save("D:\source.txt",false);
    然后调用notepad打开D:\source.txt