日期:2014-05-16 浏览次数:21502 次
[DllImport("User32.dll", EntryPoint = "SendMessage")]
private static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, string lParam);
[DllImport("user32.dll ", EntryPoint = "GetDlgItem")]
public static extern IntPtr GetDlgItem(IntPtr hParent, int nIDParentItem);
[DllImport("user32.dll", EntryPoint = "GetWindowText")]
public static extern int GetWindowText(IntPtr hwnd, StringBuilder lpString, int cch);
//控件id
int controlId = 0x000003F4;
//获取子窗口句柄
EdithWnd = GetDlgItem(dialog, controlId);
SendMessage(EdithWnd, WM_SETTEXT, (IntPtr)0, string.Format("当前时间是:{0}", DateTime.Now)); //赋值没问题,表示句柄正确
StringBuilder stringBuilder = new StringBuilder(512);
GetWindowText(EdithWnd, stringBuilder, stringBuilder.Capacity);
MessageBox.Show(string.Format("取到的值是:{0}", stringBuilder.ToString()));//取值一直是空字符串