Results 1 to 31 of 31

Thread: Menu item Bitmap Back (Mask) color

  1. #1

    Thread Starter
    Addicted Member beic's Avatar
    Join Date
    Jun 2012
    Posts
    176

    Question Menu item Bitmap Back (Mask) color

    Hi there,

    How could I change the Bitmap Back (Mask) color from Magenta to vbButtonFace (or "Transparent") in the Sub menu of the Menu bar?

    I have a 16x16 256 color BMP image loaded into Picture1 (Scale Mode - Pixel)

    Name:  vb6_menu_image.png
Views: 239
Size:  4.6 KB

    Code:
    Option Explicit
    
    Private Const MF_BYPOSITION = &H400&
    
    Private Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
    Private Declare Function SetMenuItemBitmaps Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long, ByVal hBitmapUnchecked As Long, ByVal hBitmapChecked As Long) As Long
    
    Private Sub Form_Load()
     
     Dim hMenu As Long
     Dim hSubMenuFile As Long
     Dim hBitmap As Long
    
     hMenu = GetMenu(Me.hwnd)
     hSubMenuFile = GetSubMenu(hMenu, 0)
     
     hBitmap = Picture1.Picture.Handle
     
     SetMenuItemBitmaps hSubMenuFile, 0, MF_BYPOSITION, hBitmap, hBitmap
        
    End Sub
    Is there a simple in-line solution?

    Thanks!

  2. #2

  3. #3

    Thread Starter
    Addicted Member beic's Avatar
    Join Date
    Jun 2012
    Posts
    176

    Re: Menu item Bitmap Back (Mask) color

    Quote Originally Posted by VanGoghGaming View Post
    Why don't you edit the bitmap in Paint and color it whatever you want?
    Because the Background color of the Menu item differs in OS's e.g.: Windows 7, 8, 10, 11 (they are not the same color).

  4. #4
    Addicted Member Mongoose_MHS's Avatar
    Join Date
    May 2024
    Posts
    187

    Re: Menu item Bitmap Back (Mask) color

    Post the image and i'll fix it for you as I did for the roulette thread..

    here is an example.. But again, upload your image Or feel free to use mine.
    Attached Images Attached Images  
    Last edited by Mongoose_MHS; May 16th, 2024 at 09:30 AM.
    Monroe High School.. GO HORNETS!

    If I've help you, please add to my reputation level! Each reply has a "STAR" icon followed by: "Rate this post".. click that

  5. #5

    Thread Starter
    Addicted Member beic's Avatar
    Join Date
    Jun 2012
    Posts
    176

    Re: Menu item Bitmap Back (Mask) color

    Quote Originally Posted by Mongoose_MHS View Post
    Post the image and i'll fix it for you as I did for the roulette thread..

    here is an example.. But again, upload your image Or feel free to use mine.
    Name:  Project3.bmp
