コード例 #1
0
FTL::FileFindResultHandle CLotteryMgr::OnFindFile(LPCTSTR pszFilePath, const WIN32_FIND_DATA& findData, LPVOID pParam)
{
    HRESULT hr = E_FAIL;
    BOOL    bRet = FALSE;
    Gdiplus::Status sts = Gdiplus::Ok;

    if (ftwtContinue != m_threadInit.GetThreadWaitType(INFINITE))
    {
         return rhStop;
    }

    if ((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY)
    {
        //find result file
        FTLTRACE(TEXT("OnFindFile: %s\n"), pszFilePath);

        CImage img;
        COM_VERIFY(img.Load(pszFilePath));
        if (SUCCEEDED(hr))
        {
            LotteryInfoPtr pLotteryInfo(new LotteryInfo(pszFilePath, FALSE));
            CRect rcThumbnail(0, 0, m_szThumbnail.cx, m_szThumbnail.cy);
            CSize szImage(img.GetWidth(), img.GetHeight());

            CRect rcDrawTarget = m_pCalcRect->GetFitRect(rcThumbnail, szImage);
            if (rcDrawTarget.bottom <= rcDrawTarget.top)
            {
                rcDrawTarget.bottom = rcDrawTarget.top + 1;
            }
            if (rcDrawTarget.right <= rcDrawTarget.left)
            {
                rcDrawTarget.right = rcDrawTarget.left + 1;
            }

            API_VERIFY(pLotteryInfo->imgThumbnail.Create(rcDrawTarget.Width(), rcDrawTarget.Height(), 32, CImage::createAlphaChannel));
            if (bRet)
            {
                CImageDC dc(pLotteryInfo->imgThumbnail);
                Gdiplus::Bitmap bmp((HBITMAP)img, NULL);
                Gdiplus::Graphics graphic(dc);
                GDIPLUS_VERIFY(graphic.DrawImage(&bmp, 0, 0, rcDrawTarget.Width(), rcDrawTarget.Height()));

                SendMessage(m_hWndControl, UM_ADD_LOTTERY_INFO, (WPARAM)pLotteryInfo.get(), NULL);

                m_allLotteryInfos.push_back(pLotteryInfo);
            }
        }
    }
    
    return rhContinue;
}
コード例 #2
0
ファイル: SkinTheme.cpp プロジェクト: jin1818/projectcodesync
CSize CSkinTheme::DrawControlPopupParent(CDC* pDC, CXTPControl* pButton, BOOL bDraw)
{
	CRect rcButton = pButton->GetRect();
	XTPControlType controlType = pButton->GetType();
	CRect rcText(0, 0, 0, 0), rcShortcut(0, 0, 0, 0);
	BOOL bSelected = pButton->GetSelected(), 
		bEnabled = pButton->GetEnabled(), 
		bChecked = pButton->GetChecked();

	CSize szIcon = pButton->GetParent()->GetIconSize();
	CSize szImage(max(szIcon.cx + 4, m_nTextHeight), max(szIcon.cy + 4, m_nTextHeight));

	XTPButtonStyle buttonStyle = pButton->GetStyle();
	BOOL bDrawImage = (buttonStyle == xtpButtonAutomatic && controlType != xtpControlPopup) ||
		(buttonStyle == xtpButtonIcon) || (buttonStyle == xtpButtonIconAndCaption);

	ASSERT(controlType == xtpControlButton || controlType == xtpControlPopup); // implemented only.

	if (bDraw)
	{
		CRect rcSelection(rcButton.left, rcButton.top, rcButton.right, rcButton.bottom);
		CRect rcImageRect(rcButton.left, rcButton.top, rcButton.left + szImage.cx, rcButton.bottom);
		CRect rcCheck (CPoint(rcImageRect.left + rcImageRect.Width()/2 - 10, rcImageRect.top + rcImageRect.Height()/2 - 10), CSize(20, 20));

		COLORREF clrText = !bEnabled? 0x0099A8AC: bSelected? 0x0060524B: 0x0060524B;
		pDC->SetTextColor(clrText);
		pDC->SetBkMode (TRANSPARENT);

		if (bSelected)
		{
			// µ¯³ö²Ëµ¥
			Graphics graphics(pDC->GetSafeHdc());

			Rect rc, rc1;

			rc1.X = rcSelection.left;
			rc1.Y = rcSelection.top;
			rc1.Width = rcSelection.Width();
			rc1.Height = rcSelection.Height();

			rc = m_mapRect["PopupSeled"];

			rc1.X = rcSelection.left;
			rc1.Y = rcSelection.top;
			rc1.Width = rc.Width/3;
			rc1.Height = rcSelection.Height();			
			graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width/3, rc.Height, UnitPixel, NULL, NULL);

			rc1.X = rcSelection.left+rc.Width/3;
			rc1.Y = rcSelection.top+0;
			rc1.Width = rcSelection.Width()-rc.Width/3*2;
			rc1.Height = rcSelection.Height();			
			graphics.DrawImage(m_pImg, rc1, rc.GetLeft()+rc.Width/3, rc.GetTop(), rc.Width/3, rc.Height, UnitPixel, NULL, NULL);

			rc1.X = rcSelection.left+rcSelection.Width()-rc.Width/3;
			rc1.Y = rcSelection.top+0;
			rc1.Width = rc.Width/3;
			rc1.Height = rcSelection.Height();			
			graphics.DrawImage(m_pImg, rc1, rc.GetRight()-rc.Width/3, rc.GetTop(), rc.Width/3, rc.Height, UnitPixel, NULL, NULL);


		}

		if (bChecked)
		{
			CRect rcCheck (CPoint(rcButton.left - 2, rcButton.top + rcButton.Height()/2 - 10), CSize(20, 20));
			DrawCheckMark(pDC, rcCheck, clrText);
		}

		CXTPImageManagerIcon* pImage = pButton->GetIconId() != 0 && bDrawImage? pButton->GetImage(szIcon.cx): NULL;
		if (pImage)
		{
			szIcon.cy = pImage->GetHeight() * szIcon.cx / pImage->GetWidth();
			// DrawRectangle(pDC, rcImageRect, bSelected, FALSE, bEnabled, bChecked, FALSE, FALSE);
			CPoint ptImage = CPoint(rcCheck.left + rcCheck.Width()/2 - szIcon.cx/2, rcCheck.top + rcCheck.Height()/2 - szIcon.cy/2);
			DrawImage(pDC, ptImage, szIcon, pImage, bSelected, FALSE, bEnabled, bChecked, FALSE, FALSE);
			rcSelection.left = rcImageRect.right + 1;
		}

		if (controlType == xtpControlPopup)
		{
			CPoint pt = CPoint(rcButton.right - 11, rcButton.CenterPoint().y);
			Triangle(pDC, CPoint(pt.x, pt.y - 3), CPoint(pt.x + 3, pt.y), CPoint(pt.x, pt.y + 3), clrText);
		}

		rcText.SetRect(rcButton.left + 24, rcButton.top, rcButton.right, rcButton.bottom);
		rcShortcut.SetRect(rcButton.left + 16 + 4, rcButton.top, rcButton.right - 19, rcButton.bottom);

	}

	pDC->DrawText(pButton->GetCaption(), &rcText, DT_SINGLELINE | DT_VCENTER | (!bDraw ? DT_CALCRECT : DT_END_ELLIPSIS) );

	if (controlType == xtpControlButton && pButton->GetShortcutText().GetLength() != 0 )
		pDC->DrawText(pButton->GetShortcutText(), &rcShortcut, DT_SINGLELINE | DT_VCENTER | (!bDraw ? DT_CALCRECT : DT_RIGHT) );

	return CSize(16 + 12 + rcText.Width() +  rcShortcut.Width() + 32, max(23, m_nTextHeight - 4));	
}
コード例 #3
0
CDIB* CRenderThread::Render(GP<DjVuImage> pImage, const CSize& size,
		const CDisplaySettings& displaySettings, int nDisplayMode,
		int nRotate, bool bThumbnail)
{
	if (size.cx <= 0 || size.cy <= 0)
		return NULL;

	CSize szImage(pImage->get_width(), pImage->get_height());
	int nTotalRotate = GetTotalRotate(pImage, nRotate);

	CSize szScaled(size);
	if (nTotalRotate % 2 != 0)
		swap(szScaled.cx, szScaled.cy);

	GRect rect(0, 0, szScaled.cx, szScaled.cy);

	bool bScalePnmFixed = displaySettings.bScaleColorPnm;

	// Use fast scaling for thumbnails.
	if (bThumbnail)
		bScalePnmFixed = false;

	// Use default faster scaling when zoom factor is >= 1.0.
	// Additionally, use the default scaling when requested
	// image size is small, since quality does not matter at this
	// scale. NOTE: this also deals with the special case of size (1, 1),
	// which can force PnmScaleFixed into an infinite loop.
	if ((szScaled.cx < 150 || szScaled.cy < 150)
			|| (szScaled.cx >= szImage.cx || szScaled.cy >= szImage.cy))
		bScalePnmFixed = false;

	// Disable PnmFixed scaling if we perform an integer reduction of the image.
	/*
	for (int nReduction = 1; nReduction <= 15; ++nReduction)
	{
		if (szScaled.cx*nReduction > szImage.cx - nReduction
				&& szScaled.cx*nReduction < szImage.cx + nReduction
				&& szScaled.cy*nReduction > szImage.cy - nReduction
				&& szScaled.cy*nReduction < szImage.cy + nReduction)
		{
			bScalePnmFixed = false;
			break;
		}
	}
	*/

	// Disable PnmFixed scaling for color images according to settings
	GP<IW44Image> bg44 = pImage->get_bg44();
	GP<GPixmap> bgpm = pImage->get_bgpm();
	GP<GPixmap> fgpm = pImage->get_fgpm();
	if (!displaySettings.bScaleColorPnm && (bg44 != NULL || bgpm != NULL || fgpm != NULL)
			&& nDisplayMode != CDjVuView::BlackAndWhite)
		bScalePnmFixed = false;

	if (bScalePnmFixed)
		rect = GRect(0, 0, szImage.cx, szImage.cy);

	GP<GBitmap> pGBitmap;
	GP<GPixmap> pGPixmap;

	try
	{
		switch (nDisplayMode)
		{
		case CDjVuView::BlackAndWhite:
			pGBitmap = pImage->get_bitmap(rect, rect, 4);
			break;

		case CDjVuView::Foreground:
			pGPixmap = pImage->get_fg_pixmap(rect, rect);
			if (pGPixmap == NULL)
				pGBitmap = pImage->get_bitmap(rect, rect, 4);
			break;

		case CDjVuView::Background:
			pGPixmap = pImage->get_bg_pixmap(rect, rect);
			break;

		case CDjVuView::Color:
		default:
			pGPixmap = pImage->get_pixmap(rect, rect);
			if (pGPixmap == NULL)
				pGBitmap = pImage->get_bitmap(rect, rect, 4);
		}
	}
	catch (GException&)
	{
		return NULL;
	}
	catch (CMemoryException*)
	{
		return NULL;
	}
	catch (...)
	{
		theApp.ReportFatalError();
	}

	CDIB* pBitmap = NULL;

	if (pGPixmap != NULL)
	{
		if (nTotalRotate != 0)
			pGPixmap = pGPixmap->rotate(nTotalRotate);

		if (bScalePnmFixed)
			pGPixmap = RescalePixmap_subpix(pGPixmap, size.cx, size.cy);

		pBitmap = RenderPixmap(*pGPixmap, displaySettings);
	}
	else if (pGBitmap != NULL)
	{
		if (nTotalRotate != 0)
			pGBitmap = pGBitmap->rotate(nTotalRotate);

		if (bScalePnmFixed)
		{
			pGPixmap = RescaleBitmap_subpix(pGBitmap, size.cx, size.cy);
			pBitmap = RenderPixmap(*pGPixmap, displaySettings);
		}
		else
		{
			pBitmap = RenderBitmap(*pGBitmap, displaySettings);
		}
	}
	else
	{
		pBitmap = RenderEmpty(size, displaySettings);
	}

	if (pBitmap != NULL)
		pBitmap->SetDPI(pImage->get_dpi());

	return pBitmap;
}
コード例 #4
0
//@mFunc draws the listbox items in their proper state
void CQSLItemList::DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct )
{
	CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);

	QSLItemData itemData;
	GetItemData( lpDrawItemStruct->itemID, itemData );
	
#ifdef USECACHE
	RImage* pImage = GetCachedBitmap( lpDrawItemStruct->itemID ) ;
#else
	RImage* pImage = itemData.GetImage();

	if (!itemData.m_pImage)
	{
		itemData.m_pImage = pImage;
		SetItemData( lpDrawItemStruct->itemID, itemData );
	}

//	HBITMAP hBitmap = itemData.m_hBitmap ;
//	HPALETTE hPalette = itemData.m_hPalette ;
	
//	if (!itemData.m_pImage)
//	{
//		hBitmap = itemData.m_hBitmap = 
//			LoadBitmapPreview( lpDrawItemStruct->itemID, &itemData.m_hPalette ) ;
//		hPalette = itemData.m_hPalette;
//
//		// Save the new data into the control
//		SetItemData( lpDrawItemStruct->itemID, itemData );
//	}
//
//	// If we have a palette with the bitmap, realize it into the DC prior to painting.
//	if (hPalette != NULL)
//	{
//		CPalette palBitmap;
//		palBitmap.Attach( hPalette );
//		CPalette *pOldPal = pDC->SelectPalette( &palBitmap, TRUE );
//		pDC->RealizePalette();
//		pDC->SelectPalette( pOldPal, TRUE );
//		palBitmap.Detach();
//	}
#endif

	BITMAP  bm= { 0, 0, 0, 0, 0, 0, NULL };
	HBITMAP hBitmap = NULL;
	
	if (pImage)
	{
		hBitmap = (HBITMAP) pImage->GetSystemHandle();
		::GetObject( hBitmap, sizeof( bm ), &bm );
	}

	// Determine colors to use for drawing text and selection
	//
	COLORREF crFillColor = GetSysColor( COLOR_WINDOW ) ;
	COLORREF crTextColor = GetSysColor( COLOR_WINDOWTEXT ) ;

	if (lpDrawItemStruct->itemState & ODS_SELECTED)
	{
		crFillColor = GetSysColor( COLOR_HIGHLIGHT ) ;
		crTextColor = GetSysColor( COLOR_HIGHLIGHTTEXT ) ;
	}

	// Handle drawing according to action
	//

	// Setup DC
	COLORREF oldTextColor = pDC->SetTextColor( crTextColor );
	COLORREF oldBkColor   = pDC->SetBkColor( crFillColor );
	CFont* pOldFont = pDC->SelectObject( GetParent()->GetFont() );

	// Determine location to draw bitmap.  This information 
	// is needed for all drawing modes, so might as well
	// just determine it once, and in one place.
	CSize	  szExtent = pDC->GetTextExtent( itemData.m_strDesc );

	RIntRect  cellRect( lpDrawItemStruct->rcItem );
	cellRect.Inset( RIntSize( 4, 4 ) );
	cellRect.m_Bottom -= szExtent.cy + 2; // + 2 is for spacing between graphic & text

	RIntRect  imgRect( 0, 0, bm.bmWidth - 1, bm.bmHeight - 1 );
	imgRect.ShrinkToFit( cellRect );
	imgRect.CenterRectInRect( cellRect );

	CSize  szImage( imgRect.Width(), imgRect.Height() );
