-
January 23rd, 2015, 09:03 AM
#1
[win32] - why the HBITMAP isn't showed transparent?
i did these test with gif files. when i add the HBITMAP to menu item, the HBITMAP isn't showed transparent.. why?
(with another files, works fine)
-
January 26th, 2015, 08:11 AM
#2
Re: [win32] - why the HBITMAP isn't showed transparent?
Windows GDI doesn't do transparencies other than what you explicitely provide (color keying, masking, ...) for.
if you mean alpha transparencies, that only happens when using AlphaBlend() (as opposed to one of the BitBlt variants).
-
January 26th, 2015, 08:50 AM
#3
Re: [win32] - why the HBITMAP isn't showed transparent?
Originally Posted by OReubens
Windows GDI doesn't do transparencies other than what you explicitely provide (color keying, masking, ...) for.
if you mean alpha transparencies, that only happens when using AlphaBlend() (as opposed to one of the BitBlt variants).
please see these function that can give me(i have sure... i used with a button and works fine):
Code:
void DrawHBITMAPtoHDC(HBITMAP hBitmap, HDC hdc) //hdc is the destination
{
BITMAP bm;
HDC MemDCExercising = CreateCompatibleDC(hdc);
HBITMAP oldbitmap =(HBITMAP) SelectObject(MemDCExercising, hBitmap);
GetObject(hBitmap,sizeof(bm),&bm);
TransparentBlt(hdc, 0, 0, bm.bmWidth , bm.bmHeight, MemDCExercising, 0, 0,bm.bmWidth , bm.bmHeight,GetPixel(MemDCExercising,bm.bmWidth-1,bm.bmHeight-1) );
SelectObject(MemDCExercising,oldbitmap);
DeleteDC(MemDCExercising);
}
now see how i use it on menus:
Code:
void bitmap(image imgImage)//image is my class that give me the HBITMAP image... here no problem
{
BITMAP bm;
HDC MemDCExercising = CreateCompatibleDC((HDC)imgImage);
GetObject((HBITMAP) imgImage,sizeof(bm),&bm);
HBITMAP outbitmap=CreateBitmap(bm.bmWidth,bm.bmHeight,1,32,NULL);
HBITMAP oldbitmap =(HBITMAP) SelectObject(MemDCExercising, outbitmap);
DrawHBITMAPtoHDC((HBITMAP)imgImage,MemDCExercising);//copy the HBITAMP for HDC
HMENU hMenu = NULL;
if(primeiromenu)
hMenu = mnuBar;
else
hMenu = MenuHandle;
//if i use:
//SetMenuItemBitmaps(hMenu,ID,MF_BYCOMMAND,(HBITMAP)imgImage,(HBITMAP)imgImage);
//i see the image, but with a black backcolor, instead transparent :(
SetMenuItemBitmaps(hMenu,ID,MF_BYCOMMAND,(HBITMAP)outbitmap ,(HBITMAP)outbitmap);
SelectObject(MemDCExercising,oldbitmap);
DeleteDC(MemDCExercising);
}
why i get a fill rectangle with black color?
-
January 27th, 2015, 08:20 AM
#4
Re: [win32] - why the HBITMAP isn't showed transparent?
TransparentBlt does a colorkeying blit, that isn't exactly the same as "transparency" but ok, some people call it that... The important thing to note is that it is only "transparent" (keyed) on the actual Blt call and DOES NOT make the resulting bitmap transparent.
In your "menus" sample you aren't using TransparentBlt to paint to screen.
you're setting a bitmaphandle in the menu and the menu draws itself.
it doesn't work that way. See SetMenuItemBitmaps() on MSDN, both bitmaps should be monochrome.
if you want colored bitmaps as menu items 'checks', you need to ownerdraw the menu yourself.
Note that SetMenuItemBitmaps() does NOT determine the bitmap of the menu item (which does support color) but determines the 'checkbox' bitmap left of the menu tekst/bitmap for selectable/checkable menu items.
-
January 27th, 2015, 08:32 AM
#5
Re: [win32] - why the HBITMAP isn't showed transparent?
for the ownerdraw i need change the MENUITEMINFO structure... but let me ask 1 thing: on WM_OWNERDRAW message, i can draw the menu on what i want, inclued the bitmap. but i need ask: how can i show the menu in same way of the operation system?
-
January 28th, 2015, 12:43 PM
#6
Re: [win32] - why the HBITMAP isn't showed transparent?
define "the same way"...
Note that a lot of OS apps (like IE) do not use the normal windows Menu system but instead have their own drawn menu's.
-
January 28th, 2015, 12:54 PM
#7
Re: [win32] - why the HBITMAP isn't showed transparent?
Originally Posted by OReubens
define "the same way"...
Note that a lot of OS apps (like IE) do not use the normal windows Menu system but instead have their own drawn menu's.
my problem was with that rectangle:
Code:
HTHEME hTheme = OpenThemeData(hwndWindow, L"MENU");
RECT rc={5,5,100,50};
DrawThemeBackground(hTheme, hdcWindow, MENU_POPUPITEM, MBI_HOT, &rc, 0);
CloseThemeData(hTheme);
maybe now i can do the rest
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|