Can't use a transparent BMP with MFC Button control - mfc

I am really confused here ...
I am trying to add a MFC Button control onto my dialog in the IDE.
I want it to just show a BMP file. I have another already on the dialog that shows with a transparent background.
This is the image for the good button:
This is the other button image I downloaded. But it is PNG:
I have tried to convert it so that it is 32 bit BMP so that it is transparent:
But it is failing. It shows with a black background:
You can see on that screenshot that the lower image shows OK. But not the new one. How do I fix this image file?
Update:
I used a different image in the end for the question mark. But for others I ended up using PNG and manually using the load method as outlined below:

Related

C++ displaying an image with SDL2 with different formats than .bmp

I am trying to display an image in SDL2 and the only guide I found was a guide about how to display a .bmp image. What I would like to do is displaying an image or setting a temporary image as a background. For example if I press LEFT_KEY the program should proceed to the next image. Any relevant guides or any examples you can share? It is not needed to set the image as a background (stretched), my goal is to display an image and being able to scroll through other images by pressing a key.
Use SDL_Image:
https://www.libsdl.org/projects/SDL_image/
Example:
Loading PNGs with SDL_image

Get window icon, put it on canvas, overlay image, save as ico (WinXP and Win7)

Right now I change the icon of a window with this code.
What I want to do though is get the current icon in use by a window. Then put it on a canvas. Then put another image on that (a badge) then save it as ico.
Never tried that, however the follow should work in general (with a lot of fiddling)
WM_GETICON to get the big and small icon.
Convert the icon to something the loader can understand (aka. either a BITMAP or ICO). E.g. How can I save HICON to an .ico file?
Load the image. E.g. Javascript: Render PNG stored as Uint8Array onto Canvas element without Data URI
canvas.drawImage
canvas.mozGetAsFile (Blob) or canvas.mozFetchAsStream (nsIInputStream) using the image/vnd.microsoft.icon mime.
Take the resulting data and reconstruct an icon.
LookupIconIdFromDirectoryEx and CreateIconFromResourceEx
WM_SETICON

how to change the background colour of CImage object in mfc?

I have an windows app which contains some dialogs. the dialogs have been built using mfc. I am drawing some images (.png) on every dialog using CImage::Draw() method. I want to mention that I am not using any picture contol on the dialog to render these images instead I am loading them at runtime using some handle.till this everything is ok. now when the image is loaded the background of those images are coming as white. the images in the resource file does not have the white background. my question is how to change the background of these images while drawing them on the dialog? I want the background of the image similar to the color of default dialog which i am using.
One more question the .png images are not rendering well(the images are scattered) in the dialogs of windows server 2008 R2 machine. what could be the possible remedy for this?
any help will be appreciated.
Your PNG images are obviously not 32-bit. You need an alpha channel and a transparent background. Open your images in e.g. Paint.NET. I bet your background is white there too! Regarding the image quality, are you stretching your images on draw?
Edit: For 8-bit imagers, I believe a call to SetTransparentColor is required. For 32-bit images, perhaps this function will do: TransparentBlt

win32 c++ owner draw button with transparent image

i've implemented a owner draw button into my win32 app (no MFC). The button is a normal 20x20 bitmap (round icon with transparency). The problem is that the button is positioned on a solid background and i can see the buttons gray background (since the bitmap is round). I've tried responding to WM_CTLCOLORBTN with NULL_BRUSH but no luck.. I've tried displaying the button using a bitmap and a ico file but wont budge.. Does anyone know how to solve this problem?
This is my problem, the settings icon should be transparent at the edges (not white/gray)
It sounds like you're trying to make a non-rectangular control.
You could call SetWindowRgn to tell Windows that your control is non-rectangular.
In addition to what #joel's answer, if you want to make some area transperant put a unique color in the area where you want to have transperancy using some image editors (RGB(0xFF,0x00,0xFF)) is mostly used Then use TransperantBlt
You say it's a solid background but your image shows some kind of orange-yellow gradient as a background. If it really was a standard windows button solid color you can load the bitmap with LoadImage using the LR_LOADMAP3DCOLORS or LR_LOADTRANSPARENT. Since you have a gradient you'll have to use a more complicated technique to mask out the bitmap.
http://www.winprog.org/tutorial/transparency.html

Why are disabled buttons using high depth colour in CToolBar are just grey boxes?

I've followed the steps from this question:
Higher color depth for MFC toolbar icons?
The code works. But I have another problem - any disabled buttons are just grey boxes.
Once they are enabled - they are exactly as they should be.
I suspect that the CToolBar doesn't know how to grey out the supplied images - can anyone help?
thanks in advance.
CToolBar actually accepts up to three imagelists each to handle the normal, disabled and highlighted states of the button.
To accomplish what I need - just normal and disabled button states. I need two images. One with normal coloured icons and the other with greyed out icons.
Add the images as Bitmap resources to your project - amend and make note of the IDs
Create two imagelists and set them accordingly: (m_wndToolBar is the toolbar in my project)
CImageList imgListActive;
CImageList imgListDisabled;
/* Load your CImageLists */
m_wndToolBar.GetToolBarCtrl().SetImageList(&imgListActive);
m_wndToolBar.GetToolBarCtrl().SetDisabledImageList(&imgListDisabled);
To set the highlighted versions of the toolbar:
CImageList imgListHighlighted;
/* Load your CImageList */
m_wndToolBar.GetToolBarCtrl().SetHotImageList(&imgListHighlighted);
et voila!
Usually two things are necessary to get the high color buttons and the correctly greyed out images:
Always edit the .bmp file for the toolbar outside of VisualStudio.
Add the images to MFC using a call to CMFCToolBar::AddToolBarForImageCollection(IDR_MAINFRAME); in your InitInstance() implementation.
Unfortunately this also means that you have to edit the Toolbar definition directly in the .rc resource file of the application.