我用下面的代码中获得flash控件的句柄实现屏蔽FLASH菜单的功能,但是为什么当窗体上存在有两个以上的Flash控件的时候却只屏蔽其中一个FLASH菜单呢???望哪位高人指点。Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Public Const GWL_WNDPROC = (-4)
Private Const WM_RBUTTONDOWN = &H204Private Type POINTAPI
x As Long
y As Long
End Type
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Public ret As Long'SetWindowLong 的回调函数, 利用 Msg 拦截消息
Function WindowProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If Msg = WM_RBUTTONDOWN Then Exit Function
WindowProc = CallWindowProc(ret, hwnd, Msg, wParam, lParam)
End Function
Private Sub Form_Load()
Dim hFlash As Long
hFlash = FindWindowEx(picMain(7).hwnd, 0&, "MacromediaFlashPlayerActiveX", vbNullString)
ret = SetWindowLong(hFlash, GWL_WNDPROC, AddressOf WindowProc)
End Sub
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Public Const GWL_WNDPROC = (-4)
Private Const WM_RBUTTONDOWN = &H204Private Type POINTAPI
x As Long
y As Long
End Type
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Public ret As Long'SetWindowLong 的回调函数, 利用 Msg 拦截消息
Function WindowProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If Msg = WM_RBUTTONDOWN Then Exit Function
WindowProc = CallWindowProc(ret, hwnd, Msg, wParam, lParam)
End Function
Private Sub Form_Load()
Dim hFlash As Long
hFlash = FindWindowEx(picMain(7).hwnd, 0&, "MacromediaFlashPlayerActiveX", vbNullString)
ret = SetWindowLong(hFlash, GWL_WNDPROC, AddressOf WindowProc)
End Sub
解决方案 »
- 关于WM_开关的常数
- 有人用VB连过postgreSQL,和mySql数据库吗?求代码!
- 想参加一个软件设计大赛
- 用VB捕触键盘的所有操作
- 简单问题
- 500分相送只求一段简单的代码(快来看看,采纳后再给400分)
- vb6.0中向excel文件用cells填充数据,填了数百条后出现部件要求挂起,各位大虾请帮帮忙,怎样解决???
- 这一段程序我执行错误。为什么呢??请告诉我。提示我If aa.FileExists(FileName) Then这一行错误。
- 请问VB里移位操作的运算符是什么?
- 标签控件的问题
- 用PaintPicture的方法将图片居中
- 请斑竹不要删我的帖子!我是初学者只是想学点知识,问个问题!
Dim hFlash As Long
hFlash = FindWindowEx(picMain(7).hwnd, 0&, "MacromediaFlashPlayerActiveX", vbNullString)
ret = SetWindowLong(hFlash, GWL_WNDPROC, AddressOf WindowProc) hFlash = FindWindowEx(picMain(7).hwnd, 0&, "MacromediaFlashPlayerActiveX", vbNullString)
ret = SetWindowLong(hFlash, GWL_WNDPROC, AddressOf WindowProc)
End Sub
'MacromediaFlashPlayerActiveX
Private Declare Sub ZeroMemory Lib "KERNEL32" Alias "RtlZeroMemory" (dest As Any, ByVal numBytes As Long)
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Const PM_NOREMOVE = &H0
Private Const PM_NOYIELD = &H2
Private Const PM_REMOVE = &H1
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Type Msg
hwnd As Long
Message As Long
wParam As Long
lParam As Long
time As Long
pt As POINTAPI
End Type
Private Const WM_RBUTTONDBLCLK = &H206
Private Const WM_RBUTTONDOWN = &H204
Private Const WM_RBUTTONUP = &H205Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function TranslateMessage Lib "user32" (lpMsg As Msg) As Long
Private Declare Function DispatchMessage Lib "user32" Alias "DispatchMessageA" (lpMsg As Msg) As Long
Private Declare Function PeekMessage Lib "user32" Alias "PeekMessageA" (lpMsg As Msg, ByVal hwnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long, ByVal wRemoveMsg As Long) As Long
Private Declare Function WaitMessage Lib "user32" () As Long
Private Declare Function GetMessage Lib "user32" Alias "GetMessageA" (lpMsg As Msg, ByVal hwnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long) As Long
Private bCancel As BooleanPrivate Sub ProcessMessages()
Dim Message As Msg
'loop until bCancel is set to True
Do While Not bCancel
'等待一个消息
WaitMessage
If PeekMessage(Message, 0, 0, 0, PM_REMOVE) Then
Select Case Message.Message
'过滤掉关于右键操作的三个消息WM_RBUTTONDOWN 、WM_RBUTTONUP、WM_RBUTTONDBLCLK
Case WM_RBUTTONDOWN, WM_RBUTTONUP, WM_RBUTTONDBLCLK
If mGetclassName(Message.hwnd) = "MacromediaFlashPlayerActiveX" Then
MsgBox "Webbrowser控件的WM_RBUTTONDOWN消息已经被屏蔽"
Else
TranslateMessage Message
DispatchMessage Message
End If
Case Else
TranslateMessage Message
DispatchMessage Message
End Select
End If
'将控制权交还给系统,否则将陷入死循环
DoEvents
Loop
End Sub
Private Sub Form_Load()
Dim Ret As Long
bCancel = False
Show
ProcessMessages
End SubPrivate Sub Form_Unload(Cancel As Integer)
bCancel = True
End SubPrivate Function mGetclassName(ByVal WinWnd As Long) As String
Dim lpClassName As String, RetVal As Long
lpClassName = Space(256)
RetVal = GetClassName(WinWnd, lpClassName, 256)
mGetclassName = Left$(lpClassName, RetVal)
End Function
Option ExplicitPrivate Sub Form_Load()
Dim ret As Long
Dim i As Long
ret = FindWindowEx(Me.hwnd, 0&, "MacromediaFlashPlayerActiveX", vbNullString)
If ret <> 0 Then
ReDim hFlash(0)
Do While ret <> 0
ReDim Preserve hFlash(UBound(hFlash) + 1)
hFlash(UBound(hFlash)) = ret
ret = FindWindowEx(Me.hwnd, hFlash(UBound(hFlash)), "MacromediaFlashPlayerActiveX", vbNullString)
Loop
End If
If UBound(hFlash) > 1 Then
ReDim prevWndProc(UBound(hFlash))
For i = 1 To UBound(hFlash)
prevWndProc(i) = GetWindowLong(hFlash(i), GWL_WNDPROC)
SetWindowLong hFlash(i), GWL_WNDPROC, AddressOf WndProc
Next i
End If
End SubPrivate Sub Form_Unload(Cancel As Integer)
Dim i As Long
If UBound(hFlash) > 1 Then
For i = 1 To UBound(hFlash)
SetWindowLong hFlash(i), GWL_WNDPROC, prevWndProc(i)
Next i
End IfEnd Sub
'模块代码
Option ExplicitPublic Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Public Const GWL_WNDPROC = (-4)
Public hFlash() As Long
Public prevWndProc() As LongPrivate Const WM_RBUTTONDOWN = &H204
Private Const WM_RBUTTONUP = &H205Public Function WndProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim i As Long
For i = 1 To UBound(hFlash)
If hFlash(i) = hwnd Then
If Msg = WM_RBUTTONDOWN Or Msg = WM_RBUTTONUP Then
Exit Function
Else
WndProc = CallWindowProc(prevWndProc(i), hFlash(i), Msg, wParam, lParam)
Exit For
End If
End If
Next i
End Function