What bone-head thing did I miss this time?
#10
Thumbs Up 
(10-29-2022, 02:06 AM)Pete Wrote: I've made three different ways to handle that. One of the simplest...

Code: (Select All)
CONST HWND_TOPMOST%& = -1
CONST SWP_NOSIZE%& = &H1
CONST SWP_NOMOVE%& = &H2
CONST SWP_SHOWWINDOW%& = &H40

DECLARE DYNAMIC LIBRARY "user32"
    FUNCTION SetWindowPos& (BYVAL hWnd AS LONG, BYVAL hWndInsertAfter AS _OFFSET, BYVAL X AS INTEGER, BYVAL Y AS INTEGER, BYVAL cx AS INTEGER, BYVAL cy AS INTEGER, BYVAL uFlags AS _OFFSET)
    FUNCTION GetForegroundWindow& 'find currently focused process handle
END DECLARE

' Needed for acquiring the hWnd of the window
DIM hWnd AS LONG ' Get hWnd value

DO ' Title window and get handle.
    _LIMIT 30
    _TITLE "Persistency Window Demo"
    hWnd = _WINDOWHANDLE
    i = i + 1: IF i > 100000 THEN PRINT "Cannt get window handle.": END
LOOP UNTIL hWnd

wdth = 300: hght = 400

' Set screen
s& = _NEWIMAGE(wdth, hght, 32)
SCREEN s&
_DEST 0

_SCREENMOVE 800, 50
' Main loop
Level = 175
_DELAY .1

DO
    _LIMIT 30
    FGwin& = GetForegroundWindow&

    IF hWnd <> FGwin& THEN ' QB64 no longer in focus.
        WHILE _MOUSEINPUT: WEND
        y& = SetWindowPos&(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE + SWP_SHOWWINDOW)
        PRINT y&, hWnd, HWND_TOPMOST%&, SWP_NOSIZE%& + SWP_NOMOVE%& + SWP_SHOWWINDOW%&
        DO: _LIMIT 30: LOOP UNTIL hWnd = GetForegroundWindow&
    END IF
    IF INKEY$ = CHR$(27) THEN SYSTEM
LOOP

Pete

API Queen... Dammit Steve!

OK now I've got two of 'em to lose! Smile thanks!
b = b + ...
Reply


Messages In This Thread
RE: What bone-head thing did I miss this time? - by bplus - 10-29-2022, 02:29 AM



Users browsing this thread: 7 Guest(s)