cs_Lapin26
Messages postés25Date d'inscriptionlundi 14 mai 2007StatutMembreDernière intervention23 janvier 2008
-
21 juin 2007 à 16:37
Gobillot
Messages postés3140Date d'inscriptionvendredi 14 mai 2004StatutMembreDernière intervention11 mars 2019
-
21 juin 2007 à 18:44
Bonjour, je cherche à fermer toutes les fenêtres ouvertes (sans toucher aux process de windows et sans toucher à une fenêtre dont je connais le nom), il faut donc que je fasse appel aux API EnumWindows et PostMessage mais l'utilisation de EnumWindows me pose problème... Je ne sais pas comment utiliser EnumWindows ni comment récupérer les résultats qu'elle doit me renvoyer.
cs_Lapin26
Messages postés25Date d'inscriptionlundi 14 mai 2007StatutMembreDernière intervention23 janvier 2008 21 juin 2007 à 17:20
En fait ça marche, mais il me reste juste à empêcher la fermeture de mon programme :s
Voila ce que j'ai fait déja :
Private Sub frm_principal_Load()
EnumWindows AddressOf EnumWindowsProc, ByVal 0&
End Sub
Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean
Dim sSave As String, Ret As Long
Ret = GetWindowTextLength(hwnd)
sSave = Space(Ret)
GetWindowText hwnd, sSave, Ret + 1
Handle_prj = frm_principal.hwnd
If hwnd <> Handle_prj Then
PostMessage hwnd, &H10, 0, 0
End If
EnumWindowsProc = True
End Function
Le problème c'est que ça me ferme aussi mon programme !
Gobillot
Messages postés3140Date d'inscriptionvendredi 14 mai 2004StatutMembreDernière intervention11 mars 201934 21 juin 2007 à 18:44
Le problème c'est que ça me ferme aussi mon programme !
là tu m'étonnes , j'imagine mal ce qui doit se passer ...
t'es en train de fermer toutes les fenêtres, les visibles, les invisibles, y compris même progman manager, etc ...
pour avoir une idée de ce que tu fermes:
voilà une Liste de toutes les fenêtres en cours dans une ListView (sans subclassing)
la ListView s'appelle LV.
je te laisse faire les déclarations et définitions
Private Sub Form_Load()
Lv.ColumnHeaders.Add , , "Hwnd", 60
Lv.ColumnHeaders.Add , , "Classe", 125
Lv.ColumnHeaders.Add , , "NOM", 200
Lv.ColumnHeaders.Add , , "Taille", 75
MHwnd = Me.hwnd
EnumWindows
End Sub
Function EnumWindows()
Dim Ligne As ListItem
Dim hwnd As Long
Dim Lg As Long
Dim Rp As Long
Dim Rs As Long
Dim zRw As Long
Dim zRh As Long
Dim Nom As String
Dim Class As String
Dim Tr As RECT
hwnd = GetDesktopWindow()
hwnd = GetWindow(hwnd, GW_CHILD)
Do While hwnd <> 0
Rp = IsWindowVisible(hwnd)
' If Rp = 0 Then GoTo 10
Rp = IsIconic(hwnd)
' If Rp > 0 Then GoTo 10
' If hwnd = MHwnd Then GoTo 10
Lg = GetWindowTextLength(hwnd)
' If Lg = 0 Then GoTo 10
Rp = GetWindowRect(hwnd, Tr)
zRw = Tr.Right - Tr.Left
' If zRw = 0 Then GoTo 10
zRh = Tr.Bottom - Tr.Top
' If zRh = 0 Then GoTo 10
Nom = Space$(Lg + 1)
GetWindowText hwnd, Nom, Lg + 1
Nom = Left$(Nom, Lg)
Class = Space$(120)
Lg = GetClassName(hwnd, Class, 120)
Class = Left$(Class, Lg)
' If Class = "ThunderRT6PictureBoxDC" Then GoTo 10
' If Class = "Shell_TrayWnd" Then GoTo 10
' If Class = "IEFrame" then goto 10
' if Class = "ThunderRT6FormDC" Then goto 10
Set Ligne = Lv.ListItems.Add
Ligne.Text = Format$(hwnd, "00000000")
Ligne.SubItems(1) = Class
Ligne.SubItems(2) = Nom
Ligne.SubItems(3) = zRw & "x" & zRh