Solved

mouse events

Posted on 2002-04-09
26
268 Views
Last Modified: 2013-11-25
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.

0
Comment
Question by:telebasics
  • 14
  • 6
  • 3
  • +3
26 Comments
 
LVL 49

Expert Comment

by:Ryan Chong
Comment Utility
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..    
0
 
LVL 2

Author Comment

by:telebasics
Comment Utility
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.
0
 
LVL 49

Expert Comment

by:Ryan Chong
Comment Utility
Hi,

> 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?

regards
0
 
LVL 2

Author Comment

by:telebasics
Comment Utility
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.
0
 
LVL 49

Expert Comment

by:Ryan Chong
Comment Utility
Can you send me a sample? See my email on my profile.

regards
0
 
LVL 2

Author Comment

by:telebasics
Comment Utility
i will try to make one, i dont have the problem code here (at work)
0
 
LVL 7

Expert Comment

by:Z_Beeblebrox
Comment Utility
Why not restart the count of mouse moves every time you start a new movie?

Zaphod.
0
 
LVL 2

Author Comment

by:telebasics
Comment Utility
that still tells the power save to restore
0
 
LVL 12

Expert Comment

by:jgv
Comment Utility
Try setting the "SendMouseMoveEvents" property to False before starting a new clip.
0
 
LVL 6

Expert Comment

by:sharmon
Comment Utility
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.

Regards,
Shannon
0
 
LVL 6

Expert Comment

by:sharmon
Comment Utility
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.

Regards,
Shannon
0
 
LVL 2

Author Comment

by:telebasics
Comment Utility
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.
0
 
LVL 2

Author Comment

by:telebasics
Comment Utility
Sharmon,

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 :(
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 6

Expert Comment

by:sharmon
Comment Utility
telebasics,

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

Regards,
Shannon
shannonh@vpcusa.com
0
 
LVL 2

Author Comment

by:telebasics
Comment Utility
its in the mail
0
 
LVL 2

Author Comment

by:telebasics
Comment Utility
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.
0
 
LVL 6

Expert Comment

by:sharmon
Comment Utility
Telebasics,

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
0
 
LVL 6

Expert Comment

by:sharmon
Comment Utility
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.

http://www.theharmonfamily.com/MediaTest.zip

Regards,
Shannon

PS.  Please let me know the results of this for you.
0
 
LVL 2

Author Comment

by:telebasics
Comment Utility
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
0
 
LVL 2

Author Comment

by:telebasics
Comment Utility
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?
0
 
LVL 6

Accepted Solution

by:
sharmon earned 300 total points
Comment Utility
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_ACTIVATEAPP
WM_WINDOWPOSCHANGING
WM_NCACTIVATE
WM_ACTIVATE
WM_ERASEBKGND
WM_USER+3162 (posted)
WM_PAINT
WM_SETCURSOR

I logged these messages from the Media Player window:

WM_WINDOWPOSCHANGING
WM_WINDOWPOSCHANGED
WM_STYLECHANGING
WM_STYLECHANGED
WM_ACTIVATEAPP
WM_NCACTIVATE
WM_ACTIVATE
WM_IME_SETCONTEXT
WM_IME_NOTIFY
WM_SETFOCUS
WM_MOVE
WM_KILLFOCUS
WM_DESTROY
WM_NCDESTROY

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.

Regards,
Shannon
0
 
LVL 2

Author Comment

by:telebasics
Comment Utility
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?
0
 
LVL 2

Author Comment

by:telebasics
Comment Utility
0
 
LVL 2

Author Comment

by:telebasics
Comment Utility
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
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
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
0
 
LVL 2

Author Comment

by:telebasics
Comment Utility
Oops forgot this one ;)

Ok here goes, again Sharmon, thanks for trying.
Good some good info from your suggestions.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now