[Lazarus] Custom draw menu

Sergei Gorelkin sergei_gorelkin at mail.ru
Sat Nov 6 03:09:33 CET 2010

Paul Ishenin пишет:
> 06.11.2010 0:59, Graeme Geldenhuys wrote:
>> VCL is a wrapper for Win API controls, and it supports
>> glyphs in menus - no custom drawing. So do MFC apps as far as I know.
> Why do you think VCL has no custom drawing? Did you study their code or 
> just think so? If the last then try the first.
In VCL, TMenuItem has OnDrawItem, OnMeasureItem and OnAdvancedDrawItem events (first one is somewhat 
deprecated in favour of the last one). A beautiful design, imagine assigning the same event handlers 
to each of 100+ menu items in a complex application.

As for the WinAPI, it indeed supports glyphs in menuitems, but the result is visually unusable in 
all Windows versions up to Vista. It simply does not insert margins anywhere, neither between 
adjacent menuitems nor between glyph and text in a single item. It was fixed in Vista+, but again 
for themed drawing only: switch the theming off and you get the same result as in Windows 95.

You typically don't see this ugliness in real life, because authors either use menus without glyphs 
or use custom drawing. All major GUI frameworks, including VCL and LCL, use their own drawing of 
menu items as well. And then they have to implement 'native look and feel' for all Windows versions:
- Windows 95
- Windows 98 (items in menubar are 'embossed', not painted with highlight color, remember that?)
- Windows 2000 (IIRC introduces a couple of new system colors for menus)
- Windows XP themed (XP doesnt't actually have built-in theme for menus, so it's 'flat' menus, 
mostly like Win95, but have to be painted in different colors to respect theme)
- Windows XP nonthemed (which one it resembles most, 95, 98 or 2000?)
- And finally comes Vista+ with a built-in theme which should be painted using completely different 


More information about the Lazarus mailing list