Create a CBitmap from Resources ID - c++

I need to fill a CImageList with a number of bitmaps which are stored in separate bmp files (rather than as a single bmp with numerous parts). I assume I need to create a CBitmap so I can call the Add method of CImageList. So how might one create a CBitmap object using only MFC Resource IDs?

You just need to use the method CBitmap::LoadBitmap.
You can either load the bitmap from the file or from resources.

Related

Do I need to keep the Bitmap object when using Bitmap.GetHBITMAP()?

When using Bitmap.GetHBITMAP(), do I need to keep (not delete) the Bitmap object, or does Bitmap.GetHBITMAP() creates a new HBITMAP and not just returns the one that the Bitmap object uses? (the documentation does not mention anything about this).

How to get an HBITMAP of one image from an array of images from a resource?

I have a resource that has an id ID_IMAGES which is a PNG file. This resource is an array of images, all the same size (16x16). I'm trying to figure out if it is possible to pull out any one of these images and generate an HBITMAP from it.
I've looked around on the net, but I cannot find any info. Perhaps I'm using the wrong keywords?
Have a look at CImage class. Its Load() method can load a stream of data. CImage supports PNG format. Basically, you load the image from your resource and then use its Detach() method to get your HBITMAP

HBItmap, bitmap cimage, and image

CBitmap can construct an image via CBitmap::fromhandle(hbitmap)
Cimage offers an attach method to do this, Bitmap also provides a FromHbitmap to attach hbitmap handle along with a defined pallete (I don't know what actually is a palette )
What other methods are available to interchange uses among them?

Create a BITMAPINFO from a JPG/PNG file in Windows C++

I have a function in an API I am using that request a BITMAPINFO pointer. I am suppose to give this function an image. My images are JPG/PNGs. Suppose I transform them to BMP files, I have still no clue on how to set up this struct. Is there a windows API that I can use for it?
You can use GDI+ for this.
Read BMP/JPG/PNG/GIF using Gdiplus::Bitmap::FromFile to load and Gdiplus::Bitmap::GetHBITMAP to access HBITMAP and then BITMAPINFO
A quick google turns up this MSDN article: Sizing a JPEG or PNG Image which show one way of filling a BITMAPINFO for a JPEG file (would work for PNG).
Use the links on the left of that page to get more information about the bitmap API.
PNGs have, potentially, AlphaChannel/transparency information -- which gets lost when converting to a bitmap. What does your function that requires BITMAPINFO actually do ?
If your approach is to transform the files to bitmaps; don't do that at runtime.
Convert the files using a paint program to bmp.
As previously mentioned, you can use GDI+ to make use of several different native formats;
but doing so will likely require converting your existing GDI calls to GDI+.

setting an HBITMAP object as desktop wallpaper

How do you set an HBITMAP object as the wallpaper? I am taking the screenshot of the desktop using BitBlt, so i have the screenshot as a HBITMAP object. Now i can save the object to a bmp file and the set it as wallpaper using SystemParametersInfo, SPI_SETDESKWALLPAPER.
But i am checking if there is a direct way to set the bitmap object as a wallpaper. Any API or something?
It needs to be an actual file (Think about reboots etc)
If you are trying to mimic UAC, this is not the way to do it. If you want to mimic UAC, just create a window the size of the screen and draw the bitmap there (To mimic the actual security feature, you should put this window and your "UAC dialog" on a separate desktop that does not allow hooks, the CreateDesktop() API should get you started)