C++获得其他程序窗体控件中信息的方法
本文实例讲述了C++获得其他程序窗体控件中信息的方法。分享给大家供大家参考。具体分析如下:
这里演示了获得其他程序窗体控件信息的方法,
用FindWindowAPI找到文本框句柄,用SendMessage(WM_GETTEXT)获得文本
#include<windows.h>
BOOLCALLBACKEnumChildProc(HWNDhWnd,LPARAMlParam);
intWINAPIWinMain(HINSTANCEhInstance,HINSTANCEhPrevInstance,LPSTRlpCmdLine,intnCmdShow)
{
charclassName[]="notepad";
HWNDhWnd=::FindWindow(className,NULL);
if(hWnd)
{
::EnumChildWindows(hWnd,EnumChildProc,0);
return0;
}
MessageBox(NULL,"fail!","fail",MB_OK);
return0;
}
BOOLCALLBACKEnumChildProc(HWNDhWnd,LPARAMlParam)
{
chartemp1[256],temp2[256];
::GetClassName(hWnd,temp1,255);
if(!::strcmp(temp1,"Edit"))
{
::SendMessage(hWnd,WM_GETTEXT,sizeof(temp2)/sizeof(char),(LPARAM)temp2);
//EDIT的句柄,消息,接收缓冲区大小,接收缓冲区指针
::MessageBox(NULL,temp2,"get",MB_OK);
return0;
}
::wsprintf(temp2,"classname:%s",temp1);
MessageBox(NULL,temp2,"cwnd",MB_OK);
returntrue;
}
希望本文所述对大家的C++程序设计有所帮助。