Thread: copy paste from another app

  1. #1
    Registered User
    Join Date
    Aug 2002
    Posts
    170

    copy paste from another app

    I am (once again) faced with reading text from another app. This time none of the previous methods have worked.

    I can highlight the text and copy and paste it. Is there a way I can do this in an automated way to read each new line as it comes in?

    Spy++ shows the control as being a AfxWnd42s.

    --Bonkey
    Best Regards,

    Bonkey

  2. #2
    Registered User
    Join Date
    Aug 2002
    Posts
    170
    Here is what I have tried. I'm using MFC MSVC++ 6.

    Code:
    void CReadpsDlg::OnBrowse() 
    {
    	// TODO: Add your control notification handler code here
    	WindowText="App Client";
    		while( EnumWindows(EnumWindowsProc,(LPARAM)this) );
    
    		Wnd = FindWindowEx( (HWND)pParentHwnd,NULL,"AfxWnd42s",NULL);
    		
    		CString s;
    		int STRINGLEN=255;
    		GetClassName(pParentHwnd, s.GetBuffer(STRINGLEN),STRINGLEN);
    		s.ReleaseBuffer();
    
    		CWnd* pWnd;
    		pWnd = FindWindow( s, NULL);
    		TCHAR buf[512];
    		pWnd->SendMessage(WM_GETTEXT,sizeof(buf)/sizeof(TCHAR),(LPARAM)(void*)buf);
    
    		ReadText();
    }
    
    
    BOOL CALLBACK EnumWindowsProc( HWND hwnd, LPARAM lParam)
    {
    
    	char *text = new char[255];
    	::GetWindowText(hwnd,text,255);
    
    	if( strstr(text,WindowText))
    	{
    		CReadpsDlg *myView = (CReadpsDlg *)lParam;
    		myView->pParentHwnd=hwnd;
    		delete [] text;
    		return(false);
    	}
    
    	delete [] text;
    	return(true);
    }
    
    void CReadpsDlg::ReadText(void)
    {
    	
    	char lpBuff[255];
    	int stop=0;
    
    		for(;stop!=1;m_LastLineNum++)
    		{
    		DWORD dwCount = ::SendMessage(Wnd,LB_GETTEXTLEN,m_LastLineNum,0);
    
    		if(dwCount)
    		{
    			memset(lpBuff,NULL,255);
    			if(LB_ERR != ::SendMessage(Wnd,LB_GETTEXT,m_LastLineNum,(LPARAM)lpBuff))
    			{
    				if( m_LastString == lpBuff )
    				{
    					stop=1;
    				}
    				else
    				{
    					m_text=lpBuff;
    				}
    //					ProcessLine(lpBuff);
    			}
    			else
    			{
    				m_LastLineNum-=1;
    				stop=1;
    			}
    		}
    		else
    		{
    			stop=1;
    			m_LastLineNum-=1;
    		}
    		}
    		m_LastString=lpBuff;
    
    
    }
    No text is read from the control, even though there is text present.

    --Bonkey
    Best Regards,

    Bonkey

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to copy a C struct to a C++ class?
    By Ptbamboo in forum C++ Programming
    Replies: 1
    Last Post: 02-21-2009, 02:11 PM
  2. Copying constant amount of data
    By TriKri in forum C++ Programming
    Replies: 16
    Last Post: 07-12-2008, 06:32 AM
  3. Copy constructor question
    By BigFish21 in forum C++ Programming
    Replies: 9
    Last Post: 05-04-2008, 12:18 PM
  4. pointer conversion problems with a copy constructor
    By stanlvw in forum C++ Programming
    Replies: 8
    Last Post: 01-14-2008, 12:06 AM
  5. Copy and Paste function in console apps.
    By Hakins90 in forum C Programming
    Replies: 5
    Last Post: 12-27-2007, 05:07 AM