Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. EnumChildWindows

EnumChildWindows

Scheduled Pinned Locked Moved C / C++ / MFC
questioncsharpvisual-studiotutorial
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mustafa Demirhan
    wrote on last edited by
    #1

    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

    C 1 Reply Last reply
    0
    • M 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 Demirhan

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      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

      M 1 Reply Last reply
      0
      • C Christian Graus

        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

        M Offline
        M Offline
        Mustafa Demirhan
        wrote on last edited by
        #3

        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

        C T 2 Replies Last reply
        0
        • M 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

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • M 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

            T Offline
            T Offline
            Todd Smith
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups