如何修改控件的风格?

tjroamer 2003-02-03 01:16:09
我想在程序运行中修改控件的风格,编写了如下的程序:
void CControlDlg::OnButton1()
{
CEdit *pEdit = (CEdit*)GetDlgItem(IDC_DATA);
if ((pEdit->GetStyle() & ES_READONLY) == 0x0)
{

pEdit->ModifyStyle(0x0, ES_READONLY);
}
}
但是运行后,根本没有变化,而且可以在编辑框里面输入字符,并不是预料中的只读属性。
question1:我修改了静态控件的风格,是成功的,为什么?
question2:请问怎样才能正确修改编辑控件的风格,以及如何修改其他种类控件的风格?
...全文
145 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
tjroamer 2003-02-03
  • 打赏
  • 举报
回复
谢谢你!
kingcom_xu 2003-02-03
  • 打赏
  • 举报
回复
CEdit类有一个成员函数封装了这条消息,所以上述代码可改为:
if ((pEdit->GetStyle() & ES_READONLY) == 0x0)
{
pEdit->SetReadOnly(true);

}
kingcom_xu 2003-02-03
  • 打赏
  • 举报
回复
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.
kingcom_xu 2003-02-03
  • 打赏
  • 举报
回复
文本框有特别的地方,要改为只读的不能用ModifyStyle或SetWindowLong,而是向文本框发送EM_SETREADONLY消息

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