本文整理汇总了C++中CDC::Attach方法的典型用法代码示例。如果您正苦于以下问题:C++ CDC::Attach方法的具体用法?C++ CDC::Attach怎么用?C++ CDC::Attach使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CDC
的用法示例。
在下文中一共展示了CDC::Attach方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PrintAuto
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;
}
示例2: Print
void CChartCtrl::Print(const TChartString& strTitle, CPrintDialog* pPrntDialog)
{
CDC dc;
if (pPrntDialog == NULL)
{
CPrintDialog printDlg(FALSE);
if (printDlg.DoModal() != IDOK) // Get printer settings from user
return;
dc.Attach(printDlg.GetPrinterDC()); // attach a printer DC
}
else
dc.Attach(pPrntDialog->GetPrinterDC()); // attach a printer DC
dc.m_bPrinting = TRUE;
DOCINFO di; // Initialise print doc details
memset(&di, 0, sizeof (DOCINFO));
di.cbSize = sizeof (DOCINFO);
di.lpszDocName = strTitle.c_str();
BOOL bPrintingOK = dc.StartDoc(&di); // Begin a new print job
CPrintInfo Info;
Info.m_rectDraw.SetRect(0,0, dc.GetDeviceCaps(HORZRES), dc.GetDeviceCaps(VERTRES));
OnBeginPrinting(&dc, &Info); // Initialise printing
for (UINT page = Info.GetMinPage(); page <= Info.GetMaxPage() && bPrintingOK; page++)
{
dc.StartPage(); // begin new page
Info.m_nCurPage = page;
OnPrint(&dc, &Info); // Print page
bPrintingOK = (dc.EndPage() > 0); // end page
}
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
}
示例3: CreatePrinterDC
BOOL CWinApp::CreatePrinterDC(CDC& dc)
{
HDC hDC = AfxCreateDC(m_hDevNames, m_hDevMode);
if (hDC != NULL)
{
dc.DeleteDC();
VERIFY(dc.Attach(hDC));
return TRUE;
}
return FALSE;
}
示例4: DrawItem
// 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();
}
示例5: LaunchBalloon
//
// 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);
}
示例6: DrawItem
void CProgressStatusBar::DrawItem(LPDRAWITEMSTRUCT pDIS)
{
//TRACE("CProgressStatusBar::DrawItem: %d percent!\n", m_Percent);
CDC dc;
dc.Attach(pDIS->hDC);
CRect rc(pDIS->rcItem);
CRect rc2(rc);
rc.right = rc.left + MulDiv(rc.Width(), m_Percent, 100);
rc2.left = rc.right;
dc.FillSolidRect(&rc, GetSysColor(COLOR_BTNTEXT));
dc.FillSolidRect(&rc2, GetSysColor(COLOR_BTNFACE));
dc.Detach();
}
示例7: GetPrinterInfo
void kGUISystemWin::GetPrinterInfo(const char *name,int *pw,int *ph,int *ppih,int *ppiv)
{
HDC printerHDC;
CDC dc;
CreateHDC(name,1,&printerHDC);
dc.Attach (printerHDC);
pw[0] = dc.GetDeviceCaps(HORZRES);
ph[0] = dc.GetDeviceCaps(VERTRES);
ppih[0] = dc.GetDeviceCaps(LOGPIXELSX);
ppiv[0] = dc.GetDeviceCaps(LOGPIXELSY);
dc.Detach();
}
示例8: OnCustomDraw
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;
}
示例9: OnDrawItem
void CTabpageBorrow::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// TODO: Add your message handler code here and/or call default
if (nIDCtl == IDC_RADIO_PASS || nIDCtl == IDC_RADIO_FAIL)
{
CDC dc;
RECT rc;
dc.Attach(lpDrawItemStruct->hDC);
dc.SetTextColor(RGB(255, 255, 255));
dc.Detach();
}
CDialogEx::OnDrawItem(nIDCtl, lpDrawItemStruct);
}
示例10: DrawItem
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();
}
示例11: DrawItem
void CMDITabsDialogBar::DrawItem(LPDRAWITEMSTRUCT pdis)
{
CRect rc = pdis->rcItem;
int nTabIndex = pdis->itemID;
bool fSelected = (nTabIndex == GetCurSel());
ODA_DRAWENTIRE;
char label[64];
TCITEM tci;
tci.mask = TCIF_TEXT | TCIF_PARAM;
tci.pszText = label;
tci.cchTextMax = ARRAYSIZE(label);
if (GetItem(nTabIndex, &tci))
{
CMDITabChildWnd *pActive = reinterpret_cast<CMDITabChildWnd*>(tci.lParam);
CDC dc;
dc.Attach(pdis->hDC);
int iIndex = _GetBitmapIndex(pActive->GetTabType());
CExtBitmap &bitmapToUse = fSelected ? _tabBitmap[iIndex] : _tabBitmapNS[iIndex];
CRect rcSrc(CPoint(0, 0), bitmapToUse.GetSize());
//CRect rcPadding(2, 2, 2, 2);
CRect rcPadding(0, 0, 0, 0);
bitmapToUse.AlphaBlendSkinParts(pdis->hDC, rc, rcSrc, rcPadding, /*__EXT_BMP_FLAG_PREMULTIPLIED_RGB_CHANNELS |*/ CExtBitmap::__EDM_STRETCH, true, true, 0xFF);
// Use a different font decoration depending on if this is the most recent version of this item.
bool fNotMostRecent = false;
CDocument *pDocAny = pActive->GetActiveDocument();
if (pDocAny && pDocAny->IsKindOf(RUNTIME_CLASS(CResourceDocument)))
{
CResourceDocument *pDoc = static_cast<CResourceDocument*>(pDocAny);
fNotMostRecent = !theApp._resourceRecency.IsResourceMostRecent(pDoc);
}
if (fNotMostRecent)
{
// Draw a diagonal line across the thing.
dc.MoveTo(rc.TopLeft());
dc.LineTo(rc.BottomRight());
}
rc.OffsetRect(4, 1); // indent
COLORREF crText = RGB(0, 0, 0); // g_PaintManager->PAINTPUSHBUTTONDATA::m_clrForceTextNormal; // green in release, black in debug!
int nOldText = dc.SetTextColor(crText);
int nOldBk = dc.SetBkMode(TRANSPARENT);
dc.DrawText(tci.pszText, -1, &rc, DT_SINGLELINE);
dc.SetBkMode(nOldBk);
dc.SetTextColor(nOldText);
dc.Detach();
}
}
示例12: WriteWindow2Mem
BOOL WriteWindow2Mem(BYTE* buf, int W, int H, HDC hDC)
{
CBitmap bitmap;
CDC memDC;
CRect rect;
CDC dc;
dc.Attach(hDC);
CDC* pDC = &dc;
bitmap.CreateCompatibleBitmap(pDC, W,H );
CBitmap* pOldBitmap = memDC.SelectObject(&bitmap);
memDC.BitBlt(0, 0, W,H, pDC, 0, 0, SRCCOPY);
// Create logical palette if device support a palette
CPalette pal;
if( pDC->GetDeviceCaps(RASTERCAPS) & RC_PALETTE )
{
UINT nSize = sizeof(LOGPALETTE) + (sizeof(PALETTEENTRY) * 256);
LOGPALETTE *pLP = (LOGPALETTE *) new BYTE[nSize];
pLP->palVersion = 0x300;
pLP->palNumEntries =
::GetSystemPaletteEntries( *pDC, 0, 255, pLP->palPalEntry );
// Create the palette
pal.CreatePalette( pLP );
delete[] pLP;
}
memDC.SelectObject(pOldBitmap);
// Convert the bitmap to a DIB
HANDLE hDIB = DDBToDIB( bitmap, BI_RGB, &pal );
if( hDIB == NULL )
return FALSE;
// Write it to file
WriteDIB2Mem(hDIB, W, H, buf);
// Free the memory allocated by DDBToDIB for the DIB
GlobalFree( hDIB );
dc.Detach();
return TRUE;
}
示例13: OnDraw
void CUIDesignerView::OnDraw(CDC* pDrawDC)
{
CUIDesignerDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
// TODO: 在此处为本机数据添加绘制代码
CMemDC memDC(*pDrawDC, this);
CDC* pDC = &memDC.GetDC();
CRect rectClient;
GetClientRect(rectClient);
CPoint point=GetScrollPosition();
rectClient.OffsetRect(point);
pDC->FillSolidRect(rectClient,RGB(255, 255, 255));
CSize szForm=m_LayoutManager.GetForm()->GetInitSize();
CSize szFormOffset(FORM_OFFSET_X,FORM_OFFSET_Y);
CDC hCloneDC;
HBITMAP hNewBitmap;
hCloneDC.CreateCompatibleDC(pDC);
hNewBitmap=::CreateCompatibleBitmap(pDC->GetSafeHdc(),szForm.cx,szForm.cy);
HBITMAP hOldBitmap=(HBITMAP)hCloneDC.SelectObject(hNewBitmap);
if (m_brHatch.m_hObject){
CDC cloneDC;
cloneDC.Attach(hCloneDC);
CRect rcTemp = rectClient;
rcTemp.top= rcTemp.top>=20 ? rcTemp.top-20 : 0;
rcTemp.left= rcTemp.left>=20 ? rcTemp.left-20 : 0;
//rcTemp.right = max(rcTemp.right , m_pScrollHelper->GetDisplaySize().cx);
//rcTemp.bottom = max(rcTemp.bottom, m_pScrollHelper->GetDisplaySize().cy);
m_brHatch.UnrealizeObject();
CPoint pt(0, 0);
cloneDC.LPtoDP(&pt);
pt = cloneDC.SetBrushOrg(pt.x % 8, pt.y % 8);
CBrush* old = cloneDC.SelectObject(&m_brHatch);
cloneDC.FillRect(&rcTemp, &m_brHatch);
cloneDC.SelectObject(old);
cloneDC.Detach();
}
m_LayoutManager.Draw(&hCloneDC);
pDC->BitBlt(szFormOffset.cx,szFormOffset.cy,szForm.cx,szForm.cy,&hCloneDC,0,0,SRCCOPY);
hCloneDC.SelectObject(hOldBitmap);
::DeleteDC(hCloneDC);
::DeleteObject(hNewBitmap);
m_MultiTracker.Draw(pDC,&szFormOffset);
}
示例14: DrawItem
void CMyButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CDC dc;
dc.Attach(lpDrawItemStruct->hDC);
CDC MemDC;
MemDC.CreateCompatibleDC(&dc);
CBitmap bitmap;
if (lpDrawItemStruct->itemAction == ODA_SELECT || lpDrawItemStruct->itemState == ODS_DISABLED)
{
bitmap.LoadBitmap(IDB_BITMAP7);
MemDC.SelectObject(bitmap);
this->EnableWindow(FALSE);
}
else
{
bitmap.LoadBitmap(IDB_BITMAP4);
MemDC.SelectObject(bitmap);
}
dc.BitBlt(0, 0, 18, 18, &MemDC, 0, 0, SRCCOPY);
dc.Detach();
// UINT uStyle = DFCS_BUTTONPUSH;
//
// // This code only works with buttons.
// ASSERT(lpDrawItemStruct->CtlType == ODT_BUTTON);
//
// // If drawing selected, add the pushed style to DrawFrameControl.
// if (lpDrawItemStruct->itemState & ODS_SELECTED)
// uStyle |= DFCS_PUSHED;
//
// // Draw the button frame.
// ::DrawFrameControl(lpDrawItemStruct->hDC, &lpDrawItemStruct->rcItem,
// DFC_BUTTON, uStyle);
//
// // Get the button's text.
// CString strText;
// GetWindowText(strText);
//
// // Draw the button text using the text color red.
// COLORREF crOldColor = ::SetTextColor(lpDrawItemStruct->hDC, RGB(255,0,0));
// ::DrawText(lpDrawItemStruct->hDC, strText, strText.GetLength(),
// &lpDrawItemStruct->rcItem, DT_SINGLELINE|DT_VCENTER|DT_CENTER);
// ::SetTextColor(lpDrawItemStruct->hDC, crOldColor);
}
示例15: OnDrawItem
//-------------------------------------------------------------------------
void CDlgColours::OnDrawItem( int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct )
{
COLORREF crButton = m_oColor.Get( m_id_map[ nIDCtl ] );
CDC dc;
CBrush brush( crButton );
dc.Attach( lpDrawItemStruct->hDC );
dc.SelectStockObject( BLACK_PEN );
dc.SelectObject( &brush );
dc.Rectangle( &lpDrawItemStruct->rcItem );
dc.Detach();
super::OnDrawItem( nIDCtl, lpDrawItemStruct );
}