Quelqun peut maider pour faire marcher ce code

wcwmans Messages postés 9 Date d'inscription vendredi 21 mars 2003 Statut Membre Dernière intervention 4 décembre 2003 - 10 oct. 2003 à 10:18
cs_jacques-antoine Messages postés 79 Date d'inscription mardi 7 octobre 2003 Statut Membre Dernière intervention 22 mai 2017 - 18 oct. 2003 à 10:03
ccest un code pour empecher que les fenetre contennat dans leur titre le mots sex ne souvre pas. Il est composé d'un timer d'une form et d'un module.
merci de me répondre

Dans le MODULE

Option Explicit
Private Declare Function EnumWindows& Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long)
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 IsWindowVisible& Lib "user32" (ByVal hWnd As Long)
Private Declare Function GetParent& Lib "user32" (ByVal hWnd As Long)
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const WM_CLOSE = &H10
Dim sPattern As String, hFind As Long

Dim sPattern As String, hFind As Long
Public Function CloseWindowByhWnd(hWnd As Long) As Long
On Error GoTo ErrorCloseWindowByhWnd
CloseWindowByhWnd = PostMessage(hWnd, WM_CLOSE, 0&, 0&)
Exit Function
ErrorCloseWindowByhWnd:
MsgBox Err & ":Error in CloseWindowByhWnd. Error Message: " & Err.Description, vbCritical, "Warning"
Exit Function
End Function
Function EnumWinProc(ByVal hWnd As Long, ByVal lParam As Long) As Long
On Error Resume Next
Dim k As Long, sName As String
If IsWindowVisible(hWnd) And GetParent(hWnd) = 0 Then
sName = Space$(128)
k = GetWindowText(hWnd, sName, 128)
If k > 0 Then
sName = Left$(sName, k) If lParam 0 Then sName UCase(sName)
If sName Like sPattern Then
hFind = hWnd
EnumWinProc = 0
Exit Function
End If
End If
End If
EnumWinProc = 1
End Function
Public Function FindWindowWild(sWild As String, Optional bMatchCase As Boolean = True) As Long
On Error Resume Next
hFind = 0
sPattern = sWild
If Not bMatchCase Then sPattern = UCase(sPattern)
EnumWindows AddressOf EnumWinProc, bMatchCase
FindWindowWild = hFind
End Function

dans la FORME :
Private Sub Timer1_Timer()
Call FindWindowWild("*sex*", False)

End Sub

1 réponse

cs_jacques-antoine Messages postés 79 Date d'inscription mardi 7 octobre 2003 Statut Membre Dernière intervention 22 mai 2017
18 oct. 2003 à 10:03
Salut!

m'a l'air ben compliqué ton code pour empêcher une fenêtre de s'ouvrir. Alors, question : dans quel environnement es-tu, VB pur? Si oui, est-ce que c'est toi qui affiche ces fenêtres, je veux dire : est-ce que c'est toi qui fait le load? Si c'est oui, alors le problème n'en est pas un, puisqu'il te suffit, à l'appel de ta fenêtre de mettre ceci

unload nom_fenetre
load nom_fenetre

dans la fenêtre qui n'est pas encore affichée, dans une procédure load_form() du ajoutes ceci

titre = nom_fenetre.caption
if intsr(titre, "sex") then ' le mot cherché est présent.
nom_fenetre.show

J'ai mis dans la plaque ou à côté?
0
Rejoignez-nous