Date: 02-16-2022
Return to Index
created by gbSnippets
'Compiler Comments:
'This code is written to compile in PBWin10. To compile in PBWin9, split pt
'into pt.x and pt.y as arguments wherever the PTinRect() API is used.
'Compilable Example: (Jose Includes)
#Compiler PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg, hConsole As Dword
Function PBMain() As Long
Dialog New Pixels, 0, "not captured",900,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"Push", 50,10,100,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case Cb.Msg
Case %WM_InitDialog
Case %WM_NCHitTest 'posted to window that has captured the mosue
cPrint "nchittest"
Case %WM_SetCursor 'not received if mouse is captured
cPrint "setcursor"
Case %WM_MouseMove 'posted to window that has captured the mouse
CaptureMouseIfInClientArea_ReleaseOtherwise
cPrint "mousemove"
Case %WM_LButtonDown 'posted to window that has captured the mouse
cPrint "lbuttondown"
Case %WM_LButtonUp 'posted to window that has captured the mouse
ReleaseCapture
cprint "lbuttonup"
Case %WM_Command
If Cb.Ctl = 100 And Cb.CtlMsg = %BN_Clicked Then MsgBox "I've been pushed!"
End Select
End Function
Sub CPrint (SOut As String)
Static cWritten, iCount As Long
If hConsole = 0 Then AllocConsole: hConsole = GetStdHandle(-11&) Else Incr iCount : sOut = Str$(iCount) + " " + sOut
WriteConsole hConsole, ByCopy sOut + $CrLf, Len(sOut) + 2, cWritten, ByVal 0&
End Sub
Sub CaptureMouseIfInClientArea_ReleaseOtherwise
'if mouse in client area of hDlg, then capture mouse
Local r As Rect, pt As PointAPI, w,h As Long
Dialog Get Client hDlg To w,h
GetCursorPos pt 'screen position
ScreenToClient hDlg, pt 'overlay position
GetClientRect hDlg, r
If PTinRect(r, pt) Then
SetCapture hDlg : Dialog Set Text hdlg, "captured"
SetCursor(LoadCursor(%NULL, ByVal %IDC_ARROW))
Else
ReleaseCapture : Dialog Set Text hdlg, "not captured"
End If
End Sub
'gbs_01031
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm