已经得到了一个TextBox控件的句柄,为何用WM_GetText得不到其内容?
代码:[DllImport("User32.dll",EntryPoint="SendMessage")]
private static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, string lParam);
const int WM_GETTEXT = 0x000D;
String txt = "";
int result = SendMessage(txtHwnd, WM_GETTEXT, (IntPtr)255, txt);
if (result == 0)
{
this.label1.Text = "Getting Text Failed";
return;
}
else this.label1.Text = "Getting Text Succeeded:" + txt;
最后结果label1的文本是"Getting Text Succeeded:",也就是说txt内容还是""txtHwnd肯定是没问题的,因为给他用WM_SETTEXT来SendMessage结果正确。哪位高手帮忙解决下???
代码:[DllImport("User32.dll",EntryPoint="SendMessage")]
private static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, string lParam);
const int WM_GETTEXT = 0x000D;
String txt = "";
int result = SendMessage(txtHwnd, WM_GETTEXT, (IntPtr)255, txt);
if (result == 0)
{
this.label1.Text = "Getting Text Failed";
return;
}
else this.label1.Text = "Getting Text Succeeded:" + txt;
最后结果label1的文本是"Getting Text Succeeded:",也就是说txt内容还是""txtHwnd肯定是没问题的,因为给他用WM_SETTEXT来SendMessage结果正确。哪位高手帮忙解决下???
得到一个TextBox的内容,付给txt啊
可这样就跟函数声明不一致了啊
[DllImport("User32.dll",EntryPoint="SendMessage")]
private static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, string lParam);
private static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
String txt = new string(' ', 255);
IntPtr txtPtr = Marshal.StringToHGlobalAnsi(txt);
result = SendMessage(txt1Hwnd, WM_GETTEXT, (IntPtr)255, txtPtr);
if (result == 0)
{
this.label1.Text = "Getting Text Failed";
return;
}
else this.label1.Text = "Getting Text Succeeded:" + Marshal.PtrToStringAnsi(txtPtr);