您的位置:首页 > 其它

按TAB顺序枚举窗口中的各个控件

2009-09-17 22:33 204 查看
例1:

void CMyDlg::OnButton7()
{
CWnd *pChild = this->GetWindow(GW_CHILD);
CString s;
while(pChild)
{
pChild->GetWindowText(s);
MessageBox(s);

pChild = pChild->GetWindow(GW_HWNDNEXT);
}

}

例2:

void CSimParDlg::OnButton1()
{
// TODO: Add your control notification handler code here
CWnd *pWnd;

pWnd=GetWindow(GW_CHILD);
while (pWnd!=NULL)
{
if (pWnd-> IsKindOf(RUNTIME_CLASS(CEdit)))
pWnd-> EnableWindow(false);

pWnd=pWnd-> GetNextWindow();
}
}

在对话框中按ctrl+D,编辑各控件的tab值,这样上面程序就会按照tab顺序遍历各个控件

例3:

// 遍历得到页面中的所有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);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: