win32 设置Edit控件为只读

使用CreateWindow创建了Edit控件后,想把该控件设置成只读,就可以使用:

::PostMessageW(hwnd, EM_SETREADONLY, 1, 0);
发送这个消息到Edit控件后,就可以设置成只读属性。具体介绍情况下面的MSDN:


EM_SETREADONLY Message

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.

Syntax

To send this message, call the SendMessage function as follows.
    
    
    
    
lResult = SendMessage(     // returns LRESULT in lResult
   (HWND) hWndControl,     // handle to destination control
   (UINT) EM_SETREADONLY,     // message ID
   (WPARAM) wParam,     // = (WPARAM) () wParam;
   (LPARAM) lParam     // = 0; 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 Value

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: Supported in Microsoft Rich Edit 1.0 and later. For information about the compatibility of rich edit versions with the various system versions, see About Rich Edit Controls.

Message Information

Header Declared in Winuser.h, include Windows.h
Minimum operating systems Windows 95, Windows NT 3.1

See Also

Edit Controls Overview, GetWindowLong



你可能感兴趣的:(windows,function,Microsoft,user,System,include)