.NET Compact Framework 2.0下調(diào)用EnumWindows(Callback方式) 轉(zhuǎn)
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 EnumWindows
{
public partial class Form1 : Form
{
public delegate int EnumWindowsProc(IntPtr hwnd, IntPtr lParam);
EnumWindowsProc callbackDelegate;
IntPtr callbackDelegatePointer;
[DllImport("coredll.dll", SetLastError = true)]
public static extern bool EnumWindows(IntPtr lpEnumFunc, uint lParam);
[DllImport("coredll.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern int GetWindowTextLength(IntPtr hWnd);
[DllImport("coredll.dll")]
public static extern int GetWindowText(IntPtr hWnd, [Out] StringBuilder lpString, int nMaxCount);
public Form1()
{
InitializeComponent();
callbackDelegate = new EnumWindowsProc(EnumWindowsCallbackProc);
callbackDelegatePointer = Marshal.GetFunctionPointerForDelegate(callbackDelegate);
EnumWindows(callbackDelegatePointer, 0);
}
public int EnumWindowsCallbackProc(IntPtr hwnd, IntPtr lParam)
{
int length = GetWindowTextLength(hwnd);
StringBuilder sb = new StringBuilder(length + 1);
GetWindowText(hwnd, sb, sb.Capacity);
System.Diagnostics.Debug.WriteLine("Window: " + hwnd.ToString() + "," + sb.ToString());
return 1;
}
}
}
vs.net 2005 下調(diào)試通過!
posted on 2008-10-24 16:40 井泉 閱讀(587) 評(píng)論(1) 編輯 收藏 引用 所屬分類: 雜