Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/VCL/Standard Controls/TMainMenu    [ Add a report in this area ]  
Report #:  86876   Status: Closed
Incorrect painting of hot item on menu using Vista/7 themes
Project:  Delphi Build #:  14.0.3593.25826
Version:    14.0 Submitted By:   David Heffernan
Report Type:  Minor failure / Design problem Date Reported:  8/3/2010 7:53:00 AM
Severity:    Commonly encountered problem Last Updated: 3/20/2012 2:24:39 AM
Platform:    32 Bit Internal Tracking #:   283714
Resolution: Retest (Resolution Comments) Resolved in Build: :
Duplicate of:  None
Voting and Rating
Overall Rating: No Ratings Yet
0.00 out of 5
Total Votes: None
Description
Recent versions of Delphi do a decent job of supporting the new style menus introduced in Vista.

However, there is a minor flaw in the way the menu highlight is drawn.  The code in Menus.pas draws the menu highlight after drawing the glyph.  This results in the menu highlight being blended over the top of the glyph.  In fact the opposite is what is required, namely the glyph being blended over the top of the menu highlight.

This can be seen, for example, in the RAD Studio IDE which clearly is built from the same flawed Delphi code.

The solution is trivial.  Just move the code which draws the menu highlight (the call to DrawThemeBackground with MPI_HOT parameter) before the code which draws the glyph.

Incidentally, you may be aware that Vista/7 themed menus can be obtained, with glyphs, without using owner draw code.  The trick is to set MenuItemInfo.hbmpItem to be a PARGB32 bitmap in TMenuItem.AppendTo.  This would, for me, be a much preferable approach to supported Vista/7 themed menus.  The advantage is that using system drawn menus makes your code more robust to future releases of Windows which may change things once again.  In addition, you get the system native code for greying out menu glyphs and thus making your app as native as possible.

Steps to Reproduce:
None
Workarounds
None.

Actually not strictly true.  I take Menu.pas as delivered with Delphi, fix the bug, and then include it in my project.  Because I am using static linking then the linker prefers my version of the Menus unit to the one supplied with Delphi.  So long as I don't change anything in the interface section of the unit, the linker is perfectly happy to link to my version.

Although I can work around this, it would be better to fix it in the code that you deliver!
Attachment
D2010MenuGlyphProblems.zip
Comments

Tomohiro Takahashi at 8/3/2010 6:25:09 PM -
Could you please attach sample project and some screenshots to reproduce/confirm your issue?

David Heffernan at 8/25/2010 9:04:09 AM -
Hi, I'm sorry for the delay, but I've been away on vacation.

I've added a simple project which illustrates the issue.  There are two versions of the project: one uses the version of Menus.pas supplied with Delphi and the other uses a version with a couple of modifications to deal with some of the issues I have encountered.  I think you should be able to see from the two apps what I'm referring to.

I've also included a couple of screenshots.  You will see that in the flawed version of the app the light blue highlight bar changes the glyph which is not ideal.  If you look at Windows apps which use system drawn menus rather then you will see that this issue does not arise.

Again, finding a way to allow us to use system drawn menus rather than owner drawn ones using the theme API would be the ideal solution.

David Heffernan at 11/24/2010 7:49:25 AM -
See also QC 89920

Server Response from: ETNACODE01