Autor Beitrag
TimonWorld
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 397



BeitragVerfasst: Sa 23.04.05 12:39 
Hallo!

Ich habe eine frage: Wie kriege ich ein Bild (/Icon) aus einer ImageList in ein TMenuItem hinein?

Ich arbeite mit Delphi 3 und da kann man noch nicht einmal mehr normale Bitmaps wie in Delphi 6 einfügen.

Aber ich hab schon gehört, dass das gehen soll.


Gruß,
Timon.
fvolk
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 203

Win XP (Home & Pro)
Delphi 2005 Pers
BeitragVerfasst: Sa 23.04.05 12:57 
Dem TMainMenu die TImageList-Komponenten zuweisen (such' nach einer Eigenschaft wie z.B. Images), dann kannst du für jeden Menüeintrag über ItemIndex bestimmen, welches Bild er bekommt (um kein Bild zu verwenden, -1 zuweisen).

_________________
Nichts auf der Welt ist so gerecht verteilt wie der Verstand. Denn jedermann ist überzeugt, dass er genug davon habe.
(René Descartes)
TimonWorld Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 397



BeitragVerfasst: Sa 23.04.05 13:06 
user profile iconfvolk hat folgendes geschrieben:
Dem TMainMenu die TImageList-Komponenten zuweisen (such' nach einer Eigenschaft wie z.B. Images), dann kannst du für jeden Menüeintrag über ItemIndex bestimmen, welches Bild er bekommt (um kein Bild zu verwenden, -1 zuweisen).


Ich benutze Delphi 3. Da gibt es die Eigenschaften Images und ImageIndex nicht (<-- Edit).

Gruß,
Timon.


Zuletzt bearbeitet von TimonWorld am Sa 23.04.05 13:22, insgesamt 1-mal bearbeitet
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Sa 23.04.05 13:14 
user profile iconTimonWorld hat folgendes geschrieben:

Ich benutze Delphi 3. Da gibt es die Eigenschaften Images und ImageIndex.

nicht, wolltest du noch dazu schreiben :mrgreen:. Da siehts schlecht aus, evtl mal bei Torry guggn. Ansonsten noch selberzeichnen, da D3 die Ereignisse auch noch nicht kennt, wirds wohl ganz schwierig.

Mfg Frank

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
TimonWorld Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 397



BeitragVerfasst: Sa 23.04.05 13:24 
user profile iconKeldorn hat folgendes geschrieben:
user profile iconTimonWorld hat folgendes geschrieben:

Ich benutze Delphi 3. Da gibt es die Eigenschaften Images und ImageIndex.

nicht, wolltest du noch dazu schreiben :mrgreen:. Da siehts schlecht aus, evtl mal bei Torry guggn. Ansonsten noch selberzeichnen, da D3 die Ereignisse auch noch nicht kennt, wirds wohl ganz schwierig.

Mfg Frank


Meinte ich ja... Schon geändert. Also Delphi kann Toolbar mit Imagelist aber leide kein MainMenu. Sollte ich die Glyphs über Canvas zeichen? Geht das nicht irgendwie über Windows, damit ich die ins Menü reinkriege?

Gruß,
Timon.
fvolk
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 203

Win XP (Home & Pro)
Delphi 2005 Pers
BeitragVerfasst: Sa 23.04.05 13:32 
Sorry, meine Delphi-3-Zeit liegt einiges zurück.

Aber ja: es gibt Windows-Botschaften, um Bilder in Menüs zu bekommen. Wenn du dir im MSDN die Funktion Suche im MSDN SETMENUITEMINFO ansieht, findest du einen Parameter lpmii von Typ Suche im MSDN MENUITEMINFO, in dem du ein Bild (HBITMAP hbmpItem) für den Menüeintrag festlegen kannst. Delphi 3 unterstützt das ganze von Haus aus nicht, weil Menügraphiken erst ab Windows 98 unterstützt werden.

_________________
Nichts auf der Welt ist so gerecht verteilt wie der Verstand. Denn jedermann ist überzeugt, dass er genug davon habe.
(René Descartes)
cartridge
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 209

Win XP
D4 Prof,D6 Prof
BeitragVerfasst: Sa 23.04.05 20:31 
Frage, da ich Delphi 3 nicht kenne: Du müsstest doch einen MenuItem selber zeichnen können (OwnerDraw) oder?
Wenn ja, musst Du nur das Bild aus der ImageList in den Menüpunkt zeichnen.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
procedure MenuDrawItem(Sender: TObject; ACanvas: TCanvas; ARect: TRect; Selected: Boolean);
begin
ImageList1.Draw(aCanvas,aRect.Left,aRect.Top,(Sender as MenuItem).Tag);
TextOut(Rect.left + 30, Rect.top + 2, (Sender as MenuItem).Caption);
end;


Gruß
Ingo

PS: Hab ich zwar nicht selber ausprobiert, müsste aber gehen!
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Sa 23.04.05 20:45 
nee, steht schon oben. D3 kennt noch kein Ondrawitem-ereignis.

Mfg Frank

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
fvolk
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 203

Win XP (Home & Pro)
Delphi 2005 Pers
BeitragVerfasst: So 24.04.05 08:32 
Warum so umständlich, mach's doch einfach mit Suche im MSDN SETMENUITEMINFO. (Wie oben beschrieben)

_________________
Nichts auf der Welt ist so gerecht verteilt wie der Verstand. Denn jedermann ist überzeugt, dass er genug davon habe.
(René Descartes)
TimonWorld Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 397



BeitragVerfasst: So 24.04.05 12:16 
Also SetMenuItemInfo benötigt den Typ TMenuItemInfoA:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
{* Aus windows.pas (D3 Prof, SP2) *}
  TMenuItemInfoA = packed record
    cbSize: UINT;
    fMask: UINT;
    fType: UINT;             { used if MIIM_TYPE}
    fState: UINT;            { used if MIIM_STATE}
    wID: UINT;               { used if MIIM_ID}
    hSubMenu: HMENU;         { used if MIIM_SUBMENU}
    hbmpChecked: HBITMAP;    { used if MIIM_CHECKMARKS}
    hbmpUnchecked: HBITMAP;  { used if MIIM_CHECKMARKS}
    dwItemData: DWORD;       { used if MIIM_DATA}
    dwTypeData: PAnsiChar;      { used if MIIM_TYPE}
    cch: UINT;               { used if MIIM_TYPE}
  end;

So jetzt weiß ich aber nicht was ich damit anfangen soll, und wie ich ein eigenes Bild aus einer ImageList in hbmpUnchecked einfüge. Ich habe von records eigentlich noch null Ahnung. Ich habe dafür diese Procedure aus der menus.pas noch gefunden:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
{* Aus menus.pas (D3 Prof, SP2) *}
procedure TMenuItem.AppendTo(Menu: HMENU);
const
  IBreaks: array[TMenuBreak] of Longint = (MFT_STRING, MFT_MENUBREAK, MFT_MENUBARBREAK);
  IChecks: array[Boolean] of Longint = (MFS_UNCHECKED, MFS_CHECKED);
  IDefaults: array[Boolean] of Longint = (0, MFS_DEFAULT);
  IEnables: array[Boolean] of Longint = (MFS_DISABLED or MFS_GRAYED, MFS_ENABLED);
  IRadios: array[Boolean] of Longint = (MFT_STRING, MFT_RADIOCHECK);
  ISeparators: array[Boolean] of Longint = (MFT_STRING, MFT_SEPARATOR);
var
  MenuItemInfo: TMenuItemInfo;
  Caption: string;
  NewFlags: Integer;
begin
  if FVisible then
  begin
    Caption := FCaption;
    if GetCount > 0 then MenuItemInfo.hSubMenu := GetHandle
    else if (FShortCut <> scNone) and ((Parent = nil) or
      (Parent.Parent <> nil) or not (Parent.Owner is TMainMenu)) then
      Caption := Caption + #9 + ShortCutToText(FShortCut);
    if Lo(GetVersion) >= 4 then
    begin
      MenuItemInfo.cbSize := SizeOf(TMenuItemInfo);
      MenuItemInfo.fMask := MIIM_CHECKMARKS or MIIM_DATA or MIIM_ID or
        MIIM_STATE or MIIM_SUBMENU or MIIM_TYPE;
      MenuItemInfo.fType := IRadios[FRadioItem] or IBreaks[FBreak] or
        ISeparators[FCaption = '-'];
      MenuItemInfo.fState := IChecks[FChecked] or IEnables[FEnabled]
        or IDefaults[FDefault];
      MenuItemInfo.wID := Command;
      MenuItemInfo.hSubMenu := 0;
      MenuItemInfo.hbmpChecked := 0;
      MenuItemInfo.hbmpUnchecked := 0;
      MenuItemInfo.dwTypeData := PChar(Caption);
      if GetCount > 0 then MenuITemInfo.hSubMenu := GetHandle;
      InsertMenuItem(Menu, -1, True, MenuItemInfo);
    end
    else
    begin
      NewFlags := Breaks[FBreak] or Checks[FChecked] or Enables[FEnabled] or
        Separators[FCaption = '-'] or MF_BYPOSITION;
      if GetCount > 0 then
        InsertMenu(Menu, -1, MF_POPUP or NewFlags, GetHandle,
          PChar(FCaption))
      else
        InsertMenu(Menu, -1, NewFlags, Command, PChar(Caption));
    end;
  end;
end;

Also, wie kriege ich jetzt Beispielsweise beim MenuItem NeueDatei1 das 2. Bild aus ImageList1 einfüge?

Gruß,
Timon.
fvolk
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 203

Win XP (Home & Pro)
Delphi 2005 Pers
BeitragVerfasst: So 24.04.05 13:14 
Du brauchst natürlich eine neuere Übersetzung der Windows-API (z.B. vom Projekt Jedi), die auch den erforderlichen Typen TMenuItemInfoA enthält, in dem der Eintrag hbmpItem vorhanden ist. Wie schon erwähnt kann Delphi 3 das nicht von Haus aus.

Wenn du also die neuen API-Übersetzungen verwendest, dann verfügt der Typ auch über hbmpItem, dem du die gewünschte Bitmap zuweisen kannst.

hbmpUnchecked hat mit der Graphik nicht viel zu tun (vgl. Dokumentation im MSDN: Suche im MSDN MENUITEMINFO), du musst hbmpItem verwenden.

_________________
Nichts auf der Welt ist so gerecht verteilt wie der Verstand. Denn jedermann ist überzeugt, dass er genug davon habe.
(René Descartes)