资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

vb.net鼠标穿透 窗口鼠标穿透

VB实现窗体鼠标穿透

Const

“专业、务实、高效、创新、把客户的事当成自己的事”是我们每一个人一直以来坚持追求的企业文化。 创新互联公司是您可以信赖的网站建设服务商、专业的互联网服务提供商! 专注于成都网站设计、成都网站建设、外贸网站建设、软件开发、设计服务业务。我们始终坚持以客户需求为导向,结合用户体验与视觉传达,提供有针对性的项目解决方案,提供专业性的建议,创新互联建站将不断地超越自我,追逐市场,引领市场!

GWL_EXSTYLE

=

(-20)

Const

WS_EX_LAYERED

=

H80000

Const

WS_EX_

TRANSPARENT

As

Long

=

H20

Private

Declare

Function

GetWindowLong

Lib

"user32"

Alias

"GetWindowLongA"

(ByVal

hwnd

As

Long,

ByVal

nIndex

As

Long)

As

Long

Private

Declare

Function

SetWindowLong

Lib

"user32"

Alias

"SetWindowLongA"

(ByVal

hwnd

As

Long,

ByVal

nIndex

As

Long,

ByVal

dwNewLong

As

Long)

As

Long

Private

Sub

Command1_Click()

SetWindowLong

Me.hwnd,

GWL_EXSTYLE,

GetWindowLong(Me.hwnd,

GWL_EXSTYLE)

Or

WS_EX_LAYERED

Or

WS_EX_TRANSPARENT

End

Sub

'取消鼠标穿透(一般窗体)

SetWindowLong

Me.hwnd,

GWL_EXSTYLE,

'取消鼠标穿透(UpdateLayeredWindow画窗体)

SetWindowLong

Me.hwnd,

GWL_EXSTYLE,

WS_EX_LAYERED

VB.NET模拟鼠标问题

Declare Sub mouse_event Lib "user32" Alias "mouse_event" (ByVal dwFlags As Integer, ByVal dx As Integer, ByVal dy As Integer, ByVal cButtons As Integer, ByVal dwExtraInfo As Integer)

Dim postion1 As New Point

mouse_event(H1 Or H8000, postion1.X * 65535 / 1366, postion1.Y * 65535 / 768, 0, 0)

'按绝对位置移动鼠标

'在鼠标坐标系统中,屏幕在水平和垂直方向上均匀分割成65535×65535个单元,

'当前所用显示屏分辨率为1366*768

'所以要进行如上转换

mouse_event(H2, 0, 0, 0, 0) '鼠标左键按下

mouse_event(H4, 0, 0, 0, 0) '鼠标左键弹起

msdn上有 mouse_event 的详解,大致使用如上

如何在VB.net中用程序控制鼠标移动和点击

调用api

在Visual Baisc.net中的声明:

Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)

Public Const MOUSEEVENTF_LEFTDOWN = H2 '模拟鼠标左键按下

Public Const MOUSEEVENTF_LEFTUP = H4 ’模拟鼠标左键释放

Public Const MOUSEEVENTF_MIDDLEDOWN = H20 '模拟鼠标中间键按下

Public Const MOUSEEVENTF_MIDDLEUP = H40 '模拟鼠标中间键释放

Public Const MOUSEEVENTF_RIGHTDOWN = H8 '模拟鼠标右键按下

Public Const MOUSEEVENTF_RIGHTUP = H10 '模拟鼠标右键释放

Public Const MOUSEEVENTF_MOVE = H1 '模拟鼠标指针移动

例:

mouse_event MOUSEEVENTF_LEFTDOWN,10,10,0,0

'在(10,10)模拟鼠标左键按下

VB.NET怎么可以限制窗体不能被鼠标随便拖动位置

很简单,通过WindowsAPI,删除窗体菜单项就行了

首先在窗体类中声明API:

Declare Function GetSystemMenu Lib "user32" (ByVal hWnd As IntPtr, ByVal bRevert As Boolean) As IntPtr

Declare Function RemoveMenu Lib "user32" (ByVal lngHmenu As IntPtr, ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer

其次声明API参数常量:

Const MF_BYPOSITION As Integer = H400

然后在窗体类中写入过程:

Private Sub UserForm_Initialize_stopmove() '禁止窗体移动

  Dim lngHwnd As IntPtr

  Dim lngHmenu As IntPtr

  lngHwnd = Me.Handle

  If lngHwnd 0 Then

      lngHmenu = GetSystemMenu(lngHwnd, False)

      RemoveMenu(lngHmenu, 0, MF_BYPOSITION) '这里的0代表菜单中从上往下数第一个菜单项

  End If

End Sub

Private Sub UserForm_Initialize_onmove() '恢复窗体移动

  Dim lngHwnd As IntPtr

  Dim lngHmenu As IntPtr

  lngHwnd = Me.Handle

  If lngHwnd 0 Then

      lngHmenu = GetSystemMenu(lngHwnd, True)

RemoveMenu(lngHmenu, 0, MF_BYPOSITION) '这里的0与禁止代码中的数值同步,原因时虽然表面上删除了菜单项,实则为隐藏了菜单项,各个菜单的索引值并没有变,所以0依然代表初始菜单的第一个菜单项,即被删除的那个菜单项

  End If

End Sub

然后如果你的窗口菜单是动态变化的,建议声明常数:

Const MF_BYPOSITION As Integer = H0

然后使用相关的Windows功能的常数进行删除菜单。常数需要自行查看winuser.h头文件

如果找不到该头文件,可以看这里:网页链接

其余信息详见MSDN:网页链接

最后说一下,不建议前面网友说的重写WndProc的方法,因为这样拦截标题栏点击消息会导致窗体本身的菜单也无法显示出来,有损窗体功能,并且像双击左上角图标关闭窗体这样的功能也会跟着拦截消息的操作一起被吞掉。

vb2008 ( vb .net ) 下如何实现 鼠标穿透 ??

Const GWL_EXSTYLE = (-20)

Const WS_EX_LAYERED = H80000

Const WS_EX_TRANSPARENT As Integer= H20

Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Integer, ByVal nIndex As Integer) As Integer

Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Integer, ByVal nIndex As Integer, ByVal dwNewLong As Integer) As Integer

Private Sub Command1_Click()

SetWindowLong Me.hwnd, GWL_EXSTYLE, GetWindowLong(Me.hwnd, GWL_EXSTYLE) Or WS_EX_LAYERED Or WS_EX_TRANSPARENT

End Sub

'取消鼠标穿透(一般窗体) SetWindowLong Me.hwnd, GWL_EXSTYLE, 0

'取消鼠标穿透(UpdateLayeredWindow画窗体) SetWindowLong Me.hwnd, GWL_EXSTYLE, WS_EX_LAYERED


分享标题:vb.net鼠标穿透 窗口鼠标穿透
标题来源:http://cdkjz.cn/article/hjejpc.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220