Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Think you can do better??? Moving a Borderless Window
#4
(11-25-2022, 07:45 PM)Pete Wrote: Investing in a CHEESE factory, Steve?


ROFL at use the arrow keys. Big Grin Big Grin Big Grin

Pete

For mouse movement of your borderless window, use my patented MBS function.  It works for all these type need!

Code: (Select All)
Screen _NewImage(800, 600, 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
_Title "No Border"
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)

Do
    x = _ScreenX: y = _ScreenY
    result = MBS
    If (result And 64) And (_KeyDown(100306) Or _KeyDown(100305)) Then _ScreenMove x + MMX, y + MMY 'ctrl-hold event
    _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

Now, I don't want any old mouse click and drag to move my screen, so I've set this up to require a CTRL + DRAG event to work.

Press CTRL on the keyboard and hold it.   Press the left mouse button.   Move the mouse, move the window.  

It really is that easy.  No API calls required, except for the ones to hide the title bar and all to begin with.  Wink

Code: (Select All)
Do
    x = _ScreenX: y = _ScreenY
    result = MBS
    If (result And 64) And (_KeyDown(100306) Or _KeyDown(100305)) Then _ScreenMove x + MMX, y + MMY 'ctrl-hold event
    _Limit 60
Loop Until _KeyDown(27)

^ There's my whole program, if you exclude the MBS routine and use it as a library routine, and don't count the code to hide the titlebar.
Reply


Messages In This Thread
RE: Think you can do better??? Moving a Borderless Window - by SMcNeill - 11-25-2022, 08:49 PM



Users browsing this thread: 1 Guest(s)