怎么给对话框里面的控件动态改变名称
如何给对话框里面的控件动态改变名称
就是在代码里面做判断,然后改变一个Check Box控件的名称,显示。
------解决方案--------------------
SetWindowText( "... "); ??
------解决方案--------------------
GetDlgItem(IDC_CHECK1)-> SetWindowText( "yourname ");
------解决方案--------------------
SetWindowText和SetDlgItemText都可以的
------解决方案--------------------
m_check.SetWindowText(strname);
m_check.SetDlgItemText(strname);
UpdateData(false);
------解决方案--------------------
重载OnCtlColor
HBRUSH CYourDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
pDC-> SetTextColor (RGB (255, 255 ,0)); //前景色
pDC-> SetBkColor (RGB (0,0,0)); //背景色
// TODO: Return a different brush if the default is not desired
return hbr;
}
------解决方案--------------------
更好的方法
HBRUSH CDGDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
switch (pWnd-> GetDlgCtrlID())
{
case IDC_CHECK1: pDC-> SetTextColor (RGB (255, 255 ,0)); break; //前景色1
case IDC_CHECK2: pDC-> SetTextColor (RGB (0, 255 ,255)); break; //前景色2
// ......
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
就是在代码里面做判断,然后改变一个Check Box控件的名称,显示。
------解决方案--------------------
SetWindowText( "... "); ??
------解决方案--------------------
GetDlgItem(IDC_CHECK1)-> SetWindowText( "yourname ");
------解决方案--------------------
SetWindowText和SetDlgItemText都可以的
------解决方案--------------------
m_check.SetWindowText(strname);
m_check.SetDlgItemText(strname);
UpdateData(false);
------解决方案--------------------
重载OnCtlColor
HBRUSH CYourDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
pDC-> SetTextColor (RGB (255, 255 ,0)); //前景色
pDC-> SetBkColor (RGB (0,0,0)); //背景色
// TODO: Return a different brush if the default is not desired
return hbr;
}
------解决方案--------------------
更好的方法
HBRUSH CDGDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
switch (pWnd-> GetDlgCtrlID())
{
case IDC_CHECK1: pDC-> SetTextColor (RGB (255, 255 ,0)); break; //前景色1
case IDC_CHECK2: pDC-> SetTextColor (RGB (0, 255 ,255)); break; //前景色2
// ......
}
// TODO: Return a different brush if the default is not desired
return hbr;
}