Les Snippets

Connexion

Fermer une application identifiée par son titre

Niveau requis pour utiliser/comprendre cette source : 1 ( Débutant )
Créé le 21/03/2006 17:28:12 et initié par PCPT [Liste]
Date de mise à jour : 27/03/2006 17:53:38
Vue : 9062
Catégorie(s) : API
Langages dispo pour ce code :
- VB6, VBA
- C# 1.x, C# 2.x
- C# 1.x, C# 2.x
- VB 2005, VB.NET 1.x
- Delphi 5



Langage : VB6 , VBA
Date ajout : 21/03/2006
Posté par PCPT [Liste]
Option Explicit 
  

' Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _          (ByVal lpClassName As StringByVal lpWindowName As StringAs Long  ' Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _          (ByVal hwnd As LongByVal wMsg As LongByVal wParam As Long, lParam As Any) As Long  ' Private Const WM_CLOSE      As Long = &H10  Private Const HTCAPTION     As Long = 2&  ' Private Const MON_TITRE     As String = "Sans titre - Bloc-notes"  ' ' Private Sub Command1_Click()      Dim lHwnd As Long      lHwnd = FindWindow(vbNullString, MON_TITRE)      If lHwnd = 0 Then          MsgBox "Titre non-trouvé!!!"      Else          Call SendMessage(lHwnd, WM_CLOSE, HTCAPTION, ByVal 0&)      End If  End Sub

Langage : C# 1.x , C# 2.x
Date ajout : 22/03/2006
Posté par Lutinore [Liste]

class MyForm : Form

{
    // ..
    [ DllImport( "User32.dll", SetLastError = true ) ] 
    private static extern IntPtr FindWindow( string className, string windowName );
    [ DllImport( "User32.dll" ) ] 
    private static extern IntPtr SendMessage( IntPtr hWnd, uint msg, UIntPtr wParam, IntPtr lParam );

    private const int WM_CLOSE = 0x0010; 
    private const int HTCAPTION = 2;
    private const string WINDOW_NAME = "Sans titre - Bloc-notes";
    
    private void CloseWindow( ) 
    {
        IntPtr hWnd = FindWindow( null, WINDOW_NAME );
        if ( hWnd == IntPtr.Zero ) 
            MessageBox.Show( this, "La fenêtre est introuvable." ); 
        else

            SendMessage( hWnd, WM_CLOSE, ( UIntPtr )HTCAPTION, IntPtr.Zero ); 
    }
}


Langage : C# 1.x , C# 2.x
Date ajout : 24/03/2006
Posté par sebmafate [Liste]
public void CloseApplicationByCaption(string caption) {
   foreach (Process p in Process.GetProcesses()) {
      if (p.MainWindowTitle.Equals(caption)) {
         p.Close();
      }
   } 
}

Remarque :
Solution alternative n'utilisant pas les APIs.
N'oubliez pas d'ajouter la directive :
using System.Diagnostics;
Langage : VB.NET 1.x , VB 2005
Date ajout : 24/03/2006
Posté par sebmafate [Liste]

Public Sub CloseApplicationByCaption(ByVal caption As String)
   For Each p As Process In Process.GetProcesses()
      If (p.MainWindowTitle.Equals(caption)) Then
         p.Close()
      End If
   Next
End Sub

Remarque :
Solution alternative n'utilisant pas les APIs.
N'oubliez pas d'ajouter la directive :
Imports System.Diagnostics
Langage : Delphi 5
Date ajout : 27/03/2006
Posté par ni69 [Liste]
DateMAJ : 27/03/2006
// Mode de fermeture par l'envoi d'un message Windows à l'application
SendMessage(FindWindow(nil, 'Titre de l'Application'), WM_CLOSE, 0, 0);

Snippets en rapport avec : Application, Fermer



Codes sources en rapport avec : Application, Fermer

{PHP} MYRSSREADER :: APPLICATION WEB2
DEMO SUR : http://rss.amezghal.com | =================================== Salut, MyRSS est une app...

{C / C++ / C++.NET} RANGESOURIS
c'est un petit code qui a pour bute de ranger la souris quand l'utilisateur ne la bouge pas pendant ...

{Visual Basic, VB6, VB.NET, VB 2005} HANDLISTER
Ce petit programme permet de surveiller les applications qui sont démarrées ou arrêtées et d'écrire ...

{Python} OPTI2 OU COMMENT OPTIMISER WINDOWS XP ET/2000 EN QUELQUES CLICS
Opti2 est un soft d'optimisation de windows xp et/ou 2000. Il comprend une vingtaine d'optimisati...

{C / C++ / C++.NET} EXTRAIRE UN .CAB QUI EST DANS LA RESSOURCE D 'UN EXE
decompreser un fichier .cab qui est dans le exe principal peut servir comme installateur, ou a com...

{Visual Basic, VB6, VB.NET, VB 2005} REDIRECTION D'UNE APPLICATION CONSOLE VERS UN TEXTBOX
Ce programme permet de rediriger une application console vers une fenetre graphique, le text est aff...

{Delphi} FERMER GROUPE DE PROGRAMME AVEC UNE TOUCHE
Pour des raisons pratiques ou pour ceux qui surfent ou glandent au bureau et qui ne veulent pas que ...

{JAVA / J2EE} EXEMPLE DE GESTION DE FICHE DOCUMENTAIRE SOUS WINDOWS
Mon code a été généré sous Visual java sharp express (ou comment crée des applications Java avec des...

{Visual Basic, VB6, VB.NET, VB 2005} EXÉCUTER UNE APPLICATION ET ATTENDRE OUI OU NON QU'ELLE SE TERMINE.
J'ai créer cette source car j'en avais besoin pour un de mes programme. Et, comme elle est difficil...

{Visual Basic, VB6, VB.NET, VB 2005} FERMER EXCEL CORRECTEMENT ET SIMPLEMENT
Voici un petit morceau de code qui vous permettra de fermer correctement et simplement un processus ...