• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 481
  • Last Modified:

Can't Trap MouseMove / MouseDown event

I'm learning to write a screen saver, this screen saver has some label controls and image controls on the form of the main screen.

I use Form_Keydown, Form_KeyPress, Form_MouseDown and Form_MouseMove events to trap the repsond of user.

The Form_Keydown & Form_KeyPress events are work fine, however, when the mouse pointer is on the one of the controls (label or image), the Form_MouseDown and Form_MouseMove is no repsond for the mouse clicking or moving.

I think I can't make another MouseDown and MouseMove events (eg Image1_MouseMove) for the labels or image controls, because there may not only one label or image on the form.

How can I overcome it?


Thank for helping.
0
saikit
Asked:
saikit
  • 8
  • 4
  • 3
  • +2
1 Solution
 
BeedleGuisCommented:
did you set the keypreview property of the form to true?
0
 
BeedleGuisCommented:
disregard that last comment.. I tested it and it did'nt work that way either.  Can't you just redirect all the control's mousemove events to the forms mousemove ie:
private sub image1_mousemove
form_mousemove
end sub
0
 
viktornetCommented:
you might want to try SetCapture() and ReleaseCapture() which are Win APIs...

btw, keypreview is only responsible for the keypresses.. not mouse clicks...

Good Luck!!

..-=ViKtOr=-..
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
BeedleGuisCommented:
or maybe use a timer control and call getcursorpos (API) store the posistion and compare it against the next timer_events results from getcursorpos...I can give you the code for this if it could be an opption
0
 
BeedleGuisCommented:
I tried setcapture .. did'nt work
0
 
saikitAuthor Commented:
viktornet,

Would you tell me what are SetCapture() and ReleaseCapture() ? How to use them when I have declared them?



BeedleGuis,

If just compare the pointer position, I still can trap the mouse press.



Thank you.
0
 
saikitAuthor Commented:
Typing correction of last comment :)
+++++++++++++++++++++++++++++++++++++
BeedleGuis,

If just compare the pointer position, I still CAN'T trap the mouse press.

Thank you.
0
 
magoo2Commented:
have you tried making the image and label controls as an array, then capture events that way?
0
 
viktornetCommented:
It's better to use the timer instead of an array of controls... that's just what I think...
0
 
BeedleGuisCommented:
even if you can't trap the mouse move, the user will more than likley move the mouse at least a little if they are going to click somthing
0
 
BeedleGuisCommented:
oops.. even if you can't trap the mouse click .. that is
0
 
viktornetCommented:
have you tried this...

dim CaptureHandle as long

'Forms OnLoad() event...

CaptureHandle = SetCapture(hWnd)

'Forms OnUnload() event...
call SetCapture(CaptureHandle)

'Forms OnMouseMove() event...

Unload Me

try this and see whether it works or not...

Good Luck!!

..-=ViKtOr=-..
0
 
viktornetCommented:
opps a little mistake...

replace the previous code with this one...


'Forms OnLoad() event...
call SetCapture(hWnd)

'Forms OnUnload() event...
call ReleaseCapture()

'Forms OnMouseMove() event...
Unload Me

now you should declare SetCapture() and ReleaseCapture() because they are Win API functions...

once again good luck!

..-=ViKtOr=-..
0
 
BeedleGuisCommented:
I tried that vik ..  did'nt work as I stated earlier . .
0
 
saikitAuthor Commented:
Hi viktornet,

What is the purpose of SetCapture() ?
Thanks.

0
 
BeedleGuisCommented:
SetCapture

VB Declaration

Declare Function SetCapture& Lib "user32" (ByVal hwnd As Long)

Description

Sets the mouse capture to the specified window. This window will receive all mouse input for the current application, or the entire system while the mouse button is pressed.

Use with VB

No problem.

Parameter      Type/Description
hwnd      Long—The handle of the window to receive all mouse input.
Return Value

Long—The handle of the window that previously had the mouse capture.

Platform

Windows 95, Windows NT, Win16


0
 
pakosCommented:
Create an empty image all over ur form,
1. do not put any image in it
2. set it all over your form (give it the same dimensions of the form)
3. set it on top of every thing
4. use on it the MouseDown and MouseMove events

tricky no?
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 8
  • 4
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now