- /*
- * Utilisation des API :
- * Voici les méthodes utilisées dans ce code
- *********************************************************/
-
- // Les namespaces utiles
- using System.Runtime.InteropServices;
- using System.Text;
-
- // Récuperer le handle des fenetres :
- // -> Déclarations
-
- public delegate bool EnumWindowsProc(IntPtr hwnd, int lParam);
- [DllImport("user32")]
- public static extern int EnumWindows(EnumWindowsProc lpEnumFunc, int lParam);
-
- // -> Code a mettre en oeuvre
-
- // Appel de la méthode
- EnumWindows(new EnumWindowsProc(EnumWindow), 0);
-
- // CallBack
- private bool EnumWindow(IntPtr hwnd, int lparam)
- {
- // Vous pouvez récupere ici le Handle des fenetres (paramètre hwnd)
- return true;
- }
-
-
- //Récuperer le titre des fenêtres :
- // -> Déclarations :
-
- [DllImport("user32.dll")]
- public static extern int GetWindowText(IntPtr hWnd, [Out] StringBuilder lpString, int nMaxCount);
- [DllImport("user32.dll")]
- public static extern int GetWindowTextLength(IntPtr hWnd);
-
- // -> Code a mettre en oeuvre
-
- // Paramètre hwnd : Handle de la fenêtre pour laquelle vous voulez récuperer le texte
- public static string GetWindowText(IntPtr hWnd)
- {
- StringBuilder sb = new StringBuilder(GetWindowTextLength(hWnd) + 1);
- GetWindowText(hWnd, sb, sb.Capacity);
- return sb.ToString();
- }
-
-
/*
* Utilisation des API :
* Voici les méthodes utilisées dans ce code
*********************************************************/
// Les namespaces utiles
using System.Runtime.InteropServices;
using System.Text;
// Récuperer le handle des fenetres :
// -> Déclarations
public delegate bool EnumWindowsProc(IntPtr hwnd, int lParam);
[DllImport("user32")]
public static extern int EnumWindows(EnumWindowsProc lpEnumFunc, int lParam);
// -> Code a mettre en oeuvre
// Appel de la méthode
EnumWindows(new EnumWindowsProc(EnumWindow), 0);
// CallBack
private bool EnumWindow(IntPtr hwnd, int lparam)
{
// Vous pouvez récupere ici le Handle des fenetres (paramètre hwnd)
return true;
}
//Récuperer le titre des fenêtres :
// -> Déclarations :
[DllImport("user32.dll")]
public static extern int GetWindowText(IntPtr hWnd, [Out] StringBuilder lpString, int nMaxCount);
[DllImport("user32.dll")]
public static extern int GetWindowTextLength(IntPtr hWnd);
// -> Code a mettre en oeuvre
// Paramètre hwnd : Handle de la fenêtre pour laquelle vous voulez récuperer le texte
public static string GetWindowText(IntPtr hWnd)
{
StringBuilder sb = new StringBuilder(GetWindowTextLength(hWnd) + 1);
GetWindowText(hWnd, sb, sb.Capacity);
return sb.ToString();
}