2

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. enter image description here

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?

Jabberwocky
  • 48,281
  • 17
  • 65
  • 115
  • Find the call to [`ActivateActCtx`](https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-activateactctx) in your program and reproduce it here. – IInspectable Jun 09 '23 at 19:53
  • @IInspectable there is no call to ActivateActCtx in my program. To include the common control 6.0 I added this comment to the pch.h header. `#pragma comment(linker,"\"/manifestdependency:type='win32' \ name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \ processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")` – GoodChristianBoi Jun 09 '23 at 20:19
  • 1
    Answered [here](https://stackoverflow.com/questions/1955806/how-do-i-dynamically-create-controls-with-the-same-visual-style-as-their-parent) Basically you need to use `WS_EX_CLIENTEDGE` or `WS_EX_STATICEDGE` – user20716902 Jun 12 '23 at 22:21

1 Answers1

2

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);