Hello,
I am trying to build a screen saver for our Marketing department at work. It is based around one single Flash control on the form.
Problem: The Flash control doesn't support a MouseMove event, to exit the screen saver when someone moves the mouse.
I've tried a few things, like sitting a text box on top of the control, and putting Flash into a user control - no such luck. What happens though is that if the mouse pointer is already hovering over where the form appears (I.E. outside the flash control) when one runs it, it immediately exits, when the mouse hasn't actually moved!
Also, I want to hide the mouse pointer when the form runs.
Does anyone know how to do these things
Regards

Building A Screen Saver
Terry B
Hi there,
Sorry you're going to have to be crystal clear I'm a little stupid.
Where abouts does that code go In VB 2005, I can only see the event handler code I can't work out how to get to the main section of the code
Regards
Keith Chapman
Hi,
I still need help with this, does anyone have any ideas
Regards
JiltedCitizen
Okay,
Thanks to both of you for your help.
I got to work, just me being silly to be honest, it hadn't clicked that this is a class and that I will have to create an instance of it etc.
How about hiding the cursor; I'd have thought that there was an easy VB way of hiding the cursor!
Regards
markm75c
shades921
Which part did you still need help with Both
Rather than going to the trouble of subclassing, might I suggest impelmenting the IMessageFilter interface and monitoring that way. For example, in your main form:
Public Class frmMain
Implements IMessageFilter
Private fiJitter as integer
Private ftLastMessage as Date = Now()
Private Const WM_KEYDOWN As Integer = &H100
Private Const WM_MOUSEMOVE As Integer = &H200
Private Const WM_LBUTTONDOWN As Integer = &H201
Private Const WM_RBUTTONDOWN As Integer = &H204
Private Const WM_MBUTTONDOWN As Integer = &H207
Private Const WM_XBUTTONDOWN As Integer = &H20B
Private Const WM_MOUSEWHEEL As Integer = &H20A
Public Function PreFilterMessage(ByRef m As System.Windows.Forms.Message) As Boolean _
Implements IMessageFilter.PreFilterMessage
Select Case m.Msg
Case WM_MOUSEMOVE
' some mice trasmit random movement even when untouched, allow for that
If DateDiff(DateInterval.Second, ftLastMessage, Now()) > 2 Then
fiJitter = 0
End If
fiJitter = fiJitter + 1
If fiJitter > 4 Then
' here you would trigger screensaver to terminate
End If
Case WM_KEYDOWN, WM_LBUTTONDOWN, WM_RBUTTONDOWN, WM_MBUTTONDOWN, WM_XBUTTONDOWN, WM_MOUSEWHEEL
' here user-specific things happened, terminate screensaver
End Select
ftLastMessage = Now
Return False 'we didn't handle the message
End Function
' ... rest of your screensaver code
End Class
cdolor
Hi buddy,
Really sorry did not respond to you after that.. Was unwell had temp of about 103.. just yesterday got relieved.. Any other help u need do post me..
Eric George
Sorry I haven't gotten back sooner, I've been out of the office quite a bit. Glad you've gotten it working. Personally, I've never really investigated the MessageFilter interface parameters but I would assume you can see what key was pressed as part of the WM_KEYDOWN message you are intercepting.
Alternately, if the control you are using doesn't consume the keypresses you can set the "KeyPreview" property of the form to TRUE and handle the keypresses inside the form's KeyDown/KeyPress event.
Good luck!
Yawei
Thanks for your reply,
I'm a little bit confused though, the links you sent seem to relate to C++ and the Win32 API - I'm looking for the .net v2 answer - sorry I should have been a bit more clear.
Are your links still relevant though I am a little confused.
Hussain Saffar
Hi there.
Thanks for your help.
In the code you supplied, "m.WParam" contains the code of the key that was pressed.
All sorted!
Thanks loads!
Samyag1
Okay,
I've just worked out how to access the Windows Form Designer code - as I say I am a little stupid
.
I've copied and pasted the code in to the designer code below Public Class Main, obviously removing the lines that start and end the Class.
It hasn't worked though. I've put an MsgBox in the area where you said to place the code to stop the screen saver just to test it but it hasn't worked.
Thanks for your help, if you can explain to me how I need to implement this I'd be appreciative.
Regards
Daniel
Here's what I put in Main.Designer.vb:
Implements IMessageFilter
Private fiJitter As Integer
Private ftLastMessage As Date = Now()
Private Const WM_KEYDOWN As Integer = &H100
Private Const WM_MOUSEMOVE As Integer = &H200
Private Const WM_LBUTTONDOWN As Integer = &H201
Private Const WM_RBUTTONDOWN As Integer = &H204
Private Const WM_MBUTTONDOWN As Integer = &H207
Private Const WM_XBUTTONDOWN As Integer = &H20B
Private Const WM_MOUSEWHEEL As Integer = &H20A
Public Function PreFilterMessage(ByRef m As System.Windows.Forms.Message) As Boolean _
Implements IMessageFilter.PreFilterMessage
Select Case m.Msg
Case WM_MOUSEMOVE
' some mice trasmit random movement even when untouched, allow for that
If DateDiff(DateInterval.Second, ftLastMessage, Now()) > 2 Then
fiJitter = 0
End If
fiJitter = fiJitter + 1
If fiJitter > 4 Then
' here you would trigger screensaver to terminate
MsgBox("it works")
End If
Case WM_KEYDOWN, WM_LBUTTONDOWN, WM_RBUTTONDOWN, WM_MBUTTONDOWN, WM_XBUTTONDOWN, WM_MOUSEWHEEL
' here user-specific things happened, terminate screensaver
MsgBox("it works")
End Select
ftLastMessage = Now
Return False 'we didn't handle the message
End Function
Kornfish
One more thing - really sorry.
Obviously the code you put also triggers main.close if a keyboard button is pressed.
I actually wish to make it do a different routine if the user presses "g".
I've guessed at this code:
Select Case m.Msg Case WM_MOUSEMOVE ' some mice trasmit random movement even when untouched, allow for that If DateDiff(DateInterval.Second, ftLastMessage, Now()) > 2 ThenfiJitter = 0
End IffiJitter = fiJitter + 1
If fiJitter > 4 Then ' here you would trigger screensaver to terminateSaver.Close()
End If Case WM_LBUTTONDOWN, WM_RBUTTONDOWN, WM_MBUTTONDOWN, WM_XBUTTONDOWN, WM_MOUSEWHEEL ' here user-specific things happened, terminate screensaverSaver.Close()
Case WM_KEYDOWN
Saver.Close()
End SelectBut I don't know how to find out what key was pressed
Regards
mark.b
Well buddy,
You have to Subclass and Hook the Mouse Move events and respond... Hiding the Mouse Pointer is quite Simple use the ShowCursor API
Show Cursor Reference - http://msdn.microsoft.com/library/default.asp url=/library/en-us/winui/winui/windowsuserinterface/resources/cursors/cursorreference/cursorfunctions/showcursor.asp
Subclassing Reference - http://msdn.microsoft.com/library/default.asp url=/library/en-us/winui/winui/windowsuserinterface/windowing/hooks/hookreference/hookfunctions/setwindowshookex.asp