Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
setting program to display always on top of other windows without having the focus?
#1
Is there a command or way to set your program to stay on top of other windows (and keep running), even if it doesn't have the focus? 
If there is, then I want to make line 31 enable always on top in the programs below, and line 34 disable always on top. 
Is this possible? Any info appreciated!

Program #1:
Code: (Select All)
Const cProgName = "Program #1": _Title cProgName
Const FALSE = 0: Const TRUE = Not FALSE

' TEXT MODE COLORS:
Const cBlack = 0: Const cBlue = 1: Const cGreen = 2: Const cLtBlue = 3
Const cRed = 4: Const cPurple = 5: Const cOrange = 6: Const cWhite = 7
Const cGray = 8: Const cPeriwinkle = 9: Const cLtGreen = 10: Const cCyan = 11
Const cLtRed = 12: Const cPink = 13: Const cYellow = 14: Const cLtGray = 15

' COUNT UNTIL USER HITS ESC
Screen 12 ' SCREEN 12 can use 16 color attributes with a black background. 256K possible RGB color hues. Background colors can be used with QB64.
Cls , cBlue
Color cWhite, cBlue
Dim iLoop As Integer
Dim bOnTop As Integer: bOnTop = FALSE
Locate 5, 20 ' y,x where 1,1 = top left
Print cProgName
Locate 10, 20
Print "Press A to stay on top, B for background"
Locate 25, 20 ' y,x where 1,1 = top left
Print "Hold down ESC to exit."
For iLoop = 0 To 10000
    Locate 15, 20
    Print IIFSTR$(bOnTop, "STAY ON TOP", "BACKGROUND ")
    Locate 20, 20 ' y,x where 1,1 = top left
    Print _Trim$(Str$(iLoop)) + "     "

    While _DeviceInput(1): Wend ' clear and update the keyboard buffer
    If _KeyDown(Asc("a")) Or _KeyDown(Asc("A")) Then
        bOnTop = TRUE
        '(ENABLE ALWAYS STAY ON TOP)
    ElseIf _KeyDown(Asc("b")) Or _KeyDown(Asc("B")) Then
        bOnTop = FALSE
        '(DISABLE ALWAYS STAY ON TOP)
    End If
    If _KeyDown(27) Then Exit For ' leave loop when ESC key pressed
    _Limit 4 ' keep loop at 4 frames per second
Next iLoop
End

Function IIF (Condition, IfTrue, IfFalse)
    If Condition Then IIF = IfTrue Else IIF = IfFalse
End Function
Function IIFSTR$ (Condition, IfTrue$, IfFalse$)
    If Condition Then IIFSTR$ = IfTrue$ Else IIFSTR$ = IfFalse$
End Function
Program #2:
Code: (Select All)
Const cProgName = "Program #2": _Title cProgName
Const FALSE = 0: Const TRUE = Not FALSE

' TEXT MODE COLORS:
Const cBlack = 0: Const cBlue = 1: Const cGreen = 2: Const cLtBlue = 3
Const cRed = 4: Const cPurple = 5: Const cOrange = 6: Const cWhite = 7
Const cGray = 8: Const cPeriwinkle = 9: Const cLtGreen = 10: Const cCyan = 11
Const cLtRed = 12: Const cPink = 13: Const cYellow = 14: Const cLtGray = 15

' COUNT UNTIL USER HITS ESC
Screen 12 ' SCREEN 12 can use 16 color attributes with a black background. 256K possible RGB color hues. Background colors can be used with QB64.
Cls , cRed
Color cWhite, cRed
Dim iLoop As Integer
Dim bOnTop As Integer: bOnTop = FALSE
Locate 5, 20 ' y,x where 1,1 = top left
Print cProgName
Locate 10, 20
Print "Press A to stay on top, B for background"
Locate 25, 20 ' y,x where 1,1 = top left
Print "Hold down ESC to exit."
For iLoop = 10000 To 0 Step -1
    Locate 15, 20
    Print IIFSTR$(bOnTop, "STAY ON TOP", "BACKGROUND ")
    Locate 20, 20 ' y,x where 1,1 = top left
    Print _Trim$(Str$(iLoop)) + "     "

    While _DeviceInput(1): Wend ' clear and update the keyboard buffer
    If _KeyDown(Asc("a")) Or _KeyDown(Asc("A")) Then
        bOnTop = TRUE
        '(ENABLE ALWAYS STAY ON TOP)
    ElseIf _KeyDown(Asc("b")) Or _KeyDown(Asc("B")) Then
        bOnTop = FALSE
        '(DISABLE ALWAYS STAY ON TOP)
    End If
    If _KeyDown(27) Then Exit For ' leave loop when ESC key pressed
    _Limit 4 ' keep loop at 4 frames per second
Next iLoop
End

Function IIF (Condition, IfTrue, IfFalse)
    If Condition Then IIF = IfTrue Else IIF = IfFalse
End Function
Function IIFSTR$ (Condition, IfTrue$, IfFalse$)
    If Condition Then IIFSTR$ = IfTrue$ Else IIFSTR$ = IfFalse$
End Function
Reply


Messages In This Thread
setting program to display always on top of other windows without having the focus? - by madscijr - 05-17-2024, 08:13 PM



Users browsing this thread: 1 Guest(s)