Exemplo n.º 1
0
BOOL CImageBoxEx::DrawBackground(CDC* pDC)
{
	CClientDC dcClient(this->GetParent());
	
	CRect recClient;
	CRect recWindow;
	this->GetClientRect(recClient);
	this->GetWindowRect(recWindow);
	this->GetParent()->ScreenToClient(recWindow);
	
	if (this->m_dcBackground.m_hDC == NULL && this->GetTopLevelParent() == CWnd::GetForegroundWindow())
	{
		this->m_dcBackground.CreateCompatibleDC(&dcClient);
		this->m_bmBackground.CreateCompatibleBitmap(&dcClient, recClient.Width(), recClient.Height());
		this->m_pbmRestore = this->m_dcBackground.SelectObject(&this->m_bmBackground);
		this->m_dcBackground.BitBlt(0, 0, recClient.Width(), recClient.Height(), &dcClient, recWindow.left, recWindow.top, SRCCOPY);
	}
	
	pDC->BitBlt(0, 0, recClient.Width(), recClient.Height(), &this->m_dcBackground, 0, 0, SRCCOPY);
	
	return TRUE;
}
Exemplo n.º 2
0
void CAboutPage::OnPaintAward(void)
{
	CClientDC dcClient(this);

	fipMemoryIO memIO(reinterpret_cast<BYTE*>(m_resSoftpediaAward.GetData()), m_resSoftpediaAward.GetSize());
	fipWinImage imageSoftpedia;
	imageSoftpedia.loadFromMemory(memIO);
	
	RECT rcVersion = { 0 };
	m_textVersion.GetWindowRect(&rcVersion);
	ScreenToClient(&rcVersion);
	
	RECT rcImage = { 0 };
	GetClientRect(&rcImage);
	rcImage.right -= rcVersion.left - 4;
	rcImage.left = rcImage.right - imageSoftpedia.getWidth();
	rcImage.top = rcVersion.top - 4;
	rcImage.bottom = rcImage.top + imageSoftpedia.getHeight();
	
	COLORREF cr3DFace = ::GetSysColor(COLOR_3DFACE);
	RGBQUAD rgbqBack = { GetBValue(cr3DFace), GetGValue(cr3DFace), GetRValue(cr3DFace), 0 };
	
	imageSoftpedia.drawEx(dcClient, rcImage, FALSE, &rgbqBack);
}
Exemplo n.º 3
0
HBITMAP CLiveList::CreateDragImage(CListCtrl* pList, const CPoint& ptMouse, CPoint& ptMiddle)
{
	ASSERT_VALID( pList );

	CRect rcClient, rcOne, rcAll( 32000, 32000, -32000, -32000 );
	int nIndex;

	if ( pList->GetSelectedCount() == 0 ) return NULL;

	pList->SetFocus();
	pList->GetClientRect( &rcClient );

	for ( nIndex = -1 ; ( nIndex = pList->GetNextItem( nIndex, LVNI_SELECTED ) ) >= 0 ; )
	{
		pList->GetItemRect( nIndex, rcOne, LVIR_BOUNDS );

		if ( rcOne.IntersectRect( &rcClient, &rcOne ) )
		{
			rcAll.left		= min( rcAll.left, rcOne.left );
			rcAll.top		= min( rcAll.top, rcOne.top );
			rcAll.right		= max( rcAll.right, rcOne.right );
			rcAll.bottom	= max( rcAll.bottom, rcOne.bottom );
		}

		pList->SetItemState( nIndex, 0, LVIS_FOCUSED );
	}

	BOOL bClipped = rcAll.Height() > MAX_DRAG_SIZE;

	if ( bClipped )
	{
		rcAll.left		= max( rcAll.left, ptMouse.x - MAX_DRAG_SIZE_2 );
		rcAll.right		= max( rcAll.right, ptMouse.x + MAX_DRAG_SIZE_2 );
		rcAll.top		= max( rcAll.top, ptMouse.y - MAX_DRAG_SIZE_2 );
		rcAll.bottom	= max( rcAll.bottom, ptMouse.y + MAX_DRAG_SIZE_2 );
	}

	CClientDC dcClient( pList );
	CBitmap bmAll, bmDrag;
	CDC dcAll, dcDrag;

	if ( ! dcAll.CreateCompatibleDC( &dcClient ) )
		return NULL;
	if ( ! bmAll.CreateCompatibleBitmap( &dcClient, rcClient.Width(), rcClient.Height() ) )
		return NULL;

	if ( ! dcDrag.CreateCompatibleDC( &dcClient ) )
		return NULL;
	if ( ! bmDrag.CreateCompatibleBitmap( &dcClient, rcAll.Width(), rcAll.Height() ) )
		return NULL;

	CBitmap *pOldAll = dcAll.SelectObject( &bmAll );

	dcAll.FillSolidRect( &rcClient, DRAG_COLOR_KEY );

	COLORREF crBack = pList->GetBkColor();
	pList->SetBkColor( DRAG_COLOR_KEY );
	pList->SendMessage( WM_PAINT, (WPARAM)dcAll.GetSafeHdc() );
	pList->SetBkColor( crBack );

	CBitmap *pOldDrag = dcDrag.SelectObject( &bmDrag );

	dcDrag.FillSolidRect( 0, 0, rcAll.Width(), rcAll.Height(), DRAG_COLOR_KEY );

	CRgn pRgn;

	ptMiddle.SetPoint( ptMouse.x - rcAll.left, ptMouse.y - rcAll.top );
	if ( bClipped )
	{
		pRgn.CreateEllipticRgn(	ptMiddle.x - MAX_DRAG_SIZE_2, ptMiddle.y - MAX_DRAG_SIZE_2,
								ptMiddle.x + MAX_DRAG_SIZE_2, ptMiddle.y + MAX_DRAG_SIZE_2 );
		dcDrag.SelectClipRgn( &pRgn );
	}

	for ( nIndex = -1 ; ( nIndex = pList->GetNextItem( nIndex, LVNI_SELECTED ) ) >= 0 ; )
	{
		pList->GetItemRect( nIndex, rcOne, LVIR_BOUNDS );

		if ( rcOne.IntersectRect( &rcAll, &rcOne ) )
		{
			dcDrag.BitBlt( rcOne.left - rcAll.left, rcOne.top - rcAll.top,
				rcOne.Width(), rcOne.Height(), &dcAll, rcOne.left, rcOne.top, SRCCOPY );
		}
	}

	dcDrag.SelectObject( pOldDrag );
	dcAll.SelectObject( pOldAll );

	dcDrag.DeleteDC();
	bmAll.DeleteObject();
	dcAll.DeleteDC();

	return (HBITMAP) bmDrag.Detach ();
}
// Based on code by Frank Kobs.
CImageList* CDragDropListCtrl::CreateDragImageEx(LPPOINT lpPoint)
{
	CRect rectSingle;	
	CRect rectComplete(0, 0, 0, 0);
	int	nIndex	= -1;
	BOOL bFirst	= TRUE;

	// Determine the size of the drag image.
	POSITION pos = GetFirstSelectedItemPosition();
	while (pos)
	{
		nIndex = GetNextSelectedItem(pos);
		GetItemRect(nIndex, rectSingle, LVIR_BOUNDS);
		if (bFirst)
		{
			// Initialize the CompleteRect
			GetItemRect(nIndex, rectComplete, LVIR_BOUNDS);
			bFirst = FALSE;
		}
		rectComplete.UnionRect(rectComplete, rectSingle);
	}

	// Create bitmap in memory DC
	CClientDC dcClient(this);	
	CDC dcMem;	
	CBitmap Bitmap;

	if (!dcMem.CreateCompatibleDC(&dcClient))
	{
		return NULL;
	}

	if (!Bitmap.CreateCompatibleBitmap(&dcClient, rectComplete.Width(), rectComplete.Height()))
	{
		return NULL;
	}
	
	CBitmap* pOldMemDCBitmap = dcMem.SelectObject(&Bitmap);
	// Here green is used as mask color.
	dcMem.FillSolidRect(0, 0, rectComplete.Width(), rectComplete.Height(), RGB(0, 255, 0)); 

	// Paint each DragImage in the DC.
	CImageList* pSingleImageList = NULL;
	CPoint pt;

	pos = GetFirstSelectedItemPosition();
	while (pos)
	{
		nIndex = GetNextSelectedItem(pos);
		GetItemRect(nIndex, rectSingle, LVIR_BOUNDS);

		pSingleImageList = CreateDragImage(nIndex, &pt);
		if (pSingleImageList)
		{
			// Make sure width takes into account not using LVS_EX_FULLROWSELECT style.
			IMAGEINFO ImageInfo;
			pSingleImageList->GetImageInfo(0, &ImageInfo);
			rectSingle.right = rectSingle.left + (ImageInfo.rcImage.right - ImageInfo.rcImage.left);

			pSingleImageList->DrawIndirect(
				&dcMem, 
				0, 
				CPoint(rectSingle.left - rectComplete.left, 
				rectSingle.top - rectComplete.top),
				rectSingle.Size(), 
				CPoint(0,0));

			delete pSingleImageList;
		}
	}

	dcMem.SelectObject(pOldMemDCBitmap);

	// Create the imagelist	with the merged drag images.
	CImageList* pCompleteImageList = new CImageList;
	
	pCompleteImageList->Create(rectComplete.Width(), rectComplete.Height(), ILC_COLOR | ILC_MASK, 0, 1);
	// Here green is used as mask color.
	pCompleteImageList->Add(&Bitmap, RGB(0, 255, 0)); 

	Bitmap.DeleteObject();

	// As an optional service:
	// Find the offset of the current mouse cursor to the imagelist
	// this we can use in BeginDrag().
	if (lpPoint)
	{
		CPoint ptCursor;
		GetCursorPos(&ptCursor);
		ScreenToClient(&ptCursor);
		lpPoint->x = ptCursor.x - rectComplete.left;
		lpPoint->y = ptCursor.y - rectComplete.top;
	}

	return pCompleteImageList;
}
HBITMAP CLibraryAlbumView::CreateDragImage(const CPoint& ptMouse, CPoint& ptMiddle)
{
	CRect rcClient, rcOne, rcAll( 32000, 32000, -32000, -32000 );

	GetClientRect( &rcClient );

	for ( POSITION pos = m_pSelTrack.GetHeadPosition() ; pos ; )
	{
		CLibraryAlbumTrack* pTrack = m_pSelTrack.GetNext( pos );
		GetItemRect( pTrack, &rcOne );

		if ( rcOne.IntersectRect( &rcClient, &rcOne ) )
		{
			rcAll.left		= min( rcAll.left, rcOne.left );
			rcAll.top		= min( rcAll.top, rcOne.top );
			rcAll.right		= max( rcAll.right, rcOne.right );
			rcAll.bottom	= max( rcAll.bottom, rcOne.bottom );
		}
	}

	BOOL bClipped = rcAll.Height() > MAX_DRAG_SIZE;

	if ( bClipped )
	{
		rcAll.left		= max( rcAll.left, ptMouse.x - MAX_DRAG_SIZE_2 );
		rcAll.right		= max( rcAll.right, ptMouse.x + MAX_DRAG_SIZE_2 );
		rcAll.top		= max( rcAll.top, ptMouse.y - MAX_DRAG_SIZE_2 );
		rcAll.bottom	= max( rcAll.bottom, ptMouse.y + MAX_DRAG_SIZE_2 );
	}

	CClientDC dcClient( this );
	CBitmap bmDrag;
	CDC dcDrag;

	if ( ! dcDrag.CreateCompatibleDC( &dcClient ) )
		return NULL;
	if ( ! bmDrag.CreateCompatibleBitmap( &dcClient, rcAll.Width(), rcAll.Height() ) )
		return NULL;

	CBitmap *pOldDrag = dcDrag.SelectObject( &bmDrag );

	dcDrag.FillSolidRect( 0, 0, rcAll.Width(), rcAll.Height(), DRAG_COLOR_KEY );

	CRgn pRgn;

	ptMiddle.SetPoint( ptMouse.x - rcAll.left, ptMouse.y - rcAll.top );
	if ( bClipped )
	{
		pRgn.CreateEllipticRgn(	ptMiddle.x - MAX_DRAG_SIZE_2, ptMiddle.y - MAX_DRAG_SIZE_2,
								ptMiddle.x + MAX_DRAG_SIZE_2, ptMiddle.y + MAX_DRAG_SIZE_2 );
		dcDrag.SelectClipRgn( &pRgn );
	}

	CDC* pBuffer = CoolInterface.GetBuffer( dcClient, m_szTrack );
	CRect rcBuffer( 0, 0, m_szTrack.cx, m_szTrack.cy );

	CFont* pOldFont = (CFont*)pBuffer->SelectObject( &CoolInterface.m_fntNormal );

	for ( POSITION pos = m_pSelTrack.GetHeadPosition() ; pos ; )
	{
		CLibraryAlbumTrack* pTrack = m_pSelTrack.GetNext( pos );
		GetItemRect( pTrack, &rcOne );
		CRect rcDummy;

		if ( rcDummy.IntersectRect( &rcAll, &rcOne ) )
		{
			pBuffer->FillSolidRect( &rcBuffer, DRAG_COLOR_KEY );
			pTrack->Paint( this, pBuffer, rcBuffer, -1 );
			dcDrag.BitBlt( rcOne.left - rcAll.left, rcOne.top - rcAll.top,
				m_szTrack.cx, m_szTrack.cy, pBuffer, 0, 0, SRCCOPY );
		}
	}

	pBuffer->SelectObject( pOldFont );
	dcDrag.SelectObject( pOldDrag );
	dcDrag.DeleteDC();

	return (HBITMAP) bmDrag.Detach();
}
Exemplo n.º 6
0
int CChildView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	//Trace("CChildView::OnCreate - Initializing OpenGL");
	if (CWnd::OnCreate(lpCreateStruct) == -1){
		//Trace("CChildView::OnCreate - Failed");
		return -1;
	}
	
	// Initialize OpenGL parameters
	PIXELFORMATDESCRIPTOR pfd = {
        sizeof(PIXELFORMATDESCRIPTOR), // Structure size
        1,                             // Version number
        PFD_DRAW_TO_WINDOW |           // Property flags
            PFD_SUPPORT_OPENGL |
            PFD_DOUBLEBUFFER,          // (remove if no double buf)
        PFD_TYPE_RGBA,                 // PixelType
        24,                            // 24-bit color
        0, 0, 0, 0, 0, 0,              // Color bits and shift
        0, 0, 0, 0, 0, 0, 0,           // Alpha and accum buffer bits
        32,                            // 32-bit depth buffer
        0, 0,                          // No stencil or aux buffer
        PFD_MAIN_PLANE,                // Layer type
        0,                             // Reserved
        0, 0, 0                        // Unsupported
    };

	// Tell GDI to convert device context from Win32 to OpenGL.
    CClientDC dcClient(this);
    int iPixelFormat = ChoosePixelFormat(dcClient.m_hDC,&pfd);
    if ( !iPixelFormat ) {
		// This system cannot run OpenGL
		//Trace("CChildView::OnCreate - Error retrieving pixel format index...");
		ASSERT(FALSE);
		AfxMessageBox("Cannot initialize OpenGL...quitting.",
						MB_OK | MB_ICONERROR);
		return -1; // will fail new document creation...
	} // if
	//Trace("CChildView::OnCreate - OpenGL - Chosen Pixel Format");

    if ( !SetPixelFormat(dcClient.m_hDC,iPixelFormat,&pfd) ) {
		// This system cannot run OpenGL
		//Trace("CChildView::OnCreate - Error setting new pixel format...");
		ASSERT(FALSE);
		AfxMessageBox("Cannot initialize OpenGL...quitting.",
						MB_OK | MB_ICONERROR);
		return -1; // will fail new document creation...
	} // if
	//Trace("CChildView::OnCreate - OpenGL - Pixel Format is set");

	// Update the PIXELFORMATDESCRIPTOR structure once
	// the device context has been modified.
    DescribePixelFormat(dcClient.m_hDC,iPixelFormat,
						sizeof(pfd),&pfd);

	// The PIXELFORMATDESCRIPTOR has been updated, so we now
	// determine whether to create and manage a custom
	// palette.
    if ( pfd.dwFlags & PFD_NEED_PALETTE ) {
		// We do, so build a new palette...
		//Trace("CChildView::OnCreate - Setting up palette...");
        GLSetupPalette();
		//Trace("CChildView::OnCreate - Palette is set...");
	} // if
	
	// Create the OpenGL rendering context
    m_hRC = wglCreateContext(dcClient.m_hDC);
    if ( m_hRC == NULL ) {
		// This system cannot run OpenGL
		//Trace("CChildView::OnCreate - Error creating OpenGL rendering context...\n");
		ASSERT(FALSE);
		AfxMessageBox("Cannot initialize OpenGL...quitting.",
						MB_OK | MB_ICONERROR);
		return -1; // will fail new document creation...
	} // if
	//Trace("CChildView::OnCreate - OpenGL - created rendering context");

	// We now make it the current rendering context so
	// we might set our clear color
	glClearDepth(1.0);
	glEnable(GL_DEPTH_TEST);

	wglMakeCurrent(dcClient.m_hDC,m_hRC);
	GLLoadFont();
	glClearColor(0.0,0.0,0.0,0.0); // black
	wglMakeCurrent(dcClient.m_hDC,NULL);


	//Trace("CChildView::OnCreate - Done");

	return 0;
}
Exemplo n.º 7
0
void RWinColorPalette::OnPaint( )
{
	CPaintDC dc( this );
	RDcDrawingSurface ds;
	ds.Initialize( (HDC) dc ) ;

	CRect rcWindow;
	GetClientRect( rcWindow );
	RIntRect rcClient( rcWindow );

	RBitmapImage&	biPalette	= GetPaletteBitmapImage();
	biPalette.LockImage( );
	biPalette.Render( ds, rcClient );
	biPalette.UnlockImage( );
	ds.DetachDCs();

	CClientDC dcClient( this );
	ds.Initialize( (HDC) dcClient ) ;

	RColor crOldFill = ds.GetFillColor();
	RColor crOldPen  = ds.GetPenColor();

	if (m_ptSelected.m_x >= 0 && m_ptSelected.m_y >= 0)
	{
		//
		// Draw selected cell

		RIntRect rcSelected( 
			m_ptSelected.m_x + 1,
			m_ptSelected.m_y + 1,
			m_ptSelected.m_x + kCellSize.m_dx - 1,
			m_ptSelected.m_y + kCellSize.m_dy - 1 );

		RSolidColor crBlack( kBlack );
		RSolidColor crHilight( GetSysColor( COLOR_BTNHILIGHT ) );
		ds.Draw3dRect( rcSelected, crBlack, crHilight );

		RSolidColor crShadow( GetSysColor( COLOR_BTNSHADOW ) );
		rcSelected.m_Top -= 1; rcSelected.m_Left -= 1;
		ds.Draw3dRect( rcSelected, crShadow, crHilight );

		if (GetFocus() == this)
		{
			RSolidColor rSolid = GetSysColor( COLOR_HIGHLIGHT );
			RColor rSelected( rSolid );

			rcSelected.Inflate( RIntSize( 1, 1 ), RIntSize( 2, 2 ) );
			ds.SetPenColor( RColor( rSelected ) );
			ds.FrameRectangle( rcSelected );
		}
	}

	if (m_crHilited != (COLORREF) -1L)
	{
		// Draw color chip
		m_rcColorChip = RIntRect( 
			m_ptHilited.m_x,
			m_ptHilited.m_y,
			m_ptHilited.m_x + 2 * kCellSize.m_dx,
			m_ptHilited.m_y + 2 * kCellSize.m_dy );

		YIntDimension xOffset( 2 * kCellSize.m_dx );
		YIntDimension yOffset( 2 * kCellSize.m_dy );

		if (m_rcColorChip.m_Right + xOffset > rcWindow.right)
		{
			xOffset = -3 * kCellSize.m_dx;
		}

		if (m_rcColorChip.m_Bottom + yOffset > rcWindow.bottom)
		{
			yOffset = -3 * kCellSize.m_dy;
		}

		m_rcColorChip.Offset( RIntSize( xOffset, yOffset ) );

		RColor crFill = RSolidColor( m_crHilited );
		RColor crPen = RSolidColor( kWhite );

		ds.SetPenColor( crPen );
		ds.SetFillColor( crFill );
		ds.FillRectangle( m_rcColorChip );
		ds.FrameRectangle( m_rcColorChip );
	}
	else
	{
		m_rcColorChip = RIntRect( 0, 0, 1, 1 );
	}

	ds.SetPenColor( crOldPen );
	ds.SetFillColor( crOldFill );
	ds.DetachDCs();
}
Exemplo n.º 8
0
HBITMAP CLibraryTileView::CreateDragImage(const CPoint& ptMouse, CPoint& ptMiddle)
{
	ASSUME_LOCK( Library.m_pSection );

	CRect rcClient, rcOne, rcAll( 32000, 32000, -32000, -32000 );

	GetClientRect( &rcClient );

	for ( std::list< iterator >::iterator pTile = m_oSelTile.begin(); pTile != m_oSelTile.end(); ++pTile )
	{
		GetItemRect( *pTile, &rcOne );

		if ( rcOne.IntersectRect( &rcClient, &rcOne ) )
		{
			rcAll.left		= min( rcAll.left, rcOne.left );
			rcAll.top		= min( rcAll.top, rcOne.top );
			rcAll.right		= max( rcAll.right, rcOne.right );
			rcAll.bottom	= max( rcAll.bottom, rcOne.bottom );
		}
	}

	const bool bClipped = rcAll.Height() > MAX_DRAG_SIZE;

	if ( bClipped )
	{
		rcAll.left		= max( rcAll.left, ptMouse.x - MAX_DRAG_SIZE_2 );
		rcAll.right		= max( rcAll.right, ptMouse.x + MAX_DRAG_SIZE_2 );
		rcAll.top		= max( rcAll.top, ptMouse.y - MAX_DRAG_SIZE_2 );
		rcAll.bottom	= max( rcAll.bottom, ptMouse.y + MAX_DRAG_SIZE_2 );
	}

	CClientDC dcClient( this );
	CDC dcMem, dcDrag;
	CBitmap bmDrag;

	if ( ! dcMem.CreateCompatibleDC( &dcClient ) )
		return NULL;
	if ( ! dcDrag.CreateCompatibleDC( &dcClient ) )
		return NULL;
	if ( ! bmDrag.CreateCompatibleBitmap( &dcClient, rcAll.Width(), rcAll.Height() ) )
		return NULL;

	CBitmap *pOldDrag = dcDrag.SelectObject( &bmDrag );

	dcDrag.FillSolidRect( 0, 0, rcAll.Width(), rcAll.Height(), DRAG_COLOR_KEY );

	ptMiddle.SetPoint( ptMouse.x - rcAll.left, ptMouse.y - rcAll.top );

	CRgn pRgn;
	if ( bClipped )
	{
		pRgn.CreateEllipticRgn(	ptMiddle.x - MAX_DRAG_SIZE_2, ptMiddle.y - MAX_DRAG_SIZE_2,
								ptMiddle.x + MAX_DRAG_SIZE_2, ptMiddle.y + MAX_DRAG_SIZE_2 );
		dcDrag.SelectClipRgn( &pRgn );
	}

	CDC* pBuffer = CoolInterface.GetBuffer( dcClient, m_szBlock );
	CRect rcBuffer( 0, 0, m_szBlock.cx, m_szBlock.cy );

	CFont* pOldFont = (CFont*)pBuffer->SelectObject( &CoolInterface.m_fntNormal );

	for ( std::list< iterator >::iterator pTile = m_oSelTile.begin(); pTile != m_oSelTile.end(); ++pTile )
	{
		GetItemRect( *pTile, &rcOne );
		CRect rcDummy;

		if ( rcDummy.IntersectRect( &rcAll, &rcOne ) )
		{
			pBuffer->FillSolidRect( &rcBuffer, DRAG_COLOR_KEY );
			(**pTile)->Paint( pBuffer, rcBuffer, &dcMem, (*pTile) == m_pFocus );
			dcDrag.BitBlt( rcOne.left - rcAll.left, rcOne.top - rcAll.top,
				m_szBlock.cx, m_szBlock.cy, pBuffer, 0, 0, SRCCOPY );
		}
	}

	pBuffer->SelectObject( pOldFont );

	dcDrag.SelectObject( pOldDrag );

	dcDrag.DeleteDC();

	return (HBITMAP) bmDrag.Detach();
}