先是源代码:
#include "StdAfx.h "
#include ".\surveyWnd.h "
void CALLBACK EnumFunc(HWND hWnd, LPARAM lParam ); //这里加一个声明,在这个位置应该是全局函数吧,我是VC++新手,猜的。EnumChildWindows该函数的回调函数只可以是静态函数,或者全局函数。
surveyWnd::surveyWnd(void)
{}
surveyWnd::~surveyWnd(void)
{}
bool surveyWnd::FindCCproxyWindow()
{
HWND hHWWnd = FindWindow( NULL, "Hello World! " );
if( hHWWnd == NULL )
{ AfxMessageBox( "Faild ");
return false;}
else{
CString strT;
strT.Format( "hWnd: %X ",hHWWnd );
AfxMessageBox( strT );
m_hHWWnd = hHWWnd ;}
EnumChildWindows( m_hHWWnd , (WNDENUMPROC)EnumFunc, (LPARAM)NULL); //第二个参数还要加上(WNDENUMPROC) 强制转换。
return true;
}
//这里就有问题!
void CALLBACK EnumFunc(HWND hWnd, LPARAM lParam )
{
char chText[MAX_PATH];
ZeroMemory( chText, MAX_PATH );
GetWindowText( hWnd, chText, MAX_PATH );
CString strTest;
int nID = 1;
nID = GetDlgCtrlID( hWnd );
//strTest = "asgea "; Line @1
//strTest.Format( "ID: %X\nText: ", nID ); Line @2
//str = str + chText;
AfxMessageBox( chText );
}