最近在写控制台,在设计界面按钮风格时不想通过每个按钮的ID来获取其句柄,而是通过遍历窗体所有控件,然后判断其控件类型进而来实现。
代码如下:
// 遍历得到页面中的所有Button控件,依次设定其样式和颜色
CWnd* pWnd = GetWindow(GW_CHILD);
char cClassName[255]={0};
while(pWnd)
{
GetClassName(pWnd->GetSafeHwnd(),cClassName,255);//得到控件的类名,主要有Edit,Button,Static等等
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://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)