如何屏蔽鼠标点击事件?(200分)

  • 主题发起人 主题发起人 gaisy
  • 开始时间 开始时间
G

gaisy

Unregistered / Unconfirmed
GUEST, unregistred user!
我使用下面的方法将RichEdit控件鼠标点击事件给屏蔽了,但是在屏蔽WebBrowser的鼠标时
发现程序不动了,后发现是WM_PAINT消息总在发送,从而使RichEdit1WndProc方法总执行,
有没有其他方法屏蔽WebBrowser的鼠标点击事件?但是还要使滚动条有效?请各位大哥大姐
帮帮小弟?谢谢了!!!(网页脚本代码除外,很容易被绕过的)
procedure TForm1.Loaded;
begin
inherited;
OldWndProc := RichEdit1.WindowProc;
RichEdit1.WindowProc := RichEdit1WndProc;
end;

procedure TForm1.RichEdit1WndProc(var Message: TMessage);
begin
if Message.Msg <> WM_LBUTTONDOWN then //把左键信息屏蔽了。
OldWndProc(Message);
end;
 
处理else啊
 
现在问题是我什么也不处理程序已经什么也不相应了,WebBrowser不停的发出WM_PAINT消息
程序不相应了。
 
你是否处于调试状态,如果是,程序肯定会循环处理wm_paint消息
 
我执行编译的可执行程序,怎么不让它循环处理WM_PAINT消息?
 
还有就是怎么在WebBrowser中判断鼠标所在位置是否是文字链接或图片链接?怎么得知
用户选择了文字的消息?给思路也可以的!分不够还有!
 
用一下鼠标钩子钩一下嘛。
 
用户选择文本发送的是什么消息呀?
 
还有就是怎么在WebBrowser中判断鼠标所在位置是否是文字链接或图片链接?

留个EMAIL,我给你这种实现.WebBrowser是ActiveX,消息应该不好搞。应该
用Browser Host技术,M$早就为这些功能留了接口,呵呵!
 
我的信箱
gaisy@sohu.com
或gaisylly@hotmail.com
 
给我一份吧 mdc@0451.com
 
I have email you !你收到了吗???
 
看看这个,来自torry的。
var
HookID: THandle;

function MouseProc(nCode: Integer; wParam, lParam: Longint): Longint; stdcall;
var
szClassName: array[0..255] of Char;
const
ie_name = 'Internet Explorer_Server';
begin
case nCode < 0 of
True:
Result := CallNextHookEx(HookID, nCode, wParam, lParam)
else
case wParam of
WM_RBUTTONDOWN,
WM_RBUTTONUP:
begin
GetClassName(PMOUSEHOOKSTRUCT(lParam)^.HWND, szClassName, SizeOf(szClassName));
if lstrcmp(@szClassName[0], @ie_name[1]) = 0 then
Result := HC_SKIP
else
Result := CallNextHookEx(HookID, nCode, wParam, lParam);
end
else
Result := CallNextHookEx(HookID, nCode, wParam, lParam);
end;
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
HookID := SetWindowsHookEx(WH_MOUSE, MouseProc, 0, GetCurrentThreadId());
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
if HookID <> 0 then
UnHookWindowsHookEx(HookID);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Webbrowser1.Navigate('http://www.163.com');
end;
 
唉!我不该回答。。。。。。。。。。。。。。。。,白白强了50分。。。
不过可以告诉你gaisy and cloudmoon,这个是对的。
 
对不起呀!自从上次回贴以后,我就再也找不到这个贴咯.
今天才来自大富翁关于这个贴的回应,真对不起了.下面是原码,在我这儿调试通过.
自认为比HOOK好得多.如果有什么不明白,可以EMAIL:zengxiaoxun@hotmail.com.

unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, MSHTML, OleCtrls, SHDocVw, StdCtrls, ActiveX;

type
_SELECTION_TYPE = TOleEnum;
const
SELECTION_TYPE_None = $00000000;
SELECTION_TYPE_Caret = $00000001;
SELECTION_TYPE_Text = $00000002;
SELECTION_TYPE_Control = $00000003;
SELECTION_TYPE_Max = $7FFFFFFF;

SID_SHTMLEditServices: TGUID ='{3050F7F9-98B5-11CF-BB82-00AA00BDCE0B}';

type

ISegment = interface(IUnknown)
['{3050F683-98B5-11CF-BB82-00AA00BDCE0B}']
function GetPointers(const pIStart: IMarkupPointer; const pIEnd: IMarkupPointer): HResult; stdcall;
end;

IElementSegment = interface(ISegment)
['{3050F68F-98B5-11CF-BB82-00AA00BDCE0B}']
function GetElement(out ppIElement: IHTMLElement): HResult; stdcall;
function SetPrimary(fPrimary: Integer): HResult; stdcall;
function IsPrimary(out pfPrimary: Integer): HResult; stdcall;
end;

ISelectionServicesListener = interface(IUnknown)
['{3050F699-98B5-11CF-BB82-00AA00BDCE0B}']
function BeginSelectionUndo: HResult; stdcall;
function EndSelectionUndo: HResult; stdcall;
function OnSelectedElementExit(const pIElementStart: IMarkupPointer;
const pIElementEnd: IMarkupPointer;
const pIElementContentStart: IMarkupPointer;
const pIElementContentEnd: IMarkupPointer): HResult; stdcall;
function OnChangeType(eType: _SELECTION_TYPE; const pIListener: ISelectionServicesListener): HResult; stdcall;
function GetTypeDetail(out pTypeDetail: WideString): HResult; stdcall;
end;

