SendMessage如何获取其他程序(非.Net)中标准Edit控件中的值
接
http://community.csdn.net/Expert/topic/4835/4835886.xml?temp=.1253321
大概内容
昨天断网。用GPRS发的。乱码了。在发一次。
Knight94(愚翁),谢谢。但是我试验了一下。GetWindowText似乎只能吧SetWindowText设置的文本Get出来。但是我用SetWindowText方法却又不能正常。或许内存中已经有了。但是显示是没有的
API.SetWindowText(hwnd_textbox2, "hahah中文测试");//这条执行后hwnd_textbox2句柄对应的EDIT框没显示任何东西。但是我用GetWindowText却能正确得到“hahah中文测试”
API.SendMessage(hwnd_textbox2,API.WM_SETTEXT,0,"中文测试");//这条执行后hwnd_textbox2句柄对应的EDIT框正确显示了"中文测试"。但是我用GetWindowText却不能正确得到"中文测试"。
不知道有上面方法解决么?
我的代码
API.SetWindowText(hwnd_textbox2, "hahah中文测试");
MessageBox.Show(GetText(hwnd_textbox2));
API.SendMessage(hwnd_textbox2,API.WM_SETTEXT,0,"中文测试");
MessageBox.Show(GetText(hwnd_textbox2));
public string GetText(IntPtr hWnd)
{
// Allocate correct string length first
int length = API.GetWindowTextLength(hWnd);
StringBuilder sb = new StringBuilder(length + 1);
API.GetWindowText(hWnd, sb, sb.Capacity);
return sb.ToString();
}
[DllImport("user32.dll")]
public static extern int SetWindowText(IntPtr hwnd, string lpString);
[DllImport("user32.dll")]
public static extern int GetWindowText(IntPtr hWnd, [Out] StringBuilder lpString, int nMaxCount);
[DllImport("user32.dll")]
public static extern int GetWindowTextLength(IntPtr hWnd);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int SendMessage( IntPtr hwnd, int wMsg, int wParam,string lParam);
public const int WM_SETTEXT = 0xC;