Const
“專業(yè)、務(wù)實、高效、創(chuàng)新、把客戶的事當(dāng)成自己的事”是我們每一個人一直以來堅持追求的企業(yè)文化。 創(chuàng)新互聯(lián)公司是您可以信賴的網(wǎng)站建設(shè)服務(wù)商、專業(yè)的互聯(lián)網(wǎng)服務(wù)提供商! 專注于成都網(wǎng)站設(shè)計、成都網(wǎng)站建設(shè)、外貿(mào)網(wǎng)站建設(shè)、軟件開發(fā)、設(shè)計服務(wù)業(yè)務(wù)。我們始終堅持以客戶需求為導(dǎo)向,結(jié)合用戶體驗與視覺傳達,提供有針對性的項目解決方案,提供專業(yè)性的建議,創(chuàng)新互聯(lián)建站將不斷地超越自我,追逐市場,引領(lǐng)市場!
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
'取消鼠標(biāo)穿透(一般窗體)
SetWindowLong
Me.hwnd,
GWL_EXSTYLE,
'取消鼠標(biāo)穿透(UpdateLayeredWindow畫窗體)
SetWindowLong
Me.hwnd,
GWL_EXSTYLE,
WS_EX_LAYERED
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)
'按絕對位置移動鼠標(biāo)
'在鼠標(biāo)坐標(biāo)系統(tǒng)中,屏幕在水平和垂直方向上均勻分割成65535×65535個單元,
'當(dāng)前所用顯示屏分辨率為1366*768
'所以要進行如上轉(zhuǎn)換
mouse_event(H2, 0, 0, 0, 0) '鼠標(biāo)左鍵按下
mouse_event(H4, 0, 0, 0, 0) '鼠標(biāo)左鍵彈起
msdn上有 mouse_event 的詳解,大致使用如上
調(diào)用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 '模擬鼠標(biāo)左鍵按下
Public Const MOUSEEVENTF_LEFTUP = H4 ’模擬鼠標(biāo)左鍵釋放
Public Const MOUSEEVENTF_MIDDLEDOWN = H20 '模擬鼠標(biāo)中間鍵按下
Public Const MOUSEEVENTF_MIDDLEUP = H40 '模擬鼠標(biāo)中間鍵釋放
Public Const MOUSEEVENTF_RIGHTDOWN = H8 '模擬鼠標(biāo)右鍵按下
Public Const MOUSEEVENTF_RIGHTUP = H10 '模擬鼠標(biāo)右鍵釋放
Public Const MOUSEEVENTF_MOVE = H1 '模擬鼠標(biāo)指針移動
例:
mouse_event MOUSEEVENTF_LEFTDOWN,10,10,0,0
'在(10,10)模擬鼠標(biāo)左鍵按下
很簡單,通過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參數(shù)常量:
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代表菜單中從上往下數(shù)第一個菜單項
? End If
End Sub
Private Sub UserForm_Initialize_onmove() '恢復(fù)窗體移動
? 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與禁止代碼中的數(shù)值同步,原因時雖然表面上刪除了菜單項,實則為隱藏了菜單項,各個菜單的索引值并沒有變,所以0依然代表初始菜單的第一個菜單項,即被刪除的那個菜單項
? End If
End Sub
然后如果你的窗口菜單是動態(tài)變化的,建議聲明常數(shù):
Const MF_BYPOSITION As Integer = H0
然后使用相關(guān)的Windows功能的常數(shù)進行刪除菜單。常數(shù)需要自行查看winuser.h頭文件
如果找不到該頭文件,可以看這里:網(wǎng)頁鏈接
其余信息詳見MSDN:網(wǎng)頁鏈接
最后說一下,不建議前面網(wǎng)友說的重寫WndProc的方法,因為這樣攔截標(biāo)題欄點擊消息會導(dǎo)致窗體本身的菜單也無法顯示出來,有損窗體功能,并且像雙擊左上角圖標(biāo)關(guān)閉窗體這樣的功能也會跟著攔截消息的操作一起被吞掉。
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
'取消鼠標(biāo)穿透(一般窗體) SetWindowLong Me.hwnd, GWL_EXSTYLE, 0
'取消鼠標(biāo)穿透(UpdateLayeredWindow畫窗體) SetWindowLong Me.hwnd, GWL_EXSTYLE, WS_EX_LAYERED
當(dāng)前題目:vb.net鼠標(biāo)穿透 窗口鼠標(biāo)穿透
本文來源:http://muchs.cn/article32/hjejpc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供虛擬主機、網(wǎng)站導(dǎo)航、、網(wǎng)站維護、全網(wǎng)營銷推廣、ChatGPT
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)