Hyperlisk Posted October 24, 2009 Share Posted October 24, 2009 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 Link to comment
Killboy Posted October 25, 2009 Share Posted October 25, 2009 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 :> Link to comment
atom0s Posted October 25, 2009 Share Posted October 25, 2009 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/ Link to comment
Hyperlisk Posted October 26, 2009 Author Share Posted October 26, 2009 Thanks for the help guys, I'll check it out. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now