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
[Résolu] Fermer toutes les fenêtres ouvertes
[Résolu] Fermer toutes les fenêtres ouvertes
Dernière modification par omega le dim. 28/mars/2021 22:26, modifié 1 fois.
Win7 (x64) 64 bits Pb 5.72
- Kwai chang caine
- Messages : 6962
- Inscription : sam. 23/sept./2006 18:32
- Localisation : Isere
Re: Fermer toutes les fenêtres ouvertes
Y'a noir de codes qui parlent de ce sujet
Quelques liens ou codes parmi ceux ci, en espérant que ça puisse t'aider
http://www.purebasic.fr/english/viewtop ... t=ide+open
https://www.purebasic.fr/english/viewto ... 04#p524104
De FWEIL
De Lionel_OM
Quelques liens ou codes parmi ceux ci, en espérant que ça puisse t'aider
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()
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()
Re: Fermer toutes les fenêtres ouvertes
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
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
Re: Fermer toutes les fenêtres ouvertes
Exemple vite fait :Marc56 a écrit :Et si les fenêtres sont celles de ton propre programme, alors il suffit d'utiliser : CloseWindow(#Fenetre)
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
GPU : radeon HD6370M, CPU : p6200 2.13Ghz