Valhalla Legends Forums Archive | General Programming | Win32

AuthorMessageTime
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.
April 27, 2004, 8:04 PM
Skywing
[quote author=Grok link=board=5;threadid=6507;start=0#msg57126 date=1083096241]
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.
[/quote]
Look at GetWindowRect, GetClientRect, and MapWindowPoints.
April 27, 2004, 8:05 PM
Grok
[quote author=Skywing link=board=5;threadid=6507;start=0#msg57127 date=1083096346]
[quote author=Grok link=board=5;threadid=6507;start=0#msg57126 date=1083096241]
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.
[/quote]
Look at GetWindowRect, GetClientRect, and MapWindowPoints.
[/quote]

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

[code]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[/code]
April 27, 2004, 8:13 PM
Grok
NEW SOLUTION ( thank you Skywing ):

[code]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[/code]
April 27, 2004, 8:28 PM

Search