现在的位置: 首页 > 综合 > 正文

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

2013年08月14日 ⁄ 综合 ⁄ 共 965字 ⁄ 字号 评论关闭

例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);
     }

 

抱歉!评论已关闭.