Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB6 equivalent of PointToScreen 1

Status
Not open for further replies.

AndyGroom

Programmer
May 23, 2001
972
GB
Is there a VB6 equivalent of .NET's PointToScreen method?

I need to find the absolute position of a control based on (0,0) being the top-left corner of the Windows desktop.

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
Sure. Just pop the following in a module.

Code:
[blue]Option Explicit

Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As Point) As Long
Public Type Point
        X As Long
        Y As Long
End Type

' returns absolute screen position of a control that has an hWnd
' X and Y members are in pixels
Public Function PointToScreen(Target As Control) As Point
    ClientToScreen Target.hwnd, PointToScreen
End Function[/blue]
 
That's just perfect, thanks.

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
While ClientToScreen is a direct solution to the requirement, I just wanted to highlight the alternate MapWindowPoints function which offers some additional features:
1. You can map points from any window to desktop (screen coordinates) and vice versa.
2. You can map points from one window to any other window.
3. You can map more than one point (using an array) in a single function call.
4. You can also use RECT structures in addition to POINT structures.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top