Restrict mouse movement

I have a picbox with some rect shapes inside.
With the mouse i stretch this shapes.

I need a piece of code to restrict the mouse movement (only inside my picbox!) orrizontally when i'm in "Stretching mode".

If possible (maybe another question?) i also need to return
the mouse cursor at 0 (picbox coord) if the mouse go over 360.

Thanx to all.
fcpAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

setiawanCommented:
Hi fcp, what about using ClipCursor

Private Declare Function ClipCursor Lib "user32" (lpRect As Any) As Long


Private Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type
Dim RectArea As RECT

lTwipsX = Screen.TwipsPerPixelX
lTwipsY = Screen.TwipsPerPixelY
With RectArea
   .Left = Form1.Left / lTwipsX
   .Top = Form1.Top / lTwipsY
   .Right = .Left + Form1.Width / lTwipsX
    .Bottom = .Top + Form1.Height / lTwipsY
End With

Call ClipCursor(RectArea)

Above example, will limit Mouse Cursor movement in the form1.

  danny
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
setiawanCommented:
to restore the Mouse Cursor movement :

With RectArea
    .Left = 0
    .Top = 0
    .Right = Screen.Width / lTwipsX
    .Bottom = Screen.Height / lTwipsY
End With
Call ClipCursor(RectArea)


  danny
0
fcpAuthor Commented:
Wow, very fast.
How to disable the limitation? (also if i press ALT+TAB)?
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

fcpAuthor Commented:
Sorry, i lost your last comment.
PTS are yours
P.S.
(about reposition the mouse?) ;)
0
setiawanCommented:
fcp, What do you mean repostion the mouse ? do you want to set cursor postion ?
see Q.10237803 (locked question)

to disable ALT+TAB and CTRL-ALT-DEL

Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" _
        (ByVal uAction As Long, ByVal uParam As Long, ByVal lpvParam As Any, _
        ByVal fuWinIni As Long) As Long

Call SystemParametersInfo(SPI_SCREENSAVERRUNNING, False, "1", 0)

note : It's only works for Win 9x

  danny
0
fcpAuthor Commented:
mmmm....
with form1 all works good, but with picture1 i have the mouse
cursor OVER the form.

Better if you try with a form1 that contains a picture1
Picture1.scaleleft=-20
Picture1.scaletop=0
Picture1.scalewidth=380
Picture1.scaleheight=400

the form1 scale parameters are "random" (i modify them by code), so maybe we need to take care of this condition when we look at
picture1.left and top coord.
0
fcpAuthor Commented:
1) My last comment was written before reading your last comment.

2) i don't need disable the ALT+TAB or others key combinations, i only want be sure that the mouse restriction is
active only if form1 is the active form.

3) looked at Q_10237803, is exatly what i means, thanx!   8)
0
fcpAuthor Commented:
SETIAWAN?
0
setiawanCommented:
Hi fcp,

sorry, I have a lot of work to be done.
Have you solved your problem ?
or am I missing something ?

 danny
0
fcpAuthor Commented:
Yes. The problem is that your sample don't care of Picture1.scale....,
so i need (if i have right understand my code: i've pasted a "move mouse" sample in my project and modifyed the subs without very understanding what i've made!) to get the Picture1 coord. related to Form1 (or screen?) with the ClientToScreen API.
After, your code works.

This is the source (if i'm not forgotting somewhat)



Option Explicit

Private Type POINTAPI
 x As Long
 y As Long
End Type

Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long

Dim TWX As Integer
Dim TWY As Integer

Private Declare Function ClipCursor Lib "user32" (lpRect As Any) As Long

Private Type RECT
 Left As Long
 Top As Long
 Right As Long
 Bottom As Long
End Type
   
Dim RectArea As RECT
'------------------------------------
Private Sub Form_Load()
    TWX = Screen.TwipsPerPixelX
    TWY = Screen.TwipsPerPixelY
End Sub
'------------------------------------
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)

With RectArea
 Dim pt As POINTAPI
 pt.x = x
 pt.y = y
 GetPicturePoint pt.x, pt.y
 ClientToScreen Picture1.hwnd, pt
 .Top = pt.y
 .Bottom = .Top + 1
               
 pt.x = 0 ' Limit Left
 pt.y = 1
 GetPicturePoint pt.x, pt.y
 ClientToScreen Picture1.hwnd, pt
 .Left = pt.x
 
 pt.x = 360 ' Limit Right
 pt.y = 1
 GetPicturePoint pt.x, pt.y
 ClientToScreen Picture1.hwnd, pt
 .Right = pt.x
End With
Call ClipCursor(RectArea)
'------------------------------------
Private Sub GetPicturePoint(x As Long, y As Long)
 x = Picture1.ScaleX(x - Picture1.ScaleLeft, vbUser, vbTwips) / TWX
 y = Picture1.ScaleY(y, -Picture1.ScaleLeft, vbUser, vbTwips) / TWY
End Sub

I hope the code is readable, with my browser is a garbage!
0
setiawanCommented:
Hi fcp,

forgot to tell you, ClipCursor API, won't work if the rect change
(in your case, your pict size changed).

So, try to call ClipCursor again, when your pic box resize

hope this helps

  danny
0
fcpAuthor Commented:
mmm...
No problem, now.
I change only the scale inside the pic, before the ClipCursor, and with my code i dont have problems.

Can you say me where can i find a complete list of APIs with a description of their function and the data they needs?
I have the M$DNL CDs, but i can't able to find this infos.
Thanks again for your help.

0
setiawanCommented:
Dan Appleman's Win 32 API, is good one
but If you want some free source, I have seen at fortunecity before, but sorry, I forgot the exactly url.

you can also try www.mvps.ogr/vbnet
(even not complete)

 
  danny
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.