ISelectionServices = interface(IUnknown)
['{3050F684-98B5-11CF-BB82-00AA00BDCE0B}']
function SetSelectionType(eType: _SELECTION_TYPE; const pIListener: ISelectionServicesListener): HResult; stdcall;
function GetMarkupContainer(out ppIContainer: IMarkupContainer): HResult; stdcall;
function AddSegment(const pIStart: IMarkupPointer; const pIEnd: IMarkupPointer;
out ppISegmentAdded: ISegment): HResult; stdcall;
function AddElementSegment(const pIElement: IHTMLElement; out ppISegmentAdded: IElementSegment): HResult; stdcall;
function RemoveSegment(const pISegment: ISegment): HResult; stdcall;
function GetSelectionServicesListener(out ppISelectionServicesListener: ISelectionServicesListener): HResult; stdcall;
end;


IHTMLEditDesigner = interface(IUnknown)
['{3050F662-98B5-11CF-BB82-00AA00BDCE0B}']
function PreHandleEvent(inEvtDispId: Integer; const pIEventObj: IHTMLEventObj): HResult; stdcall;
function PostHandleEvent(inEvtDispId: Integer; const pIEventObj: IHTMLEventObj): HResult; stdcall;
function TranslateAccelerator(inEvtDispId: Integer; const pIEventObj: IHTMLEventObj): HResult; stdcall;
function PostEditorEventNotify(inEvtDispId: Integer; const pIEventObj: IHTMLEventObj): HResult; stdcall;
end;

IHTMLEditServices = interface(IUnknown)
['{3050F663-98B5-11CF-BB82-00AA00BDCE0B}']
function AddDesigner(const pIDesigner: IHTMLEditDesigner): HResult; stdcall;
function RemoveDesigner(const pIDesigner: IHTMLEditDesigner): HResult; stdcall;
function GetSelectionServices(const pIContainer: IMarkupContainer;
out ppSelSvc: ISelectionServices): HResult; stdcall;
function MoveToSelectionAnchor(const pIStartAnchor: IMarkupPointer): HResult; stdcall;
function MoveToSelectionEnd(const pIEndAnchor: IMarkupPointer): HResult; stdcall;
function SelectRange(const pStart: IMarkupPointer; const pEnd: IMarkupPointer;
eType: _SELECTION_TYPE): HResult; stdcall;
end;

THTMLEditDesigner = class(TInterfacedObject,IHTMLEditDesigner)
private
function PreHandleEvent(inEvtDispId: Integer; const pIEventObj: IHTMLEventObj): HResult; stdcall;
function PostHandleEvent(inEvtDispId: Integer; const pIEventObj: IHTMLEventObj): HResult; stdcall;
function TranslateAccelerator(inEvtDispId: Integer; const pIEventObj: IHTMLEventObj): HResult; stdcall;
function PostEditorEventNotify(inEvtDispId: Integer; const pIEventObj: IHTMLEventObj): HResult; stdcall;
public
constructor Create(ABrowser:TWebBrowser);virtual;
end;

TForm1 = class(TForm)
WebBrowser1: TWebBrowser;
Button1: TButton;
Memo1: TMemo;
procedure WebBrowser1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
procedure FormCreate(Sender: TObject);
private
FHTMLEditDesigner:THTMLEditDesigner;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

uses Math;

{$R *.dfm}

{ THTMLEditDesigner }

constructor THTMLEditDesigner.Create(ABrowser: TWebBrowser);
var
ServiceProvider: IServiceProvider;
HTMLEditServices: IHTMLEditServices;
begin
if Assigned(ABrowser.Document) then
begin
ServiceProvider:=ABrowser.Document as IServiceProvider;
ServiceProvider.QueryService(SID_SHTMLEditServices,IHTMLEditServices,HTMLEditServices);
HTMLEditServices.AddDesigner(Self);
end;
end;

function THTMLEditDesigner.PostEditorEventNotify(inEvtDispId: Integer;
const pIEventObj: IHTMLEventObj): HResult;
begin
Result:=S_OK;
end;

function THTMLEditDesigner.PostHandleEvent(inEvtDispId: Integer;
const pIEventObj: IHTMLEventObj): HResult;
begin
Result:=S_False;
end;

function THTMLEditDesigner.PreHandleEvent(inEvtDispId: Integer;
const pIEventObj: IHTMLEventObj): HResult;
begin
if Assigned(pIEventObj.srcElement) and (pIEventObj.srcElement.tagName<>'BODY') then
Result:=S_OK
else
Result:=S_FALSE;
end;

function THTMLEditDesigner.TranslateAccelerator(inEvtDispId: Integer;
const pIEventObj: IHTMLEventObj): HResult;
begin
Result:=S_False;
end;

procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
begin
if not Assigned(FHTMLEditDesigner) then
FHTMLEditDesigner:=THTMLEditDesigner.Create(WebBrowser1);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
WebBrowser1.Navigate('http://www.delphibbs.com/');
end;

end.
 
后退
顶部