|
-
Aug 10th, 2000, 04:01 PM
#1
Thread Starter
Fanatic Member
Is there a way to set the pointer at a certain location without using the API SetCursor?
Chemically Formulated As:
Dr. Nitro
-
Aug 10th, 2000, 04:58 PM
#2
transcendental analytic
Why would you need any other method? Setcursor works perfect
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Aug 10th, 2000, 05:01 PM
#3
Frenzied Member
well the API you want to use is SetCursorPos. I don't know if this was a typo but If it wasn't that could explain why you're having problems.
unfortunatly SetCursorPos is the only way to get the cursor position. There's nothing to stop you writing a wrapper class to make things easier.
just make a class with some public properties MouseX and MouseY, and have an interface inside it that changes the mouse position, make sure it's in an activeX dll project and set its instancing to 6 - Global Multiuse then compile it, you can add it as a reference to other projects and you don't even need to make an instace of it every time, you can just use the functions as if they were in a module.
-
Aug 10th, 2000, 06:03 PM
#4
Thread Starter
Fanatic Member
Thanks for replying guys.
For some reason, I cannot get it to center correctly.
I am trying to make my cursor center on the current form. I got it to center on the X coordinates but it is not centering correctly on the Y coodinates. Meaning the cursor is still position higher than it suppose to be. Here is the code I used.
Code:
Call SetCursorPos(Me.ScaleX(Me.ScaleWidth / 2, vbTwips, vbPixels), Me.ScaleY((Me.ScaleHeight / 2), vbTwips, vbPixels))
There is a menu on the form too, so I also tried this one too and it is now a bit too low.
Code:
Call SetCursorPos(Me.ScaleX(Me.ScaleWidth / 2, vbTwips, vbPixels), Me.ScaleY(Me.Height- (Me.ScaleHeight / 2), vbTwips, vbPixels))
How do I know it is not centering on the Y coordinate? Easy, I position two lines like the following like a scope bueye on the screen.
Code:
'Vertical Line
Line1.Visible = True
Line1.X1 = Me.ScaleWidth / 2
Line1.Y1 = 0
Line1.X2 = Me.ScaleWidth / 2
Line1.Y2 = Me.ScaleHeight
'Horizontal Line
Line2.Visible = True
Line2.X1 = 0
Line2.Y1 = Me.ScaleHeight / 2
Line2.X2 = Me.ScaleWidth
Line2.Y2 = Me.ScaleHeight / 2
All of these codes go in the click event of something.
Chemically Formulated As:
Dr. Nitro
-
Aug 11th, 2000, 01:04 AM
#5
Thread Starter
Fanatic Member
Got it and understand now!
OK Kedaman and Sam! I finally got my code to work.
The reason why it didn't work before is because I was looking for half of the screen SCALE height which does not include the border width. Centering width wise was fine because I used regular width not SCALE width therefore the borders was included.
My objective is to make a zoom + center image control. As the user click on it, it center it and zooms in.
Drop an image control in and name it imgStretch. Load a picture in the image control. Drop two line controls in too and paste the following into your form. It will work in any type of form(border or bordless) and any type of windowstates.
Code:
Option Explicit
Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As Rect) As Long
Private Type Rect
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Sub imgStretch_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
imgStretch.Stretch = True
imgStretch.Visible = False
'------------------- Zoom Method -----------------------
Dim sin_ZoomRate As Single
sin_ZoomRate = 1.1
If Button = 1 Then
imgStretch.Width = imgStretch.Width * sin_ZoomRate
imgStretch.Left = imgStretch.Left + ((Me.ScaleWidth / 2) - (imgStretch.Left + (X * sin_ZoomRate)))
imgStretch.Height = imgStretch.Height * sin_ZoomRate
imgStretch.Top = imgStretch.Top + ((Me.ScaleHeight / 2) - (imgStretch.Top + (Y * sin_ZoomRate)))
ElseIf Button = 2 Then
imgStretch.Width = imgStretch.Width / sin_ZoomRate
imgStretch.Left = imgStretch.Left + ((Me.ScaleWidth / 2) - (imgStretch.Left + (X / sin_ZoomRate)))
imgStretch.Height = imgStretch.Height / sin_ZoomRate
imgStretch.Top = imgStretch.Top + ((Me.ScaleHeight / 2) - (imgStretch.Top + (Y / sin_ZoomRate)))
End If
'-------------------Make a Bullseye---------------------
'Vertical Line
Line1.Visible = True
Line1.ZOrder 0
Line1.X1 = Me.ScaleWidth / 2
Line1.Y1 = 0
Line1.X2 = Me.ScaleWidth / 2
Line1.Y2 = Me.ScaleHeight
'Horizontal Line
Line2.ZOrder 0
Line2.Visible = True
Line2.X1 = 0
Line2.Y1 = Me.ScaleHeight / 2
Line2.X2 = Me.ScaleWidth
Line2.Y2 = Me.ScaleHeight / 2
'------------------- Center the Cursor ------------------
'Me.Height = The overall height of the form
'Me.ScaleHeight = Start from the height beneath the menu or title bar
Dim r_Positon As Rect
Call GetWindowRect(Me.hwnd, r_Positon)
'PURPOSE: Get the thickness of the borders of the form
Dim sin_CenterY As Single
sin_CenterY = (Me.Width - Me.ScaleWidth) / 2
'PURPOSE: Add the thickness of the border to the last half of the form scale height
sin_CenterY = Me.ScaleY((Me.ScaleHeight / 2) + sin_CenterY, vbTwips, vbPixels)
'PURPOSE: Subtract that value from the location of the bottom of the form
sin_CenterY = r_Positon.Bottom - sin_CenterY
Call SetCursorPos(r_Positon.Right - Me.ScaleX(Me.Width / 2, vbTwips, vbPixels), _
sin_CenterY)
imgStretch.Visible = True
End Sub
Like always, thanks you two for your efforts!
[Edited by Nitro on 08-11-2000 at 05:03 AM]
Chemically Formulated As:
Dr. Nitro
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|