win32guieditcontrol

How can I get the 'read-only' property of a win32 edit box?


How can I get the 'read-only' property of a win32 edit box ?

And I know how to set the property. code like this.

SendDlgItemMessage(g_hwnd, IDC_EDIT_1, EM_SETREADONLY, 1, 0);

But how can I know this edit control has the 'read-only' property ? I mean not MFC\CWND or some how, just win32 method, like SendMessage api.

Thanks in advance~


Solution

  • According to MSDN:

    EM_SETREADONLY message

    Sets or removes the read-only style (ES_READONLY) of an edit control.

    So just read that style from your control using GetWindowLongPtr() with GWL_STYLE.

    Here is the Win API call:

    bool bRO = ::GetWindowLongPtr(::GetDlgItem(g_hwnd, IDC_EDIT_1), GWL_STYLE) & ES_READONLY;