0

I have a ATL ActiveX Control with Edit Control. I want to set text color to the control of as per specific conditions.
I cannot use setTextColor as there is no MFC support to the the control. I am also not able to use 'WM_CTLCOLOREDIT' message as I don't have access to CDC and CWnd.
I had similar issue setting text input limit but I accomplished it using SendMessage(EM_LIMITTEXT, (WPARAM)1000, (LPARAM)0); but could not find any message for setting text color.
Is there any other way to achieve this ?

  • First, you want to handle [`WM_CTLCOLOREDIT`](https://msdn.microsoft.com/en-us/library/windows/desktop/bb761691.aspx) message. Second, what makes you believe you need `CDC` or `CWnd` to handle it? – Igor Tandetnik Oct 21 '15 at 21:35
  • Thanks Igor. I corrected the message name to WM_CTLCOLOREDIT in my question.
    – Ankur Patil Oct 23 '15 at 06:13
  • WM_CTLCOLOREDIT handler function needed parameters HBRUSH CMyDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) so I though I would need CDC and CWnd. I found another version of handling WM_CTLCOLOREDIT. LRESULT CMyDialog::OnCtlColorEdit(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) But this message gets called while loading the dialog. Can I call it explicitly on click of a Check box to change the color of edit control text ? – Ankur Patil Oct 23 '15 at 06:22
  • `needed parameters HBRUSH` No it does not. From the documentation article I linked to: "If an application processes this message, it must **return** the handle of a brush". Emphasis mine. Why are you looking at MFC documentation at all, when you say you don't want to use MFC? `this message gets called while loading the dialog` This message is sent whenever the edit control needs to repaint itself, for whatever reason. You could call [`InvalidateRect`](https://msdn.microsoft.com/en-us/library/dd145002.aspx) to give it such a reason. – Igor Tandetnik Oct 23 '15 at 13:35
  • Igor, I am able to set the color now. The reason for the color not setting was that my edit control was set to readonly (which was the projects requirement). I have now set control to editable and ignoring user input's on the control using the OnChange event. – Ankur Patil Oct 27 '15 at 12:08
  • Read-only edit control sends `WM_CTLCOLORSTATIC` message instead. You handle it the same way as `WM_CTLCOLOREDIT` – Igor Tandetnik Oct 27 '15 at 13:53

0 Answers0