Date: 02-16-2022
Return to Index
created by gbSnippets
'Sometimes you need to know which application (dialog) is at a point, most often
'associated with the position of the cursor. The WindowFromPoint function
'does the trick.
'Compiler Comments:
'This code was written to compilete in PBWin10. To compile with PBWin9, split pt
'into pt.x and pt.y as arguments wherever the WindowFromPoint() API is used.
'Primary Code:
Local pt as Point
pt.x = 500 : pt.y = 500
hDlg = WindowFromPoint(pt)
'Compilable Example: (Jose Includes)
'This examples uses a timer to repeatedly check which window is under the
'cursor. The cursor can be anywhere on the screen.
#Compiler 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
SetTimer(hDlg, 200, 50, 0) 'creates the timer 200ms
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case CB.Msg
Case %WM_Timer
Local pt as Point, hTemp as DWord
GetCursorPos pt 'p.x and p.y are in screen coordinates
hTemp = WindowFromPoint (pt)
If hTemp = hDlg Then
Control Set Text hDlg, 100, "Over myapp"
Else
Control Set Text hDlg, 100, "NOT over myapp"
End If
End Select
End Function
'gbs_00033
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm