|
-
Sep 12th, 2000, 10:56 PM
#1
Thread Starter
Hyperactive Member
Hi,
As I've posted messages before, I'm trying to create a screensaver using the Shockwave Flash control to run a .swf file.(I was trying to use a .exe file, but not any more!). The problem is that I'm unable to detect a keypress & mousemove/mouseclick on my form. I tried setting the form's keypreview property to true, but that didn't work as well. So I tried using another form on top of the form which has the .swf file. By making this form transparent and setting it as the topmoost form I managed to detect the mouseclick. But I'm still unable to detect a keypress. Any ideas abt how it can be done????
Thanx.
-
Sep 13th, 2000, 02:01 AM
#2
Hyperactive Member
The most reliable way that I can think of would be to
subclass your window, and then just detect the mouse and
keyboard events. This way you will also be able to get rid
of the transparent form. This code should work for you. I
pulled it out of a screensaver that I created about a year
ago.
Code:
'*********put this code in a module******************
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
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Dim lpPrevWndProc As Long
Public Const WM_KEYDOWN = &H100
Public Const WM_MBUTTONDOWN = &H207
Public Const WM_LBUTTONUP = &H202
Public Const WM_RBUTTONDOWN = &H204
Public Const GWL_WNDPROC = -4
Public Function Hook(ByVal hwnd As Long)
'This function hooks the window that you would like to
'subclass
lpPrevWndProc = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindowProc)
End Function
Public Sub UnHook(ByVal hwnd As Long)
'This unhooks the window. We must do this or else
'an error is thrown when the program unloads.
Call SetWindowLong(hwnd, GWL_WNDPROC, lpPrevWndProc)
End Sub
'This is the function that receives all messages sent to
'our form.
Function WindowProc(ByVal hw As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
'MsgBox uMsg, wParam, lParam
Select Case uMsg
'First, detect if a key is pressed
Case WM_KEYDOWN
MsgBox "keydown"
'Detect if the "enter" button on a mouse was clicked
Case WM_MBUTTONDOWN
MsgBox "mouseDown"
'Detects the leftmouse click
Case WM_LBUTTONUP
MsgBox "Left Mousebutton"
'Detects the rightmouse click
Case WM_RBUTTONDOWN
MsgBox "Right MouseButton"
End Select
'let the msg get through to the form
WindowProc = CallWindowProc(lpPrevWndProc, hw, uMsg, wParam, lParam)
End Function
Now put the following in the form that you want to subclass
Code:
'***********put this code in a form****************
Private Sub form_load()
'Send the hwnd of the form that you wish to subclass
Call Hook(Me.hwnd)
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
'Before unload, always unhook you window, else a
'critical error will occur.
Call UnHook(Me.hwnd)
End Sub
Hope this helps.
-
Sep 13th, 2000, 02:41 AM
#3
Thread Starter
Hyperactive Member
reeset,
am in the process of running the code u posted. Meanwhile, what is subclassing all about???
-
Sep 16th, 2000, 12:03 AM
#4
Frenzied Member
Take a look at the introduction to subclassing on this site. As far as I can tell, it's basically a way of handling Windows messages yourself instead of letting VB create the usual events for you.
Harry.
"From one thing, know ten thousand things."
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|