VC遍历窗体控件的实现
遍历窗体所有控件代码如下:
CWnd* pwndChild = GetWindow(GW_CHILD);
while (pwndChild)
{
//....to do something
pwndChild = pwndChild->GetNextWindow();
}
如果只想得到某一类 ,比如button的。代码如下:
// 遍历得到页面中的所有Button控件,依次设定其样式和颜色
CWnd* pWnd = GetWindow(GW_CHILD);
char cClassName[255]={0};
while(pWnd)
{
//得到控件的类名,主要有Edit,Button,Static等等
GetClassName(pWnd->GetSafeHwnd(),cClassName,255);
if(strcmp(cClassName,"Button") ==0) //是Button控件
{
CXTButton *pBtn = (CXTButton*) pWnd;
pBtn->SetXButtonStyle(BS_XT_XPFLAT);
pBtn->SetColorFace(BUTTON_BKCOLOR); //按钮背景色
}
pWnd = pWnd->GetWindow(GW_HWNDNEXT);
}
原文地址: http://blog.csdn.net/guanchanghui/article/details/1491715