MapWindowPoints

Category: API Functions

Date: 07-23-2010

Return to Index


 
'Converts, or maps, a set of points from a coordinate space relative 
'to one Window to a coordinate space relative to another Window.
 
'It's versatile, in that it can do window-to-window, screen-to-window
'and window-to-screen conversions. It can also do multiple points at a
'time by passing an array of POINT structures
 
'Primary Code:
Local P(5) as Point
MapWindowPoints hDlgFrom, hDlgTo, P, UBound(P)   'window to window
MapWindowPoints %NUL, hDlgTo, P, UBound(P)      'screen to to window
MapWindowPoints hDlgFrom, %NUL, P, UBound(P)    'window to screen
MapWindowPoints hDlgFrom, %HWND_DESKTOP, P, UBound(P)    'window to screen
 
 
'Compilable Example:
'This example puts the screen coordinates in a label as the mouse is moved.
'Note that %WM_MouseMove is not received when the cursor is away from
'the dialog, so the coordinates change only when the mouse is over the dialog.
'Also, WM_MouseMove is not received by the Dialog when the cursor is over 
'most controls, since most control window procedures handle mouse events.
#Compile Exe
#Dim All
#Include "Win32API.inc"
Global hDlg As DWord, Choice& 
Function PBMain() As Long
   Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
   Control Add Label, hDlg, 100,"", 50,10,100,20
   Control Add Option, hDlg, 200,"Screen To Client", 20,40,120,20
   Control Add Option, hDlg, 201,"Client To Screen", 20,70,120,20
   Control Set Option hDlg, 200, 200, 201
   Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
   Select Case CB.Msg
      Case %WM_MouseMove   'returns client coordinates
         Local P As Point, iResult&
         If iResult& Then
               GetCursorPos P           'p.x and p.y are in screen coordinates
               MapWindowPoints %NULL, hDlg, P, 1     'screen to window
         Else
               MapWindowPoints hDlg, %NULL, P, 1     'window to screen
               p.x = Lo(Word,CB.lParam)
               p.y = Hi(Word,CB.lParam)
               Control Get Check hDlg, 201 To iResult&
         End If
         Control Set Text hDlg, 100, "X:Y " + Str$(p.x) + ":" + Str$(p.y)
 
   End Select
End Function 
 
'gbs_00028
 


created by gbSnippets: http://www.garybeene.com