VC控制元件----如何根據控制代碼判斷其型別
阿新 • • 發佈:2019-01-25
hWnd=GetWindow(hDlg,GW_CHILD);
if(hWnd == NULL || !::IsWindow(hWnd))
return FALSE;
nIdFirst=GetDlgCtrlID(hWnd);
do
{
GetClassName(hWnd,szBuf,256);
//Edit子類化
if( _tcsicmp(szBuf,_T( "Edit ")) == 0)
{
//驗證是否已經被永久對映
if(CWnd::FromHandlePermanent(hWnd) == NULL)
{
CEditEx *pEdit=new CEditEx();
if(pEdit == NULL)
return FALSE;
pSkin-> m_edtList.AddTail(pEdit);
//子類化此視窗
pEdit-> SubclassWindow(hWnd);
}
}
//button子類化
if(_tcsicmp(szBuf,_T( "Button ")) == 0)
{
dwStyle = GetWindowLong(hWnd,GWL_STYLE);
if((dwStyle & SS_TYPEMASK) == BS_DEFPUSHBUTTON)
dwStyle = BS_PUSHBUTTON;
if((dwStyle & SS_TYPEMASK) == BS_AUTOCHECKBOX)
dwStyle = BS_CHECKBOX;
TCHAR szBuf[256];
GetWindowText(hWnd,szBuf,256);
//PushButton子類化
if( (dwStyle & SS_TYPEMASK) == BS_PUSHBUTTON)
{
if(CWnd::FromHandlePermanent(hWnd) == NULL)
{
CXPButton *pBtn=new CXPButton();
if(pBtn == NULL)
return FALSE;
pSkin-> m_btnList.AddTail(pBtn);
pBtn-> SubclassWindow(hWnd);
}
}
//Checkbox子類化
else if( (dwStyle & SS_TYPEMASK) == BS_CHECKBOX )
{
if(CWnd::FromHandlePermanent(hWnd) == NULL)
{
CExCheckBox *pChk=new CExCheckBox();
if(pChk == NULL)
return FALSE;
pSkin-> m_chkList.AddTail(pChk);
pChk-> SubclassWindow(hWnd);
}
}
else if( ( dwStyle & SS_TYPEMASK) == BS_GROUPBOX)
{
if(CWnd::FromHandlePermanent(hWnd) == NULL)
{
CExGroupBox *pGrp=new CExGroupBox();
if(pGrp == NULL)
return FALSE;
pSkin-> m_grpList.AddTail(pGrp);
pGrp-> SubclassWindow(hWnd);
}
}
}
//static子類化
if( (_tcsicmp(szBuf,_T( "Static ")) == 0)
&& (GetWindowLong(hWnd,GWL_STYLE) & SS_ETCHEDHORZ) == SS_ETCHEDHORZ)
{
if(CWnd::FromHandlePermanent(hWnd) == NULL)
{
CLineStatic * pLine=new CLineStatic();
if(pLine == NULL)
return FALSE;
pSkin-> m_lineList.AddTail(pLine);
pLine-> SubclassWindow(hWnd);
}
}
//ComboBox子類化
if( _tcsicmp(szBuf,_T( "ComboBox ")) == 0)
{
if(CWnd::FromHandlePermanent(hWnd) == NULL)
{
CFlatComboBox *pCmb=new CFlatComboBox();
if(pCmb == NULL)
return FALSE;
pSkin-> m_cmbList.AddTail(pCmb);
pCmb-> SubclassWindow(hWnd);
}
}
//etc
hWnd=GetWindow(hWnd,GW_HWNDNEXT);
if(!::IsWindow(hWnd) || hWnd==NULL)
break;
}while(nIdFirst != GetDlgCtrlID(hWnd));
if(hWnd == NULL || !::IsWindow(hWnd))
return FALSE;
nIdFirst=GetDlgCtrlID(hWnd);
do
{
GetClassName(hWnd,szBuf,256);
//Edit子類化
if( _tcsicmp(szBuf,_T( "Edit ")) == 0)
{
//驗證是否已經被永久對映
if(CWnd::FromHandlePermanent(hWnd) == NULL)
{
CEditEx *pEdit=new CEditEx();
if(pEdit == NULL)
return FALSE;
pSkin-> m_edtList.AddTail(pEdit);
//子類化此視窗
pEdit-> SubclassWindow(hWnd);
}
}
//button子類化
if(_tcsicmp(szBuf,_T( "Button ")) == 0)
{
dwStyle = GetWindowLong(hWnd,GWL_STYLE);
if((dwStyle & SS_TYPEMASK) == BS_DEFPUSHBUTTON)
dwStyle = BS_PUSHBUTTON;
if((dwStyle & SS_TYPEMASK) == BS_AUTOCHECKBOX)
dwStyle = BS_CHECKBOX;
TCHAR szBuf[256];
GetWindowText(hWnd,szBuf,256);
//PushButton子類化
if( (dwStyle & SS_TYPEMASK) == BS_PUSHBUTTON)
{
if(CWnd::FromHandlePermanent(hWnd) == NULL)
{
CXPButton *pBtn=new CXPButton();
if(pBtn == NULL)
return FALSE;
pSkin-> m_btnList.AddTail(pBtn);
pBtn-> SubclassWindow(hWnd);
}
}
//Checkbox子類化
else if( (dwStyle & SS_TYPEMASK) == BS_CHECKBOX )
{
if(CWnd::FromHandlePermanent(hWnd) == NULL)
{
CExCheckBox *pChk=new CExCheckBox();
if(pChk == NULL)
return FALSE;
pSkin-> m_chkList.AddTail(pChk);
pChk-> SubclassWindow(hWnd);
}
}
else if( ( dwStyle & SS_TYPEMASK) == BS_GROUPBOX)
{
if(CWnd::FromHandlePermanent(hWnd) == NULL)
{
CExGroupBox *pGrp=new CExGroupBox();
if(pGrp == NULL)
return FALSE;
pSkin-> m_grpList.AddTail(pGrp);
pGrp-> SubclassWindow(hWnd);
}
}
}
//static子類化
if( (_tcsicmp(szBuf,_T( "Static ")) == 0)
&& (GetWindowLong(hWnd,GWL_STYLE) & SS_ETCHEDHORZ) == SS_ETCHEDHORZ)
{
if(CWnd::FromHandlePermanent(hWnd) == NULL)
{
CLineStatic * pLine=new CLineStatic();
if(pLine == NULL)
return FALSE;
pSkin-> m_lineList.AddTail(pLine);
pLine-> SubclassWindow(hWnd);
}
}
//ComboBox子類化
if( _tcsicmp(szBuf,_T( "ComboBox ")) == 0)
{
if(CWnd::FromHandlePermanent(hWnd) == NULL)
{
CFlatComboBox *pCmb=new CFlatComboBox();
if(pCmb == NULL)
return FALSE;
pSkin-> m_cmbList.AddTail(pCmb);
pCmb-> SubclassWindow(hWnd);
}
}
//etc
hWnd=GetWindow(hWnd,GW_HWNDNEXT);
if(!::IsWindow(hWnd) || hWnd==NULL)
break;
}while(nIdFirst != GetDlgCtrlID(hWnd));