Click here to Skip to main content
15,908,111 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionvideo streaming help Pin
yyosefi7-Oct-05 10:56
yyosefi7-Oct-05 10:56 
QuestionHas anyone worked with VistaDB and VC7? Pin
WREY7-Oct-05 10:42
WREY7-Oct-05 10:42 
QuestionTransparentBlt Pin
sergbox27-Oct-05 10:04
sergbox27-Oct-05 10:04 
AnswerRe: TransparentBlt Pin
Chris Losinger7-Oct-05 10:08
professionalChris Losinger7-Oct-05 10:08 
GeneralRe: TransparentBlt Pin
sergbox27-Oct-05 10:14
sergbox27-Oct-05 10:14 
GeneralRe: TransparentBlt Pin
Chris Losinger7-Oct-05 10:17
professionalChris Losinger7-Oct-05 10:17 
GeneralRe: TransparentBlt Pin
sergbox27-Oct-05 10:28
sergbox27-Oct-05 10:28 
GeneralRe: TransparentBlt Pin
Ravi Bhavnani7-Oct-05 10:59
professionalRavi Bhavnani7-Oct-05 10:59 
Perhaps this will help?

<code>//
//  Purpose:
//    Copies a bitmap transparently onto the destination DC.
//    See http://www.codeguru.com/Cpp/G-M/bitmap/specialeffects/article.php/c1749/
//
//  Returns:
//    None
//</code>
void FooButton::TransparentBlt
  (HDC      hdcDest,            <code>// destination device context</code>
   int      nXDest,             <code>// x-coord of destination rectangle's upper-left corner</code>
   int      nYDest,             <code>// y-coord of destination rectangle's upper-left corner</code>
   int      nWidth,             <code>// width of destination rectangle</code>
   int      nHeight,            <code>// height of destination rectangle</code>
   HBITMAP  hBitmap,            <code>// source bitmap</code>
   int      nXSrc,              <code>// x-coord of source rectangle's upper-left corner</code>
   int      nYSrc,              <code>// y-coord of source rectangle's upper-left corner</code>
   COLORREF colorTransparent,   <code>// transparent color</code>
   HPALETTE hPal)               <code>// logical palette to be used with bitmap (may be NULL)</code>
{
  CDC dc, memDC, maskDC, tempDC;
  dc.Attach( hdcDest );
  maskDC.CreateCompatibleDC(&dc);
  CBitmap maskBitmap;
 
  <code>// These store return of SelectObject() calls</code>
  CBitmap* pOldMemBmp = NULL;
  CBitmap* pOldMaskBmp = NULL;
  HBITMAP hOldTempBmp = NULL;
 
  memDC.CreateCompatibleDC (&dc);
  tempDC.CreateCompatibleDC (&dc);
  CBitmap bmpImage;
  bmpImage.CreateCompatibleBitmap (&dc, nWidth, nHeight);
  pOldMemBmp = memDC.SelectObject (&bmpImage);
 
  <code>// Select and realize the palette</code>
  if (dc.GetDeviceCaps (RASTERCAPS) & RC_PALETTE && hPal) {
     ::SelectPalette( dc, hPal, FALSE );
     dc.RealizePalette();
     ::SelectPalette( memDC, hPal, FALSE );
  }
 
  hOldTempBmp = (HBITMAP) ::SelectObject (tempDC.m_hDC, hBitmap);
  memDC.BitBlt (0, 0, nWidth, nHeight, &tempDC, nXSrc, nYSrc, SRCCOPY);
 
  <code>// Create monochrome bitmap for the mask</code>
  maskBitmap.CreateBitmap (nWidth, nHeight, 1, 1, NULL);
  pOldMaskBmp = maskDC.SelectObject (&maskBitmap);
  memDC.SetBkColor (colorTransparent);
 
  <code>// Create the mask from the memory DC</code>
  maskDC.BitBlt (0, 0, nWidth, nHeight, &memDC, 0, 0, SRCCOPY);
 
  <code>// Set the background in memDC to black. Using SRCPAINT with black
  // and any other color results in the other color, thus making
  // black the transparent color</code>
  memDC.SetBkColor (RGB (0,0,0));
  memDC.SetTextColor (RGB (255,255,255));
  memDC.BitBlt (0, 0, nWidth, nHeight, &maskDC, 0, 0, SRCAND);
 
  <code>// Set the foreground to black. See comment above.</code>
  dc.SetBkColor (RGB (255,255,255));
  dc.SetTextColor (RGB (0,0,0));
  dc.BitBlt (nXDest, nYDest, nWidth, nHeight, &maskDC, 0, 0, SRCAND);
 
  <code>// Combine the foreground with the background</code>
  dc.BitBlt (nXDest, nYDest, nWidth, nHeight, &memDC, 0, 0, SRCPAINT);
 
  if (hOldTempBmp)
     ::SelectObject (tempDC.m_hDC, hOldTempBmp);
  if (pOldMaskBmp)
     maskDC.SelectObject (pOldMaskBmp);
  if (pOldMemBmp)
     memDC.SelectObject (pOldMemBmp);
 
  dc.Detach();
}
/ravi

My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com

GeneralRe: TransparentBlt Pin
John R. Shaw9-Oct-05 0:01
John R. Shaw9-Oct-05 0:01 
AnswerRe: TransparentBlt Pin
John R. Shaw9-Oct-05 0:15
John R. Shaw9-Oct-05 0:15 
GeneralRe: TransparentBlt Pin
sergbox210-Oct-05 3:49
sergbox210-Oct-05 3:49 
QuestionAn easy one Pin
Shay Harel7-Oct-05 9:59
Shay Harel7-Oct-05 9:59 
AnswerRe: An easy one Pin
Wes Aday7-Oct-05 10:29
professionalWes Aday7-Oct-05 10:29 
GeneralRe: An easy one Pin
Shay Harel7-Oct-05 10:36
Shay Harel7-Oct-05 10:36 
GeneralRe: An easy one Pin
John R. Shaw9-Oct-05 0:27
John R. Shaw9-Oct-05 0:27 
GeneralRe: An easy one Pin
Shay Harel9-Oct-05 12:57
Shay Harel9-Oct-05 12:57 
QuestionMFC v C++.Net Pin
Klempie7-Oct-05 9:41
Klempie7-Oct-05 9:41 
AnswerRe: MFC v C++.Net Pin
Chris Losinger7-Oct-05 10:05
professionalChris Losinger7-Oct-05 10:05 
AnswerRe: MFC v C++.Net Pin
Michael Dunn7-Oct-05 10:47
sitebuilderMichael Dunn7-Oct-05 10:47 
QuestionPrinter Banding Pin
MR MAB7-Oct-05 9:20
MR MAB7-Oct-05 9:20 
AnswerRe: Printer Banding Pin
Blake V. Miller7-Oct-05 14:35
Blake V. Miller7-Oct-05 14:35 
QuestionSave .Wav File Using this example Pin
REU7-Oct-05 8:47
REU7-Oct-05 8:47 
QuestionEnumerate File Mappings Pin
Chintoo7237-Oct-05 7:28
Chintoo7237-Oct-05 7:28 
QuestionImage Process Pin
7-Oct-05 6:41
suss7-Oct-05 6:41 
AnswerRe: Image Process Pin
Maximilien7-Oct-05 8:18
Maximilien7-Oct-05 8:18 

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.