int WINAPI GetClassName(
_In_ HWND hWnd,
_Out_ LPTSTR lpClassName,
_In_ int nMaxCount
);
这个API的第二个参数要的是一个字符串类型的指针,C#中好像没有字符串类型的指针,我是个新手,求高人指导,小弟不胜感激!
_In_ HWND hWnd,
_Out_ LPTSTR lpClassName,
_In_ int nMaxCount
);
这个API的第二个参数要的是一个字符串类型的指针,C#中好像没有字符串类型的指针,我是个新手,求高人指导,小弟不胜感激!
static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName,int nMaxCount);
using System.Drawing;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Windows.Forms;namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{ [DllImport("user32.dll")]
static extern IntPtr WindowFromPoint(Point Point); [DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetCursorPos(out Point lpPoint); [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount); public Form1()
{
InitializeComponent(); Control.CheckForIllegalCrossThreadCalls = false; ThreadPool.QueueUserWorkItem(new WaitCallback(Foo), null);
} private void Foo(Object obj)
{
Point point;
while (true)
{
StringBuilder sb = new StringBuilder(256);
GetCursorPos(out point); GetClassName(WindowFromPoint(point), sb, 256);
this.Text = sb.ToString();
}
}
}
}