_MOUSEHIDE / _MOUSESHOW
#6
Try this.  How's it perform on your machine?

Code: (Select All)
Screen _NewImage(800, 600, 32)
$Color:32

Declare Dynamic Library "User32"
    Function GetWindowLongA& (ByVal hwnd As Long, Byval nIndex As Long)
    Function SetWindowLongA& (ByVal hwnd As Long, Byval nIndex As Long, Byval dwNewLong As Long)
    Function SetWindowPos& (ByVal hwnd As Long, Byval hWndInsertAfter As Long, Byval x As Long, Byval y As Long, Byval cx As Long, Byval cy As Long, Byval wFlags As Long)
End Declare

Do: Loop Until _ScreenExists
GWL_STYLE = -16
ws_border = &H800000
WS_VISIBLE = &H10000000
hwnd& = _WindowHandle
winstyle& = GetWindowLongA&(hwnd&, GWL_STYLE)
a& = SetWindowLongA&(hwnd&, GWL_STYLE, winstyle& And WS_VISIBLE)
a& = SetWindowPos&(hwnd&, 0, 0, 200, 400, 0, 39)

Line (0, 0)-(_Width, 30), SkyBlue, BF 'My custom titlebar
pw = _PrintWidth("ð Steve's Tripple Line Title ð")
_PrintString ((_Width - pw) \ 2, 2), "ð Steve's Tripple Line Tittle ð"

Do
    x = _ScreenX: y = _ScreenY
    result = MBS
    If (result And 64) And (_MouseY <= 30) Then startdrag = -1 '            we're in the title bar and triggered a hold event.
    If startdrag Then
        _ScreenMove x + MMX, y + MMY '                                      drag the window from the title bar
        _MouseMove Mouse_StartX, Mouse_StartY '                              keep the mouse in its original position
    End If
    If (result And 1) = 0 Then startdrag = 0 '                              hold event is over, quit dragging
    _Limit 60
Loop Until _KeyDown(27)


Function MBS% 'Mouse Button Status
    Static StartTimer As _Float
    Static ButtonDown As Integer
    Static ClickCount As Integer
    Const ClickLimit## = 0.2 'Less than 1/4th of a second to down, up a key to count as a CLICK.
    '                          Down longer counts as a HOLD event.
    Shared Mouse_StartX, Mouse_StartY, Mouse_EndX, Mouse_EndY, MMX, MMY

    MMX = 0: MMY = 0
    While _MouseInput 'Remark out this block, if mouse main input/clear is going to be handled manually in main program.
        Select Case Sgn(_MouseWheel)
            Case 1: tempMBS = tempMBS Or 512
            Case -1: tempMBS = tempMBS Or 1024
        End Select
        MMX = MMX + _MouseMovementX
        MMY = MMY + _MouseMovementY
    Wend


    If _MouseButton(1) Then tempMBS = tempMBS Or 1
    If _MouseButton(2) Then tempMBS = tempMBS Or 2
    If _MouseButton(3) Then tempMBS = tempMBS Or 4


    If StartTimer = 0 Then
        If _MouseButton(1) Then 'If a button is pressed, start the timer to see what it does (click or hold)
            ButtonDown = 1: StartTimer = Timer(0.01)
            Mouse_StartX = _MouseX: Mouse_StartY = _MouseY
        ElseIf _MouseButton(2) Then
            ButtonDown = 2: StartTimer = Timer(0.01)
            Mouse_StartX = _MouseX: Mouse_StartY = _MouseY
        ElseIf _MouseButton(3) Then
            ButtonDown = 3: StartTimer = Timer(0.01)
            Mouse_StartX = _MouseX: Mouse_StartY = _MouseY
        End If
    Else
        BD = ButtonDown Mod 3
        If BD = 0 Then BD = 3
        If Timer(0.01) - StartTimer <= ClickLimit Then 'Button was down, then up, within time limit.  It's a click
            If _MouseButton(BD) = 0 Then tempMBS = 4 * 2 ^ ButtonDown: ButtonDown = 0: StartTimer = 0
        Else
            If _MouseButton(BD) = 0 Then 'hold event has now ended
                tempMBS = 0: ButtonDown = 0: StartTimer = 0
                Mouse_EndX = _MouseX: Mouse_EndY = _MouseY
            Else 'We've now started the hold event
                tempMBS = tempMBS Or 32 * 2 ^ ButtonDown
            End If
        End If
    End If
    MBS = tempMBS
End Function


That seems to pretty well stick the mouse to my window, wherever I start dragging it from.
Reply


Messages In This Thread
_MOUSEHIDE / _MOUSESHOW - by Pete - 11-25-2022, 07:32 PM
RE: _MOUSEHIDE / _MOUSESHOW - by mnrvovrfc - 11-25-2022, 07:39 PM
RE: _MOUSEHIDE / _MOUSESHOW - by gaslouk - 11-26-2022, 08:22 AM
RE: _MOUSEHIDE / _MOUSESHOW - by SMcNeill - 11-26-2022, 08:36 AM
RE: _MOUSEHIDE / _MOUSESHOW - by Pete - 11-26-2022, 09:17 AM
RE: _MOUSEHIDE / _MOUSESHOW - by SMcNeill - 11-26-2022, 10:34 AM
RE: _MOUSEHIDE / _MOUSESHOW - by Pete - 11-26-2022, 04:55 PM
RE: _MOUSEHIDE / _MOUSESHOW - by mnrvovrfc - 11-26-2022, 08:07 PM



Users browsing this thread: 1 Guest(s)