using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace 获取进程中的QQ号码
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public delegate bool EnumWindowsProc(int hWnd, int lParam);
[DllImport("user32.dll")]
public static extern int EnumWindows(EnumWindowsProc x, int y);
[DllImport("user32.dll")]
public static extern int GetWindowText(int hwnd, StringBuilder lpstring, int cch);
private void button1_Click(object sender, System.EventArgs e)
{
textBox1.Text = "";
EnumWindowsProc enmWinProc = new EnumWindowsProc(WindowsProc);
EnumWindows(enmWinProc, 0);
}
public bool WindowsProc(int hWnd, int lParam)
{
StringBuilder vBuffer = new StringBuilder(256);
GetWindowText(hWnd, vBuffer, vBuffer.Capacity);
string S = vBuffer.ToString();
int I = S.IndexOf("_QQMusic_SmallClient");
if (I > 0)
{
S = S.Remove(I, S.Length - I);
textBox1.Text += S + Environment.NewLine;
}
return true;
}
}
}