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