有谁用过GetClassName这个API函数(C#中的字符串指针该如何处理)
int WINAPI GetClassName(
_In_ HWND hWnd,
_Out_ LPTSTR lpClassName,
_In_ int nMaxCount
);
这个API的第二个参数要的是一个字符串类型的指针,C#中好像没有字符串类型的指针,我是个新手,求高人指导,小弟不胜感激!
[最优解释]
用sb
[其他解释]
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName,int nMaxCount);
[其他解释]
高手,问你一个问题,我是用这个来获取控件的类型的,程序的效果是当我鼠标点击控件时首先获取控件的句柄,然后就用如上函数获取控件的类名(我想获取文本输入控件的类名),为什么当我点击textbox时获取的类名是windowFo,点击richtextbox也是windowFo,点击窗体和panel也是windowFo,只有点击comboBox时获取的类名才是Edit,这是为什么呢?如下图:
[其他解释]
StringBuilder sb = new StringBuilder (256);
[其他解释]
高人,再问你一个问题,我是想用这个函数查询控件的类名,程序的效果是,当我点击鼠标左键时首先获取控件的句柄,然后再用这个函数根据控件的句柄查出控件的类名,为什么当我点击窗体,textbox,richtextbox,panel时获取的类名都是windowFo,而只有comboBox获取的才是Edit呢,这是为什么呢???(我想获取文本输入控件)
[其他解释]
256长度还是不行。。。。。
[其他解释]
我错了,有一个地方没给长度。。。。改过来了,好了。。。。
[其他解释]
using System;
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();
}
}
}
}
[其他解释]
亲,再问你一个问题,那个函数的第二个参数不是要一个指针类型的字符串么,为什么用sb可以呢????
[其他解释]
期待解答!!!
[其他解释]
谢谢你!