插入的代碼如下:
Doc := IE.Document as IHTMLDocument2;
Doc.body.innerHTML:=Doc.body.innerHTML+HTML;
Doc._Release;
sendMessage(GetWindow(GetWindow(IE.Handle,GW_CHILD),GW_CHILD), WM_VSCROLL, SB_BOTTOM, 0);
sendMessage(GetWindow(GetWindow(IE.Handle,GW_CHILD),GW_CHILD), WM_VSCROLL, SB_BOTTOM, 0);
sendMessage(GetWindow(GetWindow(IE.Handle,GW_CHILD),GW_CHILD), WM_VSCROLL, SB_BOTTOM, 0);
if fForm<>nil then
begin
with fForm do
begin
if (not Focused) and (GetForegroundWindow<>Handle) and ((not Pushed and not Visible) or (Pushed and Visible)) and (not DontPlaySound) then
begin
//PlayEventSound(MsgSound);
FocusForm(fForm);
end;
end
end;
//代碼結束
請問如何解決cpu占用增加的問題,我感覺是我的插入代碼有問題
另外如果webbrower本身就占用cpu的話,有什么控件可以代替
我試過用memo控件,發現不占cpu,但memo控件沒法顯示html的一些內容
救火啊!!!!!!
17 个解决方案
樓主夠用功的啊!凌晨零點還在敲代碼!Web開發不熟悉,幫頂吧。
不是web的,是delphi操作Twebbrower控件
插入的話,如果我中間間隔時間拉開就不會出現占cpu的現象,插入的中間間隔時間太短,就會出現cpu拉高
分析應該主要是
Doc.body.innerHTML:=Doc.body.innerHTML+HTML;
這句的問題
最好的辦法是 把你要增加的HTML構造成一個HtmlElement,比如
document.createElement('<font>'+HTML+'</font>');
然后用
Doc.body.appendchild追加
我是字符是
msg:='<div>內容</div>';
是不是
document.createElement(msg);
然后再
Doc.body.appendchild
但
appendchild是要求IHtmlDomNode
createElement是創建了IHTMLElement
這怎么辦?
我doc是DoC: IHTMLDocument2;
這樣的
var
msgElement:OleVariant;
begin
msgElement:=WebBrowser1.OleObject.document.createElement('div');
msgElement.innerHTML:='內容';
WebBrowser1.OleObject.document.body.appendChild(msgElement);
當插入到一定的數據量時,webbrower1的內容變多了
我想刪除掉前面,只保留最后一個div,應當如何做呢
首先你的初始html頁面給定,里面的代碼都是不會變動的,然后在delphi動態追加的部分,就在delphi下面拼成代碼字串,然后WebBrowser1.Document.Script.Document.Body.InnerHTML增加進去,即可。這樣占用並不大。如果想重新寫body部分,就把body的內容代碼全部替換都沒問題。看你的思路來處理了。
如下舉例:
var
V: OleVariant;
h:WideString;
begin
h := ' <a href="" target="_blank" style="color:#0000ff;text-indent:1em;">單擊此處</a>查看與此聯系人的全部對話記錄'+
' <div id="footer"></div> '+
' <table id="listTable" name="listTable" border="0px" width="100%" cellpadding="0px" cellspacing="1px">'+
' </table>';
V := WebBrowser1.Document;
V.Script.Document.Body.InnerHTML := h;
end;