Page 2 of 2 FirstFirst 12
Results 41 to 45 of 45

Thread: [RESOLVED] Unicode Menus

  1. #41

    Thread Starter
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    Re: [RESOLVED] Unicode Menus

    I thought of being clever, and tried changing the BG colour of the whole menu [Light Grey] and have the ImageBG be Same Colour, but it seems changing the colour only affects the Menu area and not the Icon Drawn area, very weird :/

    Any idea on applying the colour there too ?
    [attached image has an Orange BG for demo purposes]
    Name:  Menu.jpg
Views: 796
Size:  5.0 KB
    _____________________________________________________________________

    ----If this post has helped you. Please take time to Rate it.
    ----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.



  2. #42
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [RESOLVED] Unicode Menus

    On Vista+, a 32bpp premultiplied alpha bitmap can be used and should work well only if window is themed.

    For all other cases, the best solution is to draw the image yourself. With Comctl32's subclassing APIs, this may not be very painful any longer. If that idea seems like exploring, search forum for subclassing keyword: SetWindowSubclass. Now you'll need to let Windows know you want to draw the bitmap. The SetMenuItemInfo API would be called for each menuitem you want to custom draw the image. With the associated MenuItemInfo structure, you would set the fMask to MIIM_BITMAP and the hbmpItem member to -1. Per MSDN, doing this requires you to trap 2 messages which would give you the info needed to render the image. See those two msdn links for more info.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #43
    Fanatic Member DrUnicode's Avatar
    Join Date
    Mar 2008
    Location
    Natal, Brazil
    Posts
    631

    Re: [RESOLVED] Unicode Menus

    32bpp bitmaps with transparency work OK via LoadPicture.
    However, LoadResPicture on the same image loses the transparency.
    You can store the Bitmap as "Custom" resource, use LoadResData, and use IStream to avoid using a temp file.

    Tested with Themes enabled (Vb6.exe with Manifest).

    Sample code attached.


    Name:  Menu32bpp.png
Views: 767
Size:  59.9 KB
    Attached Files Attached Files
    Last edited by DrUnicode; Oct 21st, 2014 at 11:09 PM.

  4. #44

    Thread Starter
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    Re: [RESOLVED] Unicode Menus

    On Vista+, a 32bpp premultiplied alpha bitmap can be used and should work well only if window is themed.
    So, even this version has it's limits? WinXP Machine + Themed Windows.
    BTW, any straight way on converting PNGs to 32bpp Bitmaps? It seems in Photoshop i need to create a new ALPHA Channel every time.
    _____________________________________________________________________

    ----If this post has helped you. Please take time to Rate it.
    ----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.



  5. #45
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [RESOLVED] Unicode Menus

    straight way of converting png to 32bpp? 3rd party tools?
    edited: The important thing here is that the bmp be stored as premultiplied rgb components else image used with SetMenuItemInfo or SetMenuItemBitmaps won't work right

    In VB one method would look like this, using GDI+
    1) Start GDI+ of course
    2) Load png into GDI+ image
    3) Create a GDI (not GDI+) 32bpp DIB section same target size of destination bmp (say 16x16 for example)
    4) Create an offscreen device context & select DIB section into it
    5) Use GDI+ to render the GDI+ image, scaled as needed, to the GDI hDC
    6) Clean up: destroy GDI+ image & shut GDI+ down. Unselect DIB, destroy DC, save DIB to disk & destroy DIB

    The reason why we want GDI+ to render the PNG to DIB section is that when GDI+ sees a 32bpp GDI target DC/image, it premultiplies the rgb components in relation to the alpha. That's what these APIs on Vista+ are looking for.

    Note: Even the old SetMenuItemBitmaps works with these premultiplied bitmaps on Vista
    Code:
    AppendMenu hMenu, MF_STRING, 110, "Some Menu Item"
    
        hbmp = LoadImage(0, "c:\testimages\mnubmp.bmp", 0, 32, 32, LR_CREATEDIBSECTION Or LR_LOADFROMFILE)
        SetMenuItemBitmaps hMenu, 110, 0, hbmp, hbmp
    
    ' after menu is closed: DeleteObject hBmp
    The 6 steps I listed above are an outline. There are several GDI/GDI+ related calls in between those steps.

    It may be overkill for what you want, but you could play with my AlphaImage Control (linked in my signature below). That project would do it all for you in a few steps as shown below. If you're looking for something to quickly convert png to 32bpp premultiplied bitmaps, then think it'd take you 15 minutes to whip up a simple: "Select Png File, Convert, Save To Destination" type of project, so it can be used over & over again as needed.

    1) Add new alpha image control to a form
    2) Add a command button & this code in the Click event
    3) Ensure form's project is the startup project. Run project & click button
    Code:
        Dim SS As SAVESTRUCT
        Set AlphaImgCtl1.Picture = LoadPictureGDIplus("myMenuImage.png")
        SS.ColorDepth = lvicConvert_TrueColor32bpp_pARGB
        SS.Height = 32: SS.Width = 32   ' << change as desired or remove line if saving original size
        SavePictureGDIplus AlphaImgCtl1.Picture, "C:\testimages\mnuBmp.bmp", lvicSaveAsBitmap
    Last edited by LaVolpe; Oct 22nd, 2014 at 07:52 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

Page 2 of 2 FirstFirst 12

Tags for this Thread

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