Advertisement
Guest User

Untitled

a guest
Mar 7th, 2010
381
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.68 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Runtime.InteropServices;
  10.  
  11. public delegate bool CallBack(int hwnd, int lParam);
  12.  
  13. namespace Essai_type_fenetre_2
  14. {
  15.     public partial class Form1 : Form
  16.     {
  17.         [DllImport("user32", CharSet = CharSet.Auto, SetLastError = true)]
  18.         public static extern int EnumWindows(CallBack x, int y);
  19.        
  20.         [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
  21.         static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
  22.  
  23.         [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
  24.         static extern int GetWindowTextLength(IntPtr hWnd);
  25.  
  26.  
  27.  
  28.  
  29.         public Form1()
  30.         {
  31.             InitializeComponent();
  32.         }
  33.  
  34.         private void Form1_Load(object sender, EventArgs e)
  35.         {
  36.             //Création du callback ou on recoit les résultat du enumwindows.
  37.             CallBack myCallBack = new CallBack(Form1.Report);
  38.             //Appel de la fonction :-)
  39.             EnumWindows(myCallBack, 0);
  40.  
  41.         }
  42.  
  43.         public static bool Report(int hwnd, int lParam)
  44.         {
  45.             //Console.Write("Window handle is ");
  46.             //Console.WriteLine(hwnd);
  47.  
  48.             IntPtr monint = (IntPtr)hwnd;
  49.  
  50.             int length = GetWindowTextLength(monint);
  51.  
  52.  
  53.  
  54.             StringBuilder sb = new StringBuilder(length + 1);
  55.             GetWindowText(monint, sb, sb.Capacity);
  56.             Console.WriteLine( sb.ToString());
  57.  
  58.  
  59.             return true;
  60.         }
  61.  
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement