Click here to Skip to main content
16,017,852 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: GDI / GDI+ Pin
Mark Salsbery1-Jun-07 5:50
Mark Salsbery1-Jun-07 5:50 
GeneralRe: GDI / GDI+ Pin
Hamid_RT1-Jun-07 5:55
Hamid_RT1-Jun-07 5:55 
GeneralRe: GDI / GDI+ Pin
Adno1-Jun-07 6:30
Adno1-Jun-07 6:30 
GeneralRe: GDI / GDI+ Pin
Mark Salsbery1-Jun-07 6:48
Mark Salsbery1-Jun-07 6:48 
GeneralRe: GDI / GDI+ Pin
Adno1-Jun-07 7:06
Adno1-Jun-07 7:06 
GeneralRe: GDI / GDI+ Pin
Mark Salsbery1-Jun-07 7:25
Mark Salsbery1-Jun-07 7:25 
GeneralRe: GDI / GDI+ Pin
Adno1-Jun-07 7:48
Adno1-Jun-07 7:48 
GeneralRe: GDI / GDI+ [modified] Pin
Mark Salsbery1-Jun-07 9:01
Mark Salsbery1-Jun-07 9:01 
I "think" you may be able to use a 32-bit ARGB DIBsection - I put together this test just to
make sure the alpha channel stuff was working.

(My "hdc" would be your "dcMem" and you wouldn't want to delete it or un-select your alpha bitmap
like I have if you pass it to UpdateLayeredWindow())
Image TransparentSrcBitmap(L"clockbg.bmp");
 
LONG lImageWidth = TransparentSrcBitmap.GetWidth();
LONG lImageHeight = TransparentSrcBitmap.GetHeight();
WORD wBitsPerPixel = 32;
 
//LONG lBytesPerRow = (((lImageWidth * (long)wBitsPerPixel + 31L) & (~31L)) / 8L);
LONG lBytesPerRow = lImageWidth * 4;
 
BITMAPINFO bmi;
memset(&bmi, 0, sizeof(BITMAPINFO));
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = lImageWidth;
bmi.bmiHeader.biHeight = lImageHeight;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = wBitsPerPixel;
bmi.bmiHeader.biCompression = BI_RGB;
bmi.bmiHeader.biSizeImage = lBytesPerRow * lImageHeight;
//bmi.bmiHeader.biXPelsPerMeter = 0;
//bmi.bmiHeader.biYPelsPerMeter = 0;
//bmi.bmiHeader.biClrUsed = 0;
//bmi.bmiHeader.biClrImportant = 0;
 
HDC hdc = ::CreateCompatibleDC(0);
 
BYTE* pBitmapBits;
HBITMAP hBitmap = ::CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, (void**)&pBitmapBits, NULL, 0);
 
if (hBitmap)
{   
   memset(pBitmapBits, 0, bmi.bmiHeader.biSizeImage);
 
   HGDIOBJ hOldBitmap = ::SelectObject(hdc, hBitmap);
 
   Graphics DstGraphics(hdc);
   DstGraphics.DrawImage(&TransparentSrcBitmap, 0, 0, TransparentSrcBitmap.GetWidth(), TransparentSrcBitmap.GetHeight());
 
   //** Test - blt the memory dc to the screen to make sure alpha channel data carried over
   BLENDFUNCTION bf;
   bf.BlendOp = AC_SRC_OVER;
   bf.BlendFlags = 0;
   bf.SourceConstantAlpha = 0x7F; // Alpha multiplier applied overall - use 0xFF - 0x7F is a test
   bf.AlphaFormat = AC_SRC_ALPHA;
 
   HDC hClientDC = ::GetDC(*this);
   ::AlphaBlend(hClientDC, 50, 50, TransparentSrcBitmap.GetWidth(), TransparentSrcBitmap.GetHeight(),
                hdc, 0, 0, TransparentSrcBitmap.GetWidth(), TransparentSrcBitmap.GetHeight(), bf);
   ::ReleaseDC(*this, hClientDC);
   //** End Test 
 
   ::SelectObject(hdc, hOldBitmap);<code> //<-- Don't do this when using with UpdateLayeredWindow()</code>
 
   ::DeleteObject(hBitmap);<code> //<-- Don't do this when using with UpdateLayeredWindow()</code>
}
 
::DeleteDC(hdc); <code>//<-- Don't do this when using with UpdateLayeredWindow()</code>

Sorry about all the strange extra variables - I cut and paste from assorted working code to throw
together a test - saves some typing. Smile | :)


-- modified at 15:30 Friday 1st June, 2007

"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

GeneralRe: GDI / GDI+ Pin
Adno1-Jun-07 10:39
Adno1-Jun-07 10:39 
GeneralRe: GDI / GDI+ Pin
Mark Salsbery1-Jun-07 10:48
Mark Salsbery1-Jun-07 10:48 
GeneralRe: GDI / GDI+ Pin
Mark Salsbery1-Jun-07 10:50
Mark Salsbery1-Jun-07 10:50 
GeneralRe: GDI / GDI+ Pin
Adno1-Jun-07 10:52
Adno1-Jun-07 10:52 
GeneralRe: GDI / GDI+ Pin
Mark Salsbery1-Jun-07 11:06
Mark Salsbery1-Jun-07 11:06 
GeneralRe: GDI / GDI+ Pin
Mark Salsbery1-Jun-07 11:10
Mark Salsbery1-Jun-07 11:10 
GeneralRe: GDI / GDI+ Pin
Adno1-Jun-07 11:23
Adno1-Jun-07 11:23 
GeneralRe: GDI / GDI+ Pin
Mark Salsbery1-Jun-07 11:33
Mark Salsbery1-Jun-07 11:33 
GeneralRe: GDI / GDI+ Pin
Adno1-Jun-07 11:55
Adno1-Jun-07 11:55 
GeneralRe: GDI / GDI+ Pin
Mark Salsbery1-Jun-07 12:02
Mark Salsbery1-Jun-07 12:02 
QuestionHow to get GUID Pin
john56321-Jun-07 3:31
john56321-Jun-07 3:31 
AnswerRe: How to get GUID Pin
Roger Stoltz1-Jun-07 4:13
Roger Stoltz1-Jun-07 4:13 
AnswerRe: How to get GUID Pin
CPallini1-Jun-07 5:44
mveCPallini1-Jun-07 5:44 
QuestionRe: How to get GUID Pin
john56321-Jun-07 21:15
john56321-Jun-07 21:15 
AnswerRe: How to get GUID Pin
CPallini3-Jun-07 2:55
mveCPallini3-Jun-07 2:55 
QuestionCopy constructor Pin
Karismatic1-Jun-07 1:39
Karismatic1-Jun-07 1:39 
AnswerRe: Copy constructor Pin
Maximilien1-Jun-07 1:44
Maximilien1-Jun-07 1:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.