Programatically setting a PNG to a Picture Control in Win32 APIs
c, winapi
Solution
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 needs a SS_BITMAP style. Don't forget to include gdiplus.h and its library. You need to initialize (GdiplusStartup) and shutdown GDI+. Freeing all system resources is on you.
Problem
I use Visual Studio 2008, I have the PNG file loaded in the Resource View, assigned it IDB_BANG_PNG. The Picture Control is called IDC_STATIC15. I am having trouble trying to get the PNG loaded into the picture 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 am rather naive when it comes to Win32/GUI development, doing a quick project and got stuck her, any help is appreciated.