Results 1 to 4 of 4

Thread: screensavers contd. contd. ..........urgent!

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    India
    Posts
    298
    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.

  2. #2
    Hyperactive Member
    Join Date
    May 2000
    Location
    Or
    Posts
    316
    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.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    India
    Posts
    298
    reeset,

    am in the process of running the code u posted. Meanwhile, what is subclassing all about???


  4. #4
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    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
  •  



Click Here to Expand Forum to Full Width