Reputation: 51
Recently I added the Common Controls 6.0 visual style to my MFC program which makes all the controls look more modern. When I dynamically create a CEdit button though it looks like the a old CEdit from Windows 95. All the other ctrls I dynamically create look like the newer version except for the CEdit. So, I was wondering if anyone else has experienced this problem and knows of any solution?
Here is the code that I use to dynamically create the CEdit. I have applied all the styles the other non-dynamic CEdit controls have but it made no difference.
m_CEditCtrl.Create(WS_CHILD | WS_VISIBLE | WS_BORDER | ES_AUTOHSCROLL, CRect(0, 0, 150, 100), this, IDC_VALUE_ID);
Also here is a comparison between the dynamically created one and the non-dynamic one.
I have tried looking for answers to this problem but so far have only found two other Stack Overflow questions and neither of them provided the answer I was looking for.
This question has the exact same problem but has no answer and none of the comments provide anything resembling a solution. MFC: dynamically created CEdit is not animated and does not change the appearance
This other question has a solution but it's solution doesn't apply as I have no OnCtrlEdit being applied to this CEdit. Why is my edit control ignoring the applied visual styles?
Upvotes: 2
Views: 146
Reputation: 51
Here is the answer thanks to user20716902.
In order to get the nice looking CEdit box dynamically you need to use the CreateEX function and use the WS_EX_CLIENTEDGE style.
Here is example code of creating a CEdit box that looks modern.
m_CEditCtrl.CreateEx(WS_EX_CLIENTEDGE, _T("EDIT"), _T(" "), WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL, CRect(0, 0, 0, 0), this, 1);
Upvotes: 3