Win 32 API 怎么设置文本框为不可输入
答案:1 悬赏:0 手机版
解决时间 2021-12-03 10:29
- 提问者网友:流星是天使的眼泪
- 2021-12-02 17:09
Win 32 API 怎么设置文本框为不可输入
最佳答案
- 五星知识达人网友:愁杀梦里人
- 2021-12-02 18:30
方法一 设置 edit控件 style 具有 ES_READONLY (createwindow的时候加上)
已经创建要控件的 发消息 EM_SETREADONLY
EM_SETREADONLY
The EM_SETREADONLY message sets or removes the read-only style
(ES_READONLY) of an edit control. You can send this message to either an edit
control or a rich edit control.
To send this message, call the SendMessage function with the following
parameters.
SendMessage(
(HWND) hWnd, // handle to destination window
EM_SETREADONLY, // message to send
(WPARAM) wParam, // read-only option
(LPARAM) lParam // not used; must be zero
);
Parameters
wParam
Specifies whether to set or remove the ES_READONLY style. A value of TRUE
sets the ES_READONLY style; a value of FALSE removes the ES_READONLY style.
lParam
This parameter is not used.
Return Values
If the operation succeeds, the return value is nonzero.
If the operation fails, the return value is zero.
Remarks
When an edit control has the ES_READONLY style, the user cannot change the
text within the edit control.
To determine whether an edit control has the ES_READONLY style, use the GetWindowLong function with the GWL_STYLE
flag.
Rich Edit: For information about the compatibility of rich edit
versions with the various system versions, see About
Rich Edit Controls
方法二 直接使之变灰禁用,EnableWindow(文本框句柄,False)
已经创建要控件的 发消息 EM_SETREADONLY
EM_SETREADONLY
The EM_SETREADONLY message sets or removes the read-only style
(ES_READONLY) of an edit control. You can send this message to either an edit
control or a rich edit control.
To send this message, call the SendMessage function with the following
parameters.
SendMessage(
(HWND) hWnd, // handle to destination window
EM_SETREADONLY, // message to send
(WPARAM) wParam, // read-only option
(LPARAM) lParam // not used; must be zero
);
Parameters
wParam
Specifies whether to set or remove the ES_READONLY style. A value of TRUE
sets the ES_READONLY style; a value of FALSE removes the ES_READONLY style.
lParam
This parameter is not used.
Return Values
If the operation succeeds, the return value is nonzero.
If the operation fails, the return value is zero.
Remarks
When an edit control has the ES_READONLY style, the user cannot change the
text within the edit control.
To determine whether an edit control has the ES_READONLY style, use the GetWindowLong function with the GWL_STYLE
flag.
Rich Edit: For information about the compatibility of rich edit
versions with the various system versions, see About
Rich Edit Controls
方法二 直接使之变灰禁用,EnableWindow(文本框句柄,False)
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