java 鼠标穿透_关于窗体的鼠标穿透……

在做一个图像处理程序,做了一个蒙板,想来想去,用个窗体透明,然后让鼠标穿透最简单…………

于是乎…………上网查找…………得到资料若干:

大多数提到了一个函数:SetWindowLong。

于是乎“F1”之,得到如下:(英文太烂…………没看懂…………)

SetWindowLong Function

The SetWindowLong function changes an attribute of the specified window. The function also sets the 32-bit (long) value at the specified offset into the extra window memory.

Note  This function has been superseded by the function. To write code that is compatible with both 32-bit and 64-bit versions of Microsoft Windows, use the SetWindowLongPtr function.

Syntax

LONG SetWindowLong(

HWND hWnd,

int nIndex,

LONG dwNewLong

);

Parameters

hWnd[in]

Handle to the window and, indirectly, the class to which the window belongs.

Windows 95/98/Me: The SetWindowLong function may fail if the window specified by the hWnd parameter does not belong to the same process as the calling thread.nIndex[in] Specifies the zero-based offset to the value to be set. Valid values are in the range zero through the number of bytes of extra window memory, minus the size of an integer. To set any other value, specify one of the following values.

GWL_EXSTYLESets a new extended window style. For more information, see .GWL_STYLESets a new .GWL_WNDPROCSets a new address for the window procedure.

Windows NT/2000/XP: You cannot change this attribute if the window does not belong to the same process as the calling thread.GWL_HINSTANCESets a new application instance handle.GWL_IDSets a new identifier of the window.GWL_USERDATASets the user data associated with the window. This data is intended for use by the application that created the window. Its value is initially zero.The following values are also available when the hWnd parameter identifies a dialog box.

DWL_DLGPROCSets the new address of the dialog box procedure.DWL_MSGRESULTSets the return value of a message processed in the dialog box procedure.DWL_USERSets new extra information that is private to the application, such as handles or pointers.dwNewLong[in] Specifies the replacement value.

Return Value

If the function succeeds, the return value is the previous value of the specified 32-bit integer.

If the function fails, the return value is zero. To get extended error information, call .

If the previous value of the specified 32-bit integer is zero, and the function succeeds, the return value is zero, but the function does not clear the last error information. This makes it difficult to determine success or failure. To deal with this, you should clear the last error information by calling (0) before calling SetWindowLong. Then, function failure will be indicated by a return value of zero and a GetLastError result that is nonzero.

英文巨烂

32633a5ac1cfa9cc4ddd86b9e6c50dd3.gif…………没看懂

6665a8b9421f4891ba5c2319332a19d5.gif…………不过至少知道该function有3个参数:hWnd:应该是窗体句柄,nIndex :这个好像就是设置窗体的(一堆值

34c50589935a7a5d534e378cc37248e5.gif不到干吗的)。最后的一个…………dwNewLong 翻了下是“指定代替者”?不过看看网上的好像没人用这个…………于是乎,曰:“放”………………

但查找中找到了网友ahjoe(强哥)的东西:

//做成控件了,支持透明度,支持鼠标穿透。

unit   TransForm;   {DragonPC   2001.2.21   }

interface

uses

Windows,   Messages,   SysUtils,   Classes,   Graphics,   Controls,   Forms   ;

type

TTranForm   =   class(TComponent)

private

FAlphaValue:   integer   ;

FTransMouse:   Boolean;

FParentFormHandle:   HWND   ;

procedure   SetFAlphaValue(Alpha:integer);

procedure   SetTransMouse(value:   Boolean);

protected

procedure   UpdateDisplay;

public

constructor   Create(AOwner:   TComponent);   override;

published

property   AlphaValue:   integer   read   FAlphaValue   write   SetFAlphaValue   ;

property   TransMouse:   Boolean   read   FTransMouse   write   SetTransMouse;

end;

procedure   Register;

function   SetLayeredWindowAttributes(Handle:   HWND;   COLORKEY:   COLORREF;

Alpha:   BYTE;   Flags:   DWORD):   Boolean;   stdcall;   external   'USER32.DLL';

implementation

procedure   Register;

begin

RegisterComponents('Standard',   [TTranForm]);

end;

procedure   TTranForm.SetFAlphaValue(Alpha:   integer);

begin

if   (Alpha   >=   0)   and   (Alpha   <   256)   then   begin

FAlphaValue   :=   Alpha   ;

UpdateDisplay()   ;

end;

end;

procedure   TTranForm.UpdateDisplay;

begin

if   (csDesigning   in   ComponentState)   then   Exit   ;

SetLayeredWindowAttributes(FParentFormHandle,   0,   FAlphaValue,   2);

end;

constructor   TTranForm.Create(AOwner:   TComponent);

begin

inherited;

if   (csDesigning   in   ComponentState)   then

Exit;

FAlphaValue   :=   255   ;

FParentFormHandle   :=   TForm(AOwner).Handle   ;

SetWindowLong(FParentFormHandle,   GWL_EXSTYLE,

GetWindowLong(FParentFormHandle,   GWL_EXSTYLE)   or   $80000);

end;

procedure   TTranForm.SetTransMouse(value:   Boolean);

begin

if   FTransMouse   <>   value   then

begin

FTransMouse   :=   value;

if   value   then

SetWindowLong(FParentFormHandle,   GWL_EXSTYLE,

GetWindowLong(FParentFormHandle,   GWL_EXSTYLE)   or   WS_EX_TRANSPARENT)

else

SetWindowLong(FParentFormHandle,   GWL_EXSTYLE,

GetWindowLong(FParentFormHandle,   GWL_EXSTYLE)   and   not   WS_EX_TRANSPARENT);

end;

end;

end.

本着“拿来主意”的精神,直接用了(免责!!我可是有说是谁的东西!)…………

tranForm := TTranForm.Create(Self);

TranForm.AlphaValue := 150;

TranForm.TransMouse := False;

这样就好了…………

要是要穿透只要TranForm.TransMouse := true;

不过问题是,这个好像不能将窗体设置到空中里…………会失效…………

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值