Beispiel #1
0
void CColorBtnDlg::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpd) 
{
	CDC dc;
    CPen nullpen;
    CBrush brush;
    CPen *oldpen;
    CBrush *oldbrush;

    // Draw the wells using the current color table

    nullpen.CreateStockObject(NULL_PEN);
    brush.CreateSolidBrush(colors[nIDCtl-IDC_COLOR1]);

    dc.Attach(lpd->hDC);

    oldpen = dc.SelectObject(&nullpen);
    oldbrush = dc.SelectObject(&brush);

    lpd->rcItem.right++;
    lpd->rcItem.bottom++;

    dc.Rectangle(&lpd->rcItem);

    dc.SelectObject(oldpen);
    dc.SelectObject(oldbrush);

    dc.Detach();
	
	CDialog::OnDrawItem(nIDCtl, lpd);
}
Beispiel #2
0
void CBigIcon::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
	CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
	ASSERT(pDC != NULL);

	CRect rect;
	GetClientRect(rect);
	int cxClient = rect.Width();
	int cyClient = rect.Height();

	// load icon
	HICON hicon = AfxGetApp()->LoadIcon(ID_SYM_ICON_GDB);
	if (hicon == NULL)
		return;

	// draw icon into off-screen bitmap
	int cxIcon = ::GetSystemMetrics(SM_CXICON);
	int cyIcon = ::GetSystemMetrics(SM_CYICON);

	CBitmap bitmap;
	if (!bitmap.CreateCompatibleBitmap(pDC, cxIcon, cyIcon))
		return;
	CDC dcMem;
	if (!dcMem.CreateCompatibleDC(pDC))
		return;
	CBitmap* pBitmapOld = dcMem.SelectObject(&bitmap);
	if (pBitmapOld == NULL)
		return;

	// blt the bits already on the window onto the off-screen bitmap
	dcMem.StretchBlt(0, 0, cxIcon, cyIcon, pDC,
		2, 2, cxClient-CX_SHADOW-4, cyClient-CY_SHADOW-4, SRCCOPY);

	// draw the icon on the background
	dcMem.DrawIcon(0, 0, hicon);

	// draw border around icon
	CPen pen;
	pen.CreateStockObject(BLACK_PEN);
	CPen* pPenOld = pDC->SelectObject(&pen);
	pDC->Rectangle(0, 0, cxClient-CX_SHADOW, cyClient-CY_SHADOW);
	if (pPenOld)
		pDC->SelectObject(pPenOld);

	// draw shadows around icon
	CBrush br;
	br.CreateStockObject(DKGRAY_BRUSH);
	rect.SetRect(cxClient-CX_SHADOW, CY_SHADOW, cxClient, cyClient);
	pDC->FillRect(rect, &br);
	rect.SetRect(CX_SHADOW, cyClient-CY_SHADOW, cxClient, cyClient);
	pDC->FillRect(rect, &br);

	// draw the icon contents
	pDC->StretchBlt(2, 2, cxClient-CX_SHADOW-4, cyClient-CY_SHADOW-4,
		&dcMem, 0, 0, cxIcon, cyIcon, SRCCOPY);
}
void CDiaColorD::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct) 
{
	CBrush brush;
	if(lpDrawItemStruct->CtlID==IDC_COLORON){
		brush.CreateSolidBrush(m_ColorOn);
	}else{
		brush.CreateSolidBrush(m_ColorOff);
	}

	CPen pen;
	pen.CreateStockObject(NULL_PEN);
	HPEN hOldPen=(HPEN)SelectObject(lpDrawItemStruct->hDC,pen.GetSafeHandle());
	HBRUSH hOldBrush=(HBRUSH)SelectObject(lpDrawItemStruct->hDC,brush.GetSafeHandle());
	Rectangle(lpDrawItemStruct->hDC,0,0,lpDrawItemStruct->rcItem.right,lpDrawItemStruct->rcItem.bottom);

	SelectObject(lpDrawItemStruct->hDC,hOldBrush);
	SelectObject(lpDrawItemStruct->hDC,hOldPen);

	CDialog::OnDrawItem(nIDCtl, lpDrawItemStruct);
}
Beispiel #4
0
void CBigIcon::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
	CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
	ASSERT(pDC != NULL);
	if (pDC != NULL)
	{
		CRect rect;
		GetClientRect(rect);
		int cxClient = rect.Width();
		int cyClient = rect.Height();

		// draw border around icon
		CPen pen;
		pen.CreateStockObject(BLACK_PEN);
		CPen* pPenOld = pDC->SelectObject(&pen);
		pDC->Rectangle(0, 0, cxClient-CX_SHADOW, cyClient-CY_SHADOW);
		if (pPenOld)
			pDC->SelectObject(pPenOld);

		// draw shadows around icon
		CBrush br;
		br.CreateStockObject(DKGRAY_BRUSH);
		rect.SetRect(cxClient-CX_SHADOW, CY_SHADOW, cxClient, cyClient);
		pDC->FillRect(rect, &br);
		rect.SetRect(CX_SHADOW, cyClient-CY_SHADOW, cxClient, cyClient);
		pDC->FillRect(rect, &br);

		// draw the bitmap contents
		CDC dcMem;
		if (!dcMem.CreateCompatibleDC(pDC))
			return;
		CBitmap* pBitmapOld = dcMem.SelectObject(&m_bitmap);
		if (pBitmapOld == NULL)
			return;

		pDC->BitBlt(2, 2, m_sizeBitmap.cx, m_sizeBitmap.cy, &dcMem, 0, 0, SRCCOPY);

		dcMem.SelectObject(pBitmapOld);
	}
}
Beispiel #5
0
void CMapView::OnDraw(CDC* pDC)
{
    CMapDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    int h = pDoc->GetHeight();
    int w = pDoc->GetWidth();

    CRect r;
    pDC->GetClipBox(&r);
    pDC->FillSolidRect(r, GetSysColor(COLOR_3DFACE));

    if (w > 0 && h > 0)
    {
        // calculate the bounding box that is needed to be draw
        CRect r;
        pDC->GetClipBox(&r);
        int ys = r.top    / 40;
        int ye = r.bottom / 40;
        int xs = r.left   / 40;
        int xe = r.right  / 40;
        ye = min(ye+1,h);
        xe = min(xe+1,w);

        if (m_ViewMode == VIEW_MODE_GRAPHICS)
        {
			if (pDoc->m_pMapImage)
			{
				pDC->SetStretchBltMode(COLORONCOLOR);
				CRect r(0,0,pDoc->m_pMapImage->GetWidth(), pDoc->m_pMapImage->GetHeight());
				pDoc->m_pMapImage->Draw(pDC, r,r);
			}
        }
        else
        {
            for (int y = ys; y < ye; y++)
            {
                for (int x = xs; x < xe; x++)
                {
                    DrawMegaTile(pDC, x,y);
                }
            }
        }

        if (m_GridMode)
        {
            // draw major grid lines
            {
                CPen Pen;
                Pen.CreateStockObject(BLACK_PEN);
                CPen* pOldPen = pDC->SelectObject(&Pen);
                for (int y = ys; y <= ye; y++)
                {
                    pDC->MoveTo(xs*40,y*40);
                    pDC->LineTo(xe*40,y*40);

                }
                for (int x = xs; x <= xe; x++)
                {
                    pDC->MoveTo(x*40,ys*40);
                    pDC->LineTo(x*40,ye*40);
                }
                pDC->SelectObject(pOldPen);
            }
        }
    }
}