Hello
I'm trying to get the message from a static text in another application. I have this code which works perfectly in console application:
Code:
BOOL CALLBACK EnumChildProc2(HWND hwnd, LPARAM lParam) {
counter2++;
if (counter2 == 6) // counter 6 is the static text child
{
cout << "hwnd_Child 6 = " << hwnd << endl;
HWND hand = (HWND)hwnd;
char szBuf[2048];
LONG lResult;
lResult = SendMessage(hwnd, WM_GETTEXT, sizeof(szBuf) / sizeof(szBuf[0]), (LPARAM)szBuf);
printf("%s", szBuf); // it prints the message correctly
}
return TRUE;
}
int main() {
EnumChildWindows(FindWindow("#32770", "Unable to Write"), EnumChildProc2, 0);
}
It works very well in console application but it seems that bool callback function doesn't work as i need in MFC application . This is the code i used in MFC:
Code:
BOOL CALLBACK EnumChildProc2(HWND hwnd, LPARAM lParam) {
counter_Child6++;
if (counter_Child6 == 6)
{
HWND hand = (HWND)hwnd;
char szBuf[2048];
LONG lResult;
lResult = SendMessage(hwnd, WM_GETTEXT, sizeof(szBuf) / sizeof(szBuf[0]), (LPARAM)szBuf);
CString ssString;
ssString.Format(_T("%s"), szBuf);
AfxMessageBox(ssString);
}
return TRUE;
}
CWnd *pWnd = FindWindow(_T("#32770"), _T("Unable to Write"));
if (NULL != pWnd)
{
listControl1.InsertItem(0, _T("Window Exists"));
EnumChildWindows((HWND)pWnd, EnumChildProc2, 0); //this function doesn't afxmessagebox anything
}
else
{
listControl1.InsertItem(0, _T("Does not Exists"));
}
Any help would be greatly appreciated! Thanks