VC判断控件是否按钮。

    CWnd* pwndChild = GetWindow(GW_CHILD);   
        while (pwndChild)
        {      
            //....to do sth.
            pwndChild = pwndChild->GetNextWindow();
        }

如上代码在循环获得窗口所有子控件后,得到的是一个CWnd指针。

一般的判断对象类型的方法:

            if (pwndChild -> IsKindOf (RUNTIME_CLASS( CButton )))
            {
                pwndChild ->EnableWindow(FALSE);
            }

但这里不能这样用,因为这里的类型已经成了CWnd

判断CWnd类型的一个比较笨的方法:

            char NAME[10];
            GetClassName(pwndChild->m_hWnd,NAME,10);
            pwndChild ->EnableWindow(strcmp(NAME,"Button"));

 

这个的问题是,会把标题栏上的系统按钮也禁止掉。

posted @ 2010-01-27 15:34  傲衣华少  阅读(829)  评论(0编辑  收藏  举报