Views: 255
Size:  822 Bytes

  6. #6
    Addicted Member Mongoose_MHS's Avatar
    Join Date
    May 2024
    Posts
    187

    Re: Menu item Bitmap Back (Mask) color

    yer image was blured and chunky.. but i tried to clean it up.. Here you go.. Maybe re-create the image?
    Attached Images Attached Images  
    Monroe High School.. GO HORNETS!

    If I've help you, please add to my reputation level! Each reply has a "STAR" icon followed by: "Rate this post".. click that

  7. #7

    Thread Starter
    Addicted Member beic's Avatar
    Join Date
    Jun 2012
    Posts
    176

    Re: Menu item Bitmap Back (Mask) color

    Quote Originally Posted by Mongoose_MHS View Post
    yer image was blured and chunky.. but i tried to clean it up.. Here you go.. Maybe re-create the image?
    Yes, but I can only load BMP in 256 color.

  8. #8
    Addicted Member Mongoose_MHS's Avatar
    Join Date
    May 2024
    Posts
    187

    Re: Menu item Bitmap Back (Mask) color

    Well, the only other way would be to have the bgcolor of the menu cause transparency cannot be done with .BMP

    Here you go..
    Attached Images Attached Images  
    Monroe High School.. GO HORNETS!

    If I've help you, please add to my reputation level! Each reply has a "STAR" icon followed by: "Rate this post".. click that

  9. #9

    Thread Starter
    Addicted Member beic's Avatar
    Join Date
    Jun 2012
    Posts
    176

    Re: Menu item Bitmap Back (Mask) color

    Quote Originally Posted by Mongoose_MHS View Post
    Well, the only other way would be to have the bgcolor of the menu cause transparency cannot be done with .BMP

    Here you go..
    That's why I asked, is there a way to do it by GetPixel, SetPixel or TransparentBlt on the fly.

  10. #10
    Addicted Member Mongoose_MHS's Avatar
    Join Date
    May 2024
    Posts
    187

    Re: Menu item Bitmap Back (Mask) color

    I have never used any of those, so I cannot answer that direct question. The way I do it is design the image and with paint and if i want an exact color I take a screen shot of what I want and take a little piece and paste into the other image and fill what I want with that color.. There is other ways I do it, but that sums it up for a small image as yours. Then if I want a transparent image, then I open Jasc paint Shop Pro and make whatever colors I want transparent and save it as a .PNG

    Anyways, I hope I was able to help you.
    Last edited by Mongoose_MHS; May 16th, 2024 at 11:22 AM.
    Monroe High School.. GO HORNETS!

    If I've help you, please add to my reputation level! Each reply has a "STAR" icon followed by: "Rate this post".. click that

  11. #11

    Thread Starter
    Addicted Member beic's Avatar
    Join Date
    Jun 2012
    Posts
    176

    Re: Menu item Bitmap Back (Mask) color

    Quote Originally Posted by Mongoose_MHS View Post
    I have never used any of those, so I cannot answer that direct question. The way I do it is design the image and with paint and if i want an exact color I take a screen shot of what I want and take a little piece and paste into the other image and fill what I want with that color.. There is other ways I do it, but that sums it up for a small image as yours. Then if I want a transparent image, then I open Jasc paint Shop Pro and make whatever colors I want transparent and save it as a .PNG

    Anyways, I hope I was able to help you.
    I already tried similar approach but is not working how it should.

    Attachment 191665

  12. #12
    Addicted Member Mongoose_MHS's Avatar
    Join Date
    May 2024
    Posts
    187

    Re: Menu item Bitmap Back (Mask) color

    1.) Invalid attachment - go to "Advanced" and upload the image
    2.) Maybe use the image I first provided OR use another image? Try using 24bit instead of 256 as there is only 2 colors in your design OR just use a built in icon like the "Checkmark" OR the image i am proving down below
    3.) You could also upload your project and I can try a little more to help you with the image

    I think you're over thinking it and making it harder on yourself with this specific image..
    Attached Images Attached Images  
    Last edited by Mongoose_MHS; May 16th, 2024 at 01:10 PM.
    Monroe High School.. GO HORNETS!

    If I've help you, please add to my reputation level! Each reply has a "STAR" icon followed by: "Rate this post".. click that

  13. #13

    Thread Starter
    Addicted Member beic's Avatar
    Join Date
    Jun 2012
    Posts
    176

    Re: Menu item Bitmap Back (Mask) color

    Quote Originally Posted by Mongoose_MHS View Post
    1.) Invalid attachment - go to "Advanced" and upload the image
    2.) Maybe use the image I first provided OR use another image? Try using 24bit instead of 256 as there is only 2 colors in your design OR just use a built in icon like the "Checkmark" OR the image i am proving down below
    3.) You could also upload your project and I can try a little more to help you with the image

    I think you're over thinking it and making it harder on yourself with this specific image..
    Name:  vb6_menu_image_2.png
Views: 198
Size:  4.3 KB

  14. #14
    Addicted Member Mongoose_MHS's Avatar
    Join Date
    May 2024
    Posts
    187

    Re: Menu item Bitmap Back (Mask) color

    ok, view this: and look at posts 18-21

    https://www.vbforums.com/showthread....VED-Menu-Icons
    Last edited by Mongoose_MHS; May 16th, 2024 at 01:22 PM.
    Monroe High School.. GO HORNETS!

    If I've help you, please add to my reputation level! Each reply has a "STAR" icon followed by: "Rate this post".. click that

  15. #15

    Thread Starter
    Addicted Member beic's Avatar
    Join Date
    Jun 2012
    Posts
    176

    Re: Menu item Bitmap Back (Mask) color

    I was loading the image from the ImageBox not from PictureBox, that was my first mistake.

    Now it's working, but have a square around the menu icon.

  16. #16
    Addicted Member Mongoose_MHS's Avatar
    Join Date
    May 2024
    Posts
    187

    Re: Menu item Bitmap Back (Mask) color

    again, the last link i gave you may explain that in posts 18-21

    Try it on another PC.. The results may be better.. as per those posts OR change your PC settings

    I honestly think I helped as much as I could.. Good luck
    Last edited by Mongoose_MHS; May 16th, 2024 at 01:27 PM.
    Monroe High School.. GO HORNETS!

    If I've help you, please add to my reputation level! Each reply has a "STAR" icon followed by: "Rate this post".. click that

  17. #17
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,476

    Re: Menu item Bitmap Back (Mask) color

    Take a look at this thread, maybe it does what you want.

  18. #18

    Thread Starter
    Addicted Member beic's Avatar
    Join Date
    Jun 2012
    Posts
    176

    Re: Menu item Bitmap Back (Mask) color

    Quote Originally Posted by Eduardo- View Post
    Take a look at this thread, maybe it does what you want.
    Yes, yes, that's it, but it's an overkill for my needs! And thank you for the link!

  19. #19

    Thread Starter
    Addicted Member beic's Avatar
    Join Date
    Jun 2012
    Posts
    176

    Re: Menu item Bitmap Back (Mask) color

    Quote Originally Posted by Mongoose_MHS View Post
    again, the last link i gave you may explain that in posts 18-21

    Try it on another PC.. The results may be better.. as per those posts OR change your PC settings

    I honestly think I helped as much as I could.. Good luck
    You basically helped me a lot, thanks!

    Now I just need to decide what standard back color should I use, current is RGB(240, 240, 240).

    How I see Windows 11 uses RGB(249, 249, 249) for the menu, maybe I would need to use something between, like RGB(245, 245, 245)?, however RGB(240, 240, 240) quite good looking, now there is the part if someone uses different Windows Style!

    The default style matches for Windows 7, 8, 10 (tested in VirtualBox).
    Last edited by beic; May 17th, 2024 at 03:48 PM.

  20. #20
    Addicted Member Mongoose_MHS's Avatar
    Join Date
    May 2024
    Posts
    187

    Re: Menu item Bitmap Back (Mask) color

    YW, All I can say is use a color picker.. The best one I found is "COLOR CODER", the code is free somewhere but I do not know the link but has been mention on here before.. Since uploading a zip with a .EXE is against the rules I can't upload it.. However I can make a zip and give you a link to the zip in a PM.. If i helped you, please add to my reputation as I just learned about that on here.

    Someone on here definately knows the app or the link to it.. You can also just get the bg backcolor from a form's bgcolor.. no need for a color picker at all
    Attached Images Attached Images  
    Last edited by Mongoose_MHS; May 17th, 2024 at 05:59 PM.
    Monroe High School.. GO HORNETS!

    If I've help you, please add to my reputation level! Each reply has a "STAR" icon followed by: "Rate this post".. click that

  21. #21
    Addicted Member Mongoose_MHS's Avatar
    Join Date
    May 2024
    Posts
    187

    Re: Menu item Bitmap Back (Mask) color

    Personally, I think there should be a "Tool Section" on here and that is one that definately needs to be on it.. However, that's just MY opinion. They don't want to or can't change anything on here as I can see.. I've seen a lot of suggesstions on here but none implimented. I may be new on here, but I do some searching on here.
    Last edited by Mongoose_MHS; May 17th, 2024 at 06:32 PM. Reason: spelling
    Monroe High School.. GO HORNETS!

    If I've help you, please add to my reputation level! Each reply has a "STAR" icon followed by: "Rate this post".. click that

  22. #22

    Thread Starter
    Addicted Member beic's Avatar
    Join Date
    Jun 2012
    Posts
    176

    Re: Menu item Bitmap Back (Mask) color

    Quote Originally Posted by Mongoose_MHS View Post
    YW, All I can say is use a color picker.. The best one I found is "COLOR CODER", the code is free somewhere but I do not know the link but has been mention on here before.. Since uploading a zip with a .EXE is against the rules I can't upload it.. However I can make a zip and give you a link to the zip in a PM.. If i helped you, please add to my reputation as I just learned about that on here.

    Someone on here definately knows the app or the link to it.. You can also just get the bg backcolor from a form's bgcolor.. no need for a color picker at all
    Would be nice, but cant send you PM for some reason, if you can upload it somewhere and share the link here. Thanks!

  23. #23
    Addicted Member Mongoose_MHS's Avatar
    Join Date
    May 2024
    Posts
    187

    Re: Menu item Bitmap Back (Mask) color

    I cannot post the link in the forum as it is against the rules, but I have sent you the link in a PM as YOU REQUESTED it..


    *I did find the actual source code to it.. but you don't need that.. Just the actual app so that's what I gave you that you requested.
    Last edited by Mongoose_MHS; May 18th, 2024 at 03:23 PM.
    Monroe High School.. GO HORNETS!

    If I've help you, please add to my reputation level! Each reply has a "STAR" icon followed by: "Rate this post".. click that

  24. #24

    Thread Starter
    Addicted Member beic's Avatar
    Join Date
    Jun 2012
    Posts
    176

    Re: Menu item Bitmap Back (Mask) color

    Quote Originally Posted by Mongoose_MHS View Post
    I cannot post the link in the forum as it is against the rules, but I have sent you the link in a PM as YOU REQUESTED it..


    *I did find the actual source code to it.. but you don't need that.. Just the actual app so that's what I gave you that you requested.
    Thanks, I got it, is it VB source? because I would add a Manifest to it to be nicer!

  25. #25
    Addicted Member Mongoose_MHS's Avatar
    Join Date
    May 2024
    Posts
    187

    Re: Menu item Bitmap Back (Mask) color

    yes it is a vb source code.. but again, I think you just need the app as it does have the VBHEX code for the color choices you need and want with capture color.. Work on yer own project with the tools one provides you, nevermind enhancing something else that works perfectly fine is my opinon. Finish 1 project before starting another, that's how one gets lost and overwhelmed.. I think you have enough issues working on YOUR own project than focus on someone else's work.. Stay focused on YOUR project goals.

    Their app is finished and works perfectly fine as is.. Does yours? No, so.. Finish yer own project before trying to "enhance" theirs.. get the point? You asked asked for help on YOUR project.. So, finish yours first. I'm not trying to be rude but rather straight to the point basically.
    Last edited by Mongoose_MHS; May 18th, 2024 at 08:54 PM.
    Monroe High School.. GO HORNETS!

    If I've help you, please add to my reputation level! Each reply has a "STAR" icon followed by: "Rate this post".. click that

  26. #26
    Fanatic Member BenJones's Avatar
    Join Date
    Mar 2010
    Location
    Wales UK
    Posts
    813

    Re: Menu item Bitmap Back (Mask) color


  27. #27

    Thread Starter
    Addicted Member beic's Avatar
    Join Date
    Jun 2012
    Posts
    176

    Re: Menu item Bitmap Back (Mask) color

    Thanks for that, but I'm seeking for simpler solution "if there is", without SubClassing or GDI+

  28. #28
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,109

    Re: Menu item Bitmap Back (Mask) color

    You'd better use transparent PNG images or ico resources, and then you can add different colors to them in memory to output new images.

  29. #29

    Thread Starter
    Addicted Member beic's Avatar
    Join Date
    Jun 2012
    Posts
    176

    Re: Menu item Bitmap Back (Mask) color

    Quote Originally Posted by xiaoyao View Post
    You'd better use transparent PNG images or ico resources, and then you can add different colors to them in memory to output new images.
    I know how to implement PNG and ICO files into the resource file, but how could I change the colors on the fly?

  30. #30
    Fanatic Member BenJones's Avatar
    Join Date
    Mar 2010
    Location
    Wales UK
    Posts
    813

    Re: Menu item Bitmap Back (Mask) color

    I always used to use TransparentBlt and it worked fine I used to use the pixel background color as 255,0,255, I tryed setting your original image to transpaent in a image editor and noticed there was still a little pink around the image. have you tryed a gif file. or what else you chould do it look at the first pixel and replace all that color with button face but I duno why TransparentBlt won't work. I wish I still has VB6 I know use C# so I can only guess I don't think my old VB6 will install anymore.

  31. #31

    Thread Starter
    Addicted Member beic's Avatar
    Join Date
    Jun 2012
    Posts
    176

    Re: Menu item Bitmap Back (Mask) color

    Quote Originally Posted by BenJones View Post
    I always used to use TransparentBlt and it worked fine I used to use the pixel background color as 255,0,255, I tryed setting your original image to transpaent in a image editor and noticed there was still a little pink around the image. have you tryed a gif file. or what else you chould do it look at the first pixel and replace all that color with button face but I duno why TransparentBlt won't work. I wish I still has VB6 I know use C# so I can only guess I don't think my old VB6 will install anymore.
    I did try something like this, but for some reason it wont change nothing:
    Code:
    Private Declare Function TransparentBlt Lib "msimg32.dll" ( _
        ByVal hdcDest As Long, _
        ByVal nXOriginDest As Long, _
        ByVal nYOriginDest As Long, _
        ByVal nWidthDest As Long, _
        ByVal nHeightDest As Long, _
        ByVal hdcSrc As Long, _
        ByVal nXOriginSrc As Long, _
        ByVal nYOriginSrc As Long, _
        ByVal nWidthSrc As Long, _
        ByVal nHeightSrc As Long, _
        ByVal crTransparent As Long) As Long
    
    Private Declare Function CreateCompatibleDC Lib "gdi32.dll" (ByVal hdc As Long) As Long
    Private Declare Function DeleteDC Lib "gdi32.dll" (ByVal hdc As Long) As Long
    Private Declare Function SelectObject Lib "gdi32.dll" (ByVal hdc As Long, ByVal hObject As Long) As Long
    
    Private Sub SetTransparentBackground(picBox As PictureBox, transparentColor As Long)
        Dim hdcDest As Long
        Dim hdcSrc As Long
        Dim bmpWidth As Long
        Dim bmpHeight As Long
        
        ' Get the device context (DC) of the destination PictureBox
        hdcDest = picBox.hdc
    
        ' Create a memory DC for the source bitmap
        hdcSrc = CreateCompatibleDC(hdcDest)
    
        ' Select the bitmap into the memory DC
        Dim hOldBmp As Long
        hOldBmp = SelectObject(hdcSrc, picBox.Picture.Handle)
    
        ' Get the dimensions of the bitmap
        bmpWidth = picBox.ScaleWidth
        bmpHeight = picBox.ScaleHeight
    
        ' Perform the transparent blit
        TransparentBlt hdcDest, 0, 0, bmpWidth, bmpHeight, _
                       hdcSrc, 0, 0, bmpWidth, bmpHeight, transparentColor
    
        
        ' Clean up
        SelectObject hdcSrc, hOldBmp
        DeleteDC hdcSrc
    End Sub
    Also I tried to change the background color with "BitBlt", but again I got an empty Picturebox.

    I just got from Windows 7 to 10 and it's working almost fine.

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