Example #1
0
void CCButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
	CDC dc;
	RECT rect;
	dc.Attach(lpDrawItemStruct->hDC);
	rect=lpDrawItemStruct->rcItem;
	dc.Draw3dRect(&rect,RGB(255,255,255),RGB(0,0,0)); 
    dc.FillSolidRect(&rect,color);//Here you can define the required color to appear on the Button.
    UINT state=lpDrawItemStruct->itemState;  //This defines the state of the Push button either pressed or not. 
    if((state & ODS_SELECTED))
	{
		dc.DrawEdge(&rect,EDGE_SUNKEN,BF_RECT);
	}
	else
	{
		dc.DrawEdge(&rect,EDGE_RAISED,BF_RECT);
	}

	dc.SetBkColor(color);   //Setting the Text Background color
	dc.SetTextColor(RGB(255,0,0));     //Setting the Text Color

	dc.Detach();  // Detach the Button DC        
	//AfxMessageBox("called");
	// TODO:  Add your code to draw the specified item
}
Example #2
0
void OwnerDrawBtn::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
	CDC dc;
	dc.Attach(lpDrawItemStruct->hDC); 
	
	CRect rt;
	rt = lpDrawItemStruct->rcItem; //Get button rect

	UINT state = lpDrawItemStruct->itemState; //Get state of the button
	if ( (state & ODS_SELECTED) ) // If it is pressed
	{
		dc.DrawEdge(rt,EDGE_SUNKEN,BF_RECT); // Draw a sunken face
	}
	else
	{
		dc.DrawEdge(rt,EDGE_RAISED,BF_RECT); // Draw a raised face
	}

	CString strTemp;
	GetWindowText(strTemp);
	// Get the caption which have been set
	dc.SetBkMode(TRANSPARENT);
	dc.DrawText(strTemp,rt,DT_CENTER|DT_VCENTER|DT_SINGLELINE); 

}
Example #3
0
void CAboutDlg::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDIS)
{
	CDC *pDC = CDC::FromHandle(lpDIS->hDC);

	switch (lpDIS->CtlType)
	{
	case ODT_BUTTON:
	{
		TCHAR buff[128];
		::GetWindowText(lpDIS->hwndItem, buff, 128);

		pDC->FillSolidRect(&lpDIS->rcItem, RGB(0, 0, 0)); //Button color
		pDC->DrawEdge(&lpDIS->rcItem, EDGE_RAISED, BF_RECT);
		pDC->SetTextColor(RGB(255, 255, 255));
		pDC->DrawText(buff, &lpDIS->rcItem, DT_CENTER | DT_VCENTER | DT_SINGLELINE);

		if (lpDIS->itemState & ODS_FOCUS)       // If the button has focus
		{
			if (lpDIS->itemState & ODS_SELECTED)
				pDC->DrawEdge(&lpDIS->rcItem, EDGE_SUNKEN, BF_RECT);    // Draw a sunken face

			lpDIS->rcItem.top += 4;	lpDIS->rcItem.left += 4;
			lpDIS->rcItem.right -= 4; lpDIS->rcItem.bottom -= 4;

			pDC->DrawFocusRect(&lpDIS->rcItem);
		}
		break;
	}
	}
}
void CPatchPaletteButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
{
  CDC *pDC = GetDC();
  CMainFrame* pMainFrame = STATIC_DOWNCAST(CMainFrame, AfxGetMainWnd());
  
  CModelerView *pModelerView = CModelerView::GetActiveMappingNormalView();
  if( pModelerView == NULL)
  {
    pDC->FillSolidRect( &lpDrawItemStruct->rcItem, 0x00aaaaaa);
    pDC->DrawEdge( &lpDrawItemStruct->rcItem, EDGE_RAISED, BF_RECT);
  }
  else
  {
    INDEX iButtonNo = lpDrawItemStruct->CtlID - IDC_PATCH_BUTTON_BASE;
    ULONG ulCurrentMask = pModelerView->m_ModelObject.GetPatchesMask();
    CModelerDoc* pDoc = pModelerView->GetDocument();
    ULONG ulExistingMask = pDoc->m_emEditModel.GetExistingPatchesMask();
    pDC->FillSolidRect( &lpDrawItemStruct->rcItem, 0x00aaaaaa);
    // If this patch doesn't exist
    if( (ulExistingMask & (1UL << iButtonNo)) == 0)
    {
      pDC->DrawEdge( &lpDrawItemStruct->rcItem, EDGE_RAISED, BF_RECT);
    }
    // If this patch exists but it is not turned on
    else if( (ulCurrentMask & (1UL << iButtonNo)) == 0)
    {
      // If this is active patch
      if( iButtonNo == pModelerView->m_iActivePatchBitIndex)
        pDC->DrawIcon( 2, 2, pMainFrame->m_dlgPatchesPalette->m_PatchActiveIcon);
      else
        pDC->DrawIcon( 2, 2, pMainFrame->m_dlgPatchesPalette->m_PatchExistIcon);
      pDC->DrawEdge( &lpDrawItemStruct->rcItem, EDGE_RAISED, BF_RECT);
    }
    // If this patch is turned on and it is active patch
    else if( iButtonNo == pModelerView->m_iActivePatchBitIndex)
    {
      pDC->DrawIcon( 2, 2, pMainFrame->m_dlgPatchesPalette->m_PatchActiveIcon);
      pDC->DrawEdge( &lpDrawItemStruct->rcItem, EDGE_SUNKEN, BF_RECT);
    }
    // If this patch is turned on and it is not active patch
    else
    {
      pDC->DrawIcon( 2 ,2, pMainFrame->m_dlgPatchesPalette->m_PatchInactiveIcon);
      pDC->DrawEdge( &lpDrawItemStruct->rcItem, EDGE_SUNKEN, BF_RECT);
    }
  }
  ReleaseDC( pDC);
}          
Example #5
0
void CColourButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
{
	CDC*	pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
	CRect	rc = lpDrawItemStruct->rcItem;

	if (lpDrawItemStruct->CtlType == ODT_BUTTON)
	{
		// Draw 3D frame
   if (lpDrawItemStruct->itemState & (ODS_SELECTED | ODS_DISABLED))
  		pDC->DrawEdge(rc, EDGE_SUNKEN, BF_RECT|BF_ADJUST);
   else
  		pDC->DrawEdge(rc, EDGE_RAISED, BF_RECT|BF_ADJUST);

		// Draw colour
		pDC->FillSolidRect(rc, m_colour);


  // if it has the focus, draw a dotted line
  if (lpDrawItemStruct->itemState  & ODS_FOCUS)
    {
    CRect rcFocus (rc);
    rcFocus.DeflateRect (1, 1);
     if (lpDrawItemStruct->itemState & ODS_SELECTED)
       rcFocus.OffsetRect (-1, -1);  // move text as button moves
    pDC->DrawFocusRect (rcFocus); 
    }

    // Draw button text
   CString strText;
   GetWindowText(strText);

   COLORREF crOldColor;

   // if colour is dark, use white, otherwise use black
   if (((GetRValue (m_colour) & 0xFF) +
       (GetGValue (m_colour) & 0xFF) +
       (GetBValue (m_colour) & 0xFF) ) < (128 * 3))
     crOldColor = pDC->SetTextColor(RGB(255,255,255));
   else
     crOldColor = pDC->SetTextColor(RGB(0,0,0));
   if (lpDrawItemStruct->itemState & ODS_SELECTED)
     rc.OffsetRect (-1, -1);  // move text as button moves
   pDC->DrawText (strText, rc, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
   pDC->SetTextColor(crOldColor);


	}
}
void CColourPicker::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
{
    ASSERT(lpDrawItemStruct);
    
    CDC*    pDC     = CDC::FromHandle(lpDrawItemStruct->hDC);
    CRect   rect    = lpDrawItemStruct->rcItem;
    UINT    state   = lpDrawItemStruct->itemState;
    CString m_strText;

    CSize Margins(::GetSystemMetrics(SM_CXEDGE), ::GetSystemMetrics(SM_CYEDGE));

    // Draw arrow
    if (m_bActive) state |= ODS_SELECTED;
    pDC->DrawFrameControl(&m_ArrowRect, DFC_SCROLL, DFCS_SCROLLDOWN  | 
                          ((state & ODS_SELECTED) ? DFCS_PUSHED : 0) |
                          ((state & ODS_DISABLED) ? DFCS_INACTIVE : 0));

    pDC->DrawEdge(rect, EDGE_SUNKEN, BF_RECT);

    // Must reduce the size of the "client" area of the button due to edge thickness.
    rect.DeflateRect(Margins.cx, Margins.cy);

    // Fill remaining area with colour
    rect.right -= m_ArrowRect.Width();

    CBrush brush( ((state & ODS_DISABLED) || m_crColourBk == CLR_DEFAULT)? 
                  ::GetSysColor(COLOR_3DFACE) : m_crColourBk);
    CBrush* pOldBrush = (CBrush*) pDC->SelectObject(&brush);
	pDC->SelectStockObject(NULL_PEN);
    pDC->Rectangle(rect);
    pDC->SelectObject(pOldBrush);

    // Draw the window text (if any)
    GetWindowText(m_strText);
    if (m_strText.GetLength())
    {
        pDC->SetBkMode(TRANSPARENT);
        if (state & ODS_DISABLED)
        {
            rect.OffsetRect(1,1);
            pDC->SetTextColor(::GetSysColor(COLOR_3DHILIGHT));
            pDC->DrawText(m_strText, rect, DT_CENTER|DT_SINGLELINE|DT_VCENTER);
            rect.OffsetRect(-1,-1);
            pDC->SetTextColor(::GetSysColor(COLOR_3DSHADOW));
            pDC->DrawText(m_strText, rect, DT_CENTER|DT_SINGLELINE|DT_VCENTER);
        }
        else
        {
            pDC->SetTextColor((m_crColourText == CLR_DEFAULT)? 0 : m_crColourText);
            pDC->DrawText(m_strText, rect, DT_CENTER|DT_SINGLELINE|DT_VCENTER);
        }
    }

    // Draw focus rect
    if (state & ODS_FOCUS) 
    {
        rect.DeflateRect(1,1);
        pDC->DrawFocusRect(rect);
    }
}
Example #7
0
void CPropTreeList::OnPaint() 
{
	CPaintDC dc(this);
	CDC memdc;
	CBitmap* pOldBitmap;

	ASSERT(m_pProp!=NULL);

	m_pProp->ClearVisibleList();

	memdc.CreateCompatibleDC(&dc);
	pOldBitmap = memdc.SelectObject(&m_BackBuffer);

	CRect rc;
	GetClientRect(rc);

	// draw control background
	memdc.SelectObject(GetSysColorBrush(COLOR_BTNFACE));
	memdc.PatBlt(rc.left, rc.top, rc.Width(), rc.Height(), PATCOPY);

	// draw control inside fill color
	rc.DeflateRect(2,2);
	memdc.PatBlt(rc.left, rc.top, rc.Width(), rc.Height(), m_pProp->IsWindowEnabled() ? WHITENESS : PATCOPY);
	rc.InflateRect(2,2);

	// draw expand column
	memdc.SelectObject(GetSysColorBrush(COLOR_BTNFACE));
	memdc.PatBlt(0, 0, PROPTREEITEM_EXPANDCOLUMN, rc.Height(), PATCOPY);

	// draw edge
	memdc.DrawEdge(&rc, BDR_SUNKENOUTER, BF_RECT);

	CPropTreeItem* pItem;
	LONG nTotal = 0;

	ASSERT(m_pProp->GetRootItem()!=NULL);

	rc.DeflateRect(2,2);

	// create clip region
	HRGN hRgn = CreateRectRgn(rc.left, rc.top, rc.right, rc.bottom);
	SelectClipRgn(memdc.m_hDC, hRgn);

	// draw all items
	for (pItem = m_pProp->GetRootItem()->GetChild(); pItem; pItem = pItem->GetSibling())
	{
		LONG nHeight = pItem->DrawItem(&memdc, rc, 0, nTotal);
		nTotal += nHeight;
	}

	// remove clip region
	SelectClipRgn(memdc.m_hDC, NULL);
	DeleteObject(hRgn);

	// copy back buffer to the display
	dc.GetClipBox(&rc);
	dc.BitBlt(rc.left, rc.top, rc.Width(), rc.Height(), &memdc, rc.left, rc.top, SRCCOPY);
	memdc.DeleteDC();
}
Example #8
0
/*============================================================================*/
	void CustomButton::
DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)               		/*

	Custom draw the item specified in lpDrawItemStruct: here a button.
	Invoked by the view for the owner-drawn button in response to the
	WM_DRAWITEM system message. An owner-drawn button has the BS_OWNERDRAW
	style set. Also see the BS_ style values.
	
	Note: this procedure can show the focus rectangle of the button when the
	button has focus. Howeever, the focus does not appear to be cancelled
	when another control recieves the focus, and the non-owner-draw form
	of push buttons does not have this rectangle present when pressed
*-----------------------------------------------------------------------------*/
{
	  // get the device context and attach the button handle to it
	CDC dc;
	dc.Attach(lpDrawItemStruct->hDC); 
	  // determine the button rectangle
	CRect rect = lpDrawItemStruct->rcItem;
	  // draw in the button text
	dc.DrawText(GetWindowText(), -1, rect, DT_CENTER | DT_VCENTER |
	    DT_SINGLELINE);
	  // get the current state of the button
	UINT state = lpDrawItemStruct->itemState;
	if ( (state & ODS_SELECTED) )	// if it is pressed
	{
		dc.DrawEdge(rect, EDGE_SUNKEN, BF_RECT); // draw a sunken face
	}
	else
	{
		dc.DrawEdge(rect, EDGE_RAISED, BF_RECT); // draw a raised face
	}
	  // draw the focus rectangle, a dotted rectangle just inside the
	  // button rectangle when the button has the focus.
	if (lpDrawItemStruct->itemAction & ODA_FOCUS)
	{
		int iChange = 3;
		rect.top    += iChange;
		rect.left   += iChange;
		rect.right  -= iChange;
		rect.bottom -= iChange;
		dc.DrawFocusRect(rect);
	}
	dc.Detach();
}
Example #9
0
void CCustomButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
	CDC dc;
	dc.Attach(lpDrawItemStruct->hDC); //Get device context object
	CRect rt;
	rt = lpDrawItemStruct->rcItem; //Get button rect
	UINT state = lpDrawItemStruct->itemState; //Get state of the button

	if ( (state & ODS_DISABLED) ) // If it is pressed
	{
		dc.FillSolidRect(rt, RGB(80, 80, 80)); 
		dc.SetTextColor(RGB(120,120,120)); 
	}
	else
	{
		dc.FillSolidRect(rt, RGB(80, 80, 80));
		dc.SetTextColor(RGB(180,150,0)); 
	}
	CString strTemp;
	GetWindowText(strTemp);
	dc.DrawText(strTemp,rt,DT_CENTER|DT_VCENTER|DT_SINGLELINE); 


	if ( (state & ODS_SELECTED) ) // If it is pressed
	{
		dc.DrawEdge(rt,EDGE_SUNKEN,BF_RECT);
	}
	else
	{
		dc.DrawEdge(rt,EDGE_BUMP,BF_RECT); 
	}

	if ( (state & ODS_FOCUS ) ) // If the button is focused
	{
		// Draw a focus rect which indicates the user
		// that the button is focused
		int iChange = 3;
		rt.top += iChange;
		rt.left += iChange;
		rt.right -= iChange;
		rt.bottom -= iChange;
		dc.DrawFocusRect(rt);
	}
	dc.Detach();
}
void ColorPicker::drawCrossAt(CPoint &point, CDC &dc, CSize &sz)
{
    CPoint localPoint = point;
    localPoint.x -= sz.cx / 2;
    localPoint.y -= sz.cy / 2;

    CRect localRect(localPoint, sz);
    dc.DrawEdge(localRect, EDGE_BUMP, BF_TOPLEFT | BF_BOTTOMRIGHT);
}
Example #11
0
// CColoredButton message handlers
void CColoredButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
{
  EnableToolTips( TRUE);
  CDC *pDC = GetDC();
  m_rectButton = lpDrawItemStruct->rcItem;
  m_rectButton.top+=2;
  m_rectButton.bottom-=2;
  m_dx = (m_rectButton.right-m_rectButton.left)/6;
  m_dy = (m_rectButton.top-m_rectButton.bottom)/2;
  
  if( m_bMixedColor && IsWindowEnabled())
  {
    CBrush brush;
    brush.CreateHatchBrush(HS_BDIAGONAL, CLRF_CLR( RGBToColor(100,100,100)));
    pDC->FillRect( &m_rectButton, &brush);
  }
  else
  {
    ColorToComponents();
    UBYTE ubR, ubG, ubB;
    UBYTE ubH, ubS, ubV, ubA;
    ubH = m_ubComponents[0][0];
    ubS = m_ubComponents[0][1];
    ubV = m_ubComponents[0][2];
    ubA = m_ubComponents[0][3];
    ubR = m_ubComponents[1][0];
    ubG = m_ubComponents[1][1];
    ubB = m_ubComponents[1][2];

  #define FILL_RECT( col, x, y, w, h) {\
      RECT rectToFill;\
      rectToFill.left = m_rectButton.left+m_dx*x;\
      if( w<0) rectToFill.right = m_rectButton.right-2;\
      else rectToFill.right = m_rectButton.left+rectToFill.left+m_dx*w;\
      rectToFill.top = m_rectButton.top-m_dy*y;\
      rectToFill.bottom = m_rectButton.top+rectToFill.top-m_dy*h;\
      COLORREF clrfColor = CLRF_CLR( col);\
      if( !IsWindowEnabled()) clrfColor = CLRF_CLR( 0xBBBBBBBB);\
      pDC->FillSolidRect( &rectToFill, clrfColor);\
      pDC->DrawEdge( &rectToFill, EDGE_SUNKEN, BF_RECT);}

    FILL_RECT( HSVToColor( ubH, 255, 255), 0, 0, 1, 1);
    FILL_RECT( HSVToColor( ubH, ubS, 255), 1, 0, 1, 1);
    FILL_RECT( HSVToColor( ubH, 0, ubV), 2, 0, 1, 1);
    FILL_RECT( RGBToColor( ubA, ubA, ubA), 3, 0, 1, 2);
    FILL_RECT( RGBToColor( ubR, 0, 0), 0, 1, 1, 1);
    FILL_RECT( RGBToColor( 0, ubG, 0), 1, 1, 1, 1);
    FILL_RECT( RGBToColor( 0, 0, ubB), 2, 1, 1, 1);
    FILL_RECT( m_colColor, 4, 0, 2, 2);
  }

  pDC->DrawEdge( &lpDrawItemStruct->rcItem, EDGE_BUMP, BF_RECT);
  ReleaseDC( pDC);
}
Example #12
0
void CODMenu::DrawItem (LPDRAWITEMSTRUCT lpDIS)
{
	ASSERT(lpDIS != NULL);
	CDC* pDC = CDC::FromHandle(lpDIS->hDC);
	CRect rect;
	UINT state = (((CODMenuData*)(lpDIS->itemData))->nFlags);
	if(state & MF_SEPARATOR){
		rect.CopyRect(&lpDIS->rcItem);
		rect.top+=rect.Height()>>1;
		pDC->DrawEdge(&rect,EDGE_ETCHED,BF_TOP);
	}
Example #13
0
void CColorButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
    CDC dc;
    CRect rt;

    rt = lpDrawItemStruct->rcItem;
    dc.Attach(lpDrawItemStruct->hDC);
    dc.FillSolidRect(rt, m_crBack);

    UINT state = lpDrawItemStruct->itemState;   //Get state of the button
    if ((state & ODS_SELECTED))                 // If it is pressed
    {
        dc.DrawEdge(rt, EDGE_SUNKEN, BF_RECT);  // Draw a sunken face
    }
    else
    {
        dc.DrawEdge(rt, EDGE_RAISED, BF_RECT);  // Draw a raised face
    }

    dc.Detach();
}
Example #14
0
void CMFECToolTip::DisplayInfo( ToolTipInfo* pToolTip )
{
	if( pToolTip->nInfoSize <= 0 )
		return;

	ASSERT(m_pParentWnd);

	CDC* pDC = m_pParentWnd->GetDC();

	CRect		oInfoRect;
	CBrush		oBrush, *pOldBrush, oBorderBrush;
	int			nX, nY;
	TEXTMETRIC	TM;
	int			nTextHigh;
	CFont		oFont, *pOldFont;
	CWnd*		pWnd = NULL;
	
	oBrush.CreateSolidBrush( pToolTip->nBackColor );

	pOldBrush = pDC->SelectObject( &oBrush );
	pDC->SetTextColor( pToolTip->nTextColor );

	//calculate the width and height of the box dynamically
	CalculateHeightAndWidth( pToolTip->nControlInfo ); 
	CalculateInfoBoxRect( pToolTip->nControlID, &oInfoRect );

	oFont.CreateFont(m_nFontSize, 0, 0, 0, FW_REGULAR, 0, 0, 0, 0, 0, 0, 0, 0, "���ו");
	pOldFont = pDC->SelectObject(&oFont);	
	pDC->FillRect(&oInfoRect, &oBrush);
	pDC->SelectObject(pOldBrush);
	oBrush.DeleteObject();

	oBorderBrush.CreateSolidBrush( pToolTip->nTextColor );
	pOldBrush = pDC->SelectObject(&oBorderBrush);

  pDC->DrawEdge(&oInfoRect, BDR_RAISEDINNER  , BF_RECT);

	pDC->SetTextAlign(TA_LEFT);
	pDC->GetTextMetrics(&TM);
	nTextHigh = TM.tmHeight + TM.tmExternalLeading - 2;
	nX = oInfoRect.left + 2;
	nY = oInfoRect.top + 3; 

	for( register UINT i = 0; i < pToolTip->nInfoSize; i++)
	{
		pDC->TextOut(nX, nY, pToolTip->nControlInfo[i]);
		nY += m_nFontSize - 1;
	}

	pDC->SelectObject(pOldBrush);
	oBorderBrush.DeleteObject();	
	m_pParentWnd->ReleaseDC(pDC);
}	
Example #15
0
void CMyBtn::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{

	 CDC dc;
	dc.Attach(lpDrawItemStruct->hDC); //Get device context object
	CRect rt;
	rt = lpDrawItemStruct->rcItem; //Get button rect
 
	dc.FillSolidRect(rt, RGB(0, 0, 255)); //Fill button with blue color
 
	UINT state = lpDrawItemStruct->itemState; //Get state of the button
	if ( (state & ODS_SELECTED) ) // If it is pressed
	{
	dc.DrawEdge(rt,EDGE_SUNKEN,BF_RECT); // Draw a sunken face
	}
	else
	{
	dc.DrawEdge(rt,EDGE_RAISED,BF_RECT); // Draw a raised face
	}
 
	dc.SetTextColor(RGB(255,255,120));
	// Set the color of the caption to be yellow
	CString strTemp;
	GetWindowText(strTemp);
	// Get the caption which have been set
	dc.DrawText(strTemp,rt,DT_CENTER|DT_VCENTER|DT_SINGLELINE);
	// Draw out the caption
	if ( (state & ODS_FOCUS ) ) // If the button is focused
	{
	// Draw a focus rect which indicates the user
	// that the button is focused
	int iChange = 3;
	rt.top += iChange;
	rt.left += iChange;
	rt.right -= iChange;
	rt.bottom -= iChange;
	dc.DrawFocusRect(rt);
	}
	dc.Detach();
}
Example #16
0
void CPropertyList::DrawItem(LPDRAWITEMSTRUCT lpDIS) {
	CDC dc;
	dc.Attach(lpDIS->hDC);
	CRect rectFull = lpDIS->rcItem;
	CRect rect = rectFull;
	if (m_nDivider==0) {
		m_nDivider = rect.Width() / 2;
	}
	rect.left = m_nDivider;
	CRect rect2 = rectFull;
	rect2.right = rect.left - 1;
	UINT nIndex = lpDIS->itemID;

	if (nIndex != (UINT) -1) {
		//get the CPropertyItem for the current row
		CPropertyItem* pItem = (CPropertyItem*) GetItemDataPtr(nIndex);
		//draw two rectangles, one for each row column
		if (pItem->m_nItemType == PIT_VAR) {
			dc.FillSolidRect(rect2,RGB(220,220,220));
		} else {
			dc.FillSolidRect(rect2,RGB(192,192,192));
		}
		dc.DrawEdge(rect2,EDGE_SUNKEN,BF_BOTTOMRIGHT);
		dc.DrawEdge(rect,EDGE_SUNKEN,BF_BOTTOM);
		
		if (lpDIS->itemState == ODS_SELECTED) {
			dc.DrawFocusRect(rect2);
		}

		//write the property name in the first rectangle
		dc.SetBkMode(TRANSPARENT);
		dc.DrawText(pItem->m_propName,CRect(rect2.left+3,rect2.top+3,
											rect2.right-3,rect2.bottom+3),
					DT_LEFT | DT_SINGLELINE);

		//write the initial property value in the second rectangle
		dc.DrawText(pItem->m_curValue,CRect(rect.left+3,rect.top+3, rect.right+3,rect.bottom+3), DT_LEFT | (pItem->m_nItemType == PIT_VAR) ? DT_WORDBREAK : DT_SINGLELINE);
	}
	dc.Detach();
}
void CColorSelector::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
    // TODO: Add your message handler code here and/or call default
    CDC omDc;
    omDc.Attach(lpDrawItemStruct->hDC);
	UINT unButtonState  = lpDrawItemStruct->itemState;
	int nPushState = ((unButtonState & ODS_SELECTED) ? DFCS_PUSHED : 0) |
					 ((unButtonState & ODS_DISABLED) ? DFCS_INACTIVE : 0);

    CRect omItemRect    = lpDrawItemStruct->rcItem;
    
	
    
	CRect omArrowRect;
    omArrowRect.left = max(0, omItemRect.Width()- GetSystemMetrics(SM_CXHTHUMB) - 3 );
    omArrowRect.right = max(0, omItemRect.Width()-3);
    omArrowRect.top = 3;
    omArrowRect.bottom = max(omItemRect.Height()-3, GetSystemMetrics(SM_CYVTHUMB)-3);
    
	
    omDc.DrawFrameControl(&omArrowRect, DFC_SCROLL, DFCS_SCROLLDOWN  | nPushState);

    // Create backgroung brush
    CBrush brush( m_omColorBkg);
    omDc.SelectStockObject(BLACK_PEN);
    omDc.DrawEdge(&lpDrawItemStruct->rcItem, EDGE_RAISED, BF_RECT);
    CRect omButtonRect;
    
    omButtonRect.left = lpDrawItemStruct->rcItem.left+5;
    omButtonRect.top = lpDrawItemStruct->rcItem.top+5;
    omButtonRect.right = lpDrawItemStruct->rcItem.right - omArrowRect.Width()-5;// - omArrowRect.Width() ;
    omButtonRect.bottom = lpDrawItemStruct->rcItem.bottom - 5;
    
    //omButtonRect.DeflateRect(3, 3);
    omDc.FillRect(omButtonRect, &brush);
    // Select Old Brush
    omDc.SelectObject(brush);
    
    omButtonRect.DeflateRect(-1, -1);
    
    omDc.Rectangle(omButtonRect);

    if (unButtonState & ODS_FOCUS) 
    {
        omButtonRect.DeflateRect(1,1);
        omDc.DrawFocusRect(omButtonRect);
    }
}
Example #18
0
LRESULT FProgress::OnPaint(UINT, WPARAM, LPARAM, BOOL&)
{
	CPaintDC PaintDC(m_hWnd); 
	FRect rcPaint, rcClient; 
	GetClientRect(&rcClient); 
	rcPaint = rcClient; 
	CDC dcCompat;	 dcCompat.CreateCompatibleDC(PaintDC);
	CBitmap bmCompat;bmCompat.CreateCompatibleBitmap(PaintDC, rcPaint.Width(), rcPaint.Height()); 
	dcCompat.SelectBitmap(bmCompat);

	dcCompat.FillRect(&rcPaint, m_BgBrush);

	dword dwStyle = GetWindowLong(GWL_STYLE); 
	if (dwStyle & PROG_DRAW_EDGE)
		dcCompat.DrawEdge(&rcPaint, EDGE_ETCHED, BF_RECT | BF_ADJUST);

	DrawMeter(dcCompat, rcPaint); 
	PaintDC.BitBlt(0, 0, rcClient.Width(), rcClient.Height(), dcCompat, 0, 0, SRCCOPY); 
	return 0; 
}
void CColorButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
{
	RECT ClientRect;

	// get a cdc
	CDC* pDC = CDC::FromHandle( lpDrawItemStruct->hDC );

	// now draw a solid rectangle
	pDC->FillSolidRect( &lpDrawItemStruct->rcItem, mCurrentColor);

	{
		// draw the button's text...
		CString Text;

		this->GetClientRect (&ClientRect);

		this->GetWindowText (Text);
		pDC->DrawText( Text, &ClientRect, DT_CENTER |DT_VCENTER|DT_SINGLELINE ) ;
	}
	// if we have the focus

	if( lpDrawItemStruct->itemState & ODS_FOCUS ) {
		// get a null brush
		CBrush *NullBrush = CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH)), *OldBrush;

		// select the brush
		OldBrush = pDC->SelectObject( NullBrush );

		// draw a cute rectangle around it
		pDC->Rectangle(&lpDrawItemStruct->rcItem);

		// get old
		pDC->SelectObject( OldBrush );
	}
	pDC->DrawEdge( &ClientRect, EDGE_RAISED, BF_RECT ) ;

}
Example #20
0
//***********************************************************************
// Method:	CColorButton::DrawItem()
// Notes:	None.
//***********************************************************************
void CColorButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
{
	ASSERT(lpDrawItemStruct);

	CDC*    pDC      = CDC::FromHandle(lpDrawItemStruct->hDC);
	UINT    state    = lpDrawItemStruct->itemState;
    CRect   rDraw    = lpDrawItemStruct->rcItem;
	CRect	rArrow;

	if (m_bPopupActive)
		state |= ODS_SELECTED|ODS_FOCUS;

	//******************************************************
	//**                  Draw Outer Edge
	//******************************************************
	UINT uFrameState = DFCS_BUTTONPUSH|DFCS_ADJUSTRECT;

	if (state & ODS_SELECTED)
		uFrameState |= DFCS_PUSHED;

	if (state & ODS_DISABLED)
		uFrameState |= DFCS_INACTIVE;
	
	pDC->DrawFrameControl(&rDraw,
						  DFC_BUTTON,
						  uFrameState);


	if (state & ODS_SELECTED)
		rDraw.OffsetRect(1,1);

	//******************************************************
	//**                     Draw Focus
	//******************************************************
	if (state & ODS_FOCUS) 
    {
		RECT rFocus = {rDraw.left,
					   rDraw.top,
					   rDraw.right - 1,
					   rDraw.bottom};
  
        pDC->DrawFocusRect(&rFocus);
    }

	rDraw.DeflateRect(::GetSystemMetrics(SM_CXEDGE),
					  ::GetSystemMetrics(SM_CYEDGE));

	//******************************************************
	//**                     Draw Arrow
	//******************************************************
	rArrow.left		= rDraw.right - g_ciArrowSizeX - ::GetSystemMetrics(SM_CXEDGE) /2;
	rArrow.right	= rArrow.left + g_ciArrowSizeX;
	rArrow.top		= (rDraw.bottom + rDraw.top)/2 - g_ciArrowSizeY / 2;
	rArrow.bottom	= (rDraw.bottom + rDraw.top)/2 + g_ciArrowSizeY / 2;

	DrawArrow(pDC,
			  &rArrow,
			  0,
			  (state & ODS_DISABLED) 
			  ? ::GetSysColor(COLOR_GRAYTEXT) 
			  : RGB(0,0,0));


	rDraw.right = rArrow.left - ::GetSystemMetrics(SM_CXEDGE)/2;

	//******************************************************
	//**                   Draw Separator
	//******************************************************
	pDC->DrawEdge(&rDraw,
				  EDGE_ETCHED,
				  BF_RIGHT);

	rDraw.right -= (::GetSystemMetrics(SM_CXEDGE) * 2) + 1 ;
				  
	//******************************************************
	//**                     Draw Color
	//******************************************************
	if ((state & ODS_DISABLED) == 0)
	{
		pDC->FillSolidRect(&rDraw,
						   (m_Color == CLR_DEFAULT)
						   ? m_DefaultColor
						   : m_Color);

		::FrameRect(pDC->m_hDC,
					&rDraw,
					(HBRUSH)::GetStockObject(BLACK_BRUSH));
	}
}
void COptionTreeFontSelColorButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
{
	// Validate
	ASSERT(lpDrawItemStruct);

	// Declare variables
	CDC* pDC  = CDC::FromHandle(lpDrawItemStruct->hDC);
	UINT state = lpDrawItemStruct->itemState;
    CRect rDraw = lpDrawItemStruct->rcItem;
	CRect rArrow;
	UINT uFrameState;

	// Active popup
	if (m_bPopupActive)
	{
		state |= ODS_SELECTED | ODS_FOCUS;
	}

	// Frame state
	uFrameState = DFCS_BUTTONPUSH | DFCS_ADJUSTRECT;

	// Selected
	if (state & ODS_SELECTED)
	{
		uFrameState |= DFCS_PUSHED;
	}

	// Disabled
	if (state & ODS_DISABLED)
	{
		uFrameState |= DFCS_INACTIVE;
	}
	
	// Draw frame
	pDC->DrawFrameControl(&rDraw, DFC_BUTTON, uFrameState);


	// Offset rectangle if selected
	if (state & ODS_SELECTED)
	{
		rDraw.OffsetRect(1,1);
	}

	// Draw focus
	if (state & ODS_FOCUS) 
    {
		RECT rFocus = {rDraw.left, rDraw.top, rDraw.right - 1, rDraw.bottom};
  
        pDC->DrawFocusRect(&rFocus);
    }
	rDraw.DeflateRect(::GetSystemMetrics(SM_CXEDGE), ::GetSystemMetrics(SM_CYEDGE));

	// Draw arrow
	rArrow.left = rDraw.right - g_ciArrowSizeX - ::GetSystemMetrics(SM_CXEDGE) /2;
	rArrow.right = rArrow.left + g_ciArrowSizeX;
	rArrow.top = (rDraw.bottom + rDraw.top)/2 - g_ciArrowSizeY / 2;
	rArrow.bottom = (rDraw.bottom + rDraw.top)/2 + g_ciArrowSizeY / 2;
	DrawArrow(pDC, &rArrow, 0,(state & ODS_DISABLED) ? ::GetSysColor(COLOR_GRAYTEXT) : RGB(0,0,0));
	rDraw.right = rArrow.left - ::GetSystemMetrics(SM_CXEDGE)/2;

	// Draw seperator
	pDC->DrawEdge(&rDraw, EDGE_ETCHED, BF_RIGHT);
	rDraw.right -= (::GetSystemMetrics(SM_CXEDGE) * 2) + 1 ;
				  
	// Draw color
	if ((state & ODS_DISABLED) == 0)
	{
		pDC->FillSolidRect(&rDraw, (m_crColor == CLR_DEFAULT) ? m_crDefaultColor : m_crColor);

		::FrameRect(pDC->m_hDC, &rDraw, (HBRUSH)::GetStockObject(BLACK_BRUSH));
	}
}
Example #22
0
//--------------------------------------------------------------------------
// 버튼 색을 동적으로 변하게하는 함수
//--------------------------------------------------------------------------
void CDrawProperty::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
{
	UpdateData();
	CDC dc;
	CRect rect;
	UINT state;
	
	//////////////////////////////////////////////////////////////////////////
	// 버튼 그리기 작업 초기화
	if (nIDCtl == IDC_BUTTON_LINECOLOR || nIDCtl == IDC_BUTTON_FILLCOLOR || nIDCtl == IDC_BUTTON_FILLCOLOR2)
	{
		dc.Attach(lpDrawItemStruct->hDC);
		rect = lpDrawItemStruct->rcItem;
		state = lpDrawItemStruct->itemState;	
	}

	switch (nIDCtl)
	{
	//////////////////////////////////////////////////////////////////////////
	// 라인색 버튼의 색 지정
	case IDC_BUTTON_LINECOLOR:
		{
			dc.Draw3dRect(&rect, RGB(255,255,255), RGB(0,0,0));
			if(state & ODS_DISABLED)
				dc.FillSolidRect(&rect, ::GetSysColor(COLOR_BTNFACE)); //비활성화색
			else
				dc.FillSolidRect(&rect, CDrawPropertyValue::m_sLineColor); //버튼 색 지정
				

			if(state & ODS_SELECTED)
				dc.DrawEdge(&rect, EDGE_SUNKEN, BF_RECT);
			else
				dc.DrawEdge(&rect, EDGE_RAISED, BF_RECT);

			COLORREF invertColor = CDrawPropertyValue::m_sLineColor ^ 0x00FFFFFF; //색반전
			dc.SetTextColor(invertColor);
			
			CString str = L"Line\n(Text)";
			CRect textRect = rect;
			textRect.top += textRect.CenterPoint().y/2;
			dc.DrawText(str, textRect,  DT_CENTER | DT_VCENTER | BS_MULTILINE | DT_NOCLIP);
			break;
		}
	//////////////////////////////////////////////////////////////////////////
	// 채우기 색 버튼의 색 지정
	case IDC_BUTTON_FILLCOLOR:
		{
			dc.Draw3dRect(&rect, RGB(255,255,255), RGB(0,0,0));

			if(state & ODS_DISABLED)
				dc.FillSolidRect(&rect, ::GetSysColor(COLOR_BTNFACE)); //비활성화색				
			else
				dc.FillSolidRect(&rect, CDrawPropertyValue::m_sBrushColor); //버튼 색 지정


			if(state & ODS_SELECTED)
				dc.DrawEdge(&rect, EDGE_SUNKEN, BF_RECT);
			else
				dc.DrawEdge(&rect, EDGE_RAISED, BF_RECT);

			COLORREF invertColor = CDrawPropertyValue::m_sBrushColor ^ 0x00FFFFFF; //색반전
			if(state & ODS_DISABLED)
				invertColor = ::GetSysColor(COLOR_GRAYTEXT);
			dc.SetTextColor(invertColor);

			CString str = L"Fill";
			if(state & ODS_DISABLED)
				str.SetString(L"Not Use");
			dc.DrawText(str, rect, DT_CENTER | DT_SINGLELINE | DT_VCENTER);
			break;
		}
	//////////////////////////////////////////////////////////////////////////
	// 그라디언트 끝 색 버튼의 색 지정
	case IDC_BUTTON_FILLCOLOR2:
		{
			dc.Draw3dRect(&rect, RGB(255,255,255), RGB(0,0,0));

			if(state & ODS_DISABLED)
				dc.FillSolidRect(&rect, ::GetSysColor(COLOR_BTNFACE)); //비활성화색
			else
				dc.FillSolidRect(&rect, CDrawPropertyValue::m_sGradientEndColor); //버튼 색 지정

			if(state & ODS_SELECTED)
				dc.DrawEdge(&rect, EDGE_SUNKEN, BF_RECT);
			else
				dc.DrawEdge(&rect, EDGE_RAISED, BF_RECT);

			COLORREF invertColor = CDrawPropertyValue::m_sGradientEndColor ^ 0x00FFFFFF; //색반전
			if(state & ODS_DISABLED)
				invertColor = ::GetSysColor(COLOR_GRAYTEXT);
			dc.SetTextColor(invertColor);

			CString str = L"Grd End";
			if(state & ODS_DISABLED)
				str.SetString(L"Not Use");
			dc.DrawText(str, rect, DT_CENTER | DT_SINGLELINE | DT_VCENTER);
			break;
		}
	//////////////////////////////////////////////////////////////////////////
	// 라인 패턴 그리기
	case IDC_LINEPATTERN:
		if(m_sLinePtnCombo.GetSafeHwnd())
			m_sLinePtnCombo.DrawItem(lpDrawItemStruct);
		break;
	//////////////////////////////////////////////////////////////////////////
	// 채우기 패턴(HATCH STYLE) 그리기
	case IDC_FILLPATTERN:
		if(m_sFillPtnCombo.GetSafeHwnd())
			m_sFillPtnCombo.DrawItem(lpDrawItemStruct);
		break;
	//////////////////////////////////////////////////////////////////////////
	// 그라디언트 패턴 그리기
	case IDC_COMBO_GRADIENT:
		if(m_sGradientCombo.GetSafeHwnd())
			m_sGradientCombo.DrawItem(lpDrawItemStruct);
		break;
	}
	dc.Detach();
//	CDialog::OnDrawItem(nIDCtl, lpDrawItemStruct);
}
Example #23
0
void COptionTreeList::OnPaint() 
{
	// Make sure valid
	if (m_otOption == NULL)
	{
		return;
	}
	
	// Declare variables
	CPaintDC dc(this);
	CDC* pDCMem = new CDC;
	CBitmap bpMem;
	CBitmap *bmOld;
	COptionTreeItem* otiItem;
	CRect rcClient;
	HGDIOBJ hOldBrush;
	long lTotal, lHeight;
	HRGN hRgn;

	// Get client rectangle
	GetClientRect(rcClient);

	// Clear visible list
	m_otOption->ClearVisibleList();

	// Clear all label rectangle
	m_otOption->ClearAllLabelRect();

	// Create DC
	pDCMem->CreateCompatibleDC(&dc);

	// Create bitmap
	bpMem.CreateCompatibleBitmap(&dc, rcClient.Width(), rcClient.Height());

	// Select bitmap
	bmOld = pDCMem->SelectObject(&bpMem);

	// Draw control background
	hOldBrush = pDCMem->SelectObject(GetSysColorBrush(COLOR_BTNFACE));
	pDCMem->PatBlt(rcClient.left, rcClient.top, rcClient.Width(), rcClient.Height(), PATCOPY);

	// Draw control inside fill color
	rcClient.DeflateRect(2, 2);
	if (m_otOption->IsWindowEnabled() == TRUE)
	{
		pDCMem->SelectObject(GetSysColorBrush(COLOR_WINDOW));
	}
	else
	{
		pDCMem->SelectObject(GetSysColorBrush(COLOR_3DFACE));
	}
	pDCMem->PatBlt(rcClient.left, rcClient.top, rcClient.Width(), rcClient.Height(), PATCOPY);
	rcClient.InflateRect(2, 2);

	// Draw expand column	
	if (m_otOption->GetShadeExpandColumn() == TRUE || m_otOption->IsWindowEnabled() == FALSE)
	{
		pDCMem->SelectObject(GetSysColorBrush(COLOR_BTNFACE));
	}
	else
	{
		pDCMem->SelectObject(GetSysColorBrush(COLOR_WINDOW));
	}
	pDCMem->PatBlt(0, 0, OT_EXPANDCOLUMN, rcClient.Height(), PATCOPY);

	// Create clip region
	hRgn = CreateRectRgn(rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
	SelectClipRgn(pDCMem->m_hDC, hRgn);

	// Draw all items
	lTotal = 0;
	for (otiItem = m_otOption->GetRootItem()->GetChild(); otiItem != NULL; otiItem = otiItem->GetSibling())
	{
		lHeight = otiItem->DrawItem(pDCMem, rcClient, 0, lTotal);
		lTotal += lHeight;
	}

	// Remove clip region
	SelectClipRgn(pDCMem->GetSafeHdc(), NULL);
	DeleteObject(hRgn);

	// Draw vertical sep
	_DrawDarkVLine(pDCMem->GetSafeHdc(), OT_EXPANDCOLUMN, 0, rcClient.bottom);

	// Draw edge
	pDCMem->DrawEdge(&rcClient, BDR_SUNKENOUTER, BF_RECT);

	// Draw draw column
	if (m_bColDrag == TRUE)
	{
		_DrawXorBar(pDCMem->GetSafeHdc(), m_lColumn - OT_COLRNG / 2, 0, 4, rcClient.bottom);
	}

	// Copy back buffer to the display
	dc.BitBlt(0, 0, rcClient.Width(), rcClient.Height(), pDCMem, 0, 0, SRCCOPY);
	
	// Select old objects
	pDCMem->SelectObject(hOldBrush);
	pDCMem->SelectObject(bmOld);
	
	// Delete objects
	if (pDCMem->GetSafeHdc() != NULL)
	{
		pDCMem->DeleteDC();
	}
	delete pDCMem;
	if (bpMem.GetSafeHandle() != NULL)
	{
		bpMem.DeleteObject();
	}

}
Example #24
0
//CListCtrl控件的DrawItem消息
void CMyListCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{

	// TODO:  添加您的代码以绘制指定项
	TCHAR lpBuffer[CELL_MAXLEN];
	int nRow=lpDrawItemStruct->itemID;
	
	LV_ITEM lvi;

	LV_COLUMN lvc, lvcprev ;
	::ZeroMemory(&lvc, sizeof(lvc));
	::ZeroMemory(&lvcprev, sizeof(lvcprev));
	lvc.mask = LVCF_WIDTH | LVCF_FMT;
	lvcprev.mask = LVCF_WIDTH | LVCF_FMT;

	CDC* pDC;
	pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
	
	CRect rtClient;
	GetClientRect(&rtClient);
	//////////////////////////////////////////////////////////////////////////
	for ( int nCol=0; GetColumn(nCol, &lvc); nCol++)
	{
		HEADCELL* pHead=m_Head.FindHeadCell(nCol);
		CELLVALUE* pCell=m_val.GetAt(nRow,nCol);
		if ( nCol > 0 ) 
		{
			// Get Previous Column Width in order to move the next display item
			GetColumn(nCol-1, &lvcprev) ;
			lpDrawItemStruct->rcItem.left += lvcprev.cx ;
			lpDrawItemStruct->rcItem.right += lpDrawItemStruct->rcItem.left; 
		}

		CRect rcItem;
		if (!GetSubItemRect(lpDrawItemStruct->itemID,nCol,LVIR_LABEL,rcItem))   
			continue;   

		::ZeroMemory(&lvi, sizeof(lvi));
		lvi.iItem = lpDrawItemStruct->itemID;
		lvi.mask = LVIF_TEXT | LVIF_PARAM;
		lvi.iSubItem = nCol;
		lvi.pszText = lpBuffer;
		lvi.cchTextMax = sizeof(lpBuffer);
		VERIFY(GetItem(&lvi));
		CRect rcTemp;
		rcTemp = rcItem;

		if (nCol==0)
		{
			rcTemp.left -=2;
		}

		//背景色
		CRect rcBk,rct;
		GetCellRect(nRow,nCol,rct);
		rcBk=rct;
		//////////////////////////////////////////////////////////////////////////
		if(nRow==0)	rcBk.top-=1;
		else		rcBk.top+=1;
		rcBk.bottom-=1;
		//////////////////////////////////////////////////////////////////////////
		COLORREF color;
		color = GetBkColor();
		pDC->FillSolidRect(rcBk,color);
		if(color==RGB(212,208,200)){
			rct.top-=1;
			rct.right+=1;
			pDC->DrawEdge(&rct,BDR_RAISEDINNER | EDGE_RAISED ,BF_RECT);
		}

		//列
		if(FindColColor(nCol,color)>-1)
		{
			pDC->FillSolidRect(rcBk,color);
			if(color==RGB(212,208,200)){
				rct.top-=1;
				rct.right+=1;
				pDC->DrawEdge(&rct,BDR_RAISEDINNER | EDGE_RAISED ,BF_RECT);
			}
		}
		//行
		if(FindRowColor(nRow,color)>-1)
		{
			pDC->FillSolidRect(rcBk,color);
			if(color==RGB(212,208,200)){
				rct.top-=1;
				rct.right+=1;
				pDC->DrawEdge(&rct,BDR_RAISEDINNER | EDGE_RAISED ,BF_RECT);
			}
		}
		//单元格
		if(FindItemColor(nCol,nRow,color)>-1)
		{
			pDC->FillSolidRect(rcBk,color);
			if(color==RGB(212,208,200)){
				rct.top-=1;
				rct.right+=1;
				pDC->DrawEdge(&rct,BDR_RAISEDINNER | EDGE_RAISED ,BF_RECT);
			}
		}
		//////////////////////////////////////////////////////////////////////////
		COLORREF colorBack=color;
		//////////////////////////////////////////////////////////////////////////

		UINT   uFormat = DT_CENTER;

		if (pHead && pHead->cFormat==0)
		{
			uFormat = DT_LEFT;
		}
		else if (pHead && pHead->cFormat==1)
		{
			uFormat = DT_CENTER;
		}
		else if (pHead && pHead->cFormat==2)
		{
			uFormat = DT_RIGHT;
		}
		TEXTMETRIC metric;
		pDC->GetTextMetrics(&metric);
		int ofst;
		ofst = rcItem.Height() - metric.tmHeight;
		rcItem.OffsetRect(0,ofst/2);
		//文本颜色!
		pDC->SetTextColor(RGB(0,0,0));

		//列
		if(FindColTextColor(nCol,color)>-1)
		{
			pDC->SetTextColor(color);
		}
		//行
		if(FindRowTextColor(nRow,color)>-1)
		{
			pDC->SetTextColor(color);
		}
		//单元格
		if(FindItemTextColor(nCol,nRow,color)>-1)
		{
			pDC->SetTextColor(color);
		}
		////////////////////////////////////////////////////////////////
		//选中状态!
		//if ( lpDrawItemStruct->itemState & ODS_SELECTED )//选中状态!
		////////////////////////////////////////////////////////////////
		//选中一列
		if(m_bColSelectedMode)
		{
			if(nCol==m_nColSelected)
			{
				this->GetSubItemRect(nRow,nCol,LVIR_BOUNDS,rct);
				pDC->FillSolidRect(&rct,RGB(234,236,245));

				if(nRow==0)
				{
					pDC->FillSolidRect(rct.left+2,rct.top+1,rct.Width()-3,2,RGB(10,36,106));
					pDC->FillSolidRect(rct.left+2,rct.top+1,2,rct.Height()+1,RGB(10,36,106));
					pDC->FillSolidRect(rct.right-3,rct.top+1,2,rct.Height()+1,RGB(10,36,106));
				}
				else if(nRow==GetItemCount()-1)
				{
					pDC->FillSolidRect(rct.left+2,rct.bottom-3,rct.Width()-3,2,RGB(10,36,106));
					pDC->FillSolidRect(rct.left+2,rct.top+1,2,rct.Height()-2,RGB(10,36,106));
					pDC->FillSolidRect(rct.right-3,rct.top+1,2,rct.Height()-2,RGB(10,36,106));
				}
				else
				{
					pDC->FillSolidRect(rct.left+2,rct.top,2,rct.Height()+1,RGB(10,36,106));
					pDC->FillSolidRect(rct.right-3,rct.top,2,rct.Height()+1,RGB(10,36,106));
				}
			}
		}
		//行选中
		if ( m_nCurSelected!=-1 && m_nCurSelected==nRow )
		{
			//选中一行
			if(m_bLineSelected)
			{
				CPen pen,*pOld;
				pen.CreatePen(PS_SOLID,2,RGB(10,36,106));
				CBrush *pBrush=CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH));//创建空画刷,防止遮挡内容;
				CBrush *pOldBrush;

				//先是每个单元绘制背景,然后再画一个透明背景的一行矩形框
				if(m_bLineSelectBkColor)
				{
					if(colorBack!=RGB(212,208,200) || nCol != 0){
						this->GetSubItemRect(nRow,nCol,LVIR_BOUNDS,rct);
						pDC->FillSolidRect(&rct,RGB(234,236,245));
					}
				}

				pOld=pDC->SelectObject(&pen);
				pOldBrush=pDC->SelectObject(pBrush);

				CRect rct;
				this->GetItemRect(nRow,&rct,LVIR_BOUNDS);
				FindColColor(0,colorBack);
				if(colorBack==RGB(212,208,200)){
					GetCellRect(nRow,0,rcBk);
					rct.left+=rcBk.Width();
				}
				//////////////////////////////////////////////////
				rct.top+=1;
				rct.left+=2;
				rct.bottom-=1;
				rct.right-=1;
				pDC->Rectangle(&rct);
				pDC->SetTextColor(RGB(0,0,255));
				pDC->SelectObject(pOldBrush);
				pDC->SelectObject(pOld);
				pen.DeleteObject();
			}
			//选中某一个单元
			else
			{
				if(m_nCurSelCol!=-1 && m_nCurSelCol==nCol)
				{
					CPen pen,*pOld;
					pen.CreatePen(PS_SOLID,2,RGB(10,36,106));
					CBrush *pBrush=CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH));//创建空画刷,防止遮挡内容
					CBrush *pOldBrush;

					pOld=pDC->SelectObject(&pen);
					pOldBrush=pDC->SelectObject(pBrush);

					CRect rct;
					rct=rcTemp;
					rct.top+=1;
					rct.left+=2;
					rct.bottom-=1;
					rct.right-=1;
					pDC->Rectangle(&rct);
			
					pDC->SelectObject(pOldBrush);
					pDC->SelectObject(pOld);
					pen.DeleteObject();
				}
			}
		}
		/////////////////////////////////////////////////////////////////
		//贴位图!
		CBitmap bmp,*pOldBmp;
		CDC memDC;
		memDC.CreateCompatibleDC(pDC);
		if(pCell)
		{
			CRect rect;
			GetCellRect(pCell->dwRow,pCell->dwCol,rect);
			if(pCell->nIDResource>0 && bmp.LoadBitmap(pCell->nIDResource))
			{
				BITMAP bm;
				bmp.GetBitmap(&bm);
				pOldBmp=memDC.SelectObject(&bmp);
				int offH=rect.Height()-bm.bmHeight;
				int offW=rect.Width()-bm.bmWidth;
				if(offH>0)
				{
					rect.top+=offH/2;
					rect.bottom-=(offH-offH/2);
				}
				if(offW>0)
				{
					rect.left+=offW/2;
					rect.right-=(offW-offW/2);
				}
				//显示
				pDC->StretchBlt(rect.left,rect.top,rect.Width(),rect.Height(),&memDC,0,0,\
					bm.bmWidth,bm.bmHeight,SRCCOPY);
				//Clean
				memDC.SelectObject(pOldBmp);
				bmp.DeleteObject();
			}
		}
		//Clean
		memDC.DeleteDC();
		///////////////////////////////////////////////
		//文本字体
		CFont * pOldFont=NULL; 
		if(m_pFont!=NULL)
			pOldFont = pDC->SelectObject(m_pFont);

		int nFontID=FindColFont(nCol);
		if(nFontID>=0)
		{
			pDC->SelectObject(pOldFont);
			pOldFont=pDC->SelectObject(&m_pItemFont[nFontID].font);
		}

		nFontID=FindItemFont(nRow,nCol);
		if(nFontID>=0)
		{
			pDC->SelectObject(pOldFont);
			pOldFont=pDC->SelectObject(&m_pItemFont[nFontID].font);
		}
		//输出文本
		pDC->DrawText(lpBuffer,&rcItem,uFormat);
		//恢复字体
		if(pOldFont!=NULL)
			pDC->SelectObject(pOldFont);
		///////////////////////////////////////////////
		//更新
		if(pCell)
		{
			Update(nRow,nCol,lpBuffer);
		}
		///////////////////////////////////////////////
		//控件
	}
}
Example #25
0
////////////////////////////////////////////////////////////////////////////////
//
// FUNCTION:	  DrawItem
//
// DESCRIPTION:	Called in response to draw the button
//
// NOTES:
//
// MAINTENANCE:
// Name:		  Date:	  Version:	Notes:
// NT ALMOND	210100	1.0			  Origin
//
////////////////////////////////////////////////////////////////////////////////
void CCoolBtn::DrawItem(DRAWITEMSTRUCT* lpDIS)
{
    if (lpDIS->CtlType != ODT_BUTTON)
        return;

    CFont *pFont = CFont::FromHandle((HFONT)GetStockObject(DEFAULT_GUI_FONT));

    CDC dcMem;
    CBitmap bmp;

    CRect btnRect(lpDIS->rcItem);
    CRect trueRect(btnRect);

    CDC *pDC = CDC::FromHandle(lpDIS->hDC);

    ////////////////////////////////////////
    // Button Background                  //
    ////////////////////////////////////////

    pDC->FillRect(trueRect,&CBrush(GetSysColor(COLOR_BTNFACE)));

    BOOL bDisabled = ODS_DISABLED & lpDIS->itemState;

    if (m_bDefaultBtn)
        btnRect.DeflateRect(1,1);

    CRect rectFocus(btnRect);

    rectFocus.DeflateRect(4,4);

    if (!m_bMenuPushed)
        rectFocus.OffsetRect(m_bPushed,m_bPushed);

    rectFocus.right -= nDropBtnWidth;

    ////////////////////////////////////////
    // Button in a normal state           //
    ////////////////////////////////////////
    if (!m_bPushed || m_bMenuPushed)
    {
#ifdef _VISUALSTYLE_XP_H_
        if (g_xpStyle.IsAppThemed())
        {
            HTHEME hTheme = g_xpStyle.OpenThemeData(GetSafeHwnd(), L"BUTTON");
            g_xpStyle.DrawThemeBackground(hTheme, pDC->GetSafeHdc(),
                                          BP_PUSHBUTTON, PBS_NORMAL, &btnRect, 0);
            g_xpStyle.CloseThemeData(hTheme);
        }
        else
        {
#endif
            pDC->DrawFrameControl(&btnRect,DFC_BUTTON,DFCS_BUTTONPUSH);
#ifdef _VISUALSTYLE_XP_H_
        }
#endif
    }


    ////////////////////////////////////////
    // Default Button State               //
    ////////////////////////////////////////
    if ((m_bDefaultBtn || m_bPushed) && !bDisabled)
    {

        if (m_bPushed && !m_bMenuPushed)
        {
#ifdef _VISUALSTYLE_XP_H_
            if (g_xpStyle.IsAppThemed())
            {
                HTHEME hTheme = g_xpStyle.OpenThemeData(GetSafeHwnd(), L"BUTTON");
                g_xpStyle.DrawThemeBackground(hTheme, pDC->GetSafeHdc(),
                                              BP_PUSHBUTTON, PBS_PRESSED, &btnRect, 0);
                g_xpStyle.CloseThemeData(hTheme);
            }
            else
            {
#endif
                pDC->FrameRect(&lpDIS->rcItem,CBrush::FromHandle((HBRUSH)GetStockObject(BLACK_BRUSH)));
                pDC->FrameRect(&btnRect,CBrush::FromHandle((HBRUSH)GetStockObject(BLACK_BRUSH)));
#ifdef _VISUALSTYLE_XP_H_
            }
#endif
        }
    }
    ////////////////////////////////////////
    // State Hover                        //
    ////////////////////////////////////////
    if (m_bOverControl /*lpDIS->itemState & ODS_HOTLIGHT*/)
        if (!m_bMenuPushed)
        {
#ifdef _VISUALSTYLE_XP_H_
            if (g_xpStyle.IsAppThemed())
            {
                HTHEME hTheme = g_xpStyle.OpenThemeData(GetSafeHwnd(), L"BUTTON");
                g_xpStyle.DrawThemeBackground(hTheme, pDC->GetSafeHdc(),
                                              BP_PUSHBUTTON, PBS_HOT, &btnRect, 0);
                g_xpStyle.CloseThemeData(hTheme);
            }
#endif
        }

    ////////////////////////////////////////
    // State Focus                        //
    ////////////////////////////////////////
    if (lpDIS->itemState & ODS_FOCUS || m_bPushed)
        if (!m_bMenuPushed)
            pDC->DrawFocusRect(&rectFocus);


    ////////////////////////////////////////
    // Action Focus                       //
    ////////////////////////////////////////
    if ((lpDIS->itemAction & ODA_FOCUS))
        if (!m_bMenuPushed)
            pDC->DrawFocusRect(&rectFocus);


    ////////////////////////////////////////
    // Draw out bitmap                    //
    ////////////////////////////////////////

    // Draw out bitmap
    if (m_bLoaded)
    {
        if (!bDisabled)
        {
            m_IL.DrawIndirect(pDC,0,CPoint(6+m_bPushed,6+m_bPushed), CSize(m_bm.bmWidth, m_bm.bmHeight), CPoint(0,0),ILD_NORMAL);
        }
        else
        {
            pDC->DrawState(CPoint(6+m_bPushed,6+m_bPushed), CSize(m_bm.bmWidth, m_bm.bmHeight), m_hbmpDisabled, DST_BITMAP | DSS_DISABLED);
        }
    }


    ////////////////////////////////////////
    // Draw out text                      //
    ////////////////////////////////////////
    pDC->SelectObject(pFont);
    CRect rectText(rectFocus);
    rectFocus.left += m_bm.bmWidth + 2;

    CString strCaption;
    GetWindowText(strCaption);
    pDC->SetBkMode(TRANSPARENT);
    pDC->SetBkColor(GetSysColor(COLOR_BTNFACE));

    if (ODS_DISABLED & lpDIS->itemState)
    {
        rectFocus.OffsetRect(1,1);
        pDC->SetTextColor(GetSysColor(COLOR_WINDOW));
        pDC->DrawText(strCaption,rectFocus,DT_SINGLELINE|DT_CENTER|DT_VCENTER);

        rectFocus.OffsetRect(-1,-1);
        pDC->SetTextColor(GetSysColor(COLOR_GRAYTEXT));
        pDC->DrawText(strCaption,rectFocus,DT_SINGLELINE|DT_CENTER|DT_VCENTER);
    }
    else
    {
        pDC->SetTextColor(GetSysColor(COLOR_WINDOWTEXT));
        pDC->DrawText(strCaption,rectFocus,DT_SINGLELINE|DT_CENTER|DT_VCENTER);
    }


    CRect rectSplit(btnRect);
    rectSplit.DeflateRect(2,2);
    rectSplit.right -= nDropBtnWidth;


    ////////////////////////////////////////
    // Drop down split                    //
    ////////////////////////////////////////
    CPen brFace(PS_SOLID,1,GetSysColor(COLOR_3DSHADOW));
    pDC->SelectObject(&brFace);
    pDC->MoveTo(rectSplit.right, rectSplit.top);
    pDC->LineTo(rectSplit.right, rectSplit.bottom);


    CPen brLite(PS_SOLID,1,GetSysColor(COLOR_3DHILIGHT));
    pDC->SelectObject(&brLite);
    pDC->MoveTo(rectSplit.right+1 , rectSplit.top);
    pDC->LineTo(rectSplit.right+1, rectSplit.bottom);


    rectSplit.left = rectSplit.right;
    rectSplit.right += nDropBtnWidth;

    CPoint pt(rectSplit.CenterPoint());
    pt += CPoint(m_bPushed,m_bPushed);

    CPen penBlack(PS_SOLID, 1, bDisabled ? GetSysColor(COLOR_GRAYTEXT) : GetSysColor(COLOR_WINDOWTEXT));
    pDC->SelectObject(&penBlack);
    DrawArrow(pDC,pt);

    ////////////////////////////////////////
    // Drop down state                    //
    ////////////////////////////////////////
    if (m_bMenuPushed && !bDisabled)
    {
#ifdef _VISUALSTYLE_XP_H_
        rectSplit.DeflateRect(1,1);
#else
        rectSplit.InflateRect(1,1);
#endif
        pDC->DrawEdge(rectSplit,BDR_SUNKENOUTER, BF_RECT);
    }
}
Example #26
0
void CColumnTreeView::OnTreeCustomDraw(NMHDR* pNMHDR, LRESULT* pResult)
{
	NMCUSTOMDRAW* pNMCustomDraw = (NMCUSTOMDRAW*)pNMHDR;
	NMTVCUSTOMDRAW* pNMTVCustomDraw = (NMTVCUSTOMDRAW*)pNMHDR;

	switch (pNMCustomDraw->dwDrawStage)
	{
	case CDDS_PREPAINT:
		*pResult = CDRF_NOTIFYITEMDRAW;
		break;

	case CDDS_ITEMPREPAINT:
		*pResult = CDRF_DODEFAULT | CDRF_NOTIFYPOSTPAINT;
		break;

	case CDDS_ITEMPOSTPAINT:
		{
			HTREEITEM hItem = (HTREEITEM)pNMCustomDraw->dwItemSpec;
			CRect rcItem = pNMCustomDraw->rc;

			if (rcItem.IsRectEmpty())
			{
				// nothing to paint
				*pResult = CDRF_DODEFAULT;
				break;
			}

			CDC dc;
			dc.Attach(pNMCustomDraw->hdc);

			CRect rcLabel;
			m_Tree.GetItemRect(hItem, &rcLabel, TRUE);

			COLORREF crTextBk = pNMTVCustomDraw->clrTextBk;
			COLORREF crText = pNMTVCustomDraw->clrText;
			COLORREF crWnd = GetSysColor(COLOR_WINDOW);

			// clear the original label rectangle
			CRect rcClear = rcLabel;
			if (rcClear.left > m_arrColWidths[0] - 1)
				rcClear.left = m_arrColWidths[0] - 1;
			dc.FillSolidRect(&rcClear, crWnd);

			int nColsCnt = m_Header.GetItemCount();

			// draw horizontal lines...
			int xOffset = 0;
			for (int i=0; i<nColsCnt; i++)
			{
				xOffset += m_arrColWidths[i];
				rcItem.right = xOffset-1;
				dc.DrawEdge(&rcItem, BDR_SUNKENINNER, BF_RIGHT);
			}
			// ...and the vertical ones
			dc.DrawEdge(&rcItem, BDR_SUNKENINNER, BF_BOTTOM);

			CString strText = m_Tree.GetItemText(hItem);
			CString strSub;
			AfxExtractSubString(strSub, strText, 0, '\t');

			// calculate main label's size
			CRect rcText(0,0,0,0);
			dc.DrawText(strSub, &rcText, DT_NOPREFIX | DT_CALCRECT);
			rcLabel.right = min(rcLabel.left + rcText.right + 4, m_arrColWidths[0] - 4);

			CRect rcBack = rcLabel;
			if (GetWindowLong(m_Tree.m_hWnd, GWL_STYLE) & TVS_FULLROWSELECT)
			{
				int nWidth = 0;
				for (int i=0; i<nColsCnt; i++)
					nWidth += m_arrColWidths[i];
				rcBack.right = nWidth - 1;
				if (rcBack.left > m_arrColWidths[0] - 1)
					rcBack.left = m_arrColWidths[0] - 1;
			}

			if (rcBack.Width() < 0)
				crTextBk = crWnd;
			if (crTextBk != crWnd)	// draw label's background
				dc.FillSolidRect(&rcBack, crTextBk);

			// draw focus rectangle if necessary
			if (pNMCustomDraw->uItemState & CDIS_FOCUS)
				dc.DrawFocusRect(&rcBack);

			// draw main label
			rcText = rcLabel;
			rcText.DeflateRect(2, 1);
			dc.SetTextColor(crText);
			dc.DrawText(strSub, &rcText, DT_NOPREFIX | DT_END_ELLIPSIS);

			xOffset = m_arrColWidths[0];
			dc.SetBkMode(TRANSPARENT);

			if (!(GetWindowLong(m_Tree.m_hWnd, GWL_STYLE) & TVS_FULLROWSELECT))
			dc.SetTextColor(GetSysColor(COLOR_WINDOWTEXT));

			// draw other columns text
			for (int i=1; i<nColsCnt; i++)
			{
				if (AfxExtractSubString(strSub, strText, i, '\t'))
				{
					rcText = rcLabel;
					rcText.left = xOffset;
					rcText.right = xOffset + m_arrColWidths[i];
					rcText.DeflateRect(m_xOffset, 1, 2, 1);
					dc.DrawText(strSub, &rcText, DT_NOPREFIX | DT_END_ELLIPSIS);
				}
				xOffset += m_arrColWidths[i];
			}

			dc.Detach();
		}
		*pResult = CDRF_DODEFAULT;
		break;

	default:
		*pResult = CDRF_DODEFAULT;
	}
}
Example #27
0
void COptionTreeImagePopUp::OnPaint() 
{
	// Make sure options aren't NULL
	if (m_otImageOption == NULL)
	{
		return;
	}

	// Declare variables
	CPaintDC dc(this);
	CDC* pDCMem = new CDC;
	CBitmap bpMem;
	CBitmap *bmOld;
	CRect rcClient, rcButton, rcImage;
	COLORREF crOld;
	HGDIOBJ hOldBrush;
	HGDIOBJ hOld;
	int nOldBack;

	// Get client rectangle
	GetClientRect(rcClient);

	// Create DC
	pDCMem->CreateCompatibleDC(&dc);
	
	// Create bitmap
	bpMem.CreateCompatibleBitmap(&dc, rcClient.Width(), rcClient.Height());

	// Select bitmap
	bmOld = pDCMem->SelectObject(&bpMem);

	// Set background mode
	nOldBack = pDCMem->SetBkMode(TRANSPARENT);

	// Set text color
	crOld = pDCMem->SetTextColor(GetSysColor(COLOR_WINDOWTEXT));

	// Select font
	hOld = pDCMem->SelectObject(m_otImageOption->GetNormalFont());

	// Select brush
	hOldBrush = pDCMem->SelectObject(GetSysColorBrush(COLOR_BTNFACE));

	// Fill background
	pDCMem->PatBlt(rcClient.left, rcClient.top, rcClient.right, rcClient.bottom, PATCOPY);

	// Go through all images
	for (int i = 0; i < m_pImageList->GetImageCount(); i++)
	{
		// -- Get rectangle
		rcImage = m_rcRectangles.GetAt(i);

		// -- Button
		// -- -- Hover
		if (rcImage.PtInRect(m_pHover) == TRUE)
		{
			rcButton = rcImage;
			rcButton.InflateRect(3, 3, 3, 3);

			pDCMem->DrawEdge(rcButton, BDR_RAISEDINNER, BF_RECT);
		}
		// -- -- Selected
		else if (m_nSelected == i)
		{
			rcButton = rcImage;
			rcButton.InflateRect(3, 3, 3, 3);

			for (long i = rcButton.top; i < rcButton.bottom; i++)
			{
				_DrawSelectRect(pDCMem->GetSafeHdc(), rcButton.left, i, rcButton.Width());
			}

			pDCMem->DrawEdge(rcButton, BDR_SUNKENOUTER, BF_RECT);
		}
		
		// -- Draw image
		m_pImageList->Draw(pDCMem, i, CPoint(rcImage.left, rcImage.top), ILD_NORMAL);
	}

	// Draw text
	if (m_pImageList->GetImageCount() == 0)
	{
		pDCMem->DrawText(_T("No Images."), rcClient, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
	}

	// Draw edge
	pDCMem->DrawEdge(rcClient, EDGE_RAISED, BF_RECT);

	// Copy to screen
	dc.BitBlt(0, 0, rcClient.Width(), rcClient.Height(), pDCMem, 0, 0, SRCCOPY);

	// Restore GDI ojects
	pDCMem->SelectObject(bmOld);
	pDCMem->SelectObject(hOldBrush);
	pDCMem->SetBkMode(nOldBack);
	pDCMem->SelectObject(hOld);
	pDCMem->SetTextColor(crOld);

	// Delete objects
	if (pDCMem->GetSafeHdc() != NULL)
	{
		pDCMem->DeleteDC();
	}
	delete pDCMem;
	if (bpMem.GetSafeHandle() != NULL)
	{
		bpMem.DeleteObject();
	}
}
//=============================================================================	
void CXButtonXP::DrawItem(LPDRAWITEMSTRUCT lpDIS)
//=============================================================================	
{
	CDC *pDC = CDC::FromHandle(lpDIS->hDC);
	CRect rectItem = lpDIS->rcItem;

	// set up for double buffering
	CDC memDC;
	memDC.CreateCompatibleDC(pDC);
	CBitmap bmp;
	bmp.CreateCompatibleBitmap(pDC, rectItem.Width(), rectItem.Height());
	CBitmap *pOldBitmap = memDC.SelectObject(&bmp);
	// initialize dc from existing dc
	memDC.BitBlt(0, 0, rectItem.Width(), rectItem.Height(),
		pDC, 0, 0, SRCCOPY);			
	memDC.SetBkMode(TRANSPARENT);

	if (m_bFirstTime)
	{
		// open theme for Button

		m_bFirstTime = FALSE;

		if (ThemeHelper.IsThemeLibAvailable())
		{
			if (m_hTheme)
				ThemeHelper.CloseThemeData(m_hTheme);
			m_hTheme = NULL;

			if (m_bDrawToolbar)
			{
				m_hTheme = ThemeHelper.OpenThemeData(m_hWnd, _T("Toolbar"));
			}
			else
			{
				m_hTheme = ThemeHelper.OpenThemeData(m_hWnd, _T("Button"));
			}
		}

		SaveParentBackground();
	}

	CFont *pFont = GetParent()->GetFont();

	if (pFont)
		memDC.SelectObject(pFont);

	// button state

	// get the button's title
	CString strTitle = _T("");
	GetWindowText(strTitle);
	BOOL bHasText       = !strTitle.IsEmpty();
	BOOL bIsFocused     = lpDIS->itemState & ODS_FOCUS;
	BOOL bIsDisabled    = lpDIS->itemState & ODS_DISABLED;
	BOOL bDrawFocusRect = !(lpDIS->itemState & ODS_NOFOCUSRECT);
	BOOL bIsPressed     = lpDIS->itemState & ODS_SELECTED;
	BOOL bIsDefault     = IsDefault();
	BOOL bIsThemed      = IsThemed();
	BOOL bCustomColors  = (m_crBackground != XBUTTONXP_NO_COLOR) ||
						  (m_crText != XBUTTONXP_NO_COLOR);

	if (bCustomColors)
	{
		bIsThemed = FALSE;
	}

	if (m_bIsToggle)
	{
		if (m_bLButtonDown && !m_bMouseOverButton)
		{
			// left mouse button is down outside button
			bIsPressed = !m_bToggled;
		}
		else
		{
			bIsPressed = m_bToggled;
		}
	}

	if (m_bDrawToolbar)
	{
		// restore parent window bits
		memDC.BitBlt(0, 0, m_rectButton.Width(), m_rectButton.Height(),
			&m_dcParent, 0, 0, SRCCOPY);

		bIsFocused = FALSE;
		bIsDefault = FALSE;
	}

	if (bIsThemed)
	{
		DWORD state = bIsPressed ? PBS_PRESSED : PBS_NORMAL;

		if (bIsDisabled)
		{
			state = PBS_DISABLED;
		}
		else if (state == PBS_NORMAL)
		{
			if (bIsFocused || bIsDefault)
			{
				state = PBS_DEFAULTED;
			}
			if (m_bMouseOverButton)
				state = PBS_HOT;
		}

		ThemeHelper.DrawThemeParentBackground(m_hWnd, memDC.m_hDC, &rectItem);

		ThemeHelper.DrawThemeBackground(m_hTheme, memDC.m_hDC, BP_PUSHBUTTON, state, &rectItem, NULL);
	}
	else	// not themed
	{
		CBrush brBackground;
		if (m_crBackground == XBUTTONXP_NO_COLOR)
			brBackground.CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
		else
			brBackground.CreateSolidBrush(m_crBackground);

		if (!m_bDrawToolbar || bCustomColors)
		{
			// fill in background, if custom color or not toolbar
			CRect rectClient(rectItem);
			InflateRect(&rectClient, -1, -1);
			memDC.FillRect(&rectClient, &brBackground);
		}

		if (bIsFocused || bIsDefault)
		{
			if (!m_bIsToggle || !bIsPressed)
			{
				CBrush brush(RGB(0,0,0));
				memDC.FrameRect(&rectItem, &brush);
			}
			InflateRect(&rectItem, -1, -1);
		}

		// draw the traditional pushbutton edge
		if (bIsPressed)
		{
			memDC.DrawEdge(&rectItem, EDGE_SUNKEN, BF_RECT);
		}
		else if (!m_bDrawToolbar)
		{
			memDC.DrawEdge(&rectItem, EDGE_RAISED, BF_RECT);
		}
	}

	CRect rectDraw = lpDIS->rcItem;

	// draw the icon
	DrawIcon(&memDC, bHasText, rectItem, rectDraw, bIsPressed, bIsThemed, 
		bIsDisabled);

	// draw the button title (if any)
	if (bHasText)
	{
		DrawText(&memDC, strTitle, rectDraw, bIsPressed, bIsThemed, 
			bIsDisabled);
	}

	// draw the focus rect
	if (bIsFocused && bDrawFocusRect)
	{
		CRect rectFocus = rectItem;
		if (m_pDropDownMenu)
			rectFocus.right = rectFocus.right - MENUBTN_WIDTH + 1;
		if (!bIsThemed && bIsPressed)
			rectFocus.OffsetRect(1, 1);
		rectFocus.InflateRect(-3, -3);
		memDC.DrawFocusRect(&rectFocus);
	}

	if (m_pDropDownMenu)
	{
		DrawSplit(&memDC, rectItem, bIsPressed, bIsThemed, bIsDisabled);
		DrawArrow(&memDC, rectItem, bIsPressed, bIsThemed, bIsDisabled);
	}

	// end double buffering
	pDC->BitBlt(0, 0, rectItem.Width(), rectItem.Height(),
		&memDC, 0, 0, SRCCOPY);			

	// swap back the original bitmap
	if (pOldBitmap)
		memDC.SelectObject(pOldBitmap);
	if (bmp.GetSafeHandle())
		bmp.DeleteObject();

	memDC.DeleteDC();
}
void PaletteViewControl::OnPaint() 
{
  CPaintDC dc(this); // device context for painting
  
  RECT rect;
  GetClientRect(&rect);
  int w = rect.right - rect.left;
  int h = rect.bottom - rect.top;
  
  CDC memDC;
  memDC.CreateCompatibleDC(&dc);
  CBitmap bitmap, *pOldBitmap;
  bitmap.CreateCompatibleBitmap(&dc, w, h);
  pOldBitmap = memDC.SelectObject(&bitmap);
  
  StretchDIBits(memDC.GetSafeHdc(),
                0,
                0,
                w,
                h,
                0,
                0,
                this->w,
                this->h,
                data,
                &bmpInfo,
                DIB_RGB_COLORS,
                SRCCOPY);
  int sw = this->w / 16;
  int sh = this->h / 16;
  int mult  = w / sw;
  int multY = h / sh;
  CPen pen;
  pen.CreatePen(PS_SOLID, 1, RGB(192,192,192));
  CPen *old = memDC.SelectObject(&pen);
  int i;
  for(i = 1; i < sh; i++) {
    memDC.MoveTo(0, i * multY);
    memDC.LineTo(w, i * multY);
  }
  for(i = 1; i < sw; i++) {
    memDC.MoveTo(i * mult, 0);
    memDC.LineTo(i * mult, h);
  }
  memDC.DrawEdge(&rect, EDGE_SUNKEN, BF_RECT);
  memDC.SelectObject(old);
  pen.DeleteObject();

  if(selected != -1) {
    pen.CreatePen(PS_SOLID, 2, RGB(255, 0, 0));
    old = memDC.SelectObject(&pen);

    int startX = (selected & (sw-1))*mult+1;
    int startY = (selected / sw)*multY+1;
    int endX = startX + mult-2;
    int endY = startY + multY-2;
    
    memDC.MoveTo(startX, startY);
    memDC.LineTo(endX, startY);
    memDC.LineTo(endX, endY);
    memDC.LineTo(startX, endY);
    memDC.LineTo(startX, startY-1);

    memDC.SelectObject(old);
    pen.DeleteObject();
  }
  
  dc.BitBlt(0,0,w,h,
            &memDC,0,0,SRCCOPY);

  memDC.SelectObject(pOldBitmap);
  bitmap.DeleteObject();
  memDC.DeleteDC();
}
void CPrimitiveHistoryCombo::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
{
  INDEX iItem = lpDrawItemStruct->itemID;
  BOOL bSelected = lpDrawItemStruct->itemState & (ODS_FOCUS|ODS_SELECTED);
  COLORREF clrfBcgColor;
  UINT ulEdgeType;
  if( bSelected)
  {
    clrfBcgColor = CLRF_CLR( 0xDFDFFF00UL); 
    ulEdgeType = EDGE_SUNKEN;
  }
  else
  {
    clrfBcgColor = CLRF_CLR( C_WHITE);
    ulEdgeType = EDGE_RAISED;
  }
  
  CValuesForPrimitive *pVFP = (CValuesForPrimitive *) GetItemData( iItem);
  if( (ULONG) pVFP == CB_ERR) return;

  CDC *pDC = CDC::FromHandle( lpDrawItemStruct->hDC);
  RECT rectItem = lpDrawItemStruct->rcItem;
  pDC->SetBkMode( TRANSPARENT);
  pDC->SetBkColor( clrfBcgColor);
  pDC->FillSolidRect( &rectItem, clrfBcgColor);
  
  // polygon color
  RECT rectPolygon = rectItem;
  rectPolygon.top+=1;
  rectPolygon.bottom-=1;
  rectPolygon.left += 2;
  rectPolygon.right = rectPolygon.left+16;
  COLORREF clrfColor = CLRF_CLR( pVFP->vfp_colPolygonsColor);
  pDC->FillSolidRect( &rectPolygon, clrfColor);

  // sector color
  RECT rectSector = rectPolygon;
  rectSector.left += 16;
  rectSector.right += 16;
  clrfColor = CLRF_CLR( pVFP->vfp_colSectorsColor);
  pDC->FillSolidRect( &rectSector, clrfColor);

  RECT rectBorder = rectPolygon;
  rectBorder.right += 16;
  pDC->DrawEdge( &rectBorder, ulEdgeType, BF_RECT);

  // used for rendering from left to right
  PIX pixCursor = 38;
  
  UINT uiPrimitiveIconID;
  switch( pVFP->vfp_ptPrimitiveType)
  {
  case PT_CONUS:{       uiPrimitiveIconID = IDR_ICON_CONUS; break;}
  case PT_TORUS:{       uiPrimitiveIconID = IDR_ICON_TORUS; break;}
  case PT_STAIRCASES:
    {
    if( pVFP->vfp_bLinearStaircases) uiPrimitiveIconID = IDR_ICON_LINEAR_STAIRCASES;
    else                             uiPrimitiveIconID = IDR_ICON_SPIRAL_STAIRCASES; 
    break;
    }
  case PT_SPHERE:{      uiPrimitiveIconID = IDR_ICON_SPHERE; break;}
  case PT_TERRAIN:{     uiPrimitiveIconID = IDR_ICON_TERRAIN; break;}
  }
  HICON hPrimitiveIcon = theApp.LoadIcon( uiPrimitiveIconID);
  pDC->DrawIcon( pixCursor, rectItem.top, hPrimitiveIcon);
  pixCursor += 22;

  UINT uiPrimitiveOperationID;
  switch( pVFP->vfp_csgtCSGOperation)
  {
  case CSG_ADD: {             uiPrimitiveOperationID = IDR_ICON_ADD; break;}
  case CSG_ADD_REVERSE: {     uiPrimitiveOperationID = IDR_ICON_ADD_REVERSE; break;}
  case CSG_REMOVE:  {         uiPrimitiveOperationID = IDR_ICON_REMOVE; break;}
  case CSG_REMOVE_REVERSE:  { uiPrimitiveOperationID = IDR_ICON_REMOVE_REVERSE; break;}
  case CSG_SPLIT_SECTORS: {   uiPrimitiveOperationID = IDR_ICON_SPLIT_SECTORS; break;}
  case CSG_SPLIT_POLYGONS:  { uiPrimitiveOperationID = IDR_ICON_SPLIT_POLYGONS; break;}
  case CSG_JOIN_LAYERS: {     uiPrimitiveOperationID = IDR_ICON_JOIN_LAYERS; break;}
  }
  HICON hOperationIcon = theApp.LoadIcon( uiPrimitiveOperationID);
  pDC->DrawIcon( pixCursor, rectItem.top, hOperationIcon);
  pixCursor += 22;

  HICON hRoomIcon;
  if( pVFP->vfp_bClosed) hRoomIcon = theApp.LoadIcon( IDR_ICON_ROOM);
  else                   hRoomIcon = theApp.LoadIcon( IDR_ICON_MATERIAL);
  pDC->DrawIcon( pixCursor, rectItem.top, hRoomIcon);
  pixCursor += 22;

  if( !pVFP->vfp_bOuter &&
      (pVFP->vfp_csgtCSGOperation != PT_SPHERE) &&
      (pVFP->vfp_csgtCSGOperation != PT_TERRAIN) )
  {
    HICON hOuterIcon;
    hOuterIcon = theApp.LoadIcon( IDR_ICON_INNER);
    pDC->DrawIcon( pixCursor, rectItem.top, hOuterIcon);
    pixCursor += 22;
  }

  if( pVFP->vfp_ptPrimitiveType == PT_STAIRCASES)
  {
    HICON hTopStairsIcon;
    if(      pVFP->vfp_iTopShape == 0) hTopStairsIcon = theApp.LoadIcon( IDR_ICON_TOP_STAIRS);
    else if( pVFP->vfp_iTopShape == 1) hTopStairsIcon = theApp.LoadIcon( IDR_ICON_TOP_SLOPE);
    else                               hTopStairsIcon = theApp.LoadIcon( IDR_ICON_TOP_CEILING);
    pDC->DrawIcon( pixCursor, rectItem.top, hTopStairsIcon);
    pixCursor += 22;

    HICON hBottomStairsIcon;
    if(      pVFP->vfp_iTopShape == 0) hBottomStairsIcon = theApp.LoadIcon( IDR_ICON_BOTTOM_STAIRS);
    else if( pVFP->vfp_iTopShape == 1) hBottomStairsIcon = theApp.LoadIcon( IDR_ICON_BOTTOM_SLOPE);
    else                               hBottomStairsIcon = theApp.LoadIcon( IDR_ICON_BOTTOM_FLOOR);
    pDC->DrawIcon( pixCursor, rectItem.top, hBottomStairsIcon);
    pixCursor += 22;
  }

  // obtain text of drawing item
  CString strText;
  GetLBText( iItem, strText);
  pDC->TextOut( pixCursor, rectItem.top, strText);
}