Example #1
0
void CVolumeCtrl::OnNMCustomdraw(NMHDR* pNMHDR, LRESULT* pResult)
{
    LPNMCUSTOMDRAW pNMCD = reinterpret_cast<LPNMCUSTOMDRAW>(pNMHDR);

    LRESULT lr = CDRF_DODEFAULT;

    if (m_fSelfDrawn)
        switch (pNMCD->dwDrawStage) {
            case CDDS_PREPAINT:
                lr = CDRF_NOTIFYITEMDRAW;
                break;

            case CDDS_ITEMPREPAINT:
                if (pNMCD->dwItemSpec == TBCD_CHANNEL) {
                    CDC dc;
                    dc.Attach(pNMCD->hdc);

                    CRect r;
                    GetClientRect(r);
                    r.DeflateRect(8, 4, 10, 6);
                    CopyRect(&pNMCD->rc, &r);
                    CPen shadow(PS_SOLID, 1, GetSysColor(COLOR_3DSHADOW));
                    CPen light(PS_SOLID, 1, GetSysColor(COLOR_3DHILIGHT));
                    CPen* old = dc.SelectObject(&light);
                    dc.MoveTo(pNMCD->rc.right, pNMCD->rc.top);
                    dc.LineTo(pNMCD->rc.right, pNMCD->rc.bottom);
                    dc.LineTo(pNMCD->rc.left, pNMCD->rc.bottom);
                    dc.SelectObject(&shadow);
                    dc.LineTo(pNMCD->rc.right, pNMCD->rc.top);
                    dc.SelectObject(old);

                    dc.Detach();
                    lr = CDRF_SKIPDEFAULT;
                } else if (pNMCD->dwItemSpec == TBCD_THUMB) {
                    CDC dc;
                    dc.Attach(pNMCD->hdc);
                    pNMCD->rc.bottom--;
                    CRect r(pNMCD->rc);
                    r.DeflateRect(0, 0, 1, 0);

                    COLORREF shadow = GetSysColor(COLOR_3DSHADOW);
                    COLORREF light = GetSysColor(COLOR_3DHILIGHT);
                    dc.Draw3dRect(&r, light, 0);
                    r.DeflateRect(0, 0, 1, 1);
                    dc.Draw3dRect(&r, light, shadow);
                    r.DeflateRect(1, 1, 1, 1);
                    dc.FillSolidRect(&r, GetSysColor(COLOR_BTNFACE));
                    dc.SetPixel(r.left + 7, r.top - 1, GetSysColor(COLOR_BTNFACE));

                    dc.Detach();
                    lr = CDRF_SKIPDEFAULT;
                }

                break;
        };

    pNMCD->uItemState &= ~CDIS_FOCUS;

    *pResult = lr;
}
Example #2
0
void CPredView::OnFilePrint()
{
	CDC dc;
	CPrintDialog printDlg(false);
	if(printDlg.DoModal()==IDCANCEL)
		return;
	dc.Attach(printDlg.GetPrinterDC());
	dc.m_bPrinting=true;

	DOCINFO di;
	::ZeroMemory(&di,sizeof(DOCINFO));
	di.cbSize=sizeof(DOCINFO);
	di.lpszDocName="FCC Prediction";
	

	bool bPrintingOK=dc.StartDocA(&di);
	CPrintInfo info;
	info.m_rectDraw.SetRect(0,0,dc.GetDeviceCaps(HORZRES),dc.GetDeviceCaps(VERTRES));
	
	
	//OnPreparePrinting(&info);
	OnBeginPrinting(&dc,&info);
	OnPrint(&dc,&info);
	OnEndPrinting(&dc,&info);
	
	if(bPrintingOK)
		dc.EndDoc();
	else
		dc.AbortDoc();
	dc.Detach();
}
void CWndMapPartsGrp::OnPaint()
{
	int x, y, cx, cy;
	HDC hDC;
	CDC DCTmp;
	CRect rc, rcTmp;
	CRgn rgn;
	CPaintDC dc(this);

	hDC = m_pImgParts->Lock ();
	DCTmp.Attach (hDC);

	GetClientRect (rc);
	rgn.CreateRectRgn (0, 0, rc.Width (), rc.Height ());
	dc.SelectClipRgn (&rgn, RGN_COPY);

	x = GetScrollPos (SB_HORZ);
	y = GetScrollPos (SB_VERT);

	cx = min (rc.Width (), m_pImgParts->Width ());
	cy = min (rc.Height (), m_pImgParts->Height ());
	dc.FillSolidRect (rc, RGB (128, 128, 128));
	dc.BitBlt (0, 0, cx, cy, &DCTmp, x * 16, y * 16, SRCCOPY);

	x = m_ptCursor.x * 16;
	y = (m_ptCursor.y - m_nPos) * 16;
	rcTmp.SetRect (x, y, x + 15, y + 15);

	dc.DrawEdge (rcTmp, EDGE_BUMP, BF_FLAT | BF_RECT);

	m_pImgParts->Unlock ();
	DCTmp.Detach ();
}
void CLMenu::UpdateLayer(CDIB *dib)
{
	if(!dib)
	{
		dib = CLMenu::dib;
	}

	CRect r;
	GetWindowRect(&r);

	CWnd *wndDst = GetDesktopWindow();
	CDC *hdcDst = wndDst->GetDC();
	CDC *dc = new CDC();
	dc->Attach(dib->dc);
	
	BLENDFUNCTION bf = {AC_SRC_OVER, 0, 255, AC_SRC_ALPHA};
	POINT zp = {0, 0};
	POINT sp = {r.left, r.top};
	SIZE sz = {r.Width(), r.Height()};

	UpdateLayeredWindow(hdcDst, &sp, &sz, dc, &zp, NULL, &bf, ULW_ALPHA);

	dc->Detach();
	delete dc;
	wndDst->ReleaseDC(hdcDst);
}
Example #5
0
void CODCombo::DrawItem(LPDRAWITEMSTRUCT lpDIS)
{
	if (SendMessage(CB_GETCOUNT, 0, 0) == 0) return;
	
	CDC dc;
	dc.Attach(lpDIS->hDC);	
	dc.SelectStockObject(DEFAULT_GUI_FONT);   
	// Save these value to restore them when done drawing.
	COLORREF oldText = dc.GetTextColor(),
			 oldBkgnd = dc.GetBkColor();

	if (!IsWindowEnabled()) dc.SetTextColor(::GetSysColor(COLOR_GRAYTEXT));		
	if ((lpDIS->itemAction | ODA_SELECT) && (lpDIS->itemState  & ODS_SELECTED))
	{
		dc.SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
		dc.SetBkColor(::GetSysColor(COLOR_HIGHLIGHT));
		dc.FillSolidRect(&lpDIS->rcItem, ::GetSysColor(COLOR_HIGHLIGHT));
	}
	else dc.FillSolidRect(&lpDIS->rcItem, oldBkgnd);		

	RECT rc(lpDIS->rcItem);
	rc.left += 2;
	rc.right -= 2;	   

	TCHAR line[32];
	memset(line, 0, 32);
	SendMessage(CB_GETLBTEXT, lpDIS->itemID, (LPARAM)line);

	dc.DrawText(line, &rc, DT_LEFT | DT_SINGLELINE | DT_VCENTER);				

	dc.SetTextColor(oldText);
	dc.SetBkColor(oldBkgnd);
	dc.Detach();
}
Example #6
0
void CColorBtnDlg::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpd) 
{
	CDC dc;
    CPen nullpen;
    CBrush brush;
    CPen *oldpen;
    CBrush *oldbrush;

    // Draw the wells using the current color table

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

    dc.Attach(lpd->hDC);

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

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

    dc.Rectangle(&lpd->rcItem);

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

    dc.Detach();
	
	CDialog::OnDrawItem(nIDCtl, lpd);
}
Example #7
0
LRESULT OMenu::onDrawItem(HWND /*hWnd*/, UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
	bHandled = FALSE;
	if (wParam == NULL) {
		DRAWITEMSTRUCT dis = *(DRAWITEMSTRUCT*)lParam;
		if (dis.CtlType == ODT_MENU) {
			OMenuItem* mi = (OMenuItem*)dis.itemData;
			if (mi) {
				bHandled = TRUE;
				CRect rc(dis.rcItem);
				//rc.top += 2;
				rc.bottom -= 2;

				CDC dc;
				dc.Attach(dis.hDC);

				if (BOOLSETTING(MENUBAR_TWO_COLORS))
					OperaColors::FloodFill(dc, rc.left, rc.top, rc.right, rc.bottom, SETTING(MENUBAR_LEFT_COLOR), SETTING(MENUBAR_RIGHT_COLOR), BOOLSETTING(MENUBAR_BUMPED));
				else
					dc.FillSolidRect(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SETTING(MENUBAR_LEFT_COLOR));

				dc.SetBkMode(TRANSPARENT);
				dc.SetTextColor(OperaColors::TextFromBackground(SETTING(MENUBAR_LEFT_COLOR)));
				HFONT oldFont = dc.SelectFont(WinUtil::boldFont);
				tstring buf = mi->text;
				dc.DrawText(buf.c_str(), _tcslen(buf.c_str()), rc, DT_CENTER | DT_NOPREFIX | DT_SINGLELINE | DT_VCENTER);
				dc.SelectFont(oldFont);

				dc.Detach();
				return TRUE;
			}
		}
	}
	return S_OK;
}
      /// <summary>Custom draws an entire listview item</summary>
      /// <param name="pDraw">Draw/Item data</param>
      /// <param name="stage">Draw stage.</param>
      /// <returns></returns>
      bool  ListViewCustomDraw::onDrawItem(NMLVCUSTOMDRAW* pDraw, Stage stage)
      {
         try
         {
            // DEBUG
            //Console << "onDrawItem item=" << (int)pDraw->nmcd.dwItemSpec << " Stage=" << GetString(stage) << " state=" << pDraw->nmcd.uItemState << ENDL;
      
            // PostPaint: Do nothing
            if (stage == Stage::PostPaint)
               return true;

            // Init
            CDC dc;
            dc.Attach(pDraw->nmcd.hdc);

            // Get item data
            ItemData item((int)pDraw->nmcd.dwItemSpec, 0);
            ListView.GetItemRect(item.Index, item.Rect, LVIR_BOUNDS);
            item.Selected = ListView.GetItemState(item.Index, LVIS_SELECTED) != 0;
            item.Focused  = ListView.GetItemState(item.Index, LVIS_FOCUSED) != 0;

            // Draw background
            bool ListHasFocus = (::GetFocus() == ListView.GetSafeHwnd());
            auto backColour   = (item.Selected ? (ListHasFocus ? ActiveHighlight : InactiveHighlight) : ListView.GetBkColor());
            dc.FillSolidRect(item.Rect, backColour);

            // BugFix: check for header ctrl
            if (!ListView.GetHeaderCtrl())
               throw GenericException(HERE, L"Listview has no header ctrl");

            // Draw sub items:
            for (int count = ListView.GetHeaderCtrl()->GetItemCount(); item.SubItem < count; ++item.SubItem)
            {
               // Get sub-item rectangle
               ListView.GetSubItemRect(item.Index, item.SubItem, LVIR_LABEL, item.Rect);
               item.Rect.DeflateRect(GetSystemMetrics(SM_CXEDGE),0);

               // Reset text colour   [Invert if selected]
               dc.SetTextColor(GetSysColor(item.Selected ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT));

               // Allow derived-class to do drawing
               onDrawSubItem(&dc, item);
            }

            // Draw Focus rect:
            if (ListHasFocus && item.Focused)
            {
               ListView.GetItemRect(item.Index, item.Rect, LVIR_BOUNDS);
               dc.DrawFocusRect(item.Rect);
            }

            // Cleanup
            dc.Detach();
            return true;
         }
         catch (ExceptionBase& e) {
            Console.Log(HERE, e);
            return false;
         }
      }
