📄 form1.cs
字号:
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 FunctionPointer
{
public partial class Form1 : Form
{
System.Text.StringBuilder sb = new StringBuilder(260);
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
NativeMethods.EnumWindows(new EnumWindowsDelegate(EnumWindowsProc), 0);
}
private bool EnumWindowsProc(IntPtr hwnd, int lParam)
{
//Add to list on UI thread.
int chars = NativeMethods.GetWindowText(hwnd, sb, sb.Capacity);
this.Invoke(new AddToListDelegate(AddToList), new object[] { hwnd, sb.ToString() });
return true;
}
internal delegate void AddToListDelegate(IntPtr hwnd, string text);
private void AddToList(IntPtr hwnd, string text)
{
listBox1.Items.Add(string.Format("[{0}] - {1}", hwnd.ToInt32().ToString("X"), text));
}
[return: MarshalAs(UnmanagedType.Bool)]
private delegate bool EnumWindowsDelegate(IntPtr hwnd, int lParam);
private static class NativeMethods
{
[DllImport("coredll")]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool EnumWindows(EnumWindowsDelegate lpEnumFunc, int lParam);
[DllImport("coredll")]
internal static extern int GetWindowText(IntPtr hWnd, System.Text.StringBuilder lpString, int nMaxCount);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -