PNG programmatic setting for snapshot management in Win32 API

I am using Visual Studio 2008, I have a PNG file loaded into the resource view assigned to it by IDB_BANG_PNG.

Image management is called IDC_STATIC15.

I am having trouble trying to load a PNG into an image control.

LRESULT CALLBACK DialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { // Way of loading a bmp with a mask perhaps? Or a PNG file programatically? static HBRUSH hBrushStatic; HBITMAP hBmp = LoadBitmap(hDlg,MAKEINTRESOURCE(IDB_BANG_PNG)); switch(message) { case WM_INITDIALOG: CheckDlgButton(hDlg, IDC_CHECK, FALSE); EnableWindow(GetDlgItem(hDlg, IDOK), FALSE); // Bitmap version is IDB_BANG, PNG is at IDB_BANG_PNG // IDC_STATIC15 is the picture frame HWND item = GetDlgItem(hDlg,IDC_STATIC15); SendMessage(item,STM_SETIMAGE,IMAGE_BITMAP,(LPARAM)hBmp); return TRUE; // .... snip 

I'm a little naive when it comes to developing Win32 / GUI, doing a quick project and sticking it on, any help is appreciated.

+6
c winapi
source share
4 answers

This works using GDI + and the bitmap class :

 Bitmap oBmp(L"D:\\test.png"); HBITMAP hBmp; oBmp.GetHBITMAP(0, &hBmp); SendMessage(item,STM_SETIMAGE,IMAGE_BITMAP,(LPARAM)hBmp); 

Some caveats. Your control requires the SS_BITMAP style. Remember to include gdiplus.h and its library. You need to initialize (GdiplusStartup) and complete GDI +. Release all system resources from you.

+4
source share

I don’t think that LoadBitmap or any other simple GDI function (like LoadImage ) will load PNG.

You can save your resource to 32-bit BMP using the image editing tool, and then use LoadImage with LR_CREATEDIBSECTION .

Or you can use a library that will load a PNG file into a DIBSECTION. GDI + will load PNG and JPG in addition to BMP.

The OLE automation libraries also have an IPicture interface that you can create with various types of images and then get the basic DIBSECTION. This is inconvenient to use, especially if you are not familiar with COM. See OleLoadPicture for a starting point.

+2
source share

Personally, I use the CPictureEx class. I think it does not support png, but bmp, jpeg and animated gif.

I also use Cairo for custom rendering. Cairo supports png format.
Of course, Cairo is a little harder to use.

0
source share

Have you checked the DevIL / OpenIL library? It follows the name OpenGL for function naming and is written in good ol C.

I have used in the past, successfully. It is also very portable.

Take a look here: http://openil.sourceforge.net/features.php

0
source share

All Articles