Page 1 sur 1
fermer la fenêtre active

Publié:
05 Nov 2007 à 17:58
par Michael DELIQUE
- Code : Tout sélectionner
Public Sub CloseActiveWindow_API(wTitreFenetreAfermer As String)
%REM
' Variables API pour la fonction CloseActiveWindow_API
Declare Function GetForegroundWindow Lib "User32" Alias "GetForegroundWindow" () As Long
Declare Function GetWindow Lib "user32" Alias "GetWindow" (Byval HWND As Long, Byval UINT As Integer) As Long
Declare Function GetWindowTextLength Lib "user32.dll" Alias "GetWindowTextLengthA" (Byval hwnd As Long) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (Byval HWND As Long, Byval LPTSTR As String, Byval nMaxCount As Integer) As Integer
Declare Function PostMessage Lib "user32" Alias "PostMessageA" (Byval HWND As Long, Byval UINT As Integer, Byval WPARAM As Integer, Byval LPARAM As Integer) As Integer
Const GW_CHILD = 5
Const GW_HWNDNEXT = 2
Const WM_CLOSE = 16
%END REM
'Déclaration Variables
Dim hwnd As Long
Dim hwndMDI_1 As Long
Dim hwndChild As Long
Dim nRet As Integer
Dim iLongueurTitreFenetre As Integer
Dim sTitreFenetre As String
On Error Goto ErreurCloseActiveWindow_API
hwnd = GetForegroundWindow() 'obtention du handle de la fenêtre Notes actuelle
hwndMDI_1 = GetWindow( hwnd , GW_CHILD ) 'obtention du handle de la liste de fenêtres ouvertes (Multiple Document Interface)
hwndChild = GetWindow( hwndMDI_1 , GW_CHILD ) 'on parcours toutes les fenêtres actives et dès que le titre de la fenêtre à fermer est trouver, on ferme la vue
While hwndChild > 0
iLongueurTitreFenetre = GetWindowTextLength(hwndChild)
sTitreFenetre = String$(iLongueurTitreFenetre, " ") + Chr$(0)
Call GetWindowText(hwndChild, sTitreFenetre, 100)
If Left(sTitreFenetre, iLongueurTitreFenetre) = wTitreFenetreAfermer Then
Call PostMessage(hwndChild, WM_CLOSE, 0, 0 )
End If
hwndChild = GetWindow( hwndChild , GW_HWNDNEXT )
Wend
Exit Sub
ErreurCloseActiveWindow_API:
Msgbox "("+Cstr(Getthreadinfo (1))+" Call by "+Cstr(Getthreadinfo(10))+")"+Chr(10)+"Erreur " + Str(Err) + " : "+Chr(10) + Cstr(Error)+". "+Chr(10)+"Ligne N° "+Cstr(Erl),16," ERREUR !"
Exit Sub
End Sub

Publié:
06 Nov 2007 à 14:30
par Michael DELIQUE
une autre version
- Code : Tout sélectionner
Public Sub CloseCurrentWindows_API(wMessage As String)
'ferme la fentre en cours
%REM
'variableAPI pour la fonction CloseCurrentWindows_API
Declare Function NEMStopSubprogramWindow Lib "nnotesws.dll" (Byval wHandle As Long) As Integer
Declare Function NEMGetCurrentSubprogramWindow Lib "nnotesws.dll" () As Long
%END REM
On Error Goto ErreurHandle
Call NEMStopSubprogramWindow(NEMGetCurrentSubprogramWindow)
Exit Sub
ErreurHandle:
Msgbox "("Cstr(Getthreadinfo (1))+" Call by "+Cstr(Getthreadinfo(10))+")"+Chr(10)+"Erreur " + Str(Err) + " : "+Chr(10) + Cstr(Error)+". "+Chr(10)+"Ligne N° "+Cstr(Erl),16," ERREUR !"
Exit Sub
End Sub