Click to See Complete Forum and Search --> : Need To Know How To Find Coordinates Of Form


iCeD
August 19th, 1999, 12:36 AM
I'm using the GetCursorPos API Call To Get The Cursor POS And Deposit It Into CsrCoords Which Is A PointAPI Type.

I Want To Determine Whether The Cursor Is In The Form, If It Goes Out Of The Form Or On The TitleBar I Want To Call HideLinedControls Which Is A Sub In frmMain.

The Code I Have In The Timer Form Is:
Private Sub MNUTmr_Timer()
If CsrCoords.Y < frmMain.Top Or CsrCoords.Y > frmMain.Top + frmMain.Height Then
Debug.Print "Too High Or Low"
frmMain.HideLinedControls
MNUTmr.Enabled = False
End If
If CsrCoords.X < frmMain.Left Or CsrCoords.X > frmMain.Left + frmMain.Width Then
frmMain.HideLinedControls
Debug.Print "Too Much To Side!"
MNUTmr.Enabled = False
End If
End Sub

HideLinedControls Is A Sub I'm Using To Hide The Lines Of A Control I Made.

How Can I Find Out The Coordinates Of The Form And Use Them In The Above Timer Code To See Whether The Mouse Is OutSide Of The Form Or In The TitleBar?

Lothar Haensler
August 19th, 1999, 02:31 AM
just an idea: I think the Top and height properties are in Twips by default.
I think you should transform those to pixels using screen.TwipsPerPixelx and so on.

(BTW: capitalizing the first letter of each word makes your post very hard to read)

iCeD
August 19th, 1999, 07:59 PM
well, i tried setting the scalemode to twips but it would not work. How would i use the Screen.TwipsPerPixelX to determine the top of the form?

Lothar Haensler
August 20th, 1999, 02:37 AM
Ok, I haven't tried this, but I'd code like this:

dim lTop as long
ltop = frm.Top * screen.TwipsPerPixelY



lTop whould now contain the Top coordinate in Pixels, right? Now you should compare that with the result from GetCursorPos.

iCeD
August 20th, 1999, 03:34 AM
Thank you man, it worked... i used the following code to determine whether the mouse has gone over the Titllebar or off the form:

Dim MainTop, MainLeft, MainRight, MainBottom As Integer

Private Sub MNUTmr_Timer()
MainTop = (frmMain.Top / Screen.TwipsPerPixelY) + 29
MainLeft = frmMain.Left / Screen.TwipsPerPixelX
MainRight = MainLeft + (frmMain.Width / Screen.TwipsPerPixelX)
MainBottom = MainTop + (frmMain.Height / Screen.TwipsPerPixelY)

If CsrCoords.Y < MainTop Or CsrCoords.Y > MainBottom Then
Debug.Print "Too High Or Low"
frmMain.HideLinedControls
MNUTmr.Enabled = False
End If
If CsrCoords.X < MainLeft Or CsrCoords.X > MainRight Then
frmMain.HideLinedControls
Debug.Print "Too Much To Side!"
MNUTmr.Enabled = False
End If
End Sub

Lothar Haensler
August 20th, 1999, 03:38 AM
Thanks for sharing the final code with us.

Lothar Haensler
August 20th, 1999, 03:44 AM
I wonder where the +29 in
"MainTop = (frmMain.Top / Screen.TwipsPerPixelY) + 29"
comes from?
Is that because of the border width?
if so, you can probably get the true value from GetSystemMetrics API SM_CYBORDER...