OVH Cloud OVH Cloud

Détection fenêtre ouverte

4 réponses
Avatar
Stéphane ANDRE
Bonjour,
comment d=E9tecter si une form vb est charg=E9e en m=E9moire=20
depuis une autre form VB dans une application ?

Merci d'avance

4 réponses

Avatar
le_troll
Bonjour,
Je n'arrive pas à trouver, mais il y a une API qui gère ça, les fenêtres
(handles) ouverts, ainsi tu peux comparer ceux ouvert avec celui que tu vas
ouvrir...

--
Merci, @+, bye, Joe
troll75 AROBASE iFrance POINT com
------------------------------------------
Le_Troll, éleveur de Trolls depuis César, qui disait:
Avec une hache, celui qui tient le manche a toujours raison !


"Stéphane ANDRE" a écrit dans le
message de news:6a6a01c493f4$21363340$
Bonjour,
comment détecter si une form vb est chargée en mémoire
depuis une autre form VB dans une application ?

Merci d'avance
Avatar
le_troll
Re-salut, tiens j'ai trouvé:


' Form1
'****************************************
' OBJETS = List1 (Sorted = True) + Text1 = 2 objets
' ***************************************
' form1 tous les handles
'
Private Declare Function GetForegroundWindow Lib "user32" () As Long
'hwnd (handle de la forme)
'
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA"
_
(ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As
Long
'
Private Declare Function EnumWindows Lib "user32" _
(ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
'
Sub Form_Load() ' LIST1 + TEXT1
Dim hwnd
'
List1.Clear
GetWindowsList
'
' handle de cette form
hwnd = GetForegroundWindow
Text1 = "Handle en cours : " & hwnd
End Sub

Private Function EnumWindowsProc(ByVal lgHwnd As Long, ByVal lgParam As
Long) As Long
Dim stTmp As String, lgTmp As Long, lgRet As Long
'
stTmp = Space$(120)
lgTmp = 119
lgRet = GetWindowText(lgHwnd, stTmp, lgTmp)
If Len(stTmp) > 1 And lgRet <> 0 Then
Form1.List1.AddItem Format(lgHwnd, "00000000") & " : " & stTmp
End If
EnumWindowsProc = 1
End Function


'********************
' Module1
'********************
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA"
_
(ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As
Long
'
Public Declare Function EnumWindows Lib "user32" _
(ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
'

Public Function GetWindowsList()
Dim lgRep As Long
'
stGetWindowsList = vbNullString
lgRep = EnumWindows(AddressOf EnumWindowsProc, 0)
End Function

Public Function EnumWindowsProc(ByVal lgHwnd As Long, ByVal lgParam As Long)
As Long
Dim stTmp As String, lgTmp As Long, lgRet As Long
'
stTmp = Space$(120)
lgTmp = 119
lgRet = GetWindowText(lgHwnd, stTmp, lgTmp)
If Len(stTmp) > 1 And lgRet <> 0 Then
Form1.List1.AddItem Format(lgHwnd, "00000000") & " : " & stTmp
End If
EnumWindowsProc = 1
End Function



--
Merci, @+, bye, Joe
troll75 AROBASE iFrance POINT com
------------------------------------------
Le_Troll, éleveur de Trolls depuis César, qui disait:
Avec une hache, celui qui tient le manche a toujours raison !


"Stéphane ANDRE" a écrit dans le
message de news:6a6a01c493f4$21363340$
Bonjour,
comment détecter si une form vb est chargée en mémoire
depuis une autre form VB dans une application ?

Merci d'avance
Avatar
Pascal B.
Bonjour Stéphane,

La collection Forms contient toutes les Form chargés dans une application.
Il suffit donc de parcourir cette collection pour vérifier si une Form précise à été ouverte.

Sinon, il y a plus simple en déclarant une variable publique (dans un modul .BAS) et de la mettre à True dans l' évenement Form_Load
et à False dans Form_Unload de cette Form; puis de tester la valeur de cette variable.

Pascal B.

"Stéphane ANDRE" wrote in message news:6a6a01c493f4$21363340$
Bonjour,
comment détecter si une form vb est chargée en mémoire
depuis une autre form VB dans une application ?

Merci d'avance
Avatar
Stéphane ANDRE
Merci à tous

-----Message d'origine-----
Re-salut, tiens j'ai trouvé:


' Form1
'****************************************
' OBJETS = List1 (Sorted = True) + Text1 = 2 objets
' ***************************************
' form1 tous les handles
'
Private Declare Function GetForegroundWindow


Lib "user32" () As Long
'hwnd (handle de la forme)
'
Private Declare Function GetWindowText Lib "user32"


Alias "GetWindowTextA"
_
(ByVal hwnd As Long, ByVal lpString As String, ByVal


cch As Long) As
Long
'
Private Declare Function EnumWindows Lib "user32" _
(ByVal lpEnumFunc As Long, ByVal lParam As Long) As


Long
'
Sub Form_Load() ' LIST1 + TEXT1
Dim hwnd
'
List1.Clear
GetWindowsList
'
' handle de cette form
hwnd = GetForegroundWindow
Text1 = "Handle en cours : " & hwnd
End Sub

Private Function EnumWindowsProc(ByVal lgHwnd As Long,


ByVal lgParam As
Long) As Long
Dim stTmp As String, lgTmp As Long, lgRet As Long
'
stTmp = Space$(120)
lgTmp = 119
lgRet = GetWindowText(lgHwnd, stTmp, lgTmp)
If Len(stTmp) > 1 And lgRet <> 0 Then
Form1.List1.AddItem Format(lgHwnd, "00000000")


& " : " & stTmp
End If
EnumWindowsProc = 1
End Function


'********************
' Module1
'********************
Public Declare Function GetWindowText Lib "user32"


Alias "GetWindowTextA"
_
(ByVal hwnd As Long, ByVal lpString As String, ByVal


cch As Long) As
Long
'
Public Declare Function EnumWindows Lib "user32" _
(ByVal lpEnumFunc As Long, ByVal lParam As Long) As


Long
'

Public Function GetWindowsList()
Dim lgRep As Long
'
stGetWindowsList = vbNullString
lgRep = EnumWindows(AddressOf EnumWindowsProc, 0)
End Function

Public Function EnumWindowsProc(ByVal lgHwnd As Long,


ByVal lgParam As Long)
As Long
Dim stTmp As String, lgTmp As Long, lgRet As Long
'
stTmp = Space$(120)
lgTmp = 119
lgRet = GetWindowText(lgHwnd, stTmp, lgTmp)
If Len(stTmp) > 1 And lgRet <> 0 Then
Form1.List1.AddItem Format(lgHwnd, "00000000")


& " : " & stTmp
End If
EnumWindowsProc = 1
End Function



--
Merci, @+, bye, Joe
troll75 AROBASE iFrance POINT com
------------------------------------------
Le_Troll, éleveur de Trolls depuis César, qui disait:
Avec une hache, celui qui tient le manche a toujours


raison !


"Stéphane ANDRE" a


écrit dans le
message de news:6a6a01c493f4$21363340$
Bonjour,
comment détecter si une form vb est chargée en mémoire
depuis une autre form VB dans une application ?

Merci d'avance



.