Click to See Complete Forum and Search --> : winapi getting text
hollow44
April 19th, 2007, 01:14 AM
Hey,
I have a little problem. I've tried to get text from window (like firefox opened site text) but only what i got is window title with SendMessage with WM_GETTEXT attribute. Can you guys tell me (or write some piece of code) how to get body text of my firefox opened window?
Pliiiz help me :] Thx.
ovidiucucu
April 19th, 2007, 05:39 AM
The thext you want to get isn't written in the main application window but in a child. First use GetWindow or EnumChildWindows to get a handle to that child window.
hollow44
April 19th, 2007, 09:46 AM
BOOL CALLBACK EnumChildProc(HWND hwndChild, LPARAM lParam)
{
char tekst3[10000];
SendMessage(hwndChild, WM_GETTEXT, 10000, (LPARAM)text3);
Write_text_my_function(text3);
return TRUE;
}
main () {
HWND handle = FindWindow(NULL, "window title");
EnumChildWindows(handle, EnumChildProc, 0);
}
---------------------------------------------------------------
I've got sth like this above. It work for Notepad but no effect with Mozilla Window... What is wrong?
golanshahar
April 19th, 2007, 11:15 AM
Hey,
I have a little problem. I've tried to get text from window (like firefox opened site text) but only what i got is window title with SendMessage with WM_GETTEXT attribute. Can you guys tell me (or write some piece of code) how to get body text of my firefox opened window?
Pliiiz help me :] Thx.
Do you want to get text of the webpage itself?
Cheers
hollow44
April 19th, 2007, 11:37 AM
that's right... so, do you have any idea?
or maybe i can just select the text with ctrl+a and then get selected text into a string... any idea how i can get selected text? cause i've tried with no result :/
ncode
April 23rd, 2007, 02:33 PM
maybe i can just select the text with ctrl+a and then get selected text into a string... any idea how i can get selected text? cause i've tried with no result :/
You can get all page code (not actually text, but HTML code) by using CHtmlView class form MFC or directly WebBrowser ActiveX control. In this case you don`t require a browser itself.
hollow44
April 24th, 2007, 05:16 PM
and what under WinApi?
TheCPUWizard
April 24th, 2007, 05:45 PM
1) PLEASE use code tags.
BOOL CALLBACK EnumChildProc(HWND hwndChild, LPARAM lParam)
{
char tekst3[10000];
SendMessage(hwndChild, WM_GETTEXT, 10000, (LPARAM)text3);
Write_text_my_function(text3);
return TRUE;
}
main () {
HWND handle = FindWindow(NULL, "window title");
EnumChildWindows(handle, EnumChildProc, 0);
}
2) The code you posted will not even compile. Please make sure you are posting the actual code you are running. Copy and Paste it, do NOT type it in. After posting, it is a good idea to copy it back to an empty .cpp file, compile that file and verify that the post is accurate.
ncode
April 25th, 2007, 01:31 AM
and what under WinApi?
Retrievng web page HTML code in MFC is not difficult:
1) CHtmlView::Navigate(...); //or CHtmlView::Navigate2(...)
2) CHtmlView::GetSource(...);
In WinAPI you have to use COM interfaces such as IHTMLDocument.
Refer to MSDN section "Programming and Reusing the Browser" and "MSHTML Reference".
hollow44
April 25th, 2007, 12:29 PM
hmmm. but that is kinda route... :/
i simulate keys press to get to my website and then i want to retrive text in this site. after this i simulate other keys press and so on...
i mean... i don't want to go to specified url in MFC, cause i'm already at this site.
can't i simply move the selected text to a buffer? or get the text from clipboard (after simulating ctrl+c)? or maybe i can get url of this site? ....
do you feel me? :P
hollow44
May 4th, 2007, 08:59 AM
you don't :P
golanshahar
May 4th, 2007, 10:49 AM
that's right... so, do you have any idea?
or maybe i can just select the text with ctrl+a and then get selected text into a string... any idea how i can get selected text? cause i've tried with no result :/
Look at the attached sample. ;)
Cheers
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.