MFC foundation - How to post a circular bitmap

zhaozj2021-02-11  260

MFC Basics - How to post a round bitmap If you have to do anything about chess, there are two beautiful pieces of pictures, but unfortunately two bitmaps are square, and there is background .. Delphi, just set the background color to transparent, how to remove the background with a round chess piece in the MFC? Example, // to invoke this function with the position bool isblack = true; // set the black stone defautly CBitMap m_bStoneB; CBitMap m_bStoneW; // load bmp from resource m_bStoneB.LoadBitmap (IDB_BLACKSTONE); m_bStoneW.LoadBitmap (IDB_WHITESTONE); void CxxDlg :: OnPutStone (CPoint point) {CDC * pDC = GetDC (); // Get Device Context CBitmap * pOldBitmap; CBrush * pOldBrush; CPen * pOldPen; if (pDC == NULL) return; CDC dcimage; if // Create MemDC return (dcimage.CreateCompatibleDC (pDC)!); CRect rect; // Get the rectangle RECT.EFT = POINT.X - 25/3; Rect.right = Point.x 25/3; Rect.top = Point.y - 25/3; Rect.Bottom = Point.y 25/3 ; if (IsBlack) // judge whether stone is black {// Select blackstone in memory and select out oldbitmap pOldBitmap = dcimage.SelectObject (& m_bStoneB); CBrush br (RGB (0, 0, 0)); // set brush to Black CPEN PEN (PS_SOLID, 1, RGB (0, 0, 0)); // set Pen to Black PoldPen = PDC-> SelectObject (& Pen); // select in pen (black) // and out oldpen polDbrush = PDC-> SelectObject (& br); // select in brush (black) PDC-> Ellipse (& Re); //// draw a ellipse in defined rectangle BITMAP bm; m_bStoneB.GetBitmap (& bm); // Get blackstone bitmap info // paint memory bitmap (blackstone) with the operator OR pDC-> StretchBlt (rect.left, rect.top, rect.Width . (), rect.Height (), & dcimage, 0,0, bm mWidth, bm.bmHeight, SRCPAINT);} else // the same to draw whitestone bitmap {// select in whitestone and select out blackstone pOldBitmap = dcimage. SelectObject (& M_Bstonew); CBRUSH BR (RGB (255, 255, 255)); // SET White Brush CPEN PEN (PS_SOLID, 1, RGB (255, 255, 255));

转载请注明原文地址:https://www.9cbs.com/read-4030.html

New Post(0)