PDA

View Full Version : گرفتن متن یک پنجره



adabyron
دوشنبه 26 آذر 1386, 08:50 صبح
سلام . با چه api ی میشه متن داخل یک پنجره دلخواه مثل notepad یا word رو گرفت ؟؟ با تشکر

sinpin
دوشنبه 26 آذر 1386, 08:54 صبح
سلام . با چه api ی میشه متن داخل یک پنجره دلخواه مثل notepad یا word رو گرفت ؟؟ با تشکر


GetWindowsText (http://www.andreavb.com/API_USER32.html)

adabyron
دوشنبه 26 آذر 1386, 09:06 صبح
getWindowText فقط متن عنوان پنجره رو میگره نه متن داخل پنجره رو .

sinpin
دوشنبه 26 آذر 1386, 09:16 صبح
getWindowText فقط متن عنوان پنجره رو میگره نه متن داخل پنجره رو .
بله همینطوره
متن داخل پنجره یعنی چی ؟ شما متن کنترلهای درون اون پنجره رو میخواین ؟

adabyron
دوشنبه 26 آذر 1386, 09:22 صبح
بله دیگه .
ببینید من میخوام برنامه ای بنویسم که وقتی اشاره گر ماوس رفت روی یه پنجره متنی مثل نوتپد بتونه متن محتواشو بگیره و به برنامه من پاس بده . البته میدونم که این کار با sendMessage api انجام میشه اما روش کار رو نمیدونم . میشه لطفا به این لینک هم یه نگاهی بندازین
http://www.thescripts.com/forum/thread445880.html

adabyron
دوشنبه 26 آذر 1386, 11:43 صبح
جدی جدی کسی نمیدونه ؟؟؟ !!!

rohullah
دوشنبه 26 آذر 1386, 13:45 عصر
اینجا یه مثال هست:
http://michaelsync.net/2006/07/04/sendmessage-c
شما به هندل کنترلی که میخوای نیاز داری و پیغامی که باید بفرستی.
اینجام توضیحات بیشتر رو دربارش میتونی پیدا کنی:
http://msdn2.microsoft.com/en-us/library/ms644950.aspx
پیغامت که مشخصه باید WM_GETTEXT باشه.

rohullah
دوشنبه 26 آذر 1386, 14:36 عصر
اینم یه مثال که متن داخل 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());
}

adabyron
دوشنبه 26 آذر 1386, 15:07 عصر
وقتی این برنامه رو اجرا میکنم این error رو میده

sendMessage00 has encountered a problem and needs to close. We are sorry for the inconvenience.