Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Think you can do better??? Moving a Borderless Window
#1
This is a mix of WIN32 API and QB64 code. I would have posted it all in Win API, but I haven't looked into controlling the mouse cursor, only locating it. So what it does is produce a borderless window with a fake blank top strip you can drag around the screen. The limits placed on the cursor, to keep it from racing away from the window, are a bit choppy. Maybe that could be improved with a different approach. If anyone has a pure Win API example to compare it to, that would be nice.

Code: (Select All)
DIM WinMse AS POINTAPI
TYPE POINTAPI
    X_Pos AS LONG
    Y_Pos AS LONG
END TYPE

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)
    FUNCTION GetAsyncKeyState% (BYVAL vkey AS LONG)
    FUNCTION GetCursorPos (lpPoint AS POINTAPI)
END DECLARE

WIDTH 50, 25
DO: LOOP UNTIL _SCREENEXISTS
GWL_STYLE = -16
ws_border = &H800000
WS_VISIBLE = &H10000000
_TITLE "No Border"
hwnd& = _WINDOWHANDLE
winstyle& = GetWindowLongA&(hwnd&, GWL_STYLE)
_DELAY .25
a& = SetWindowLongA&(hwnd&, GWL_STYLE, winstyle& AND WS_VISIBLE)
a& = SetWindowPos&(hwnd&, 0, 0, 200, 400, 0, 39)

LOCATE 1, 1
COLOR 0, 7
PRINT SPACE$(_WIDTH);
fw = _FONTWIDTH
fh = _FONTHEIGHT
x = _SCREENX: y = _SCREENY

DO
    _LIMIT 60

    IF GetAsyncKeyState(1) < 0 THEN
        IF lb = 0 THEN lb = 1
    ELSE
        IF lb THEN lb = 0: dragpt = 0
    END IF

    z = GetCursorPos(WinMse)

    IF lb THEN
        IF dragpt THEN
            IF WinMse.X_Pos <> oldxpos THEN
                j = SGN(WinMse.X_Pos - oldxpos) ' This will be multiplied in statements to speed things up.
                DO
                    x = x + j * 8
                    _SCREENMOVE x, y
                    _MOUSEMOVE dragpt, 1
                    IF j > 0 THEN
                        IF x + dragpt * fw >= WinMse.X_Pos THEN EXIT DO
                    ELSE
                        IF x + dragpt * fw <= WinMse.X_Pos THEN EXIT DO
                    END IF
                LOOP
            END IF
            IF WinMse.Y_Pos <> oldypos THEN
                j = SGN(WinMse.Y_Pos - oldypos)
                DO
                    IF j > 0 THEN
                        y = y + j * 3
                        _SCREENMOVE x, y
                        _MOUSEMOVE dragpt, 1
                        IF y >= WinMse.Y_Pos THEN EXIT DO
                    ELSE
                        y = y + j * 8
                        _SCREENMOVE x, y
                        _MOUSEMOVE dragpt, 1
                        IF y <= WinMse.Y_Pos THEN EXIT DO
                    END IF
                LOOP
            END IF
            z = GetCursorPos(WinMse)
        ELSE
            IF WinMse.Y_Pos >= _SCREENY AND WinMse.Y_Pos <= _SCREENY + fh THEN
                x = _SCREENX: y = _SCREENY
                dragpt = (WinMse.X_Pos - x) \ fw
            END IF
        END IF
    END IF
    IF LEN(INKEY$) THEN SYSTEM
    oldypos = WinMse.Y_Pos
    oldxpos = WinMse.X_Pos
LOOP

Pete
Reply


Messages In This Thread
Think you can do better??? Moving a Borderless Window - by Pete - 11-25-2022, 07:10 PM



Users browsing this thread: 5 Guest(s)