Date: 02-16-2022
Return to Index
created by gbSnippets
'Compiler Comments:
'To compile with PBWin9, split pt into pt.x and pt.y as arguments wherever
'the WindowFromPoint() and PtInRect() API is used.
'Compilable Example: (Jose Includes)
#Compiler PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "WIN32API.INC"
Global hDlg As Dword
Function PBMain
Local Result As Long
Dialog New 0, "", , , 200, 60, %WS_OverlappedWindow To hDlg
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc()
Local rc As Rect, pt As PointAPI, hTemp As Dword
Select Case Cb.Msg
Case %WM_LButtonDown
SetFocus hDlg 'why?
SetCapture hDlg 'start capturing, so can detect LButtonUp when it occurs
Case %WM_MouseMove
If GetCapture() = hDlg Then 'app has capture 'why?
' Drawing and dragging operations
GetCursorPos pt
Dialog Set Text hDlg, Str$(pt.x) + Str$(pt.y)
hTemp = WindowFromPoint (pt) '(pt) for PBWin10
If hTemp = hDlg Then
Dialog Set Text hDlg, "Over myapp" +Str$(pt.x) + Str$(pt.y) + Str$(hTemp)
Else
Dialog Set Text hDlg, "Not over myapp" + Str$(pt.x) + Str$(pt.y) + Str$(hTemp)
End If
End If
Case %WM_LButtonUp
ReleaseCapture 'generates a WM_CAPTURECHANGED message 'why not do my mouse up stuff here?
Case %WM_CaptureChanged
'sent to window losing the mouse capture
'window receives this message if it calls ReleaseCapture itself
GetClientRect hDlg, rc 'relative coordinates of hDlg client area
MapWindowPoints hDlg, %NULL, ByVal VarPtr(rc), 2 'screen coordinate of hDlg client area
GetCursorPos pt 'screen coordinates of cursor
If PtInRect(rc, pt) Then
Dialog Set Text hDlg, "Inside"
Else
Dialog Set Text hDlg, "Outside"
End If
Case %WM_CancelMode
'msg received when system windows (Task Mgr, Task Switch, ...) pop up
End Select
End Function
'gbs_01033
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm