|
-
September 12th, 2007, 12:29 AM
#16
Re: How to load & save irregular dialog to bitmap?
Ok. I found this:
http://www.flipcode.com/articles/art...n32skins.shtml
Idea is this. You don't do the UpdateLayeredWindow thing.
These are the steps:
- In LoadPNG(), you will now load the bitmap like below and save the m_hBitmap for later use like below:
Code:
void CPngTestDlg::LoadPNG()
{
//load background
TCHAR szCurrentPath [MAX_PATH];
strcpy (szCurrentPath, "res\\pngtest.png");
CT2W pszWCharString (szCurrentPath);
m_pBitmap = Gdiplus::Bitmap::FromFile(pszWCharString);
int nImageWidth = m_pBitmap->GetWidth();
int nImageHeight = m_pBitmap->GetHeight();
CDC dcScreen;
dcScreen.Attach(::GetDC(NULL));
m_hBitmap = CreateCompatibleBitmap(dcScreen.GetSafeHdc(),nImageWidth,nImageHeight);
CDC oMemDC;
oMemDC.CreateCompatibleDC(&dcScreen);
HBITMAP hOldBitmap = (HBITMAP)SelectObject(oMemDC.GetSafeHdc(),m_hBitmap);
Gdiplus::Graphics graphics(oMemDC.GetSafeHdc());
graphics.DrawImage(m_pBitmap, 0, 0, nImageWidth,nImageHeight);
SelectObject(oMemDC.GetSafeHdc(),hOldBitmap);
dcScreen.Detach();
.. see next step
}
- With this bitmap, what you now do is, scan it and create a region which has all pixels except the transparent color that you decide. This area will appear hollow. You can use this region to set the window region for the dialog like below..( the ScanRegion code is from that link in the beginning )
Code:
m_hDialogRgn = ScanRegion(m_hBitmap,GetRValue(m_crTransparentColor),GetGValue(m_crTransparentColor),GetBValue(m_crTransparentColor));
RECT oRect;
GetRgnBox(m_hDialogRgn,&oRect);
SetWindowPos(NULL,0,0,oRect.right - oRect.left,oRect.bottom - oRect.top, SWP_NOZORDER | SWP_NOMOVE | SWP_FRAMECHANGED);
::SetWindowRgn (GetSafeHwnd(), m_hDialogRgn, TRUE);
- Change the dialog style to have no border.
- Change your paint handler like below:
Code:
CPaintDC dc(this);
if(m_hBitmap)
{
CDC memDC;
memDC.CreateCompatibleDC(&dc);
HBITMAP hOldBitmap = (HBITMAP)SelectObject(memDC.GetSafeHdc(), m_hBitmap);
BITMAP bmpBmp;
GetObject(m_hBitmap, sizeof(bmpBmp),&bmpBmp);
dc.BitBlt(0,0,bmpBmp.bmWidth,bmpBmp.bmHeight,&memDC,0,0,SRCCOPY);
SelectObject(memDC.GetSafeHdc(), hOldBitmap);
}
-
October 1st, 2007, 08:34 PM
#17
Re: How to load & save irregular dialog to bitmap?
Hi Kirants,
(Sorry that I didn't see this post. I didn't see the >2 to continue to the next page.)
Question, this approach, is it supported for per-pixel alpha blending since one would have to define a transparent color.
THanks, sorry again,
Jiac
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|