mouse events

Hi there,

I have a big problem here is my prject description:
Screensaver that uses Windows Media Player activeX to play movies.

My problem is that when media player starts a new movie i get mousemove events, ok not a biggie but.....

these events also prevents my display from going into powersave.

How is this possible? how can the start of an movie generate windows mousemoves, i understand that windows generates a mousemove when a form or something is being resized.
Could it be that Media player resize itself at start of movie and windows generates a mousemove event. Then still how is it possible that the totaly different process of powersave detects this mousemove also.

This is anoying, who will want a screensaver that prevents your screen from going into powersave.

I need any working sollution to make sure powersave works again, how i dont care, should work for vb6 and winXP.

Who is Participating?

Improve company productivity with a Business Account.Sign Up

sharmonConnect With a Mentor Commented:
If you track all the messages through SPY++ you will see that there are no mouse move messages getting through.  But at the moment that the video change these are the messages I logged.

I logged these messages from the Form window:

WM_USER+3162 (posted)

I logged these messages from the Media Player window:


I would assume our next step would be to answer these questions....

Which of these will cause powersave to be cancelled? Which of those are able to be destroyed without hurting functionality?

I didn't test long enough to make sure all was fixed with that little project I through together, but figured that would get us to where we are now.  I'm happy to help you till we find a solution though if you wanna keep working on it.

Ryan ChongCommented:
Use SetCursorPos API to set the mouse cursor position

Declare Function SetCursorPos Lib "user32" Alias "SetCursorPos" (ByVal x As Long, ByVal y As Long) As Long

Use this to set a window to maximize:

Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Const SW_HIDE = 0
Private Const SW_SHOW = 5
Private Const SW_MAXIMIZE = 3
Private Const SW_MINIMIZE = 6
Private Const SW_NORMAL = 1

Dim retval As Long, retval1 As Long, retval2 As Long
    s = Space(255)
    retval = FindWindow(vbNullString, "Windows Media Player")
    retval2 = ShowWindow(retval, SW_MAXIMIZE)

    'retval2 = ShowWindow(retval, SW_SHOW)
    'retval2 = ShowWindow(retval, SW_MINIMIZE)
    'retval2 = ShowWindow(retval, SW_HIDE)
    'retval2 = ShowWindow(retval, SW_NORMAL)

Then do the code to open a movie..    
telebasicsAuthor Commented:
tnx, for the quick response, it does raise some questions from my side though.

- For what am i going to use the SetCursorPos in this case?
- How is Maximizing the window before playing the movie prevent the mousemove event.
- My media player is inside another form (as activex) so do i need to maximize that form with your function or do i need to do something with the media player object itself.
- I resize the media player on startup to match the user preferences, so it needs to be inside a form of some kind.

Can you please explain how your code should help me.
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Ryan ChongCommented:

> how can the start of an movie generate windows mousemoves, i understand that windows
generates a mousemove when a form or something is being resized.

Are you mean the MouseMove event fired when you play a movie in Media Player? I'm not quite understand this.

Any codes here?

telebasicsAuthor Commented:
well, i have a mousemove on the mediaplayer control as well as on my mainform

this code checks to see if the mouse is moved more then 5 times if so end the screensaver.
Now my screensaver plays multiple movie clips, i have a small debug label on my form that displays the counter i keep to see if movement happens more then 5 times.

When my screensaver plays i see that the counter immidatly jumps to 2, no problem thats why the check is there.

After that on every start of a new movieclip the counter goes up 1 or 2 points again.

So i think that somehow a mousemove is detected by windows when media player starts a new clip.

If i dont play the clips just have media player loaded, this effect doesn't happen and my power save works fine, but when the clip play every start of a new clip gets me out of my powersave.

So i think that media player somehow generates a windows level mouseevent, this one i then get back in my screensaver, but it also is detected by the powersave.
Ryan ChongCommented:
Can you send me a sample? See my email on my profile.

telebasicsAuthor Commented:
i will try to make one, i dont have the problem code here (at work)
Why not restart the count of mouse moves every time you start a new movie?

telebasicsAuthor Commented:
that still tells the power save to restore
Try setting the "SendMouseMoveEvents" property to False before starting a new clip.
Just some thoughts,

For whatever reason the Media Player ActiveX is sending these mouse move messages, they are of course your problem.  I would assume that the power save feature is monitoring the system for mouse move messages which means that even the ones sent by the Media Player ActiveX in your situation will still count towards power save restoring.  Just because the mouse wasn't physically moved, doesn't really matter.  All this is only an asumption by me, but I would think that the only solutions to this problem would be to either stop using the Media Player ActiveX and find another way to play your videos that doesn't do this, or to subclass the Media Player ActiveX and destroy the mouse move messages that are the root of this problem if possible.

If you wanna send me a copy of your code, I would be happy to give it a look for you if you haven't figured it out yet.

