[Résolu] Fermer toutes les fenêtres ouvertes

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
Avatar de l’utilisateur
omega
Messages : 617
Inscription : sam. 26/nov./2011 13:04
Localisation : Alger

[Résolu] Fermer toutes les fenêtres ouvertes

Message par omega »

Bonsoir,

En supposant qu'un programme principal contient des menus, chaque menu consiste à ouvrir une fenêtre donnée (avec ses évènements et traitements). Je voudrais fermer toutes les fenêtres ouvertes dès que celles-ci restent immobilisées un certain temps T (20 secondes par exemples). Ma question:
Comment fermer les fenêtres ouvertes? (comment savoir celles qui sont ouvertes??)

Merci
Dernière modification par omega le dim. 28/mars/2021 22:26, modifié 1 fois.
Win7 (x64) 64 bits Pb 5.72
Avatar de l’utilisateur
Kwai chang caine
Messages : 6962
Inscription : sam. 23/sept./2006 18:32
Localisation : Isere

Re: Fermer toutes les fenêtres ouvertes

Message par Kwai chang caine »

Y'a noir de codes qui parlent de ce sujet :wink:
Quelques liens ou codes parmi ceux ci, en espérant que ça puisse t'aider :D

http://www.purebasic.fr/english/viewtop ... t=ide+open
https://www.purebasic.fr/english/viewto ... 04#p524104

De FWEIL

Code : Tout sélectionner

; Liste les fenêtres ouvertes et affiche leur nom

Procedure Window()
    hwnd.l = FindWindow_( 0, 0 )
     While hwnd <> 0
         If GetWindowLong_(hwnd, #GWL_STYLE ) & #WS_VISIBLE = #WS_VISIBLE
             ; If GetwindowLong_(Hwnd, #GWL_EXSTYLE) & #WS_EX_TOOLWINDOW <> #WS_EX_TOOLWINDOW
            txt.s = Space(256)
             GetWindowText_(hwnd, txt, 256)
             If txt <> ""
                 Debug txt
             EndIf
             ; EndIf
         EndIf
        hwnd = GetWindow_(hwnd, #GW_HWNDNEXT )
     Wend
EndProcedure

Window()
De Lionel_OM

Code : Tout sélectionner

; Liste les fenêtres ouvertes et affiche leur nom

Procedure Window()
    hwnd.l = FindWindow_( 0, 0 )
     While hwnd <> 0
         If GetWindowLong_(hwnd, #GWL_STYLE ) & #WS_VISIBLE = #WS_VISIBLE
             ; If GetwindowLong_(Hwnd, #GWL_EXSTYLE) & #WS_EX_TOOLWINDOW <> #WS_EX_TOOLWINDOW
            txt.s = Space(256)
             GetWindowText_(hwnd, txt, 256)
             If txt <> ""
                 Debug txt
             EndIf
             ; EndIf
         EndIf
        hwnd = GetWindow_(hwnd, #GW_HWNDNEXT )
     Wend
EndProcedure

Window()
ImageLe bonheur est une route...
Pas une destination

PureBasic Forum Officiel - Site PureBasic
Marc56
Messages : 2146
Inscription : sam. 08/févr./2014 15:19

Re: Fermer toutes les fenêtres ouvertes

Message par Marc56 »

Et si les fenêtres sont celles de ton propre programme, alors il suffit d'utiliser : CloseWindow(#Fenetre)

Pour ne pas avoir de message d'erreur si une fenêtre n'est pas ouverte, on la teste avant

Code : Tout sélectionner

If IsWindow(#Fenetre) : CloseWindow(#Fenetre) : EndIf
Avatar de l’utilisateur
venom
Messages : 3071
Inscription : jeu. 29/juil./2004 16:33
Localisation : Klyntar
Contact :

Re: Fermer toutes les fenêtres ouvertes

Message par venom »

Marc56 a écrit :Et si les fenêtres sont celles de ton propre programme, alors il suffit d'utiliser : CloseWindow(#Fenetre)
Exemple vite fait :

Code : Tout sélectionner

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;- Window Constants
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Enumeration
  #Window_0
  #Window_1
  #Window_2
  #Window_3
  #Window_4
  #Window_5
EndEnumeration


; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;- Gadgets Constants
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Enumeration
  #Win1
  #Win2
  #Win3
  #Win4
  #Win5
  #CloseWin
EndEnumeration


; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;- Ouverture de la fenetre principale
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  If OpenWindow(#Window_0, 0, 0, 370, 80, "Window 0", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered)
    ButtonGadget(#Win1, 10, 10, 70, 25, "window 1",0)     
    ButtonGadget(#Win2, 80, 10, 70, 25, "window 2",0)   
    ButtonGadget(#Win3, 150, 10, 70, 25, "window 3",0)   
    ButtonGadget(#Win4, 220, 10, 70, 25, "window 4",0)   
    ButtonGadget(#Win5, 290, 10, 70, 25, "window 5",0)  
    ButtonGadget(#CloseWin, 10, 40, 350, 25, "Close window",0)
  EndIf 


; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;- Boucle
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  Repeat
   EventID = WaitWindowEvent()
    If EventID = #PB_Event_Gadget
      Select EventGadget()
          
        Case #Win1
         OpenWindow(#Window_1, 0, 0, 100, 100, "Window 1", 0) ; ouvre la fenetre Window 1
          
        Case #Win2
         OpenWindow(#Window_2, 150, 0, 100, 100, "Window 2", 0)
          
        Case #Win3
         OpenWindow(#Window_3, 300, 0, 100, 100, "Window 3", 0)
           
        Case #Win4
         OpenWindow(#Window_4, 450, 0, 100, 100, "Window 4", 0)
           
        Case #Win5
         OpenWindow(#Window_5, 600, 0, 100, 100, "Window 5", 0)
           
        Case #CloseWin
         If IsWindow(#Window_1) > 0 ; si differant de 0 alors la fenetre #Window_1 est ouverte
          CloseWindow(#Window_1) ; on la ferme
         EndIf 
         If IsWindow(#Window_2) > 0
          CloseWindow(#Window_2)
         EndIf 
         If IsWindow(#Window_3) > 0
          CloseWindow(#Window_3)
         EndIf 
         If IsWindow(#Window_4) > 0
          CloseWindow(#Window_4)
         EndIf 
         If IsWindow(#Window_5) > 0
          CloseWindow(#Window_5)
         EndIf

      EndSelect
    EndIf
  Until EventID = #PB_Event_CloseWindow





@++
Windows 10 x64, PureBasic 5.73 x86 & x64
GPU : radeon HD6370M, CPU : p6200 2.13Ghz
Avatar de l’utilisateur
omega
Messages : 617
Inscription : sam. 26/nov./2011 13:04
Localisation : Alger

Re: Fermer toutes les fenêtres ouvertes

Message par omega »

Merci à tous, ça marche!
Win7 (x64) 64 bits Pb 5.72
Répondre