2

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~

D J
  • 845
  • 1
  • 13
  • 27

1 Answers1

4

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;
Vlad Feinstein
  • 10,960
  • 1
  • 12
  • 27
  • And for things defined as `CWnd*` variables: `bool bRO = ::GetWindowLongPtr(pWnd->GetSafeHwnd(), GWL_STYLE) & ES_READONLY;` – sergiol Jun 30 '21 at 19:10