CPen* PenOld,PenNew; CBrush* BrushOld,BrushNew; //选用库存黑色画笔 PenOld = (CPen*)pDC->SelectStockObject(BLACK_PEN); //选用库存浅灰色画刷 BrushOld = (CBrush*)pDC->SelectStockObject(LTGRAY_BRUSH); pDC->Rectangle(100,100,300,300); //关联GDI 库存对象 PenNew.CreateStockObject(WHITE_PEN); pDC->SelectObject(&PenNew); pDC->MoveTo(100,100); pDC->LineTo(300,300); pDC->MoveTo(100,300); pDC->LineTo(300,100); //恢复系统默认的GDI对象 pDC->SelectObject(PenOld); pDC->SelectObject(BrushOld); PenNew.DeleteObject(); //创建有一个实心的画刷 CBrush* brush = new CBrush; brush->CreateSolidBrush(RGB(255,0,0)); pDC->SelectObject(brush); pDC->Rectangle(400,400,500,500); //创建阴影画刷 CBrush BrushOl; BrushOl.CreateHatchBrush(HS_BDIAGONAL,RGB(0,0,255)); pDC->SelectObject(&BrushOl); pDC->Rectangle(200,400,300,500); //创建位图刷函数 CBrush BrushBit; CBitmap Bitmap; Bitmap.LoadBitmap(IDB_BITMAP1); BrushBit.CreatePatternBrush(&Bitmap); pDC->SelectObject(&BrushBit); pDC->Rectangle(0,0,100,100); //设置文本背景 pDC->SetBkColor(RGB(0,255,0));//背景颜色 pDC->SetBkMode(OPAQUE);//背景模式 pDC->SetTextAlign(TA_LEFT|TA_BOTTOM);//设置文本对齐方式 pDC->TextOut(0,100,"哈哈~~~//设置文本背景~~~"); //设置文本字体 CFont font; VERIFY(font.CreatePointFont(200, "黑体", pDC)); pDC->SelectObject(&font); pDC->TextOut(400,300,"哈哈~~~//设置文本字体~~~"); //使用CBitmap类,显示位图 CBitmap* pBitmap = new CBitmap; pBitmap->LoadBitmap(IDB_BITMAP2);//将位图装入内存 CDC MemDc; MemDc.CreateCompatibleDC(pDC);//创建内存设备环境 //将位图对象选入设备环境中,并保存原来设备环境的指针 CBitmap* pBitmapOld = MemDc.SelectObject(pBitmap); BITMAP stBitmap; pBitmap->GetBitmap(&stBitmap);//获取位图信息 //输出位图函数: 把源设备环境中的位图复制到目标设备环境中//显示位图 pDC->BitBlt(70,70,stBitmap.bmWidth,stBitmap.bmHeight,&MemDc,0,0,SRCCOPY); pDC->SelectObject(pBitmapOld); //恢复设备环境
最近做的项目与MFC的图像方面比较有联系,所以搜藏下