Example #9
0
void HSliderCtrl::OnPaint()
{
	CPaintDC dc(this);
	//获取位置
	CRect rect;
	GetClientRect(&rect);
	//建双缓冲
	CImage		imgBuffer;
	CDC			dcBuffer;
	imgBuffer.Create(rect.Width(), rect.Height(), 24);
	dcBuffer.Attach(imgBuffer.GetDC());

	if (!m_imgBk.IsNull())
	{
		m_imgBk.TransparentBlt(dcBuffer.GetSafeHdc(),0,0,rect.Width(),rect.Height(),
			0,0,m_imgBk.GetWidth(),m_imgBk.GetHeight()/5,RGB(255,0,255));
		CRect thuRect;
		GetThumbRect(&thuRect);
		m_imgBk.TransparentBlt(dcBuffer.GetSafeHdc(),thuRect.left,thuRect.top,thuRect.Width(),thuRect.Height(),
			0,0+m_imgBk.GetHeight()/5*(m_byThuState+2),11,m_imgBk.GetHeight()/5,RGB(255,0,255));
		m_imgBk.TransparentBlt(dcBuffer.GetSafeHdc(),0,0,thuRect.left,rect.Height(),
			0,0+m_imgBk.GetHeight()/5,thuRect.left,m_imgBk.GetHeight()/5,RGB(255,0,255));
	}

	//清除缓冲
	dc.BitBlt(0, 0, rect.Width(), rect.Height(), &dcBuffer, 0, 0, SRCCOPY);
	dcBuffer.Detach();
	imgBuffer.ReleaseDC();
}
void CNotification::LayerUpdate(CDIB *dib)
{
	if(!dib)
	{
		dib = CNotification::dib;
	}
	if(!dib->Ready())
	{
		return;
	}
	CRect rect;
	GetWindowRect(&rect);

	CWnd *wndDst = GetDesktopWindow();
	CDC *hdcDst = wndDst->GetDC();
	CDC *dc = new CDC();
	dc->Attach(dib->dc);
	
	BLENDFUNCTION blend = {AC_SRC_OVER, 0, 255, AC_SRC_ALPHA};
	CPoint zp(0, 0);
	CPoint pt(rect.left, rect.top);
	CSize size(rect.Width(), rect.Height());

	UpdateLayeredWindow(hdcDst, &pt, &size, dc, &zp, NULL, &blend, ULW_ALPHA);

	dc->Detach();
	delete dc;
	wndDst->ReleaseDC(hdcDst);
}
Example #11
0
void CCoolMenu::SetWatermark(HBITMAP hBitmap)
{
	if ( m_bmWatermark.m_hObject != NULL )
	{
		m_dcWatermark.SelectObject( CBitmap::FromHandle( m_hOldMark ) );
		m_bmWatermark.DeleteObject();
		m_dcWatermark.DeleteDC();
	}

	if ( hBitmap != NULL )
	{
		CDC dc;
		dc.Attach( GetDC( 0 ) );
		if ( Settings.General.LanguageRTL )
			SetLayout( dc.m_hDC, LAYOUT_BITMAPORIENTATIONPRESERVED );
		m_dcWatermark.CreateCompatibleDC( &dc );
		ReleaseDC( 0, dc.Detach() );

		m_bmWatermark.Attach( hBitmap );
		m_hOldMark = (HBITMAP)m_dcWatermark.SelectObject( &m_bmWatermark )->GetSafeHandle();

		BITMAP pInfo;
		m_bmWatermark.GetBitmap( &pInfo );
		m_czWatermark.cx = pInfo.bmWidth;
		m_czWatermark.cy = pInfo.bmHeight;
	}
}
Example #12
0
void CStatusLabel::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
    CString str;
    GetWindowText(str);
    CRect clientRect;
    GetClientRect(&clientRect);

    CDC dc;
    dc.Attach(lpDrawItemStruct->hDC);
    dc.SetTextColor(0xffffff);
    dc.SetBkColor(0);
    CFont* old = dc.SelectObject(&m_font);
    const UINT style = DT_SINGLELINE | DT_NOPREFIX | (m_fAddEllipses ? DT_END_ELLIPSIS : 0);
    CRect textRect(clientRect);
    dc.DrawText(str, textRect, style | DT_CALCRECT);
    if (m_fRightAlign) {
        textRect.MoveToX(clientRect.Width() - textRect.Width());
    }
    textRect.MoveToY((clientRect.Height() - textRect.Height()) / 2);
    dc.DrawText(str, textRect, style);
    dc.ExcludeClipRect(textRect);
    dc.FillSolidRect(clientRect, 0);
    dc.SelectObject(&old);
    dc.Detach();
}
void CStaticMapShadow::OnPaint()
{
	int x, y, cy;
	HDC hDC;
	CDC DCTmp;
	CRect rc, rcTmp;
	CRgn rgn;
	CPaintDC dc(this);

	hDC = m_pImgShadow->Lock ();
	DCTmp.Attach (hDC);

	GetWindowRect (rc);
	rgn.CreateRectRgn (0, 0, rc.Width (), rc.Height ());
	dc.SelectClipRgn (&rgn, RGN_COPY);

	ScreenToClient (rc);
	cy = min (rc.Height (), m_pImgShadow->Height ());
	dc.BitBlt (0, 0, m_pImgShadow->Width (), cy, &DCTmp, 0, 0, SRCCOPY);

	x = m_ptCursor.x * 16;
	y = (m_ptCursor.y - m_nPos) * 16;
	cy = y + 15;
	cy = min (cy, rc.Height ());
	rcTmp.SetRect (x, y, x + 15, cy);

	dc.DrawEdge (rcTmp, EDGE_BUMP, BF_FLAT | BF_RECT);

	m_pImgShadow->Unlock ();
	DCTmp.Detach ();
}
Example #14
0
void CStatusLabel::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
	CDC dc;
	dc.Attach(lpDrawItemStruct->hDC);
		CString str;
		GetWindowText(str);
		CRect r;
		GetClientRect(&r);
		CFont* old = dc.SelectObject(&m_font);
		dc.SetTextColor(0xffffff);
		dc.SetBkColor(0);
		CSize size = dc.GetTextExtent(str);
		CPoint p = CPoint(m_fRightAlign ? r.Width() - size.cx : 0, (r.Height()-size.cy)/2);

		if(m_fAddEllipses)
		while(size.cx > r.Width()-3 && str.GetLength() > 3)
		{
			str = str.Left(str.GetLength()-4) + _T("...");
			size = dc.GetTextExtent(str);
		}

		dc.TextOut(p.x, p.y, str);
		dc.ExcludeClipRect(CRect(p, size));
		dc.SelectObject(&old);
		dc.FillSolidRect(&r, 0);
	dc.Detach();
}
Example #15
0
void CChartCtrl::SaveAsImage(const TChartString& strFilename, 
							 const CRect& rect,
							 int nBPP,
							 REFGUID guidFileType)
{
	//AFX_MANAGE_STATE(AfxGetStaticModuleState()); 

	CImage chartImage;
	CRect chartRect = rect;
	if (chartRect.IsRectEmpty())
	{
		GetClientRect(&chartRect);
	}
    
	chartImage.Create(chartRect.Width(), chartRect.Height(), nBPP);
	CDC newDC;
	newDC.Attach(chartImage.GetDC());

	DrawBackground(&newDC, chartRect);
	chartRect.DeflateRect(3,3);
	DrawChart(&newDC, chartRect);

	newDC.Detach();
	chartImage.Save(strFilename.c_str(), guidFileType);
	chartImage.ReleaseDC();
}
Example #16
0
void CCoolMenu::OnMeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct) 
{
	if ( lpMeasureItemStruct->itemID == ID_SEPARATOR )
	{
		lpMeasureItemStruct->itemWidth	= 16;
		lpMeasureItemStruct->itemHeight	= 2;
	}
	else
	{
		CString strText;
		CDC dc;
		
		m_pStrings.Lookup( lpMeasureItemStruct->itemData, strText );
		
		dc.Attach( GetDC( 0 ) );
		
		CFont* pOld = (CFont*)dc.SelectObject( &CoolInterface.m_fntNormal );
		CSize sz = dc.GetTextExtent( strText );
		dc.SelectObject( pOld );
		
		ReleaseDC( 0, dc.Detach() );
		
		lpMeasureItemStruct->itemWidth	= sz.cx + 32;
		lpMeasureItemStruct->itemHeight	= 23;
	}
	
	if ( m_hMsgHook == NULL ) lpMeasureItemStruct->itemHeight ++;
}
void CWndMapPartsAnimeList::OnPaint()
{
	int x, cx, cy;
	HDC hDC;
	CDC DCTmp;
	CRect rc, rcTmp;
	CRgn rgn;
	CPaintDC dc(this);

	hDC = m_pImgParts->Lock ();
	DCTmp.Attach (hDC);

	GetClientRect (rc);
	rgn.CreateRectRgn (0, 0, rc.Width (), rc.Height ());
	dc.SelectClipRgn (&rgn, RGN_COPY);

	x = GetScrollPos (SB_HORZ);

	cx = min (rc.Width (), m_pImgParts->Width ());
	cy = min (rc.Height (), m_pImgParts->Height ());
	dc.FillSolidRect (rc, RGB (128, 128, 128));
	dc.BitBlt (0, 0, cx, cy, &DCTmp, x * 16, 0, SRCCOPY);

	m_pImgParts->Unlock ();
	DCTmp.Detach ();
}
//////////////////
// Draw the tab: mimic SysTabControl32, except use gray if tab is disabled
//
void CMyTabCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
	DRAWITEMSTRUCT& ds = *lpDrawItemStruct;

	int iItem = ds.itemID;

	// Get tab item info
	char text[128];
	TCITEM tci;
	tci.mask = TCIF_TEXT;
	tci.pszText = text;
	tci.cchTextMax = sizeof(text);
	GetItem(iItem, &tci);

	// use draw item DC
	CDC dc;
	dc.Attach(ds.hDC);

	// calculate text rectangle and color
	CRect rc = ds.rcItem;
	rc += CPoint(1,4);						 // ?? by trial and error

	// draw the text
	OnDrawText(dc, rc, text, !IsTabEnabled(iItem));

	dc.Detach();
}
Example #19
0
void CPWStatusBar::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
  switch (lpDrawItemStruct->itemID) {
    case SB_FILTER:
      // Attach to a CDC object
      CDC dc;
      dc.Attach(lpDrawItemStruct->hDC);

      // Get the pane rectangle and calculate text coordinates
      CRect rect(&lpDrawItemStruct->rcItem);
      if (m_bFilterStatus) {
        // Centre bitmap in pane.
        int ileft = rect.left + rect.Width() / 2 - m_bmWidth / 2;
        int itop = rect.top + rect.Height() / 2 - m_bmHeight / 2;

        CBitmap *pBitmap = &m_FilterBitmap;
        CDC srcDC; // select current bitmap into a compatible CDC
        srcDC.CreateCompatibleDC(NULL);
        CBitmap* pOldBitmap = srcDC.SelectObject(pBitmap);
        dc.BitBlt(ileft, itop, m_bmWidth, m_bmHeight,
                  &srcDC, 0, 0, SRCCOPY); // BitBlt to pane rect
        srcDC.SelectObject(pOldBitmap);
      } else {
        dc.FillSolidRect(&rect, ::GetSysColor(COLOR_BTNFACE));
      }
      // Detach from the CDC object, otherwise the hDC will be
      // destroyed when the CDC object goes out of scope
      dc.Detach();

      return;
  }

  CStatusBar::DrawItem(lpDrawItemStruct);
}
Example #20
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 #21
0
void CCoolMenu::SetWatermark(HBITMAP hBitmap)
{
	if ( m_bmWatermark.m_hObject != NULL )
	{
		m_dcWatermark.SelectObject( CBitmap::FromHandle( m_hOldMark ) );
		m_bmWatermark.DeleteObject();
		m_dcWatermark.DeleteDC();
	}
	
	if ( hBitmap != NULL )
	{
		CDC dc;		  
		dc.Attach( GetDC( 0 ) );
		m_dcWatermark.CreateCompatibleDC( &dc );
		ReleaseDC( 0, dc.Detach() );
		
		m_bmWatermark.Attach( hBitmap );
		m_hOldMark = (HBITMAP)m_dcWatermark.SelectObject( &m_bmWatermark )->GetSafeHandle();
		
		BITMAP pInfo;
		m_bmWatermark.GetBitmap( &pInfo );
		m_czWatermark.cx = pInfo.bmWidth;
		m_czWatermark.cy = pInfo.bmHeight;
	}
}
Example #22
0
void CFontComboBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
{
	ASSERT(lpDrawItemStruct->CtlType == ODT_COMBOBOX);
	CString strText;
	//判断当前索引的字体名称是否为空
	int nIndex = lpDrawItemStruct->itemID;
	if (GetLBTextLen(nIndex) < 0)
		return ;
	GetLBText(nIndex, strText);
	ASSERT(!strText.IsEmpty());
	int nImage = 0;
	//根据索引值从m_pFontVec得到字体图像类型
	if (!m_pFontVec.empty())
		nImage = m_pFontVec[nIndex]->GetImage();
	CDC dc;
	dc.Attach(lpDrawItemStruct->hDC);
	COLORREF crOldTextColor = dc.GetTextColor();
	COLORREF crOldBkColor = dc.GetBkColor();
	//如果Item处于选择焦点、状态下,用系统高亮色改变文本和背景色
	if ((lpDrawItemStruct->itemAction | ODA_SELECT) &&
		(lpDrawItemStruct->itemState & ODS_SELECTED))
	{
		dc.SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
		dc.SetBkColor(::GetSysColor(COLOR_HIGHLIGHT));
		dc.FillSolidRect(&lpDrawItemStruct->rcItem, ::GetSysColor(COLOR_HIGHLIGHT));
	}
	else
		dc.FillSolidRect(&lpDrawItemStruct->rcItem, crOldBkColor);
	CRect     rItem(lpDrawItemStruct->rcItem);
	CRect     rText(rItem);
	CRect     rBmp(&rItem);
	if(m_FontBmp)
	{
		//计算Item中字体预览图的贴图位置
		rBmp.top +=  (rBmp.Height() - FNTIMG_Y) / 2;
		rBmp.bottom = rBmp.top + FNTIMG_Y + 1;
		rText.left += FNTIMG_X;
		if (nImage != (int)0XFF)
		{
			int x,y;
			x = nImage * FNTIMG_X;   //根据预览图类型计算源图的矩形大小
			y = FNTIMG_Y;
			CDC mdc;
			mdc.CreateCompatibleDC(&dc);
			CBitmap* pOldBmp = mdc.SelectObject(CBitmap::FromHandle(m_FontBmp));
			COLORREF clrTransparent = mdc.GetPixel(0, y);
			//调用TransparentBlt进行透明贴图,此函数需要加入MsImg32.Lib文件
			::TransparentBlt (dc.GetSafeHdc(),rBmp.left, rBmp.top, FNTIMG_X, FNTIMG_Y,  
				mdc, x, y, FNTIMG_X, FNTIMG_Y, clrTransparent);
		}
	}
	else
		rText.left += 10;
	//rText所代表的字体名称填充位置需要右移图片的宽度
	dc.DrawText(strText, rText, DT_LEFT|DT_SINGLELINE|DT_VCENTER);
	dc.SetTextColor(crOldTextColor);
	dc.SetBkColor(crOldBkColor);
	dc.Detach();
} 
Example #23
0
void kGUIPrintJobWin::EndPage(void)
{
	if (m_pdc.EndPage ()<=0)
	{
		m_error=true;
		m_pdc.Detach();
	}
}
Example #24
0
/* false=error, true=ok */
bool kGUIPrintJobWin::End(void)
{
	if(m_error==true) /* some error occured previously, abort */
        m_pdc.AbortDoc ();
	else
		m_pdc.EndDoc ();
	m_pdc.Detach();
	return(!m_error);
}
void CComboColorPicker::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
	CDC dc;
	CBrush brushBlack;
	brushBlack.CreateStockObject(BLACK_BRUSH);
	
	if (!dc.Attach(lpDrawItemStruct->hDC))
		return;

	COLORREF rgbTextColor = dc.GetTextColor();
	COLORREF rgbBkColor = dc.GetBkColor();

	if (lpDrawItemStruct->itemAction & ODA_FOCUS)
	{
		dc.DrawFocusRect(&lpDrawItemStruct->rcItem);
	}
	else if (lpDrawItemStruct->itemAction & ODA_DRAWENTIRE)
	{
		if (lpDrawItemStruct->itemState & ODS_FOCUS)
			dc.DrawFocusRect(&lpDrawItemStruct->rcItem);
		else
			dc.ExtTextOut(0, 0, ETO_OPAQUE, &lpDrawItemStruct->rcItem, _T(""), 0, NULL);
	}

	if (0 <= (int)lpDrawItemStruct->itemID)	// Any item selected?
	{
		::InflateRect(&lpDrawItemStruct->rcItem, -2, -2);

		if( (COLORREF)lpDrawItemStruct->itemData == 0xFFFFFFFF )
		{
			CSize	textSize = dc.GetTextExtent( _T("default") );
			dc.FillSolidRect( &lpDrawItemStruct->rcItem, RGB( 0xFF, 0xFF, 0xFF ) );
			dc.FrameRect( &lpDrawItemStruct->rcItem, &brushBlack );

			dc.SetTextColor( RGB( 0x00, 0x00, 0x00 ) );
			dc.SetBkColor( RGB( 0xFF, 0xFF, 0xFF ) );
			dc.SetTextAlign( TA_CENTER | TA_TOP | TA_NOUPDATECP );
			dc.TextOut( 
				lpDrawItemStruct->rcItem.left + (lpDrawItemStruct->rcItem.right - lpDrawItemStruct->rcItem.left) / 2, 
				lpDrawItemStruct->rcItem.top +
					((lpDrawItemStruct->rcItem.bottom - lpDrawItemStruct->rcItem.top) / 2) -
					(textSize.cy / 2), 
				_T("default") );
		}
		else
		{
			dc.FillSolidRect(&lpDrawItemStruct->rcItem, (COLORREF)lpDrawItemStruct->itemData);
			dc.FrameRect(&lpDrawItemStruct->rcItem, &brushBlack);
		}
	}

	// Restore the DC state
	dc.SetTextColor(rgbTextColor);
	dc.SetBkColor(rgbBkColor);
	dc.Detach();
}
Example #26
0
BOOL CEdRptDoc::PrintAuto(CPrintDialog *pPntDlg)
{
	// 严禁在不使用省却打印机情况下不指定打印机
	ASSERT(m_bDefaultPrint || pPntDlg);
	
	// get default print
	CPrintDialog defaultDlg (FALSE, PD_RETURNDC );
	AfxGetApp()->GetPrinterDeviceDefaults( &defaultDlg.m_pd );	

	if (!pPntDlg)
		pPntDlg = &defaultDlg;
	
	HDC hdc = pPntDlg->CreatePrinterDC();
	ASSERT(hdc);
	CDC dc;
	dc.Attach( hdc );
	
    dc.m_bPrinting = TRUE;
	
    CString strTitle = m_szTitle;
	if (strTitle.IsEmpty())
		strTitle.LoadString(AFX_IDS_APP_TITLE);
		
    DOCINFO di;                                 // Initialise print doc details
    memset(&di, 0, sizeof (DOCINFO));
    di.cbSize = sizeof (DOCINFO);
    di.lpszDocName = strTitle;
	
    BOOL bPrintingOK = dc.StartDoc(&di);        // Begin a new print job
	
    CPrintInfo Info;
    Info.m_rectDraw.SetRect(0,0, dc.GetDeviceCaps(HORZRES), dc.GetDeviceCaps(VERTRES));
	
    m_Grid.OnBeginPrinting(&dc, &Info);                // Initialise printing
	m_Grid.SetFocus();
    for (UINT page = Info.GetMinPage(); page <= Info.GetMaxPage() && bPrintingOK; page++)
    {
        dc.StartPage();                         // begin new page
        Info.m_nCurPage = page;
        m_Grid.OnPrint(&dc, &Info);                    // Print page
        bPrintingOK = (dc.EndPage() > 0);       // end page
    }
    m_Grid.OnEndPrinting(&dc, &Info);                  // Clean up after printing
	
    if (bPrintingOK)
        dc.EndDoc();                            // end a print job
    else
        dc.AbortDoc();                          // abort job.
	
    dc.Detach();                                // detach the printer DC
	
	DeleteDC(hdc);

	return TRUE;
}
Example #27
0
//
// Show a help balloon on screen
// Parameters:
//    strTitle    |  Title of balloon
//    strContent  |  Content of balloon
//    ptAnchor    |  point tail of balloon will be "anchor"ed to
//    szIcon      |  One of:
//                   IDI_APPLICATION
//                   IDI_INFORMATION IDI_ASTERISK (same)
//                   IDI_ERROR IDI_HAND (same)
//                   IDI_EXCLAMATION IDI_WARNING (same)
//                   IDI_QUESTION
//                   IDI_WINLOGO
//                   NULL (no icon)
//    unOptions   |  One or more of:
//                :     unCLOSE_ON_LBUTTON_UP   |  closes window on WM_LBUTTON_UP
//                :     unCLOSE_ON_MBUTTON_UP   |  closes window on WM_MBUTTON_UP
//                :     unCLOSE_ON_RBUTTON_UP   |  closes window on WM_RBUTTON_UP
//                :     unCLOSE_ON_LBUTTON_DOWN |  closes window on WM_LBUTTON_DOWN
//                :     unCLOSE_ON_MBUTTON_DOWN |  closes window on WM_MBUTTON_DOWN
//                :     unCLOSE_ON_RBUTTON_DOWN |  closes window on WM_RBUTTON_DOWN
//                :     unCLOSE_ON_MOUSE_MOVE   |  closes window when user moves mouse past threshhold
//                :     unCLOSE_ON_KEYPRESS     |  closes window on the next keypress message sent to this thread.  (!!! probably not thread safe !!!)
//                :     unSHOW_CLOSE_BUTTON     |  shows close button in upper right
//                :     unSHOW_INNER_SHADOW     |  draw inner shadow in balloon
//                :     unSHOW_TOPMOST          |  place balloon above all other windows
//                :     unDISABLE_FADE          |  disable the fade-in/fade-out effects (overrides system and user settings)
//                :     unDISABLE_FADEIN        |  disable the fade-in effect
//                :     unDISABLE_FADEOUT       |  disable the fade-out effect
//    pParentWnd  |  Parent window.  If NULL will be set to AfxGetMainWnd(), and anchor to screen
//    strURL      |  If not empty, when the balloon is clicked ShellExecute() will
//                |  be called, with strURL passed in.
//    unTimeout   |  If not 0, balloon will automatically close after unTimeout milliseconds.
//
void CBalloonHelp::LaunchBalloon(const CString& strTitle, const CString& strContent, 
								 const CPoint& ptAnchor, 
								 LPCTSTR szIcon /*= IDI_EXCLAMATION*/,
								 unsigned int unOptions /*= unSHOW_CLOSE_BUTTON*/,
								 CWnd* pParentWnd /*= NULL*/,
								 const CString strURL /*= ""*/,
								 unsigned int unTimeout /*= 10000*/)
{
	CBalloonHelp* pbh = new CBalloonHelp;
	if ( NULL != szIcon )
	{
		HICON hIcon = (HICON)::LoadImage(NULL, szIcon, IMAGE_ICON, 16,16, LR_SHARED);
		if (NULL != hIcon)
		{
			// Use a scaled standard icon (looks very good on Win2k, XP, not so good on Win9x)
			CDC dc;
			CDC dcTmp1;
			CDC dcTmp2;
			CBitmap bmpIcon;
			CBitmap bmpIconSmall;
			dc.Attach(::GetDC(NULL));
			dcTmp1.CreateCompatibleDC(&dc);
			dcTmp2.CreateCompatibleDC(&dc);
			bmpIcon.CreateCompatibleBitmap(&dc, 32,32);
			bmpIconSmall.CreateCompatibleBitmap(&dc, 16,16);
			::ReleaseDC(NULL, dc.Detach());
			
			// i now have two device contexts and two bitmaps.
			// i will select a bitmap in each device context,
			// draw the icon into the larger one,
			// scale it into the smaller one,
			// and set the small one as the balloon icon.
			// This is a rather long process to get a small icon,
			// but ensures maximum compatibility between different
			// versions of Windows, while producing the best possible
			// results on each version.
			CBitmap* pbmpOld1 = dcTmp1.SelectObject(&bmpIcon);
			CBitmap* pbmpOld2 = dcTmp2.SelectObject(&bmpIconSmall);
			dcTmp1.FillSolidRect(0,0,32,32, pbh->m_crBackground);
			::DrawIconEx(dcTmp1, 0,0,hIcon,32,32,0,NULL,DI_NORMAL);
			dcTmp2.SetStretchBltMode(HALFTONE);
			dcTmp2.StretchBlt(0,0,16,16,&dcTmp1, 0,0,32,32,SRCCOPY);
			dcTmp1.SelectObject(pbmpOld1);
			dcTmp2.SelectObject(pbmpOld2);
			
			pbh->SetIcon(bmpIconSmall, pbh->m_crBackground);
		}
	}
	
	pbh->Create(strTitle, strContent, ptAnchor, unOptions|unDELETE_THIS_ON_CLOSE, 
		pParentWnd, strURL, unTimeout, NULL);
}
// CMyODListBox is my owner-drawn list box derived from CListBox. This 
// example draws an item's text centered vertically and horizontally. The 
// list box control was created with the following code:
//   m_myODListBox.Create(
//      WS_CHILD|WS_VISIBLE|WS_BORDER|WS_HSCROLL|WS_VSCROLL|
//      LBS_SORT|LBS_MULTIPLESEL|LBS_OWNERDRAWVARIABLE|LBS_WANTKEYBOARDINPUT,
//      CRect(10,250,200,450), pParentWnd, IDC_MYODLISTBOX);
//
void CMyODListBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
   ASSERT(lpDrawItemStruct->CtlType == ODT_LISTBOX);
   LPCTSTR lpszText = (LPCTSTR) lpDrawItemStruct->itemData;
   ASSERT(lpszText != NULL);
   CDC dc;

   dc.Attach(lpDrawItemStruct->hDC);

   // Save these value to restore them when done drawing.
   COLORREF crOldTextColor = dc.GetTextColor();
   COLORREF crOldBkColor = dc.GetBkColor();

   // If this item is selected, set the background color 
   // and the text color to appropriate values. Also, erase
   // rect by filling it with the background color.
   if ((lpDrawItemStruct->itemAction | ODA_SELECT) &&
      (lpDrawItemStruct->itemState & ODS_SELECTED))
   {
      dc.SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
      dc.SetBkColor(::GetSysColor(COLOR_HIGHLIGHT));
      dc.FillSolidRect(&lpDrawItemStruct->rcItem, 
         ::GetSysColor(COLOR_HIGHLIGHT));
   }
   else
   {
      dc.FillSolidRect(&lpDrawItemStruct->rcItem, crOldBkColor);
   }

   // If this item has the focus, draw a red frame around the
   // item's rect.
   if ((lpDrawItemStruct->itemAction | ODA_FOCUS) &&
      (lpDrawItemStruct->itemState & ODS_FOCUS))
   {
      CBrush br(RGB(255, 0, 0));
      dc.FrameRect(&lpDrawItemStruct->rcItem, &br);
   }

   // Draw the text.
   dc.DrawText(
      lpszText,
      (int)_tcslen(lpszText),
      &lpDrawItemStruct->rcItem,
      DT_CENTER|DT_SINGLELINE|DT_VCENTER);

   // Reset the background color and the text color back to their
   // original values.
   dc.SetTextColor(crOldTextColor);
   dc.SetBkColor(crOldBkColor);

   dc.Detach();
}
void CShareFilesCountStatic::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
	// TODO:  添加您的代码以绘制指定项
	CDC	dc;
	dc.Attach(lpDrawItemStruct->hDC);

	CRect	rect = lpDrawItemStruct->rcItem;
	DrawBk(&dc, rect);
	rect.DeflateRect(8, 3);
	DrawText(&dc, rect);

	dc.Detach();
}
Example #30
0
void CPlayerToolBar::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult)
{
    LPNMTBCUSTOMDRAW pTBCD = reinterpret_cast<LPNMTBCUSTOMDRAW>(pNMHDR);
    LRESULT lr = CDRF_DODEFAULT;
    switch (pTBCD->nmcd.dwDrawStage) {
        case CDDS_PREERASE:
            m_volctrl.Invalidate();
            lr = CDRF_DODEFAULT;
            break;
        case CDDS_PREPAINT: {
            // paint the control background, this is needed for XP
            CDC dc;
            dc.Attach(pTBCD->nmcd.hdc);
            RECT r;
            GetClientRect(&r);
            dc.FillSolidRect(&r, ::GetSysColor(COLOR_BTNFACE));
            dc.Detach();
        }
        lr |= CDRF_NOTIFYITEMDRAW;
        break;
        case CDDS_ITEMPREPAINT:
            // notify we want to paint after the system's paint cycle
            lr |= CDRF_NOTIFYPOSTPAINT;
            lr |= CDRF_NOTIFYITEMDRAW;
            break;
        case CDDS_ITEMPOSTPAINT:
            // paint over the duplicated separator
            CDC dc;
            dc.Attach(pTBCD->nmcd.hdc);
            RECT r;
            GetItemRect(11, &r);
            dc.FillSolidRect(&r, GetSysColor(COLOR_BTNFACE));
            dc.Detach();
            lr |= CDRF_SKIPDEFAULT;
            break;
    }

    *pResult = lr;
}