void CSkinDlg::OnSize(UINT nType, int cx, int cy)
{
	CDialogEx::OnSize(nType, cx, cy);
	if (nType != SIZE_MAXIMIZED)
	{
		CRect rc;
		GetClientRect(&rc);

		CRgn rgn;
		CPoint points[8] = { CPoint(rc.left, CORNER_SIZE), CPoint(CORNER_SIZE, rc.top),
			CPoint(rc.right - CORNER_SIZE, rc.top), CPoint(rc.right, CORNER_SIZE),
			CPoint(rc.right, rc.bottom - CORNER_SIZE - 1), CPoint(rc.right - CORNER_SIZE - 1, rc.bottom),
			CPoint(CORNER_SIZE + 1, rc.bottom), CPoint(rc.left, rc.bottom - CORNER_SIZE - 1) };
		int nPolyCounts[1] = { 8 };
		int dd = rgn.CreatePolyPolygonRgn(points, nPolyCounts, 1, WINDING);
		SetWindowRgn(rgn, TRUE);
	}
	else
	{
		SetWindowRgn(NULL, FALSE);
	}
	// TODO:  在此处添加消息处理程序代码
}
Esempio n. 2
0
BOOL CDrawing::DrawRaster(CDC* pDC, OgdcDatasetRaster* pDatasetR)
{
    OGDCASSERT(!OGDCIS0(m_dCoordRatio) && !m_rcClient.IsRectEmpty());

    OgdcRect2D rcDraw = pDatasetR->GetBounds();
    if(!rcDraw.IntersectRect(m_rcViewBounds, rcDraw))
    {
        return FALSE;
    }

    BYTE *lp = new BYTE[sizeof(BITMAPINFOHEADER)+sizeof(RGBQUAD)*256];
    if(lp == NULL)
    {
        return FALSE;
    }

    int i = 0;
    BITMAPINFO *pBitMapInfo = (BITMAPINFO*)lp;
    PixelFormat ePixelFormat = pDatasetR->GetPixelFormat();
    pBitMapInfo->bmiHeader.biBitCount = BitCount(ePixelFormat);

    if(pDatasetR->GetBandCount() <= 1)
    {
        if(pDatasetR->GetType() == OgdcDataset::Image && ePixelFormat <= IPF_BYTE)
        {
            OgdcColorset colorset = pDatasetR->m_info.m_colorset;
            if(colorset.GetSize() == 0)
            {
                if(ePixelFormat == IPF_MONO)
                {
                    pBitMapInfo->bmiColors[0].rgbBlue = 0;
                    pBitMapInfo->bmiColors[0].rgbGreen = 0;
                    pBitMapInfo->bmiColors[0].rgbRed =  0;
                    pBitMapInfo->bmiColors[0].rgbReserved = 0;

                    pBitMapInfo->bmiColors[1].rgbBlue = 255;
                    pBitMapInfo->bmiColors[1].rgbGreen = 255;
                    pBitMapInfo->bmiColors[1].rgbRed =  255;
                    pBitMapInfo->bmiColors[1].rgbReserved = 0;
                }
                else if(ePixelFormat == IPF_FBIT)
                {
                    for(i = 0; i < 16; i++)
                    {
                        pBitMapInfo->bmiColors[i].rgbBlue = (16*i);
                        pBitMapInfo->bmiColors[i].rgbGreen = (16*i);
                        pBitMapInfo->bmiColors[i].rgbRed =  (16*i);
                        pBitMapInfo->bmiColors[i].rgbReserved = 0;
                    }
                }
                else
                {
                    for(i = 0; i < 256; i++)
                    {
                        pBitMapInfo->bmiColors[i].rgbBlue = i;
                        pBitMapInfo->bmiColors[i].rgbGreen = i;
                        pBitMapInfo->bmiColors[i].rgbRed =  i;
                        pBitMapInfo->bmiColors[i].rgbReserved = 0;
                    }
                }
            }
            else
            {
                for(i=0; i<256 && i<colorset.GetSize(); i++)
                {
                    //! 因为读进来的r和b是反的,所以要再反一次。
                    OgdcColor color = colorset.GetAt(i);
                    pBitMapInfo->bmiColors[i].rgbRed = GetBValue(color);
                    pBitMapInfo->bmiColors[i].rgbGreen = GetGValue(color);
                    pBitMapInfo->bmiColors[i].rgbBlue =  GetRValue(color);
                    pBitMapInfo->bmiColors[i].rgbReserved = 0;
                }
            }
        }
        else if(pDatasetR->GetType() == OgdcDataset::Grid)
        {
            pBitMapInfo->bmiHeader.biBitCount = 24;
            if(pDatasetR->m_colorTable.m_Colorset.GetSize() <= 0)
            {
                pDatasetR->m_colorTable.CreateDefault();
            }
        }
    }
    else
    {
        OgdcArray<OgdcInt> aryBand;
        aryBand.Add(0);
        aryBand.Add(1);
        aryBand.Add(pDatasetR->GetBandCount() > 2 ? 2:1);

        ImgColorSpace nColorSpace = ICS_RGB;
        pDatasetR->SetBandCombineMode(aryBand, nColorSpace);
        pBitMapInfo->bmiHeader.biBitCount = 24;
    }


    pBitMapInfo->bmiHeader.biPlanes = 1;
    pBitMapInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    pBitMapInfo->bmiHeader.biCompression = BI_RGB;
    pBitMapInfo->bmiHeader.biSizeImage = 0L;
    pBitMapInfo->bmiHeader.biXPelsPerMeter = 0L;
    pBitMapInfo->bmiHeader.biYPelsPerMeter = 0L;
    pBitMapInfo->bmiHeader.biClrUsed = 0L;
    pBitMapInfo->bmiHeader.biClrImportant = 0L;

    CRect rcBlock;
    CRgn *pClipRgn = NULL;
    OgdcElemRegion *pDTRasterClipRegion = pDatasetR->m_pClipRgn;
    if(pDTRasterClipRegion != NULL && !pDTRasterClipRegion->m_rcBounds.IsEmpty())
    {
        OgdcPoint2D *pPoint2Ds = pDTRasterClipRegion->m_points.GetData();
        CPoint *pClipPoints = NULL;
        if(GeoToDevice(pPoint2Ds, pDTRasterClipRegion->m_points.GetSize(), pClipPoints))
        {
            int nSubCount = pDTRasterClipRegion->m_polyCounts.GetSize();
            int *lpPolyCount = pDTRasterClipRegion->m_polyCounts.GetData();

            pClipRgn = new CRgn;
            if(pClipRgn != NULL)
            {
                pClipRgn->CreatePolyPolygonRgn(pClipPoints, lpPolyCount, nSubCount, ALTERNATE);
                pDC->SelectClipRgn(pClipRgn, RGN_AND);
            }
            delete[] pClipPoints;
            pClipPoints = NULL;
        }
    }

    OgdcSize szBMP(OGDCROUND(rcDraw.Width()/m_dCoordRatio), OGDCROUND(rcDraw.Height()/m_dCoordRatio));
    OgdcRasterBlock* pImgBlock = pDatasetR->GetViewBlock(rcDraw, szBMP.cx, szBMP.cy);
    if(pImgBlock != NULL)
    {
        DrawRasterBlock(pDC, pImgBlock, pDatasetR, pBitMapInfo);

        delete pImgBlock;
        pImgBlock = NULL;
    }
    pDatasetR->ReleaseAllBlocks();

    if(lp != NULL)
    {
        delete[] lp;
        lp = NULL;
    }

    if(pClipRgn != NULL)
    {
        pDC->SelectClipRgn(NULL, RGN_COPY);
        delete pClipRgn;
        pClipRgn = NULL;
    }
    return TRUE;
}