5

I use Beyond Compare (a great program), and was very impressed when it displayed a "New Version Available" label on its Menu Bar. I clicked on it, up popped an install new version box, it installed, the program restarted itself and there was the new version and no more label.

I thought that was a great feature. The label is there prominently on the menu bar where the user can't miss it. I've already got the update procedure, so all I had to do was add the label. That should be easy.

Here's the label where I want it: The Label Where I Want It
(source: beholdgenealogy.com)

... Wrong. I couldn't figure out how to add a label there. The menu bar and the control area above it appear to be hands-off area for visual components. I couldn't place one there.

But I know it can be done, because Beyond Compare is a Delphi program.

Can anyone tell me what I have to do to put a TLabel in my Menu Bar or at least make it appear to be over the Menu Bar in the correct position?

For reference, I use Delphi 2009.


Conclusion: Christopher seems to have correctly figured out what the Beyond Compare people did. I've decided to implement the menu item, but without the customization of his "owner draw" solution. So I don't get the blue bold underline hyperlink look, but I also don't lose all the automatic things (like the Vista styling) that owner draw skips.

To space the menu item over to the right, I've added an item after the "Help" that has the caption " " and is disabled.

Thanks, Christopher. I was stuck thinking it must be a Label, but you saw around that.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
lkessler
  • 19,819
  • 36
  • 132
  • 203
  • 1
    Are you sure that Beyond Compare uses the native menu (TMainMenu). Maybe it's some third party menu (Toolbar2000, DevEx, ...). – Uli Gerhardt Nov 19 '09 at 06:28
  • Ulrich: I don't know what Beyond Compare uses. I only know it was developed with Delphi. – lkessler Nov 19 '09 at 06:31
  • 1
    If it´s made with delphi, it should be failrly easy to find what component is used by inspecting the resources. – Vegar Nov 19 '09 at 09:30
  • Good thinking. I should look at the components some other Delphi programs that I respect use. I might get some ideas from that. – lkessler Nov 19 '09 at 14:32
  • 1
    I use EDA/EN_DIS_ABLE (available at http://www.heise.de/software/download/enable_disable_en_dis_able/7279 or http://www.delphipraxis.net/topic166020,0,asc,0.html) if I'm curious. :-) – Uli Gerhardt Nov 19 '09 at 15:14

2 Answers2

13

Are you sure it's a label?

I haven't used the program, but it could just be a menu item, set to 'owner draw' and painted to look like a link?

http://sirmonkeys.com/images/updatelink.png
(done in Delphi 7)

procedure TForm1.MYITem1DrawItem(Sender: TObject; ACanvas: TCanvas;
  ARect: TRect; Selected: Boolean);
begin
  acanvas.Font.Style := [fsUnderline,fsbold];
  acanvas.Font.color := clblue;
  acanvas.Brush.Style := bsClear;
  acanvas.TextOut(arect.left+1,arect.top+1,'Link to Update...');
end;

procedure TForm1.MYITem1MeasureItem(Sender: TObject; ACanvas: TCanvas;
  var Width, Height: Integer);
begin
  width := 100;
end;

and then either a have an ImageList assigned to MainMenu1.Images or set MainMenu1.OwnerDraw to true.

Andreas Rejbrand
  • 105,602
  • 8
  • 282
  • 384
Christopher Chase
  • 2,840
  • 6
  • 36
  • 57
  • That might be possible. I'll try that. – lkessler Nov 19 '09 at 03:56
  • Now I'm sure you're right. Thanks. P.S., my accelerators (the underlines under the letters) vanished. But your example has them in. How do I get them back. I've already got the & as part of their caption. – lkessler Nov 19 '09 at 04:25
  • 1
    Accelerators appear automatically when you act like you're going to use the keyboard to activate the menu, which means pushing the Alt key. Christopher probably pressed Alt+PrntScr to make the image, so the accelerator indicators appeared. This has been the default Windows behavior for about 10 years now. If you want them visible all the time, adjust your display settings in the OS control panel. – Rob Kennedy Nov 19 '09 at 06:31
  • Christopher solution is a replica so exact that even reproduces the bug(?)feature(?) of erasing the menu background on the menu item display area. – PA. Nov 19 '09 at 13:04
  • @lkessler: You can't get the accelerators back unless the VCL bug which kills them is fixed (see your own question http://stackoverflow.com/questions/280247/menu-accelerator-keys-not-showing-up-delphi-2009). – mghie Nov 19 '09 at 14:33
  • PA: Actually, for the picture of my question, I cut and pasted the "New Version Available" onto the image of my program, which is why the background behind the words appears white. – lkessler Nov 19 '09 at 14:34
  • No this is a bit different because that bug only applied to submenus. But in this case, the accelerators were no longer on the main menu items when I went to OwnerDraw. None-the-less I decided not to use the OwnerDraw technique (see my conclusion on the question) – lkessler Nov 19 '09 at 14:45
  • @lkessler: It's not really a VCL bug, more of a failure to work around a Windows problem. I have edited my answer to your question with code to work around the issue. This should take care of this one as well, if you go with an owner drawn menu item. – mghie Nov 19 '09 at 15:16
2

Beyond Compare's implementation is actually a TLabel. We use Toolbar 2000 for our menus and toolbars, so embedding a control on the menu directly is supported (with a correct background), and it has the advantage that it supports right-justified menu items.

Zoë Peterson
  • 13,094
  • 2
  • 44
  • 64
  • Thanks, Craig. So it actually is a label then. You technically have the correct answer (using Toolbar 2000), but I've already implemented it as an uncolored menu item, so I'll leave the accepted answer with Christopher. Didn't know you were here at StackOverflow. Love your Beyond Compare. I use it for comparing my versions, updating my website, and doing my backups. – lkessler Dec 01 '09 at 08:45