Date: 02-16-2022
Return to Index
created by gbSnippets
'Converts the client coordinates of a specified point to screen coordinates.
'Primary Code:
'First, you'll need the client coordinates, in this case of the cursor within the dialog.
'Although, the API can be used with coordinates in general, such as control coordinates.
Case %WM_MouseMove 'returns client coordinates
x = Lo(Integer,CB.lParam)
y = Hi(Integer,CB.lParam)
'Then, use the ClientToScreen API to do the conversion
Dim P as Point
p.x = x : p.y = y
ClientToScreen hDlg, P 'p.x and p.y are back to screen coordinates
'Compilable Example: (Jose Includes)
'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.
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg As Dword
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
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
p.x = Lo(Integer,CB.lParam)
p.y = Hi(Integer,CB.lParam)
ClientToScreen hDlg, P 'p.x and p.y are now screen coordinates
Control Set Text hDlg, 100, "X:Y " + Str$(p.x) + ":" + Str$(p.y)
End Select
End Function
'gbs_00020
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm