Results 1 to 6 of 6

Thread: SetMenuItemBitmaps ...LR_CREATEDIBSECTION (Transparent Background)

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2013
    Posts
    554

    SetMenuItemBitmaps ...LR_CREATEDIBSECTION (Transparent Background)

    Code:
    sFile = "C:\Temp\MyBMP.bmp"
    hDib = LoadImage(0, sFile, IMAGE_BITMAP, 16, 16, LR_LOADFROMFILE Or LR_CREATEDIBSECTION)
    Call SetMenuItemBitmaps(hMenu, 1, MF_BYPOSITION, hDib, hDib)
    Hi,

    Trying to add a bitmap to a menu item with the above code . The bitmap is added successfully BUT the background is not transparent... It has a white background.

    According to the docs, when passing the LR_CREATEDIBSECTION flag to the LoadImage function, the resulting image background should be transparent.

    Is this issue due to the bmp resolution ? pixels per inch.

    Am I understanding this correctly ?

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Posts
    22,728

    Re: SetMenuItemBitmaps ...LR_CREATEDIBSECTION (Transparent Background)

    Menu rendering does not alphablend those bitmaps.

    If you want to use color bitmaps you will have to simulate this. Typically you need to create a memory DC, select a color Bitmap into it, paint the background in the COLOR_MENU color, then blend your image on top of that. Then fetch that painted Bitmap to assign to the Menu item.

    Example here uses icon source images, but the details are similar:

    https://www.vbforums.com/showthread....=1#post5010883

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2013
    Posts
    554

    Re: SetMenuItemBitmaps ...LR_CREATEDIBSECTION (Transparent Background)

    Quote Originally Posted by dilettante View Post
    Menu rendering does not alphablend those bitmaps.

    If you want to use color bitmaps you will have to simulate this. Typically you need to create a memory DC, select a color Bitmap into it, paint the background in the COLOR_MENU color, then blend your image on top of that. Then fetch that painted Bitmap to assign to the Menu item.

    Example here uses icon source images, but the details are similar:

    https://www.vbforums.com/showthread....=1#post5010883

    Thanks.

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2013
    Posts
    554

    Re: SetMenuItemBitmaps ...LR_CREATEDIBSECTION (Transparent Background)

    paint the background in the COLOR_MENU color, then blend your image on top of that
    How will I paint the background ?
    Will I need to create a temp memory bitmap for that and then use AlphaBlend to blend the 2 bitmaps ?

    Thanks.

  5. #5
    PowerPoster
    Join Date
    Feb 2006
    Posts
    22,728

    Re: SetMenuItemBitmaps ...LR_CREATEDIBSECTION (Transparent Background)

    Probably. Unless somebody can offer an alternative.

  6. #6
    Hyperactive Member
    Join Date
    Dec 2008
    Location
    Argentina
    Posts
    326

    Re: SetMenuItemBitmaps ...LR_CREATEDIBSECTION (Transparent Background)

    Why don't you use A 32 BIT DIB with alpha channel?
    leandroascierto.com Visual Basic 6 projects

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