用WebBrowser控件写了调用网页的程序,但网页中如有文本框,则在该文本框中输入文字时,无法回车换行。请教如何解决???(100分)

  • 主题发起人 主题发起人 zmj94
  • 开始时间 开始时间
Z

zmj94

Unregistered / Unconfirmed
GUEST, unregistred user!
用WebBrowser控件写了调用网页的程序,但网页中如有文本框,
则在该文本框中输入文字时,无法回车换行。如果用IE直接调用,则可以换行。
 
我试一下
 
是的,我也碰到过,不过我没有继续做了,因为现在有好我的browser了
 
以webbrowser为关键字搜索一下就知道了。
 
[red]搜索过了,没有相关的。找了很多相关的程序,都存在此问题!!![/red]
 
//取得按键消息
const
StdKeys = [VK_RETURN];
if (Msg.message = WM_KEYDOWN) then
begin
Handled := False;
with Msg do begin
if (wParam in StdKeys) then begin //回车
try
msg.hwnd:=(Homepage.ActivePage.Controls[n] as TWebBrowser).Handle;
sendkeys('~',true); //发送一个回车,这个sendkeys是D5安装盘中的一个东东sndkey32.pas ,你可以用其它方法回车
Handled := True;
except
end;
end;
 
to yousoft:
还是没法传到ASP文件中的文本框?
 
能不能给我源码我学习学习?
Blackbeam@21cn.com。
 
你可以看看TEmbeddedWB的源代码,它有两个处理办法
对Delphi5(VER130)使用窗口过程TEmbeddedWB.WBWndProc
对其他版本就拦消息:IEMessageHandler

procedure TEmbeddedWB.WBWndProc(var Message: TMessage);
const
StdKeys = [VK_RETURN, VK_BACK]; { standard keys }
ExtKeys = [VK_LEFT, VK_RIGHT]; { extended keys }
fExtended = $01000000; { extended key flag }
var
bClose: Boolean;
{$IFDEF VER130}
WinMsg: TMsg;
{$ENDIF}
begin
with Message do
begin
{$IFDEF VER130}
if (Msg >= (CN_BASE + WM_KEYFIRST)) and (Msg <= (CN_BASE + WM_DEADCHAR)) then
begin
WinMsg.HWND := Handle;
WinMsg.Message := Msg - CN_BASE;
WinMsg.WPARAM := WPARAM;
WinMsg.LPARAM := LPARAM;
WinMsg.Time := GetMessageTime;
WinMsg.pt.X := $115DE1F1;
WinMsg.pt.Y := $115DE1F1;
if not ((WPARAM in StdKeys) or
(WPARAM in ExtKeys) and ((LPARAM and fExtended) = fExtended)) then
with Application as IOleInPlaceActiveObject do
Result := Integer(TranslateAccelerator(WinMsg) = S_OK);
end
else
{$ENDIF}
case Msg of
WM_CLOSE:
begin
bClose := True;
if Assigned(FOnCloseQuery) then
FOnCloseQuery(Self, bClose);
if bClose then
OldWBWndProc(Message);
end;
WM_DDE_EXECUTE:
try
DDEExecute(WPARAM, LPARAM);
except
//
end;
WM_DDE_TERMINATE:
try
DDETerminate(WPARAM, LPARAM);
except
//
end;
else
OldWBWndProc(Message);
end;
end;
end;

{$IFNDEF VER130}

procedure TEmbeddedWB.IEMessageHandler(var Msg: TMsg; var Handled: Boolean);
{ fixes the malfunction of some keys within webbrowser control }
const
StdKeys = [VK_TAB, VK_RETURN]; { standard keys }
ExtKeys = [VK_DELETE, VK_BACK, VK_LEFT, VK_RIGHT]; { extended keys }
fExtended = $01000000; { extended key flag }
begin
Handled := False;
with Msg do
if ((Message >= WM_KEYFIRST) and (Message <= WM_KEYLAST)) and
((WPARAM in StdKeys) or {$IFDEF VER120}(GetKeyState(VK_CONTROL) < 0) or {$ENDIF}
(WPARAM in ExtKeys) and ((LPARAM and fExtended) = fExtended)) then
try
if IsChild(Handle, HWND) then
{ handles all browser related messages }
begin
with {$IFDEF VER120}Application_{$ELSE}Application{$ENDIF} as IOleInPlaceActiveObject do
Handled := TranslateAccelerator(Msg) = S_OK;
if not Handled then
begin
Handled := True;
TranslateMessage(Msg);
DispatchMessage(Msg);
end;
end;
except
end;
end; // IEMessageHandler
{$ENDIF}
 
换行处加 <br>
 
yousoft说的方法没错,我已经用过了。
不过现在我换用xianjun说的控件了。
 
yousoft:还是没调试出来,能否把整段代码发给我,谢谢!
 
xianjun:那边可以下载TEmbeddedWB的源代码?还是传不过去,如何处理?
procedure TForm1.Button1Click(Sender: TObject);
var
a,b,c,d:OleVariant;
str:string;
begin
str:=Edit1.Text; //http://....
WebBrowser1.Navigate(str,a,b,c,d);
end;
 
http://www.euromind.com/iedelphi/
 
谢谢大家!!!
 
多人接受答案了。
 
后退
顶部