| Home | About Us | Support | Link |
SSControll Class
VC++ > code >Translate copy (2000.1.6)

ありきたりな、マスク処理による透過処理


  HDC pDC = GetDC(m_hWnd);
  COLORREF T_COLOR=RGB(255,0,255);
  HBITMAP wBMP;
  HDC wDC = CreateCompatibleDC(NULL);
  wBMP=(HBITMAP)LoadBitmap(GetModuleHandle(NULL),MAKEINTRESOURCE(IDB_BITMAP2));
  HBITMAP oldBMP = (HBITMAP)SelectObject(wDC,wBMP);
  BITMAP bm;
  GetObject(wBMP,sizeof(BITMAP),&bm);

  HBITMAP MskBMP= CreateBitmap(bm.bmWidth,bm.bmHeight,1,1,NULL);
  HDC MskDC = CreateCompatibleDC(NULL);
  HBITMAP oldBMP2 = (HBITMAP)SelectObject(MskDC,MskBMP);
  
  SetBkColor(MskDC,T_COLOR);
  SetBkColor(wDC,T_COLOR);

  BitBlt(MskDC,0,0,bm.bmWidth,bm.bmHeight,wDC,0,0,SRCCOPY);  //マスクへ転送

  SetBkColor(wDC,RGB(0,0,0));
  SetTextColor(wDC,RGB(255,255,255));      //カラーを白に
  BitBlt(wDC,0,0,bm.bmWidth,bm.bmHeight,MskDC,0,0,SRCAND);  //マスクをソースへ

  SetBkColor(pDC,RGB(255,255,255));    //背景色に白
  SetTextColor(pDC,RGB(0,0,0));      //カラーを黒に
  
  BitBlt(pDC,sx,sy,bm.bmWidth,bm.bmHeight,MskDC,0,0,SRCAND);  //MemDCにマスクDCを転送
  BitBlt(pDC,sx,sy,bm.bmWidth,bm.bmHeight,wDC,0,0,SRCPAINT);  //MemDCに展開画像を転送
  SelectObject(wDC, oldBMP);
  SelectObject(MskDC, oldBMP2);        //選択の解除
  DeleteObject(wBMP);
  DeleteObject(MskBMP);            //始末
  DeleteDC(wDC);
  DeleteDC(MskDC);
  ReleaseDC(m_hWnd, pDC);


[Back]