J'ai réussi, pour ceux que ça interesse :
// Déclarations API et délégué : // -------------------------------------------------------------------------------------------------------- [DllImport("user32")] public static extern int EnumWindows(EnumWindowsProc lpEnumFunc, int lParam);
[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); [DllImport("user32.dll")] public static extern int SendMessage(int hWnd, uint Msg, int wParam,int lParam ); public const int WM_SYSCOMMAND = 0x0112; public const int SC_CLOSE = 0xF060;
public delegate bool EnumWindowsProc(IntPtr hwnd, int lParam); // --------------------------------------------------------------------------------------------------------
public string[] ProcessList; public IntPtr[] ProcessHandle; public int ProcessCount=0;
public void CloseWindow(string Name){ for(int i=0;i<ProcessCount;i++){ if(ProcessList[i] == Name){ SendMessage(ProcessHandle[i].ToInt32(),WM_SYSCOMMAND,SC_CLOSE,0); } } } public void ScanWindows(){ ProcessCount=0; EnumWindows(new EnumWindowsProc(EnumWindow), 0); } public void ListProcess(){ lstMain.Items.Clear(); for(int i=0;i<ProcessCount;i++){ lstMain.Items.Add(ProcessList[i]); } lstMain.Sorted=true; } public static string GetWindowText(IntPtr hWnd) { StringBuilder sb = new StringBuilder(GetWindowTextLength(hWnd) + 1); GetWindowText(hWnd, sb, sb.Capacity); return sb.ToString(); } public bool EnumWindow(IntPtr hwnd, int lparam) { string sBuffer = GetWindowText(hwnd); if(sBuffer!=""){ ProcessHandle[ProcessCount] = hwnd; ProcessList[ProcessCount] = sBuffer; ProcessCount+=1; } return true; }
-=Ar$£nik=-
|