//	CPoint centerPt( cellRect.CenterPoint() );
//	CPoint ptTopLeft( centerPt.x - szImage.cx / 2, centerPt.y - szImage.cy / 2 - 2 );

	switch (lpDrawItemStruct->itemAction)
	{
	case ODA_DRAWENTIRE:
		{
		CDC memDC;
		memDC.CreateCompatibleDC( pDC );

		// Get the bitmap
		CBitmap* pBmp    = CBitmap::FromHandle( hBitmap );
		CBitmap* pOldBmp = memDC.SelectObject( pBmp );

		pDC->StretchBlt( imgRect.m_Left, imgRect.m_Top, imgRect.Width(), imgRect.Height(), 
			&memDC, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY );

		memDC.SelectObject( pOldBmp );

		if (!(lpDrawItemStruct->itemState & ODS_SELECTED))
		{
			break ;
		}

		// Fall through
		}

	case ODA_SELECT:
		{
		// Draw/Clear the highlight rect
//		CRect bmpRect( ptTopLeft.x, ptTopLeft.y, ptTopLeft.x + bm.bmWidth, ptTopLeft.y + bm.bmHeight);
		
		CRect bmpRect( imgRect );
		bmpRect.InflateRect( 2, 2 );

		CPen pen( PS_SOLID, 2, crFillColor );
		CPen* pOldPen = pDC->SelectObject( &pen );

		pDC->MoveTo( bmpRect.left, bmpRect.top );
		pDC->LineTo( bmpRect.right, bmpRect.top );
		pDC->LineTo( bmpRect.right, bmpRect.bottom );
		pDC->LineTo( bmpRect.left, bmpRect.bottom );
		pDC->LineTo( bmpRect.left, bmpRect.top );
		pDC->SelectObject( pOldPen );
		}

	} // switch

	// Draw the text
	CPoint ptText( cellRect.m_Left + (cellRect.Width() - szExtent.cx) / 2, cellRect.m_Bottom + 4 );
	pDC->TextOut( ptText.x, ptText.y, itemData.m_strDesc );

//	pDC->DrawText( itemData.m_strDesc, &textRect, DT_CALCRECT | DT_SINGLELINE  );
//	textRect.OffsetRect( -textRect.Width() / 2, 2 );
//	pDC->DrawText( itemData.m_strDesc, &textRect, DT_CENTER | DT_VCENTER );

	// restore DC
	pDC->SelectObject( pOldFont );
	pDC->SetTextColor( oldTextColor );
	pDC->SetBkColor( oldBkColor );
}