日期:2014-05-17 浏览次数:20786 次
Win32Api.GUITHREADINFO guiInfo;
Point caretPosition;
public void GetCaretPosition()
{
guiInfo = new Win32Api.GUITHREADINFO();
guiInfo.cbSize = (uint)Marshal.SizeOf(guiInfo);
Win32Api.GetGUIThreadInfo(0, out guiInfo);
}
private void EvaluateCaretPosition()
{
caretPosition = new Point();
GetCaretPosition();
//caretPosition.X = (int)guiInfo.rcCaret.Left + 25;
//caretPosition.Y = (int)guiInfo.rcCaret.Bottom + 25;
Win32Api.ClientToScreen(guiInfo.hwndCaret, out caretPosition);
}
private void WinProcTest_KeyUp(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.F2:
//这里是调用
EvaluateCaretPosition();
txtPoint.Text = caretPosition.ToString();
IntPtr ptr = Win32Api.WindowFromPoint(caretPosition.X, caretPosition.Y);
StringBuilder buffer = new StringBuilder(1024);
string w = "";
//这里获取文本框的值
IntPtr ptr1 = Marshal.StringToHGlobalAnsi(w);
Win32Api.SendMessage(ptr, Win32Api.WM_GETTEXT, 1024, ptr1);
&nbs