如何修改控件的风格?
我想在程序运行中修改控件的风格,编写了如下的程序:
void CControlDlg::OnButton1()
{
CEdit *pEdit = (CEdit*)GetDlgItem(IDC_DATA);
if ((pEdit->GetStyle() & ES_READONLY) == 0x0)
{
pEdit->ModifyStyle(0x0, ES_READONLY);
}
}
但是运行后,根本没有变化,而且可以在编辑框里面输入字符,并不是预料中的只读属性。
question1:我修改了静态控件的风格,是成功的,为什么?
question2:请问怎样才能正确修改编辑控件的风格,以及如何修改其他种类控件的风格?
问题点数:100、回复次数:4Top
1 楼kingcom_xu(冷羽)回复于 2003-02-03 01:43:26 得分 100
文本框有特别的地方,要改为只读的不能用ModifyStyle或SetWindowLong,而是向文本框发送EM_SETREADONLY消息Top
2 楼kingcom_xu(冷羽)回复于 2003-02-03 01:43:47 得分 0
Edit Control Styles
To create an edit control using the CreateWindow or CreateWindowEx function, specify the EDIT class, appropriate window style constants, and a combination of the following edit control styles. After the control has been created, these styles cannot be modified, except as noted.
ES_READONLY Prevents the user from typing or editing text in the edit control.
To change this style after the control has been created, use the EM_SETREADONLY message.
Top
3 楼kingcom_xu(冷羽)回复于 2003-02-03 01:45:16 得分 0
CEdit类有一个成员函数封装了这条消息,所以上述代码可改为:
if ((pEdit->GetStyle() & ES_READONLY) == 0x0)
{
pEdit->SetReadOnly(true);
}Top
4 楼tjroamer(Cpp高手)回复于 2003-02-03 14:17:46 得分 0
谢谢你!Top




