Quelle drôle d'idée, vous allez me dire.
Je m'explique.
Je suis en train de coder un dock (du moins un truc dans le genre), je préfère appeler cela un lanceur d'application
Donc j'ai une barre en haut de mon écran qui me permet de lancer des programmes.
Je lance une vidéo en plein écran, et bien je vois toujours ma barre en haut de l'écran.
C'est pas terrible du coup.
Donc le code suivant me permet de savoir si je suis en train d'utiliser une fenêtre en plein écran.
En gros, pour la fenêtre qui a le focus, je teste :
- Si elle n'a pas de barre de titre
- Si elle occupe tout l'écran (écran principal dans cette exemple)
et si les 2 conditions sont vrai, la fenêtre qui a le focus est en plein écran
Et j'utilise ce résultat pour afficher ou masquer ma barre.
Voici le code
Code : Tout sélectionner
; Auteur : Le Soldat Inconnu
; Version de PB : 4.40
; Explication du programme :
; Détection d'une fenêtre plein écran
Procedure FullScreenWindowDetected()
Protected Window, DesktopWindow, Detected, WindowRect.RECT
Structure Structure_Monitor
Size.l
Screen.RECT
WorkArea.RECT
Principal.l
EndStructure
Protected Monitor.Structure_Monitor, MonitorID
Monitor\Size = SizeOf(Structure_Monitor)
DesktopWindow = FindWindow_(0, "Program Manager")
GetWindowThreadProcessId_(DesktopWindow, @DesktopWindow_PId)
MonitorID = MonitorFromWindow_(DesktopWindow, 0)
If MonitorID
GetMonitorInfo_(MonitorID, @Monitor)
Window = FindWindow_(0, 0)
While Window
If Window <> DesktopWindow
Style = GetWindowLongPtr_(Window, #GWL_STYLE)
If Style & #WS_VISIBLE = #WS_VISIBLE And Style & #WS_THICKFRAME = 0
GetWindowRect_(Window, @WindowRect)
If WindowRect\left <= Monitor\Screen\left And WindowRect\top <= Monitor\Screen\top And WindowRect\right >= Monitor\Screen\right And WindowRect\Bottom >= Monitor\Screen\Bottom
GetWindowThreadProcessId_(Window, @Window_PId)
If Window_PId <> DesktopWindow_PId
Detected = Window
Break
EndIf
EndIf
EndIf
EndIf
Window = GetWindow_(Window, #GW_HWNDNEXT)
Wend
EndIf
ProcedureReturn Detected
EndProcedure
If OpenWindow(0, 0, 0, 256, 48, "Plein écran", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget) = 0
End
EndIf
StickyWindow(0, 1)
TextGadget(0, 0, 0, 256, 48, "")
AddWindowTimer(0, 1, 250)
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Timer
Select EventTimer()
Case 1
; Forcer toujours au dessus
If WindowFromPoint_(WindowX(0) | WindowY(0) << 32) <> WindowID(0)
BringWindowToTop_(WindowID(0))
EndIf
; Test
Window = FullScreenWindowDetected()
If Window
Texte.s = Space(255)
GetWindowText_(Window, @Texte, 255)
SetGadgetText(0, "Un programme actif est en plein écran : " + Chr(10) + Texte)
Else
SetGadgetText(0, "Aucun programme actif n'est en plein écran")
EndIf
EndSelect
EndIf
Until Event = #PB_Event_CloseWindow
Lancez le code, une petite fenêtre apparait.
Ouvrez votre navigateur internet.
Mettez vite le navigateur en plein écran et revenez en normal, vous verrez le texte changer en fonction que la fenêtre qui a le focus est plein écran ou non.