Click here to Skip to main content
15,922,696 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: a vector question Pin
Jeffrey Walton1-Apr-04 12:42
Jeffrey Walton1-Apr-04 12:42 
GeneralRegular Expressions - e-mail validation Pin
BlackDice1-Apr-04 9:27
BlackDice1-Apr-04 9:27 
GeneralRe: Regular Expressions - e-mail validation Pin
David Crow1-Apr-04 9:45
David Crow1-Apr-04 9:45 
GeneralRe: Regular Expressions - e-mail validation Pin
BlackDice1-Apr-04 10:14
BlackDice1-Apr-04 10:14 
GeneralCreating a DLL Pin
schnee2k31-Apr-04 9:25
schnee2k31-Apr-04 9:25 
GeneralRe: Creating a DLL Pin
Alexander M.,1-Apr-04 22:59
Alexander M.,1-Apr-04 22:59 
GeneralDrawing a transparent bitmap Pin
the one dono1-Apr-04 9:10
the one dono1-Apr-04 9:10 
GeneralRe: Drawing a transparent bitmap Pin
Ravi Bhavnani1-Apr-04 9:44
professionalRavi Bhavnani1-Apr-04 9:44 
//
//  Purpose:
//    Copies a bitmap transparently onto the destination DC.
//
//  Returns:
//    None
//
void FooButton::TransparentBlt
  (HDC      hdcDest,            // destination device context
   int      nXDest,             // x-coord of destination rectangle's upper-left corner
   int      nYDest,             // y-coord of destination rectangle's upper-left corner
   int      nWidth,             // width of destination rectangle
   int      nHeight,            // height of destination rectangle
   HBITMAP  hBitmap,            // source bitmap
   int      nXSrc,              // x-coord of source rectangle's upper-left corner
   int      nYSrc,              // y-coord of source rectangle's upper-left corner
   COLORREF colorTransparent,   // transparent color
   HPALETTE hPal)               // logical palette to be used with bitmap (may be NULL)
{
  CDC dc, memDC, maskDC, tempDC;
  dc.Attach( hdcDest );
  maskDC.CreateCompatibleDC(&dc);
  CBitmap maskBitmap;
 
  // These store return of SelectObject() calls
  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);
 
  // Select and realize the palette
  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);
 
  // Create monochrome bitmap for the mask
  maskBitmap.CreateBitmap (nWidth, nHeight, 1, 1, NULL);
  pOldMaskBmp = maskDC.SelectObject (&maskBitmap);
  memDC.SetBkColor (colorTransparent);
 
  // Create the mask from the memory DC
  maskDC.BitBlt (0, 0, nWidth, nHeight, &memDC, 0, 0, SRCCOPY);
 
  // 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
  memDC.SetBkColor (RGB (0,0,0));
  memDC.SetTextColor (RGB (255,255,255));
  memDC.BitBlt (0, 0, nWidth, nHeight, &maskDC, 0, 0, SRCAND);
 
  // Set the foreground to black. See comment above.
  dc.SetBkColor (RGB (255,255,255));
  dc.SetTextColor (RGB (0,0,0));
  dc.BitBlt (nXDest, nYDest, nWidth, nHeight, &maskDC, 0, 0, SRCAND);
 
  // Combine the foreground with the background
  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 | Articles | Freeware | Music
ravib@ravib.com

GeneralRe: Drawing a transparent bitmap Pin
John R. Shaw1-Apr-04 9:51
John R. Shaw1-Apr-04 9:51 
GeneralCFormView without dyncreate Pin
Adam Preble1-Apr-04 9:05
Adam Preble1-Apr-04 9:05 
GeneralAccess violations Pin
packetlos1-Apr-04 8:20
packetlos1-Apr-04 8:20 
GeneralRe: Access violations Pin
David Crow1-Apr-04 8:52
David Crow1-Apr-04 8:52 
GeneralRe: Access violations Pin
packetlos1-Apr-04 12:24
packetlos1-Apr-04 12:24 
GeneralRe: Access violations Pin
Neville Franks1-Apr-04 20:42
Neville Franks1-Apr-04 20:42 
GeneralThe riight question Pin
doctorpi1-Apr-04 7:59
doctorpi1-Apr-04 7:59 
GeneralRe: The riight question Pin
David Crow1-Apr-04 8:56
David Crow1-Apr-04 8:56 
GeneralRe: The riight question Pin
John R. Shaw1-Apr-04 12:35
John R. Shaw1-Apr-04 12:35 
GeneralRe: The right question Pin
Jeffrey Walton1-Apr-04 12:49
Jeffrey Walton1-Apr-04 12:49 
GeneralRe: The riight question Pin
gUrM33T1-Apr-04 16:34
gUrM33T1-Apr-04 16:34 
GeneralRe: The riight question Pin
doctorpi1-Apr-04 20:47
doctorpi1-Apr-04 20:47 
GeneralRe: The riight question Pin
doctorpi1-Apr-04 20:56
doctorpi1-Apr-04 20:56 
GeneralRe: Installer Package Problems Pin
mjmcinto1-Apr-04 7:53
mjmcinto1-Apr-04 7:53 
GeneralSoftware protection Pin
Wes Aday1-Apr-04 7:41
professionalWes Aday1-Apr-04 7:41 
GeneralRe: Software protection Pin
grigsoft1-Apr-04 8:27
grigsoft1-Apr-04 8:27 
GeneralRe: Software protection Pin
Wes Aday1-Apr-04 9:54
professionalWes Aday1-Apr-04 9:54 

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.