Solved

Graphics in popup-menus

Posted on 1997-11-11
5
170 Views
Last Modified: 2010-04-04
I want to be able to make a menu like the Start-menu on
Windows 95 / Win NT (with a vertical bitmap thing).
Is there any component around that does this or if not can
I get a hint about how to do this?
0
Comment
Question by:mortenmo
  • 3
  • 2
5 Comments
 
LVL 3

Expert Comment

by:Pegasus100397
Comment Utility
hehehehe 50 points for bitmapped menu items? With 3 screens of code to re-type here? hehehehe
0
 
LVL 3

Accepted Solution

by:
Pegasus100397 earned 100 total points
Comment Utility
ok, I'll bite:

unit radmenuu;

interface

uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics,
  Controls, Forms, Dialogs, Menus, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    Justification1: TMenuItem;
    Left1: TMenuItem;
    Right1: TMenuItem;
    Center1: TMenuItem;
    Memo1: TMemo;
    Dummy1: TMenuItem;
    N1: TMenuItem;
    N2: TMenuItem;
    Dummy2: TMenuItem;
    procedure FormCreate(Sender: TObject);
    procedure JustClick(Sender: TObject);
  private
    { Private declarations }
    bmCheck, bmUncheck: TBitmap;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}
FUNCTION MakeCheckBmp(C: Char): TBitmap;
VAR
  L : LongInt;
  R : TRect;
BEGIN
  L := GetMenuCheckMarkDimensions;
  Result := TBitmap.Create;
  WITH Result DO
    BEGIN
      Width  := LoWord(L);
      Height := HiWord(L);
      Canvas.FillRect(Rect(0, 0, Width, Height));
      Canvas.Font.Name := 'WingDings';
      Canvas.Font.Size := 10;
      R := Rect(0, 0, Width, Height);
      DrawText(Canvas.Handle, @C, 1, R, DT_CENTER OR DT_VCENTER);
    END;
END;

procedure TForm1.FormCreate(Sender: TObject);
VAR N : Integer;
begin
  bmCheck   := MakeCheckBmp('l'); {try 'n'}
  bmUncheck := MakeCheckBmp('m'); {try 'o'}
  Justification1.Items[2].Checked := True;
  FOR N := 2 TO 4 DO
    SetMenuItemBitmaps(Justification1.Handle, N, MF_BYPOSITION,
      bmUncheck.Handle, bmCheck.Handle);
end;

procedure TForm1.JustClick(Sender: TObject);
VAR N : Integer;
begin
  Memo1.Alignment := TAlignment((Sender AS TMenuItem).Tag);
  {don't set Checked property, else lose bitmaps in 16-bit}
  WITH Justification1 DO
    FOR N := 2 TO 4 DO
      IF Items[N] = Sender THEN
        CheckMenuItem(Handle, N, MF_BYPOSITION OR MF_CHECKED)
      ELSE CheckMenuItem(Handle,N,MF_BYPOSITION OR MF_UNCHECKED);
end;

end.
0
 
LVL 1

Author Comment

by:mortenmo
Comment Utility
Maybe I didn't get how the menuitems were setup, but it didn't
work exactly as I ment. Why do you start on MenuItem 2? There
must be something I'm missing here. Can you explain how the
menu is build up?

I've increased the points, maybe 50 were a bit low yes I've never
used this before.

0
 
LVL 3

Expert Comment

by:Pegasus100397
Comment Utility
The code doesn't really reflect the correct ordering of the menu items. In order (from top to bottom) is
Dummy1
Left
Right
Center
Dummy2

I start on menu item 2 because the first item is a "dummy" menu item with no bitmap. MakeCheckBmp simply creates a bitmap to use with the menu item. Give me your email address and I can zip the entire sample and send it so you can see how it works.

What version of Delphi are you using?
0
 
LVL 1

Author Comment

by:mortenmo
Comment Utility
I'm using Delphi 3. My address is morten@nvg.ntnu.no ;)
Thanks a lot

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now