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. GetWindowText

GetWindowText

Scheduled Pinned Locked Moved C / C++ / MFC
question
6 Posts 5 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.
  • R Offline
    R Offline
    RobJones
    wrote on last edited by
    #1

    Hello, I am trying to pull text from inside a edit box on another application.. Here is what I have tried, this only pulls the windows title bar text.. any ideas on how i can pull text from with in a edit box on another app?

        CWnd\* cWnd;
    POINT pt;
    ::GetCursorPos(&pt);
    cWnd = WindowFromPoint(pt);
    CString strBuf;
    cWnd->GetWindowText(strBuf);
    MessageBox(strBuf);
    

    Thanks Rob

    J W P F 4 Replies Last reply
    0
    • R RobJones

      Hello, I am trying to pull text from inside a edit box on another application.. Here is what I have tried, this only pulls the windows title bar text.. any ideas on how i can pull text from with in a edit box on another app?

          CWnd\* cWnd;
      POINT pt;
      ::GetCursorPos(&pt);
      cWnd = WindowFromPoint(pt);
      CString strBuf;
      cWnd->GetWindowText(strBuf);
      MessageBox(strBuf);
      

      Thanks Rob

      J Offline
      J Offline
      Joaquin M Lopez Munoz
      wrote on last edited by
      #2

      I guess you can call ChildWindowFromPoint on the cWnd retrieved, sort of like this (warning: didn't compile it):

      CWnd* cWnd;
      POINT pt;
      ::GetCursorPos(&pt);
      cWnd = WindowFromPoint(pt);
      cWnd->ScreenToClient(&pt);
      CWnd* cChildWnd = cWnd->ChildWindowFromPoint(pt);
      CString strBuf;
      cChildWnd->GetWindowText(strBuf);
      MessageBox(strBuf);

      Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

      1 Reply Last reply
      0
      • R RobJones

        Hello, I am trying to pull text from inside a edit box on another application.. Here is what I have tried, this only pulls the windows title bar text.. any ideas on how i can pull text from with in a edit box on another app?

            CWnd\* cWnd;
        POINT pt;
        ::GetCursorPos(&pt);
        cWnd = WindowFromPoint(pt);
        CString strBuf;
        cWnd->GetWindowText(strBuf);
        MessageBox(strBuf);
        

        Thanks Rob

        W Offline
        W Offline
        Williams
        wrote on last edited by
        #3

        I think the better way is to use SendMessage and OnCopyData. 1. First you search your target window handle. 2. You send a WM_COPYDATA to target window. 3. Write in your target app a function to handlw WM_COPYDATA Code: char szWindowName[60]; // "Target App" is the target app main window caption CString szTargetWindowName = "Target App"; int nFound; int nLength = strlen(szTargetWindowName); HWND hSearchHandle; for(hSearchHandle=::GetWindow(::GetDesktopWindow(), GW_CHILD);hSearchHandle; hSearchHandle = ::GetWindow(hSearchHandle, GW_HWNDNEXT)) { ::GetWindowText(hSearchHandle, szWindowName, 58); szWindowName[nLength] = '\0'; nFound = lstrcmpi(szWindowName, szTargetWindowName); if(nFound == 0) { CWnd pCwnd; COPYDATASTRUCT cds; char myStr[60]; strcpy(myStr,"Lets go."); cds.dwData = 0; cds.lpData = myStr; cds.cbData = sizeof(myStr); LONG lResult; lResult = ::SendMessage(hSearchHandle, WM_COPYDATA,(WPARAM)&pCwnd.m_hWnd, (LPARAM)(COPYDATASTRUCT*)&cds); } } ----------------------------------------- Now in your target app: BOOL CAppADlg::OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruct) { MessageBox((char *)pCopyDataStruct->lpData); return CDialog::OnCopyData(pWnd, pCopyDataStruct); } Try it.

        R 1 Reply Last reply
        0
        • W Williams

          I think the better way is to use SendMessage and OnCopyData. 1. First you search your target window handle. 2. You send a WM_COPYDATA to target window. 3. Write in your target app a function to handlw WM_COPYDATA Code: char szWindowName[60]; // "Target App" is the target app main window caption CString szTargetWindowName = "Target App"; int nFound; int nLength = strlen(szTargetWindowName); HWND hSearchHandle; for(hSearchHandle=::GetWindow(::GetDesktopWindow(), GW_CHILD);hSearchHandle; hSearchHandle = ::GetWindow(hSearchHandle, GW_HWNDNEXT)) { ::GetWindowText(hSearchHandle, szWindowName, 58); szWindowName[nLength] = '\0'; nFound = lstrcmpi(szWindowName, szTargetWindowName); if(nFound == 0) { CWnd pCwnd; COPYDATASTRUCT cds; char myStr[60]; strcpy(myStr,"Lets go."); cds.dwData = 0; cds.lpData = myStr; cds.cbData = sizeof(myStr); LONG lResult; lResult = ::SendMessage(hSearchHandle, WM_COPYDATA,(WPARAM)&pCwnd.m_hWnd, (LPARAM)(COPYDATASTRUCT*)&cds); } } ----------------------------------------- Now in your target app: BOOL CAppADlg::OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruct) { MessageBox((char *)pCopyDataStruct->lpData); return CDialog::OnCopyData(pWnd, pCopyDataStruct); } Try it.

          R Offline
          R Offline
          RobJones
          wrote on last edited by
          #4

          The target app is not mine (It's commercial software and I don't have the source code).. :( Basicly what I am trying to do is pull text from the Rich edit control on Yahoo! Messenger (The chat window. When you are talking to someone) and store the whole msg in a string.

          1 Reply Last reply
          0
          • R RobJones

            Hello, I am trying to pull text from inside a edit box on another application.. Here is what I have tried, this only pulls the windows title bar text.. any ideas on how i can pull text from with in a edit box on another app?

                CWnd\* cWnd;
            POINT pt;
            ::GetCursorPos(&pt);
            cWnd = WindowFromPoint(pt);
            CString strBuf;
            cWnd->GetWindowText(strBuf);
            MessageBox(strBuf);
            

            Thanks Rob

            P Offline
            P Offline
            Peter Occil
            wrote on last edited by
            #5

            GetWindowText will not retrieve the text in an edit control in another application (thread?). GetWindowText retrieves the caption from the window's internal data. Even with a lot of text, edit controls always have an empty string as its caption. The workaround is to send the edit control a WM_GETTEXT message (preferably using SendMessageTimeout) to retrieve the text. Peter O.

            1 Reply Last reply
            0
            • R RobJones

              Hello, I am trying to pull text from inside a edit box on another application.. Here is what I have tried, this only pulls the windows title bar text.. any ideas on how i can pull text from with in a edit box on another app?

                  CWnd\* cWnd;
              POINT pt;
              ::GetCursorPos(&pt);
              cWnd = WindowFromPoint(pt);
              CString strBuf;
              cWnd->GetWindowText(strBuf);
              MessageBox(strBuf);
              

              Thanks Rob

              F Offline
              F Offline
              firecow
              wrote on last edited by
              #6

              You can't use GetWindowText() to get the text from an edit control. At least that's what it says in MSDN. You will have to use SendMessage() to copy data like the guy above me said.

              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