webbrowser 的巨难问题!我头都大了。(100分)

  • 主题发起人 主题发起人 xbxsoft
  • 开始时间 开始时间
X

xbxsoft

Unregistered / Unconfirmed
GUEST, unregistred user!
[:(!]如何给载入网页的webbrowser指定光标。
!·##·#
不要告诉我是Webbrowser.cursor.
 
什么叫指定光标,光标指定到某个页面元素上?
 
我的意思是说,当webbrowser载入网页后,光标移到webbrowser时显示我指定的光标。
如: Screen.Cursors[crmycur1] :=LoadCursor(hInstance,'NEW');
screen.Cursor := crmycur1;

哪位大虾能帮帮我呀:
 
截获WM_SETCURSOR消息试试,MSDN的说明是:
The DefWindowProc function passes the WM_SETCURSOR message to a parent window before processing.
If the parent window returns TRUE, further processing is halted.
Passing the message to a window's parent window gives the parent window control over the cursor's setting in a child window
 
TO: astros 你说的方法不行呀我怎么截也截不到。
if IsChild(WebBrowser_Main.Handle,Msg.hwnd) and
(Msg.message = WM_SETCURSOR) then
begin
handled :=True;
end;
 
是重载主窗口的消息响应函数对WM_SETCURSOR进行处理
你的代码我没看明白,不是自己创建的WebBrowser吗?
我测试过了,挺好的
下面是我的BCB测试代码:
void __fastcall TForm1::WndProc(TMessage &Msg)
{
if(Msg.Msg == WM_SETCURSOR)
{
TPoint pt;
::GetCursorPos(&pt);
TRect r;
::GetWindowRect(CppWebBrowser1->Handle, &r);
if(PtInRect(&r, pt))
{
::SetCursor(hCursor);
Msg.Result = 1;
return;
}
}
TForm::WndProc(Msg);
}
初始化时加一句:
hCursor = LoadCursor(NULL, IDC_HAND);
鼠标一进WebBrowser控件就变成手了
 
to: astros, 你好,我看了你的C++代码后下面是我用dephi写的,用一些不明白的地方
请多多指点,谢了。:
private
//截获WM_SETCURSOR消息
procedure WM_SetCur(var msg:Tmessage); message WM_SETCURSOR;
Const
CRMYCUR1= 99;

procedure TForm_Main.FormCreate(Sender: TObject);
begin
初始化光标
Screen.Cursors[crmycur1] := LoadCursor(hInstance,'NEW');
end;

procedure TForm_Main.WM_SetCur(var msg: Tmessage);
var
pt:Tpoint; //对应你的C++代码 : TPoint pt;
r:TRect; //TRect r;
begin
// if(Msg.Msg == WM_SETCURSOR)
if msg.Msg = WM_SETCURSOR then
begin
//::GetCursorPos(&pt);
GetCursorPos(pt);
//::GetWindowRect(CppWebBrowser1->Handle, &r);
getwindowRect(WebBrowser_Main.Handle,r);
//if(PtInRect(&r, pt))
if ptInRect(r,pt) then;
begin
// ::SetCursor(hCursor);
SetCursor(crmycur1);
//Msg.Result = 1;
msg.Result := 1;
[red]//return;[/red]我不知怎么换

end;
end;
//TForm::WndProc(Msg);
WM_SetCur(msg);
end;
===================================
执行时出现堆栈溢出的错误
 
return=exit
 
给你另外一种思路吧,我的方法很简单,但确实很奏效

我曾用类似的方法把WebBrowser控件的窗口客户区边框给改掉了
利用样式表可以做到这些, 样式表所起的作用也不过是修改了一些对象的属性
查一下MSDN, 用下面的方法试一下:
这是我的代码,已经验证通过
procedure TForm1.FormCreate(Sender: TObject);
begin
WebBrowser1.Navigate('about:blank');
end;

procedure TForm1.Button1Click(Sender: TObject);
var
vDoc: OleVariant;
begin
vDoc := WebBrowser1.Document;
if Assigned(IDispatch(vDoc)) then
begin
vDoc.body.style.cursor := 'hand';
end;
end;
关于cursor的取值
参照MSDN上的,
http://msdn.microsoft.com/workshop/browser/mshtml/reference/ifaces/style/cursor.asp
下面我贴出一部分内容---->>>>

IHTMLStyle::cursor Property Internet Development Index

--------------------------------------------------------------------------------

Sets or retrieves the type of cursor to display as the mouse
pointer moves over the object.

What's New for Microsoft® Internet Explorer 6
The cursor property supports progress, not-allowed, no-drop,
vertical-text, all-scroll, col-resize, row-resize, and url(uri)
as new cursor styles.

Syntax

HRESULT IHTMLStyle::get_cursor(BSTR* p);HRESULT IHTMLStyle::put_cursor(BSTR v);
Parameters

p
Pointer to a variable of type BSTR that receives one or more of the values
listed in Possible Values, separated by commas.
v
BSTR that specifies one or more of the values listed in Possible Values,
separated by commas.
Possible Values

all-scroll Internet Explorer 6 and later. Arrows pointing up, down, left,
and right with a dot in the middle, indicating that the page can be scrolled
in any direction.
auto Default. Browser determines which cursor to display based on the current
context.
col-resize Internet Explorer 6 and later. Arrows pointing left and right
with a vertical bar separating them, indicating that the item/column can be
resized horizontally.
crosshair Simple cross hair.
default Platform-dependent default cursor; usually an arrow.
hand Hand with the first finger pointing up, as when the user moves the
pointer over a link.
help Arrow with question mark, indicating help is available.
move Crossed arrows, indicating something is to be moved.
no-drop Internet Explorer 6 and later. Hand with a small circle with a line
through it, indicating that the dragged item cannot be dropped at the current cursor location.
not-allowed Internet Explorer 6 and later. Circle with a line through it, indicating that the requested action will not be carried out.
pointer Internet Explorer 6 and later. Hand with the first finger pointing up, as when the user moves the pointer over a link. Identical to hand.
progress Internet Explorer 6 and later. Arrow with an hourglass next to it, indicating that a process is running in the background. User interaction with the page is unaffected.
row-resize Internet Explorer 6 and later. Arrows pointing up and down with a horizontal bar separating them, indicating that the item/row can be resized vertically.
text Editable text; usually an I-bar.
url(uri) Internet Explorer 6 and later. Cursor is defined by the author, using a custom Uniform Resource Identifier (URI), such as url('mycursor.cur'). Cursors of type .CUR and .ANI are the only supported cursor types.
vertical-text Internet Explorer 6 and later. Editable vertical text, indicated by a horizontal I-bar.
wait Hourglass or watch, indicating that the program is busy and the user should wait.
*-resize Arrows, indicating an edge is to be moved; the asterisk (*) can be N, NE, NW, S, SE, SW, E, or W—each representing a compass direction.

Return Value

Returns S_OK if successful, or an error value otherwise.

Remarks

The property handles a comma-separated list of cursor values. If the user agent does not understand or cannot find the first cursor specified, it looks at the next cursor in the comma-separated list and continues until it finds a usable cursor. If the user agent does not understand any of the cursors that are listed, the cursor does not change.
 
MSDN Home > MSDN Library > Programming and Reusing the Browser > MSHTML Reference > Interfaces and Scripting Objects > IHTMLStyle
下面是cursor的一些可能的取值
all-scroll
auto
col-resize
crosshair
default
hand
help
move
但是如果要是想实现自定义的光标,取值可以是一个url地址,指出
光标文件所在的位置

当然楼上的一些方法也是可取的
 
后退
顶部