本文整理汇总了C++中CDC::Detach方法的典型用法代码示例。如果您正苦于以下问题:C++ CDC::Detach方法的具体用法?C++ CDC::Detach怎么用?C++ CDC::Detach使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CDC
的用法示例。
在下文中一共展示了CDC::Detach方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OnNMCustomdraw
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;
}
示例2: OnFilePrint
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();
}
示例3: OnPaint
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 ();
}
示例4: UpdateLayer
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);
}
示例5: DrawItem
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();
}
示例6: OnDrawItem
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);
}
示例7: onDrawItem
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;
}
示例8: onDrawItem
/// <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;
}
}
示例9: OnPaint
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();
}
示例10: LayerUpdate
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);
}
示例11: SetWatermark
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;
}
}
示例12: DrawItem
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();
}
示例13: OnPaint
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 ();
}
示例14: DrawItem
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();
}
示例15: SaveAsImage
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();
}