Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Can't Trap MouseMove / MouseDown event

Posted on 1999-07-21
17
Medium Priority
?
477 Views
Last Modified: 2008-03-10
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
Comment
Question by:saikit
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 4
  • 3
  • +2
17 Comments
 
LVL 2

Expert Comment

by:BeedleGuis
ID: 1526526
did you set the keypreview property of the form to true?
0
 
LVL 2

Expert Comment

by:BeedleGuis
ID: 1526527
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
 
LVL 10

Expert Comment

by:viktornet
ID: 1526528
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:BeedleGuis
ID: 1526529
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
 
LVL 2

Expert Comment

by:BeedleGuis
ID: 1526530
I tried setcapture .. did'nt work
0
 

Author Comment

by:saikit
ID: 1526531
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
 

Author Comment

by:saikit
ID: 1526532
Typing correction of last comment :)
+++++++++++++++++++++++++++++++++++++
BeedleGuis,

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

Thank you.
0
 
LVL 1

Expert Comment

by:magoo2
ID: 1526533
have you tried making the image and label controls as an array, then capture events that way?
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1526534
It's better to use the timer instead of an array of controls... that's just what I think...
0
 
LVL 2

Expert Comment

by:BeedleGuis
ID: 1526535
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
 
LVL 2

Expert Comment

by:BeedleGuis
ID: 1526536
oops.. even if you can't trap the mouse click .. that is
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1526537
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
 
LVL 10

Expert Comment

by:viktornet
ID: 1526538
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
 
LVL 2

Expert Comment

by:BeedleGuis
ID: 1526539
I tried that vik ..  did'nt work as I stated earlier . .
0
 

Author Comment

by:saikit
ID: 1526540
Hi viktornet,

What is the purpose of SetCapture() ?
Thanks.

0
 
LVL 2

Expert Comment

by:BeedleGuis
ID: 1526541
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
 

Accepted Solution

by:
pakos earned 120 total points
ID: 1526542
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

722 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