CWnd*pWnd为你控件的指针,LPCTSTRlpszClassName是你控件的类名,比如编辑框是"Edit",按钮是"Button",详情可以使用SPY 查看.
BOOLModifyControlStyle(CWnd*pWnd,LPCTSTRlpszClassName,DWORDdwRemove,DWORDdwAdd,DWORDdwRemoveEx,DWORDdwAddEx)
{
CWnd*pParentWnd=pWnd->GetParent();
CFont*pFont=pWnd->GetFont();
CStringstrText;
pWnd->GetWindowText(strText);
{
//在此添加保存控件其他属性的代码,我只保存了字体和文字
}
CRectrcWindow;
pWnd->GetWindowRect(&rcWindow);
pParentWnd->ScreenToClient(rcWindow);
DWORDdwNewStyle=(pWnd->GetStyle()&~dwRemove)|dwAdd;
DWORDdwNewStyleEx=(pWnd->GetExStyle()&~dwRemoveEx)|dwAddEx;
UINTnID=pWnd->GetDlgCtrlID();
pWnd->ShowWindow(SW_HIDE);
pWnd->DestroyWindow();
BOOLbResult=pWnd->CreateEx(dwNewStyleEx,lpszClassName,strText,dwNewStyle,rcWindow,pParentWnd,nID);
pWnd->SetFont(pFont); 软件开发网
returnbResult;
}
测试代码:
voidCAboutDlg::OnButton()
{
CWnd*pWnd=GetDlgItem(IDC_EDIT1);