Jump to content
Tuts 4 You

PNG As Window/Region?


Hyperlisk

Recommended Posts

Posted

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... :sweat:

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

Posted

Here's a small C snippet using pnglib, pretty straight forward really:


#include <windows.h>
#include <commctrl.h>
#include "resource.h"
#include "pnglib.h"// Prototypes
INT_PTR CALLBACK Messagehandler(HWND, UINT, WPARAM, LPARAM);// Global vars
HINSTANCE 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 :>

Posted

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/

Posted

Thanks for the help guys, I'll check it out.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...