Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi Transparente BMP mit SetMenuItemBitmaps (https://www.delphipraxis.net/111184-transparente-bmp-mit-setmenuitembitmaps.html)

bobo220673 31. Mär 2008 10:36


Transparente BMP mit SetMenuItemBitmaps
 
Hallo!
Ich habe ein kleines Problem mit SetMenuItemBitmaps. Es will einfach nicht klappen das die erzeugten Bilder Transparent sind.
Hier mein Code :

Delphi-Quellcode:
procedure TToolbar.ShowSearchMain(var Message: TMessage);
var
  pt: TPOINT;
  rect: TRect;
  hPopup: HMENU;
  BMP: TBitmap;
begin
  SendMessage(hToolbarMain, TB_GETITEMRECT, 3, LPARAM(@Rect));
  pt.x := Rect.Right;
  pt.y := Rect.Bottom - 1;
  Windows.ClientToScreen(hToolbarMain, pt);
  if pt.x < 0 then pt.x := 0;
  begin
    hPopup := CreatePopupMenu;
    bmp := TBitmap.Create;
    bmp.LoadFromResourceID(hinstance, 101);
    bmp.TransparentColor := rgb(255, 0, 255);
    bmp.Transparent := true;
    AppendMenu(hPopup, MF_STRING, IDM_SEARCH1, PChar('SUCHTYPE 1'));
    SetMenuItemBitmaps(hPopUp, 0, MF_BYPOSITION, Bmp.Handle, Bmp.Handle);
    AppendMenu(hPopup, MF_SEPARATOR, 0, '');
    AppendMenu(hPopup, MF_STRING, IDM_SEARCH2, PChar('SUCHTYPE 2'));
    TrackPopupMenu(hPopup, TPM_CENTERALIGN or TPM_LEFTBUTTON,
      pt.x, pt.y, 0, hToolbarMain, nil);
    DestroyMenu(hPopup);
  end;
end;
Habe schon alles versucht auch ein Umstellen auf pf24/32bit. Zum Testen habe ich auch versucht ein TForm mit einer Imagelist zu erstellen, wo ich dann per GetBitmap(0,bmp) auf das Bild zugreife. Aber auch kein Erfolg :wall:
Achso... Ich versuche das ganze unter Vista.
Wäre schön wenn mir da jemand weiterhelfen könnte

BeerBear 31. Mär 2008 15:27

Re: Transparente BMP mit SetMenuItemBitmaps
 
Mahlzeit!

Hat der transparente Hintergrund deines Bitmaps möglicherweise nicht die Farbe rgb(255,0,255) (Pink)?

Ich würde es testweise mal damit versuchen:
Delphi-Quellcode:
bmp.TransparentColor := bmp.Canvas.Pixels[0,0]
Sofern der linke obere Pixel des bmp zum transparenten Hintergrund gehört.

Gruß Bear

bobo220673 31. Mär 2008 15:39

Re: Transparente BMP mit SetMenuItemBitmaps
 
Hi!
Klappt auch nicht :(

Ich habe jetzt eine Notlösung gefunden, aber Perfekt ist die leider nicht weil das Bild nicht wirklich Transparent ist. Ausserdem geht das so nur mit 16 Farben

Delphi-Quellcode:
procedure TToolbar.ShowSearchMain(var Message: TMessage);
var
  pt: TPOINT;
  rect: TRect;
  hPopup: HMENU;
  hBitmap: THandle ;
  cm : array[0..3]of TColorMap;

begin
  SendMessage(hToolbarMain, TB_GETITEMRECT, 3, LPARAM(@Rect));
  pt.x := Rect.Right;
  pt.y := Rect.Bottom - 1;
  Windows.ClientToScreen(hToolbarMain, pt);
  if pt.x < 0 then pt.x := 0;
  begin
    hPopup := CreatePopupMenu;
    cm[0].cFrom := $00ff00ff;
    cm[0].cTo := GetSysColor(COLOR_3DFACE);
    hBitmap := CreateMappedBitmap( hInstance,101,0,@cm[0],length(cm));
    AppendMenu(hPopup, MF_STRING, IDM_SEARCH1, PChar('SUCHTYPE 1'));
    SetMenuItemBitmaps(hPopUp, 0, MF_BYPOSITION, hBitmap, hBitmap);
    AppendMenu(hPopup, MF_SEPARATOR, 0, '');
    AppendMenu(hPopup, MF_STRING, IDM_SEARCH2, PChar('SUCHTYPE 2'));
    TrackPopupMenu(hPopup, TPM_CENTERALIGN or TPM_LEFTBUTTON,
      pt.x, pt.y, 0, hToolbarMain, nil);
    DestroyMenu(hPopup);
  end;
end;


Alle Zeitangaben in WEZ +1. Es ist jetzt 23:15 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz