Thread: transparentblt

  1. #1
    Registered User
    Join Date
    Dec 2005

    Cool transparentblt

    i just thought some would find this link useful

    When ever I use the Windows API function TransparentBlt my compiler tells me it is undefined. I have msimg32.lib in my linker list. Does any one know how to fix this?
    To fix this just find your windows.h file and after the first block of code that ends with end if put this:

    #ifndef WINVER
    #define WINVER 0x0501
    #if defined(_WIN32_WINNT) && (WINVER < 0x0400) && (_WIN32_WINNT > 0x0400)
    #error WINVER setting conflicts with _WIN32_WINNT setting
    is this any better than putting
    #define WINVER 0x0500
    #include <windows.h>

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    TransparentBlt is limited in that it does not support any size other than the original size of the image. Stretching and shrinking are not supported.

    The only way to do transparency in GDI with scaling support is to create a mask image from the original image. The mask image is then blitted used SRC_AND and the original image is blitted using SRC_PAINT.

    To create a mask:

    void CTileGDI::PrepareMask(void)
      //AfxMessageBox(L"Preparing mask");
      CMainFrame *pFrame=(CMainFrame *)AfxGetMainWnd();
      //AfxMessageBox(L"Creating DCs");
      CDC *pMaskDC=new CDC();
      CDC *pDC=new CDC();
      //AfxMessageBox(L"Creating mask");
      m_pMask=new CBitmap;
      //AfxMessageBox(L"Selecting objects into DCs");
      CBitmap *pPrevSource=(CBitmap *)pDC->SelectObject(m_pImage);
      CBitmap *pPrevMask=(CBitmap *)pMaskDC->SelectObject(m_pMask);
      // Change the background to trans color
      COLORREF clrSaveBk  = pDC->SetBkColor(pFrame->m_dlgNewProject->m_dwTrans);
      // This call sets up the mask bitmap.
      //AfxMessageBox(L"Doing bitblt for mask");
      pMaskDC->BitBlt(0,0,m_iTileW, m_iTileH, pDC,0,0,SRCCOPY);
      COLORREF clrSaveDstText = pDC->SetTextColor(RGB(255,255,255));
      pDC->BitBlt(0,0,m_iTileW, m_iTileW, pMaskDC,0,0,SRCAND);
      // Clean up by deselecting any objects, and delete the
      // DC's.
      //AfxMessageBox(L"Cleaning up");
      if (pPrevSource) pDC->SelectObject(pPrevSource);
      if (pPrevMask) pMaskDC->SelectObject(pPrevMask);
      delete pDC;
      delete pMaskDC;
    This is in part from code I found at and are good sites for MFC and Windows programming.
    Last edited by VirtualAce; 09-13-2006 at 01:40 AM.

  3. #3
    Join Date
    Jan 2002
    Quote Originally Posted by h_howee
    s this any better than putting?
    Using the windows headers should hopefully offer some insight into and clarification of this issue.

    >>This is in part from code I found at<<

    The original transparent blitting technique was first described in this old msdn knowledge base article which is probably the precursor of all subsequent examples. This revised version describes the method but more succinctly.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  4. #4
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    I got the idea from the old BASIC Put and Get doing the same thing but couldn't get it to work so I went with TransparentBlt. But I needed scaling support so did some searching on the net and after a couple of pages of google links finally found this.

    But yeah the article is on MSDN even though that one is a bit more confusing.

  5. #5
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    I think you should define 0x0501, not 0x0500, because the headers check, if the version is over 0x0500, but 0x0500 is not OVER 0x0500.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. TransparentBlt()
    By SniperSAS in forum Windows Programming
    Replies: 6
    Last Post: 03-03-2006, 11:17 PM
  2. TransparentBlt error
    By jmd15 in forum Windows Programming
    Replies: 3
    Last Post: 08-29-2005, 08:22 PM
  3. TransparentBlt
    By rEtard in forum Windows Programming
    Replies: 2
    Last Post: 04-13-2005, 04:00 AM
  4. TransparentBlt
    By Trauts in forum Windows Programming
    Replies: 2
    Last Post: 02-27-2003, 07:40 PM