jqv also has a good idea, just by turning that property off it may no longer send the unexplained mouse move message period, and if you still need the move events, you can always turn it back on after the video has began playing.  Make sure you try this out.

telebasicsAuthor Commented:
Ok, i tried the turning of the sendmousemoveevents totaly (wich was the only events given) and the problem still occurs.

Basicly i see always 2 mouseevents generated at start of a movie.

Sharmon, thats exactly why i came here hoping not to be needing to do that ( i mean using something else), you other comment about subcalssing, sounds very interesting, you have any documentation/tutorial or example i can use to try this one.

Maybey a hook on the mouse basic API could do the trick also.

The code is multiform and several modules, i will send you all my current version of the screensaver it has the debug label in the left top corner, the project is included.

Just put some short viseo files in a folder and select that folder to see my problem.
telebasicsAuthor Commented:

send me a mail and i will send the code to you, or post you email adres here

If someone fins a sollutions or give the golden hint, will get 2 more 300 question

I hate this stupid bug in media player :(

Sorry, forgot it wasn't in my's my email, send it over and I'll see what I can come up with.

telebasicsAuthor Commented:
its in the mail
telebasicsAuthor Commented:
ok, sharmon discovered that when the mouse starts over the Media Player my code doesn't get mousevents on start enymore, he based this after some testing with the code i send him.

I used then the code posted by ryancys to set the mouse above the media player on start.

This seemed to solve the problem, but i discovered that the media player was still disabled (as a test) after enabling the problem re apeared. So i thought so i disable media player when a new movie is started.

This works for the part that my code doesn;t get mouse events on startup anymore.

But power save still sees the mousemove events and still doesn;t go into power save.

So my program now just doesn't recieve them anymore cause the media player is disabled when they accure, but they still are generated.

sharmon did some test to find out what part of the program recieved the mouse events , and it was the form itself, sugesting that the form generates the mouse events, but i think that (since when i dont play a movie it doesn't happen) they are generated by something media player does.

I will also reward points for someone that can give me another (free) activeX with the same player capability's as media player that doesn;t have the problem (it also must be able to play mp3,wav and tells me when the mouse moves) that i can use instead.

This is less prefered sollution, since i really dont want to distribute more then the scr file.

Maybe you didn't totally understand what I emailed you.  It will happen without Media Player even in the project.  I am working on a better solution today after I am finished with my work.

Try This....

Start a new standard blank project with one form.
Add a label: Label1, Make it autosize or big enough.

Add the code below, try the same thing, have the mouse over a position the form will appear at but not moving, press F5 to run the application, and watch....then try again, making sure the mouse is in a position that is not on the form when it starts.

Option Explicit

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Static lngMouseMove As Long
    lngMouseMove = lngMouseMove + 1
    Label1.Caption = "Form_MouseMove Event: " & lngMouseMove
End Sub
Well I wrote a small test application that easily recreated the problem.  I then hooked all the mouse events and discarded the ones as needed.  You should not have any problems with the example, you'll just need to apply the same techniques to your application.  If you have any questions or this doesn't help you as it seems to have for me, be sure to let me know.

You can download it from my personal website, here.


PS.  Please let me know the results of this for you.
telebasicsAuthor Commented:
So.... I tested your program.
Even though indeed the program never receives a mousemove enymore while the hook is operational it still wont go into powersave.

I think the power save already detects the mouse event before your hook discards them.

Cant whe move the hook up higher in the structure, lets say.... main windows process?

Does it work for you? Remember: set the powersave time longer then the playing of 1 movie, otherwise it will timeout, but if a movie changes before or after timeout it will cancel the power save
telebasicsAuthor Commented:
ok did some more testing:

- With you app level mouse hook
result: No mouseevents detected but no power save, mouse still moves

- I put a LowLevel mouse hook
result: Multiple mouse events detected (injected?) at start of movie, mouse wont move

- LowLevel Hook besides the app level hook
result: No mouse events detected and mouse is unable to move, powersave will still NOT work.

I dont get it, the lowlevel hook is directly behind the driver, before windows gets the info. thats why it wont move around the screen anymore, where does power save gets the info......?

please help anyone?
telebasicsAuthor Commented:
I see that media player itself also doesnt allow the power safe to activate, maybey they hardcaded something to prevent monitor going into powersafe while playing message.

Do you know if theres a api call that would trigger powersafe immidiatly? or one that enables disables power safe fully, like there is for the screensaver?
telebasicsAuthor Commented:
telebasicsAuthor Commented:
sharnon, i am going to close this thread and want to give you the points for trying.
But it will be a B grade you want this?
Or i delete thread
Hi telebasics,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept sharmon's comment(s) as an answer.
    *** Please award an 'A' for effort.  It costs nothing and says 'thank you' writ large.

telebasics, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
DanRollins -- EE database cleanup volunteer
telebasicsAuthor Commented:
Oops forgot this one ;)

Ok here goes, again Sharmon, thanks for trying.
Good some good info from your suggestions.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.