Jump to content
Tuts 4 You

[solved] using transparent png as window like uPPP (c++)


alaphate

Recommended Posts

I created a simple oval png and used it as the frame window of my application.

I noticed that some patch used pnglib and UpdateLayeredWindow to realize regioned

and transparent window.

Any buddy could fix my code? Thanks a lot.

Here's the main code:


//UpdateLayeredWindow using Visual Studio 2003 above
//or VC6 with upgraded SDK, tools->options->directories
//set include path of newer SDK
case WM_CREATE:
PNG_Init(&g_pnginfo);
PNG_LoadResource(&g_pnginfo, g_hInst, MAKEINTRESOURCE(IDR_PNG_FRAME));
PNG_Decode(&g_pnginfo);
g_bmpHandle = PNG_CreateBitmap(&g_pnginfo, hwnd, PNG_OUTF_AUTO, false);
PremultipliedAlpha(g_bmpHandle);
return 0;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);hdcMem = CreateCompatibleDC(hdc);
SelectObject(hdcMem, g_bmpHandle);
BitBlt(hdc, 0, 0, g_pngWidth, g_pngHeight, hdcMem, 0, 0, SRCCOPY);
SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED);
UpdateLayeredWindow(hwnd, hdc, 0, 0, hdcMem, 0, 0, &bf, ULW_ALPHA);
DeleteDC(hdcMem);EndPaint(hwnd, &ps);
return 0;
case WM_RBUTTONDOWN:
case WM_DESTROY:
PNG_Cleanup(&g_pnginfo);
PostQuitMessage(0);
return 0;

Attachment is the full source cpp and exe file.

pngAsWindow.zip

Edited by alaphate
Link to comment

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