CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 2009
    Posts
    1,355

    [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)

  2. #2
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    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).

  3. #3
    Join Date
    Apr 2009
    Posts
    1,355

    Resolved Re: [win32] - why the HBITMAP isn't showed transparent?

    Quote Originally Posted by OReubens View Post
    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?

  4. #4
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    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.

  5. #5
    Join Date
    Apr 2009
    Posts
    1,355

    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?

  6. #6
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    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.

  7. #7
    Join Date
    Apr 2009
    Posts
    1,355

    Re: [win32] - why the HBITMAP isn't showed transparent?

    Quote Originally Posted by OReubens View Post
    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
  •  





Click Here to Expand Forum to Full Width

Featured