سلام . با چه api ی میشه متن داخل یک پنجره دلخواه مثل notepad یا word رو گرفت ؟؟ با تشکر
سلام . با چه api ی میشه متن داخل یک پنجره دلخواه مثل notepad یا word رو گرفت ؟؟ با تشکر
...مرا به خانه ام ببر، اگرچه خانه؛ خانه نیست
getWindowText فقط متن عنوان پنجره رو میگره نه متن داخل پنجره رو .
بله دیگه .
ببینید من میخوام برنامه ای بنویسم که وقتی اشاره گر ماوس رفت روی یه پنجره متنی مثل نوتپد بتونه متن محتواشو بگیره و به برنامه من پاس بده . البته میدونم که این کار با sendMessage api انجام میشه اما روش کار رو نمیدونم . میشه لطفا به این لینک هم یه نگاهی بندازین
http://www.thescripts.com/forum/thread445880.html
اینجا یه مثال هست:
http://michaelsync.net/2006/07/04/sendmessage-c
شما به هندل کنترلی که میخوای نیاز داری و پیغامی که باید بفرستی.
اینجام توضیحات بیشتر رو دربارش میتونی پیدا کنی:
http://msdn2.microsoft.com/en-us/library/ms644950.aspx
پیغامت که مشخصه باید WM_GETTEXT باشه.
اینم یه مثال که متن داخل notepad رو میده:
private const int WM_GETTEXTLENGTH = 0x000E;
private const int WM_GETTEXT = 0x000D;
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int msg, int wParam, StringBuilder lParam);
[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);
private void button1_Click(object sender, EventArgs e)
{
IntPtr notepad = FindWindow("notepad", null);
IntPtr editx = FindWindowEx(notepad, IntPtr.Zero, "edit", null);
int length = SendMessage(editx, WM_GETTEXTLENGTH, 0, 0);
StringBuilder text = new StringBuilder(length);
int hr = SendMessage(editx, WM_GETTEXT, length, text);
MessageBox.Show(text.ToString());
}
آخرین ویرایش به وسیله rohullah : دوشنبه 26 آذر 1386 در 14:40 عصر دلیل: اشتباه تايپي
وقتی این برنامه رو اجرا میکنم این error رو میده
sendMessage00 has encountered a problem and needs to close. We are sorry for the inconvenience.