• Welcome to Valhalla Legends Archive.
 

Win32

Started by Grok, April 27, 2004, 03:04 PM

Previous topic - Next topic

Grok

Problem:  How to get x,y of a window in a window in a window?  Actually, it is a Cell on a FlexGrid on a Picturebox on a VBThunderMain.  If I know the window handle to something, is there an API to find its screen coordinates relative to another window?  Or even relative to the screen?  If the latter, I could call it for both and calculate the difference.

Otherwise, I have no way of showing a PopupMenu over a cell on which a user clicked.

Skywing

Quote from: Grok on April 27, 2004, 03:04 PM
Problem:  How to get x,y of a window in a window in a window?  Actually, it is a Cell on a FlexGrid on a Picturebox on a VBThunderMain.  If I know the window handle to something, is there an API to find its screen coordinates relative to another window?  Or even relative to the screen?  If the latter, I could call it for both and calculate the difference.

Otherwise, I have no way of showing a PopupMenu over a cell on which a user clicked.
Look at GetWindowRect, GetClientRect, and MapWindowPoints.

Grok

Quote from: Skywing on April 27, 2004, 03:05 PM
Quote from: Grok on April 27, 2004, 03:04 PM
Problem:  How to get x,y of a window in a window in a window?  Actually, it is a Cell on a FlexGrid on a Picturebox on a VBThunderMain.  If I know the window handle to something, is there an API to find its screen coordinates relative to another window?  Or even relative to the screen?  If the latter, I could call it for both and calculate the difference.

Otherwise, I have no way of showing a PopupMenu over a cell on which a user clicked.
Look at GetWindowRect, GetClientRect, and MapWindowPoints.

Oooh thanks.   Here was my kludgey way of doing it:

Private Type POINTAPI
   x As Long
   y As Long
End Type

Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long

Private Function GetMouseX() As Long
   Dim pPt As POINTAPI
   Dim lRet As Long
   lRet = GetCursorPos(pPt)
   GetMouseX = pPt.x
End Function

Private Function GetMouseY() As Long
   Dim pPt As POINTAPI
   Dim lRet As Long
   lRet = GetCursorPos(pPt)
   GetMouseY = pPt.y
End Function

Private Sub msfFields_EnterCell()
   Dim pX As Long, pY As Long
   pX = GetMouseX * Screen.TwipsPerPixelX
   pY = GetMouseY * Screen.TwipsPerPixelY
   'Debug.Print "( " & pX & ", " & pY & " )"
   PopupMenu mnuProfileFields, , pX - Me.Left + 120, pY - Me.Top - picPanel(2).Top
End Sub

Grok

NEW SOLUTION ( thank you Skywing ):

Private Sub msfFields_EnterCell()
   'popup menu showing list of profile fields to pick from
   Dim pX As Long, pY As Long
   Dim pScreenPoint As POINTAPI
   Call GetCursorPos(pScreenPoint)
   Call MapWindowPoints(ByVal 0&, Me.hwnd, pScreenPoint, 1)
   pX = pScreenPoint.x * Screen.TwipsPerPixelX
   pY = pScreenPoint.y * Screen.TwipsPerPixelY
   PopupMenu mnuProfileFields, , pX + 120, pY
End Sub