Posted October 24, 200915 yr Hi, I was wondering if anyone has any code they could share that demonstrates how to use a png image as a window. I have no idea where to start... I assume Either GDI+ or pnglib, but that's about it... But yeah... If anyone has anything they can share, I would be delighted to look at it. Hopefully in C/C++ or MASM, but I'm sure anything will be fine if I can adapt it. Thanks, Hyperlisk
October 25, 200915 yr Here's a small C snippet using pnglib, pretty straight forward really:#include <windows.h>#include <commctrl.h>#include "resource.h"#include "pnglib.h"// PrototypesINT_PTR CALLBACK Messagehandler(HWND, UINT, WPARAM, LPARAM);// Global varsHINSTANCE Instance;PNGINFO PNGMain;HBITMAP BmpMain;BITMAP BmpDimensions;// ---int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow){ Instance = hInstance; InitCommonControls(); DialogBox(Instance, MAKEINTRESOURCE(IDD_MAIN), 0, &Messagehandler); ExitProcess(NULL);}INT_PTR CALLBACK Messagehandler(HWND Window, UINT Message, WPARAM wParam, LPARAM lParam){ switch(Message) { case WM_INITDIALOG: // Load background png PNG_Init(&PNGMain); PNG_LoadResource(&PNGMain, Instance, MAKEINTRESOURCE(PNG_MAIN)); PNG_Decode(&PNGMain); BmpMain = PNG_CreateBitmap(&PNGMain, Window, PNG_OUTF_AUTO, false); GetObject(BmpMain, sizeof(BmpDimensions), &BmpDimensions); break; case WM_PAINT: PAINTSTRUCT ps; HDC hdc, hdcMem; hdc = BeginPaint(Window, &ps); hdcMem = CreateCompatibleDC(hdc); SelectObject(hdcMem, BmpMain); BitBlt(hdc, 0, 0, BmpDimensions.bmWidth, BmpDimensions.bmHeight, hdcMem, 0, 0, SRCCOPY); DeleteDC(hdcMem); EndPaint(Window, &ps); break; case WM_CLOSE: EndDialog(Window, 0); break; case WM_DESTROY: DeleteObject(BmpMain); PNG_Cleanup(&PNGMain); break; default: return false; } return true;}I removed some stuff to make it a more basic example, there might be an error two, haven't run it through a compiler :>
October 25, 200915 yr My lib patchLib does this as well if you want to take a look at it's code to see how I did it. You can find it here:/>http://wiccaan.gamedeception.net/patchLib/
Create an account or sign in to comment