Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Runtime.InteropServices;
- public delegate bool CallBack(int hwnd, int lParam);
- namespace Essai_type_fenetre_2
- {
- public partial class Form1 : Form
- {
- [DllImport("user32", CharSet = CharSet.Auto, SetLastError = true)]
- public static extern int EnumWindows(CallBack x, int y);
- [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
- static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
- [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
- static extern int GetWindowTextLength(IntPtr hWnd);
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- //Création du callback ou on recoit les résultat du enumwindows.
- CallBack myCallBack = new CallBack(Form1.Report);
- //Appel de la fonction :-)
- EnumWindows(myCallBack, 0);
- }
- public static bool Report(int hwnd, int lParam)
- {
- //Console.Write("Window handle is ");
- //Console.WriteLine(hwnd);
- IntPtr monint = (IntPtr)hwnd;
- int length = GetWindowTextLength(monint);
- StringBuilder sb = new StringBuilder(length + 1);
- GetWindowText(monint, sb, sb.Capacity);
- Console.WriteLine( sb.ToString());
- return true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement