Blog信息 |
blog名称:注册会计师(注会)练习软件 日志总数:398 评论数量:116 留言数量:27 访问次数:3274238 建立时间:2005年6月6日 |

| |
[delpih编程]delphi中将webbrowser用作网页编辑器 软件技术
吕向阳 发表于 2009/4/28 9:49:18 |
引用单元 ComObj,ActiveX;
1.在formcreate事件中加入Application.OnMessage := IEMessageHandler;这是用作对webbrowser回车事件处理消息2。打开网页时作相应处理,进入网页编辑状态webbrowser1.Navigate(htmfile);while webbrowser1.busy doApplication.ProcessMessages;(webbrowser1.Document as IHTMLDocument2).designMode := 'On';3.加入一按钮,处理点击时使用网页中文字变红,这对粗procedure Tformmp3.Button2Click(Sender: TObject);beginwith webbrowser1.Document as IHTMLDocument2 dobeginexecCommand('ForeColor', False, 'red'); //使选中文字变红execCommand('Bold', False, 1); //加粗选中文字webbrowser1.ExecWB(OLECMDID_SAVE,OLECMDEXECOPT_DONTPROMPTUSER ); //这是对修改后的网页保存end;end;4.响应回车等的消息处理程序procedure Tformmp3.IEMessageHandler(var Msg: TMsg; var Handled: Boolean);constStdKeys = [VK_TAB, VK_RETURN]; { 标准键 }ExtKeys = [VK_DELETE, VK_BACK, VK_LEFT, VK_RIGHT]; { 扩展键 }fExtended = $01000000; { 扩展键标志 }beginHandled := False;with Msg doif ((Message >= WM_KEYFIRST) and (Message <= WM_KEYLAST)) and((wParam in StdKeys) or (GetKeyState(VK_CONTROL) < 0) or(wParam in ExtKeys) and ((lParam and fExtended) = fExtended)) thentryif IsChild(webbrowser1.Handle, hWnd) then{ 处理所有的浏览器相关消息 }beginwith webbrowser1.Application as IOleInPlaceActiveObject doHandled := TranslateAccelerator(Msg) = S_OK;if not Handled thenbeginHandled := True;TranslateMessage(Msg);DispatchMessage(Msg);end;end;exceptend;end; // IEMessageHandler |
|
|