Date: 07-23-2010
Return to Index
'Sometimes you need to know which child window is at a point, most often
'associated with the position of the cursor. The WindowFromPoint function
'does the trick.
'Primary Code:
x = 500 : y = 500
hDlg = ChildWindowFromPoint( hDlg, x,y )
'Compilable Example:
'This example displays the control under the cursor
#Compile Exe
#Dim All
#Include "Win32API.inc"
Global hDlg As DWord, h100 as DWord, h200 as DWord, h300 as DWord, h400 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, %WS_Border
Control Add Label, hDlg, 200,"", 50,40,100,20, %WS_Border
Control Add Label, hDlg, 300,"", 50,70,100,20, %WS_Border
Control Add Label, hDlg, 400,"", 50,100,100,20, %WS_Border
Control Handle hDlg, 100 To h100 : Control Handle hDlg, 200 To h200
Control Handle hDlg, 300 To h300 : Control Handle hDlg, 400 To h400
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case CB.Msg
Case %WM_SetCursor
Local P as Point, hTemp as DWord
GetCursorPos P 'p.x and p.y are in screen coordinates
ScreenToClient hDlg, P 'p.x and p.y are now dialog client coordinates
Control Set Text hDlg, 200, "X:Y " + Str$(p.x) + ":" + Str$(p.y)
hTemp = ChildWindowFromPoint( hDlg, p.x, p.y )
Select Case hTemp
Case h100 : Control Set Text hDlg, 100, "Label 100"
Case h200 : Control Set Text hDlg, 100, "Label 200"
Case h300 : Control Set Text hDlg, 100, "Label 300"
Case h400 : Control Set Text hDlg, 100, "Label 400"
Case Else : Control Set Text hDlg, 100, "No Match"
End Select
End Select
End Function
'gbs_00019
created by gbSnippets: http://www.garybeene.com