3

I would like to provide highly styled form elements for a client within an MFC application.

I am coming to the conclusion that 'Web-2.0'-style widgets are simply not possible in the MFC universe without major custom painting/programming work.

I include screenshots to compare:

  • A desired 'Web 2.0'-style edit widget, and
  • the 'best' edit widgets straightforwardly available in the MFC universe.

Example A: Here is a screenshot of a (randomly chosen) nicely styled edit widget that is easily available and trivial to use in the web programming world with HTML/CSS:

Web-2.0 style widgets are easy in HTML!

Example B: In contrast, here is a screenshot taken from one of BCGSoft's MFC library's example applications. This very example application is titled "Edit Box Demo", and provides - it seems - the best edit widgets available in the MFC universe:

The best MFC edit widgets don't cut it

You can see that there is a 'generation of difference' between easily-available HTML edit widgets, and the seemingly best-available MFC/C++ widgets for Windows desktop applications.

My question is therefore straightforward: How is it possible to style a CEdit control with rounded corners and shadow in MFC?

Dan Nissenbaum
  • 13,558
  • 21
  • 105
  • 181
  • 1
    http://stackoverflow.com/questions/1955538/win32-how-to-custom-draw-an-edit-control – Jonathan Jul 26 '16 at 14:49
  • 1
    You have to make your own ownerdraw controls to get those rounded edges. Or use `CDHtmlDialog`. It won't necessarily look good in Windows 8 & 10 which are big on square edges. – Barmak Shemirani Jul 26 '16 at 15:34

1 Answers1

1

Just pointing you to Example B you used

Using CBCGPEdit it should be simple and straight forward to overwrite OnNcPaint.

But! Usually you can instruct the BCG to use a visual manager and in this case the visual manager will be responsible to draw the controls frame. And the visual manager will use round corners if it is designed to do so... I know even no visual manager that uses round corners ;) (CBCGPVisualManager::OnDrawControlBorder)

But feel free to write your own.

xMRi
  • 14,982
  • 3
  • 26
  • 59
  • Thanks! Any quick suggestion regarding how to increase the size of the NC area... which will have the effect of adding padding, which is important if this is to be a realistic solution. Of course, I'd want any increase of the size of the non-client area to actually easily display on the screen, without being clipped by any clipping area at any layer of the system. – Dan Nissenbaum Jul 27 '16 at 16:26
  • Thanks again - a couple more questions - Do you think there's any advantage to using `CBCGPEdit`, rather than `CEdit` directly? `OnNcPaint` (the `ON_WM_NCPAINT` handler) corresponds directly to `CEdit`, not to `CBCGPEdit`. Just from the API for `CBCGPEdit` I don't see the advantages - perhaps being able to use a custom `CBCGPVisualManager`? Thanks. – Dan Nissenbaum Jul 28 '16 at 01:47
  • ...And my second question - I actually just tested it, and it does seem the NC area is quite tiny. Do you happen to know how to expand it? – Dan Nissenbaum Jul 28 '16 at 01:48
  • No! You have to enlarge the window at all, than you can enlarge the NC area. The text must still fit. I see no adnavntag eto use CBCGEdit except it hass millions of features ;) Just changing the NC area can be done with any edit control. – xMRi Jul 28 '16 at 06:10
  • This solution does not, unfortunately, seem to work, because the EDIT control itself seems to usurp the drawing no matter what you do, and clip off the bottom and right non-client regions - with no possible way for the program to overcome this. Perhaps I am wrong, but this seems clearly to be occurring. – Dan Nissenbaum Jul 30 '16 at 02:34