EnumChildWindows
-
Hi there, I am trying to find a text in a window. For example, I am trying to find if an open Notepad contains a specific text or not. This works for simple windows, like Notepad and Message boxes. However, when I try to find a text in Internet Explorer, Visual Studio or MS Word, it does not work. How can I find a text in a window? What's wrong with the following code? Thank you very much for any helps in advance.
bool FindText (HWND hwnd) { if (pWndOp == NULL) return false; bool bResult = false; LPARAM lParam = (LPARAM)(&bResult); EnumChildWindows (hwnd, (WNDENUMPROC)EnumChildProc, lParam); return bResult; } BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lParam) { if (hwnd) { TCHAR szTemp [1024] = {_T('\0')}; SendMessage (hwnd, WM_GETTEXT, sizeof(szTemp) / sizeof(TCHAR), (LPARAM)szTemp); CString sText (szTemp); if(!sText.IsEmpty ()) { if ( sText.Find (pWndOp->m_sText, 0) != -1) { *((bool*)lParam) = true; return FALSE; } } //if(FindText (hwnd)) //{ // *((bool*)lParam) = true; // return FALSE; //} return TRUE; } else return FALSE; }
Mustafa Demirhan -
Hi there, I am trying to find a text in a window. For example, I am trying to find if an open Notepad contains a specific text or not. This works for simple windows, like Notepad and Message boxes. However, when I try to find a text in Internet Explorer, Visual Studio or MS Word, it does not work. How can I find a text in a window? What's wrong with the following code? Thank you very much for any helps in advance.
bool FindText (HWND hwnd) { if (pWndOp == NULL) return false; bool bResult = false; LPARAM lParam = (LPARAM)(&bResult); EnumChildWindows (hwnd, (WNDENUMPROC)EnumChildProc, lParam); return bResult; } BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lParam) { if (hwnd) { TCHAR szTemp [1024] = {_T('\0')}; SendMessage (hwnd, WM_GETTEXT, sizeof(szTemp) / sizeof(TCHAR), (LPARAM)szTemp); CString sText (szTemp); if(!sText.IsEmpty ()) { if ( sText.Find (pWndOp->m_sText, 0) != -1) { *((bool*)lParam) = true; return FALSE; } } //if(FindText (hwnd)) //{ // *((bool*)lParam) = true; // return FALSE; //} return TRUE; } else return FALSE; }
Mustafa DemirhanYou're looking for text in the window title bar, or in the main edit area ? I would have thought that doing this for a title bar would work for any program, but if it's the latter, then you're obviously going to need to get a handle on the child window that is the actual edit area, and check that. Christian After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
-
You're looking for text in the window title bar, or in the main edit area ? I would have thought that doing this for a title bar would work for any program, but if it's the latter, then you're obviously going to need to get a handle on the child window that is the actual edit area, and check that. Christian After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
I am looking for the text in the main edit area. So, I am enumerating all child windows and get the text in it. However, this approach does not work with complex programs, like MS Word and VS. I get the text of the toolbars and combo boxes, but I cannot get the text of the main writing area. Mustafa Demirhan
-
I am looking for the text in the main edit area. So, I am enumerating all child windows and get the text in it. However, this approach does not work with complex programs, like MS Word and VS. I get the text of the toolbars and combo boxes, but I cannot get the text of the main writing area. Mustafa Demirhan
Ah, you're enumerating CHILD windows. I'd suggest the relationship in a more complex app is a little more, well, complex, than one main window with a couple of direct children, hence your problem. Try doing it recursively and see how you go. Christian After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
-
I am looking for the text in the main edit area. So, I am enumerating all child windows and get the text in it. However, this approach does not work with complex programs, like MS Word and VS. I get the text of the toolbars and combo boxes, but I cannot get the text of the main writing area. Mustafa Demirhan
A program like MS Word or VS does not use standard windows components (ie edit box, listbox, etc.) to display text. Standard windows components do not handle custom drawing such as tables, embeded graphics etc. If you want to get the text from a program such as MS Word then you'll have to use OLE Automation.
Todd Smith