Win 32 API 怎么设置文本框为不可输入
1个回答
展开全部
方法一 设置 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)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询