@StevieNIcks
I figured I owed her one since she let me watch her change on stage in the 70's. True story... Anyway, just a demo of using the WinAPI mouse to do a few things. If you position the mouse in the QB64 window (window must be active), hold the left button down, and move the mouse (drag) you will see the effect. If you drag past the window, unfortunately the object stops following but the mouse cursor will change. When you release the left button, when dragged outside the window, a sound will occur.
It is interesting to note the value of the left click is -32767 and -32768 when held down.
You have to accommodate 2 font heights for the title bar. (I also noticed I had to shorten the bottom by 1 for the drag, go figure.) Remember, in QB if a print occurs below the screen a change from _font 16 to _font 8 may occur in SCREEN 0. An alternative wouldbe to restrict QB4 printing to the QB63 window size, directly with...
r1 = (my - _ScreenY) \ fh - 1: r2 = (mx - _ScreenX) \ fw
IF r1 > 0 and r1 <= _Height and r2 > 0 and r2 <= _Width Then Print Chr$(3);
Anyway, good enough for now...
Pete
Code: (Select All)
Const True = 1
Const False = 0
Type POINTAPI
X_Pos As Long
Y_Pos As Long
End Type
Dim WinMse As POINTAPI
Declare Dynamic Library "User32"
Function GetAsyncKeyState% (ByVal vkey As Long)
Function GetCursorPos (lpPoint As POINTAPI)
End Declare
fh = _FontHeight: fw = _FontWidth
Do
_Limit 60
If Len(InKey$) Then System
z& = GetCursorPos(WinMse)
a& = GetAsyncKeyState(1)
hasFocus%% = _WindowHasFocus
my = WinMse.Y_Pos: mx = WinMse.X_Pos
If hasFocus%% And my >= _ScreenY And my <= _ScreenY + fh * (_Height + 2) And mx - fw >= _ScreenX And mx <= _ScreenX + fw * _Width Then
If a& And lb = 0 Then lb = -1
_MouseShow "link"
If my >= _ScreenY + fh * 2 And my < _ScreenY + fh * (_Height + 2) Then MouseInside = True Else MouseInside = False ' Adjust for title bar.
Else
If lb = 2 Then
Sound 1000, .2 ' Button released outside of QB64 app window.
End If
_MouseShow "default"
MouseInside = False
End If
If MouseInside = True Then
_Title "Win32 API Left Mouse Demo: Mouse Inside. WinMouse =" + Str$(a&) + " Left Button =" + Str$(lb): If lb = -1 Or lb = 2 Then _Delay .2 ' Just to see the change.
Else
_Title "Win32 API Left Mouse Demo: Mouse Outside. WinMouse =" + Str$(a&) + " Left Button =" + Str$(lb): If lb = -1 Or lb = 2 Then _Delay .2 ' Just to see the change.
End If
If lb = 1 And MouseInside = True Then If oldmy <> my Or oldmx <> mx Then Cls: Locate (my - _ScreenY) \ fh - 1, (mx - _ScreenX) \ fw: Print Chr$(3);: drag = 1
If lb = 2 Then lb = 0
If lb = 1 And a& = 0 Then lb = 2: Cls: If drag Then drag = 0: Locate 1, 1: Print "Stop dragging my heart around!"
If lb = -1 Then lb = 1
oldmy = my: oldmx = mx
Loop
I figured I owed her one since she let me watch her change on stage in the 70's. True story... Anyway, just a demo of using the WinAPI mouse to do a few things. If you position the mouse in the QB64 window (window must be active), hold the left button down, and move the mouse (drag) you will see the effect. If you drag past the window, unfortunately the object stops following but the mouse cursor will change. When you release the left button, when dragged outside the window, a sound will occur.
It is interesting to note the value of the left click is -32767 and -32768 when held down.
You have to accommodate 2 font heights for the title bar. (I also noticed I had to shorten the bottom by 1 for the drag, go figure.) Remember, in QB if a print occurs below the screen a change from _font 16 to _font 8 may occur in SCREEN 0. An alternative wouldbe to restrict QB4 printing to the QB63 window size, directly with...
r1 = (my - _ScreenY) \ fh - 1: r2 = (mx - _ScreenX) \ fw
IF r1 > 0 and r1 <= _Height and r2 > 0 and r2 <= _Width Then Print Chr$(3);
Anyway, good enough for now...
Pete

