本文整理汇总了C++中CDC类的典型用法代码示例。如果您正苦于以下问题:C++ CDC类的具体用法?C++ CDC怎么用?C++ CDC使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CDC类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OpenProcess
void CMemoryWatcherDlg::OnTimer(UINT_PTR nIDEvent)
{
if (nIDEvent == 1)
{
if (!h)
{
if (m_ProcessID)
h = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, m_ProcessID);
else
h = GetCurrentProcess();
if (!h)
return;
}
PROCESS_MEMORY_COUNTERS pmc;
if (GetProcessMemoryInfo(h, &pmc, sizeof(pmc)))
{
points.push(pmc.WorkingSetSize);
points_pagefile.push(pmc.PagefileUsage);
peak = pmc.PeakWorkingSetSize;
peak_pagefile = pmc.PeakPagefileUsage;
}
else
{
points.push(0);
points_pagefile.push(0);
}
if (points.size() > m_NumSteps + 1)
{
points.pop();
points_pagefile.pop();
}
SIZE_T l, total;
CDC * idc = CDC::FromHandle(img->GetDC());
CPen pen, * oldpen, * oldpen2, pen2, pen3;
CString s;
// setting pen color
pen.CreatePen(PS_SOLID, 3, RGB(0, 200, 0));
oldpen = idc->SelectObject(&pen);
double dx = double(img->GetWidth()) / (m_NumSteps - 1), dy = double(img->GetHeight()) / (m_MaxMem - 1);
int x, y;
// clearing image
idc->FillSolidRect(-1, -1, img->GetWidth() + 2, img->GetHeight() + 2, RGB(0, 0, 0));
// drawing grid
pen2.CreatePen(PS_SOLID, 1, RGB(150, 150, 150));
oldpen2 = idc->SelectObject(&pen2);
for (UINT i = 0; i < points.size(); i++)
{
x = int(i * dx);
idc->MoveTo(x, 0);
idc->LineTo(x, img->GetHeight());
}
for (double i = 0.0; i < img->GetHeight(); i += img->GetHeight() / 10.0)
{
idc->MoveTo(0, int(i));
idc->LineTo(img->GetWidth(), int(i));
}
idc->SelectObject(oldpen2);
// setting text color
idc->SetTextColor(RGB(0, 200, 0));
// drawing points
for (UINT i = 0; i < points.size(); i++)
{
l = points._Get_container()[i];
x = int(i * dx);
y = img->GetHeight() - int(l * dy) - 1;
if (!i)
{
idc->MoveTo(x, y);
}
else
{
idc->LineTo(x, y);
}
if (i == points.size() - 1)
{
s.Format(L"Memory: %u KB of %u KB, peak %u KB", l / 1024, m_MaxMem / 1024, peak / 1024);
idc->TextOutW(1, 1, s);
total = l;
}
}
// drawing points_pagefile
// setting other pen color
pen3.CreatePen(PS_SOLID, 3, RGB(200, 0, 0));
oldpen2 = idc->SelectObject(&pen3);
// setting text color
idc->SetTextColor(RGB(200, 0, 0));
for (UINT i = 0; i < points_pagefile.size(); i++)
{
l = points_pagefile._Get_container()[i];
x = int(i * dx);
y = img->GetHeight() - int(l * dy) - 1;
if (!i)
{
idc->MoveTo(x, y);
}
else
{
idc->LineTo(x, y);
}
if (i == points_pagefile.size() - 1)
//.........这里部分代码省略.........
示例2: DrawWindow
// 画文字信息
void CPopupList::DrawWindow(CDC &dc, CRect rcClient)
{
int nItemCount = m_vecItem.size();
CFont *pOldFont = dc.SelectObject(&m_font);
COLORREF clrOld = dc.SetTextColor(RGB(0, 20, 35));
CRect rcItem, rcText;
CSize sizeImage;
for(int i = 0; i < nItemCount; i++)
{
EditListItem &editListItem = m_vecItem.at(i);
rcItem = editListItem.rcItem;
sizeImage = editListItem.sizeImage;
int nLeftStart = 47;
if(editListItem.pImage == NULL)
{
nLeftStart = 5;
}
// 显示当前项
if((i == m_nHoverItem) && !editListItem.strDesc.IsEmpty())
{
dc.FillSolidRect(&rcItem, RGB(0, 147, 209));
// 显示name和desc
dc.SetTextColor(RGB(0, 20, 35));
rcText.SetRect(rcItem.left + nLeftStart, rcItem.top + 6, rcItem.right - 2, rcItem.top + 24);
dc.DrawText(editListItem.strName, &rcText, DT_TOP | DT_LEFT | DT_SINGLELINE | DT_WORD_ELLIPSIS);
dc.SetTextColor(RGB(255, 255, 255));
rcText.OffsetRect(0, 21);
dc.DrawText(editListItem.strDesc, &rcText, DT_TOP | DT_LEFT | DT_SINGLELINE | DT_WORD_ELLIPSIS);
}
else
{
if(i == m_nHoverItem)
{
dc.FillSolidRect(&rcItem, RGB(0, 147, 209));
}
// 只显示name
dc.SetTextColor(RGB(0, 20, 35));
rcText.SetRect(rcItem.left + nLeftStart, rcItem.top, rcItem.right - 2, rcItem.bottom);
dc.DrawText(editListItem.strName, &rcText, DT_VCENTER | DT_LEFT | DT_SINGLELINE | DT_WORD_ELLIPSIS);
}
}
dc.SelectObject(pOldFont);
dc.SetTextColor(clrOld);
}
示例3: ASSERT
void CXTPReportRecordItemPercentNumber::OnDrawCaption(XTP_REPORTRECORDITEM_DRAWARGS* pDrawArgs, XTP_REPORTRECORDITEM_METRICS* pMetrics)
{
ASSERT(pDrawArgs->pItem == this);
CString sTxt = pMetrics->strText;
if (sTxt.Find('%') > -1)
{
sTxt.Replace(_T("%"), _T(""));
int iTxt = _ttoi(sTxt);
if (m_bPercentCompleteDisplay)
{
iTxt = max(0, iTxt);
iTxt = min(100, iTxt);
pMetrics->strText.Format(_T("%d"), iTxt);
CDC* pDC = pDrawArgs->pDC;
if (pDC)
{
CRect rc = pDrawArgs->rcItem;
rc.DeflateRect(2, 2, 2, 2);
int W = rc.Width();
if (pMetrics->nColumnAlignment == xtpColumnTextLeft)
rc.right = rc.left + W * iTxt / 100;
else if (pMetrics->nColumnAlignment == xtpColumnTextRight)
rc.left = rc.right - W * iTxt / 100;
else if (pMetrics->nColumnAlignment == xtpColumnTextCenter)
{
rc.left += W * (100 - iTxt) / 200;
rc.right -= W * (100 - iTxt) / 200;
}
if (pDrawArgs->pControl
&& pDrawArgs->pControl->GetPaintManager()
&& pDrawArgs->pControl->GetPaintManager()->m_bShowNonActiveInPlaceButton)
rc.right -= rc.Height();
pDC->FillSolidRect(rc, m_clr);
//CRgn rgnEvent;
//rgnEvent.CreateRoundRectRgn(rc.left, rc.top, rc.right, rc.bottom, 7, 7);
//CXTPPaintManagerColorGradient* pGrad = new CXTPPaintManagerColorGradient(m_clr);
//pDC->SelectClipRgn(&rgnEvent);
//CRect rcBk = rc;
//rcBk.DeflateRect(0, 1, 0, 1);
//XTPDrawHelpers()->GradientFill(pDC, &rcBk, *pGrad, FALSE);
//pDC->SelectClipRgn(NULL);
//delete pGrad;
}
}
}
if (m_pMarkupUIElement)
{
CRect rcItem = pDrawArgs->rcItem;
rcItem.DeflateRect(2, 1, 2, 0);
XTPMarkupSetDefaultFont(XTPMarkupElementContext(m_pMarkupUIElement), (HFONT)pMetrics->pFont->GetSafeHandle(), pMetrics->clrForeground);
XTPMarkupMeasureElement(m_pMarkupUIElement, rcItem.Width(), INT_MAX);
XTPMarkupRenderElement(m_pMarkupUIElement, pDrawArgs->pDC->GetSafeHdc(), &rcItem);
}
else
{
pDrawArgs->pControl->GetPaintManager()->DrawItemCaption(pDrawArgs, pMetrics);
}
}
示例4: memcpy
void CCheckListBox::PreDrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
_AFX_CHECKLIST_STATE* pChecklistState = _afxChecklistState;
DRAWITEMSTRUCT drawItem;
memcpy(&drawItem, lpDrawItemStruct, sizeof(DRAWITEMSTRUCT));
if ((((LONG)drawItem.itemID) >= 0) &&
((drawItem.itemAction & (ODA_DRAWENTIRE | ODA_SELECT)) != 0))
{
int cyItem = GetItemHeight(drawItem.itemID);
CDC* pDC = CDC::FromHandle(drawItem.hDC);
COLORREF newBkColor = GetSysColor(COLOR_WINDOW);
BOOL fDisabled = !IsWindowEnabled() || !IsEnabled(drawItem.itemID);
if ((drawItem.itemState & ODS_SELECTED) && !fDisabled)
newBkColor = GetSysColor(COLOR_HIGHLIGHT);
COLORREF oldBkColor = pDC->SetBkColor(newBkColor);
CDC bitmapDC;
if (bitmapDC.CreateCompatibleDC(pDC))
{
int nCheck = GetCheck(drawItem.itemID);
HBITMAP hOldBitmap = (HBITMAP)::SelectObject(bitmapDC.m_hDC, pChecklistState->m_hbitmapCheck);
CRect rectCheck = drawItem.rcItem;
rectCheck.left += 1;
rectCheck.top += 1 + max(0, (cyItem - pChecklistState->m_sizeCheck.cy) / 2);
rectCheck.right = rectCheck.left + pChecklistState->m_sizeCheck.cx;
rectCheck.bottom = rectCheck.top + pChecklistState->m_sizeCheck.cy;
CRect rectItem = drawItem.rcItem;
rectItem.right = rectItem.left + pChecklistState->m_sizeCheck.cx + 2;
CRect rectCheckBox = OnGetCheckPosition(rectItem, rectCheck);
ASSERT(rectCheck.IntersectRect(rectItem, rectCheckBox));
ASSERT((rectCheck == rectCheckBox) && (rectCheckBox.Size() == pChecklistState->m_sizeCheck));
CBrush brush(newBkColor);
pDC->FillRect(rectItem, &brush);
pDC->BitBlt(rectCheckBox.left, rectCheckBox.top,
pChecklistState->m_sizeCheck.cx, pChecklistState->m_sizeCheck.cy, &bitmapDC,
pChecklistState->m_sizeCheck.cx * nCheck, 0, SRCCOPY);
::SelectObject(bitmapDC.m_hDC, hOldBitmap);
}
pDC->SetBkColor(oldBkColor);
}
if (drawItem.itemData != 0)
{
AFX_CHECK_DATA* pState = (AFX_CHECK_DATA*)drawItem.itemData;
drawItem.itemData = pState->m_dwUserData;
}
drawItem.rcItem.left = drawItem.rcItem.left + pChecklistState->m_sizeCheck.cx + 2;
DrawItem(&drawItem);
}
示例5: dc
//绘画函数
VOID CUserInfoView::OnPaint()
{
CPaintDC dc(this);
//获取位置
CRect rcClient;
GetClientRect(&rcClient);
//建立缓冲
CDC BufferDC;
CBitmap ImageBuffer;
BufferDC.CreateCompatibleDC(&dc);
ImageBuffer.CreateCompatibleBitmap(&dc,rcClient.Width(),rcClient.Height());
//设置 DC
BufferDC.SetBkMode(TRANSPARENT);
BufferDC.SelectObject(&ImageBuffer);
BufferDC.SetTextColor(RGB(0,0,0));
//填充背景
BufferDC.FillSolidRect(&rcClient,COLOR_VIEW_BACKGROUND);
//绘画边框
CRect rcPhotoFram(PHOTO_FRAME_EXCURSION_X, PHOTO_FRAME_EXCURSION_Y, PHOTO_FRAME_EXCURSION_X+PHOTO_FRAME_WIDTH, PHOTO_FRAME_EXCURSION_Y+PHOTO_FRAME_HEIGHT);
CPen BorderPen(PS_SOLID,2,COLOR_PHOTO_FRAM);
CPen * pOldPen=BufferDC.SelectObject(&BorderPen);
BufferDC.RoundRect(&rcPhotoFram,CPoint(0,00));
BufferDC.SelectObject(pOldPen);
//创建字体
CFont Font;
VERIFY(Font.CreateFont(12,0,0,0,FW_NORMAL,FALSE,FALSE,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH | FF_SWISS,TEXT("宋体")));
CFont *pOldFont = BufferDC.SelectObject(&Font);
//绘画用户
if (m_pCurrentUserData!=NULL)
{
//变量定义
TCHAR szString[256]=TEXT("");
tagServerAttribute const* pGameAttribute=m_pIClientKernel->GetServerAttribute();
//绘画标识
if ( m_pCurrentUserData->dwCustomFaceVer == 0 )
{
//设置大小
rcPhotoFram.DeflateRect(1, 1, 2, 2);
if ( m_pCurrentUserData->cbGender != 2 )
{
CImageHandle ImageHandleMaleFace(&m_ImageMaleFace);
m_ImageMaleFace.BitBlt(BufferDC.GetSafeHdc(), rcPhotoFram.left, rcPhotoFram.top);
}
else
{
CImageHandle ImageHandleFemaleFace(&m_ImageFemaleFace);
m_ImageFemaleFace.BitBlt(BufferDC.GetSafeHdc(), rcPhotoFram.left, rcPhotoFram.top);
}
}
//用户头像
else
{
ASSERT(m_pIUserFaceRes!=NULL);
m_pIUserFaceRes->DrawCustomBigFace(&BufferDC,rcPhotoFram.left+1, rcPhotoFram.top+1,m_pCurrentUserData->dwUserID,m_pCurrentUserData->dwCustomFaceVer);
}
//用户属性
INT nUserInfoCuont = 6;
const tagUserData *pMeUserData = m_pIClientKernel->GetMeUserInfo();
if(pMeUserData!=NULL && m_pCurrentUserData->dwUserID==pMeUserData->dwUserID)
nUserInfoCuont++;
for (INT i=0;i<nUserInfoCuont;i++)
{
//位置定义
CRect rcString;
rcString.SetRect(PHOTO_FRAME_EXCURSION_X+PHOTO_FRAME_WIDTH+10,6+i*20,rcClient.Width()-5,6+i*20+15);
TCHAR szString[128];
//绘画信息
switch (i)
{
case 0: //用户帐号
{
//用户帐号
_sntprintf(szString,CountArray(szString),TEXT("用户名:%s"),m_pCurrentUserData->szName);
BufferDC.DrawText(szString,lstrlen(szString),&rcString,DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS);
break;
}
case 1:
{
//输出信息
if ( m_pCurrentUserData->cbGender == 0 )
_sntprintf(szString,CountArray(szString),TEXT("性别:保密"));
else if ( m_pCurrentUserData->cbGender == 1 )
_sntprintf(szString,CountArray(szString),TEXT("性别:男"));
else _sntprintf(szString,CountArray(szString),TEXT("性别:女"));
BufferDC.DrawText(szString,lstrlen(szString),&rcString,DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS);
//.........这里部分代码省略.........
示例6: MakeLightBitmap
static void
MakeLightBitmap(CBitmap *bitmap, CPaintDC *dc, CRect *rect, COLORREF color)
{
CBrush brush(dc->GetNearestColor(GetSysColor(COLOR_3DFACE)));
CBrush colorBrush(dc->GetNearestColor(color));
CPen pen(PS_SOLID, 1, dc->GetNearestColor(GetSysColor(COLOR_3DFACE)));
CDC lightDC;
CRect workRect;
//Make the bitmap we'll work on:
lightDC.CreateCompatibleDC(dc);
bitmap->CreateCompatibleBitmap(dc,
rect->Width(),
rect->Height());
lightDC.SelectObject(bitmap);
//The first step is to blank out the background
lightDC.SelectObject(&brush);
lightDC.SelectObject(&pen);
lightDC.Rectangle(0, 0, rect->Width(), rect->Height());
//Next, get a black pen and make a circle...
pen.DeleteObject();
pen.CreatePen(PS_SOLID, 1, dc->GetNearestColor(RGB(0, 0, 0)));
lightDC.SelectObject(&pen);
lightDC.Ellipse(rect);
workRect = *rect;
workRect.DeflateRect(LIGHT_WIDTH / 4, LIGHT_HEIGHT / 4);
lightDC.Ellipse(workRect);
//Last, fill it with the appropriate color:
//Next, get a black pen and make a circle...
lightDC.SelectObject(colorBrush);
lightDC.FloodFill(LIGHT_WIDTH / 2,
LIGHT_HEIGHT / 2,
dc->GetNearestColor(RGB(0, 0, 0)));
}
示例7: rcAll
HBITMAP CLibraryAlbumView::CreateDragImage(const CPoint& ptMouse, CPoint& ptMiddle)
{
CRect rcClient, rcOne, rcAll( 32000, 32000, -32000, -32000 );
GetClientRect( &rcClient );
for ( POSITION pos = m_pSelTrack.GetHeadPosition() ; pos ; )
{
CLibraryAlbumTrack* pTrack = m_pSelTrack.GetNext( pos );
GetItemRect( pTrack, &rcOne );
if ( rcOne.IntersectRect( &rcClient, &rcOne ) )
{
rcAll.left = min( rcAll.left, rcOne.left );
rcAll.top = min( rcAll.top, rcOne.top );
rcAll.right = max( rcAll.right, rcOne.right );
rcAll.bottom = max( rcAll.bottom, rcOne.bottom );
}
}
BOOL bClipped = rcAll.Height() > MAX_DRAG_SIZE;
if ( bClipped )
{
rcAll.left = max( rcAll.left, ptMouse.x - MAX_DRAG_SIZE_2 );
rcAll.right = max( rcAll.right, ptMouse.x + MAX_DRAG_SIZE_2 );
rcAll.top = max( rcAll.top, ptMouse.y - MAX_DRAG_SIZE_2 );
rcAll.bottom = max( rcAll.bottom, ptMouse.y + MAX_DRAG_SIZE_2 );
}
CClientDC dcClient( this );
CBitmap bmDrag;
CDC dcDrag;
if ( ! dcDrag.CreateCompatibleDC( &dcClient ) )
return NULL;
if ( ! bmDrag.CreateCompatibleBitmap( &dcClient, rcAll.Width(), rcAll.Height() ) )
return NULL;
CBitmap *pOldDrag = dcDrag.SelectObject( &bmDrag );
dcDrag.FillSolidRect( 0, 0, rcAll.Width(), rcAll.Height(), DRAG_COLOR_KEY );
CRgn pRgn;
ptMiddle.SetPoint( ptMouse.x - rcAll.left, ptMouse.y - rcAll.top );
if ( bClipped )
{
pRgn.CreateEllipticRgn( ptMiddle.x - MAX_DRAG_SIZE_2, ptMiddle.y - MAX_DRAG_SIZE_2,
ptMiddle.x + MAX_DRAG_SIZE_2, ptMiddle.y + MAX_DRAG_SIZE_2 );
dcDrag.SelectClipRgn( &pRgn );
}
CDC* pBuffer = CoolInterface.GetBuffer( dcClient, m_szTrack );
CRect rcBuffer( 0, 0, m_szTrack.cx, m_szTrack.cy );
CFont* pOldFont = (CFont*)pBuffer->SelectObject( &CoolInterface.m_fntNormal );
for ( POSITION pos = m_pSelTrack.GetHeadPosition() ; pos ; )
{
CLibraryAlbumTrack* pTrack = m_pSelTrack.GetNext( pos );
GetItemRect( pTrack, &rcOne );
CRect rcDummy;
if ( rcDummy.IntersectRect( &rcAll, &rcOne ) )
{
pBuffer->FillSolidRect( &rcBuffer, DRAG_COLOR_KEY );
pTrack->Paint( this, pBuffer, rcBuffer, -1 );
dcDrag.BitBlt( rcOne.left - rcAll.left, rcOne.top - rcAll.top,
m_szTrack.cx, m_szTrack.cy, pBuffer, 0, 0, SRCCOPY );
}
}
pBuffer->SelectObject( pOldFont );
dcDrag.SelectObject( pOldDrag );
dcDrag.DeleteDC();
return (HBITMAP) bmDrag.Detach();
}
示例8: GetStyle
void CWndImage::OnPaint()
{
DWORD style = GetStyle();
if (!(style & WS_VISIBLE)) return;
CPaintDC dc(this);
CRect r;
GetClientRect(&r);
CDC memdc;
memdc.CreateCompatibleDC( &dc );
CBitmap * prev = memdc.SelectObject(&m_bmp);
dc.SetStretchBltMode(HALFTONE); // works only under NT/2000, anyway..
CRect & src = m_srcRect;
CRect & dst = m_dstRect;
if (m_bltMode == bltTile)
{
if (!src.IsRectEmpty()) {
for(int x=m_origin.x; x < r.right; x+=src.Width()) {
if (x>-r.right) {
for(int y=m_origin.y; y<r.bottom; y+=src.right) {
if (y>-r.bottom) {
dc.BitBlt(x, y, src.Width(), src.Height(), &memdc, src.left, src.top,
SRCCOPY);
}
}
}
}
}
}
else {
dc.StretchBlt(dst.left, dst.top, dst.Width(), dst.Height(),
&memdc,
src.left, src.top, src.Width(), src.Height(),
SRCCOPY);
// clean background
CRect wipe;
if (dst.left > 0) {
wipe.SetRect(0,0, dst.left, r.bottom);
::FillRect(dc.m_hDC, &wipe, m_backBrush);
}
if (dst.top > 0) {
wipe.SetRect(dst.left, 0, dst.right, dst.top);
::FillRect(dc.m_hDC, &wipe, m_backBrush);
}
if (dst.right < r.right) {
wipe.SetRect(dst.right, 0, r.right, r.bottom);
::FillRect(dc.m_hDC, &wipe, m_backBrush);
}
if (dst.bottom < r.bottom) {
wipe.SetRect(dst.left, dst.bottom, dst.right, r.bottom);
::FillRect(dc.m_hDC, &wipe, m_backBrush);
}
}
memdc.SelectObject( prev );
}
示例9: defined
void
CMainFrame::updateImageInfo()
{
const CFlyCapDoc* pDoc = (CFlyCapDoc*)GetActiveDocument();
CView* pView = (CView*)GetActiveView();
if( m_wndStatusBar &&
pDoc != NULL &&
pView != NULL )
{
char pszText[ 64 ];
if( m_ImageInfoMode == TIMESTAMP )
{
// Setup the timestamp information
FlyCaptureTimestamp timeStamp = pDoc->m_imageRaw.timeStamp;
#if defined (WIN64)
__time64_t tmpTime = timeStamp.ulSeconds;
char* pszTemp = ::_ctime64( &tmpTime );
#elif defined (WIN32)
time_t lTemp = timeStamp.ulSeconds;
char* pszTemp = ::ctime( &lTemp );
#else
#error ** No time conversion **
#endif
if( pszTemp == NULL )
{
return;
}
int iMilliSec = timeStamp.ulMicroSeconds / 1000;
sprintf(
pszText,
"%.19s.%.03d %s (%03u,%04u)\n",
pszTemp,
iMilliSec,
&pszTemp[ 20 ],
timeStamp.ulCycleSeconds,
timeStamp.ulCycleCount );
}
else if( m_ImageInfoMode == CURSOR )
{
// Setup the cursor and image information
CRect rect;
CPoint pt;
COLORREF cr;
int iWidth = 0;
int iHeight = 0;
int iSBOffsetX = 0; // the offset of the horizontal scrollbar
int iSBOffsetY = 0; // the offset of the vertical scrollbar
// get the position of the scroll bars.
// used to calculate the co-ordinates of the image.
iSBOffsetX = pView->GetScrollPos(SB_HORZ);
iSBOffsetY = pView->GetScrollPos(SB_VERT);
pDoc->getImageSize( &iWidth, &iHeight );
CDC* pDC = pView->GetDC();
pDC->GetClipBox( &rect );
GetCursorPos( &pt );
pView->ScreenToClient( &pt );
cr = GetPixel( pDC->GetSafeHdc(), pt.x, pt.y );
pView->ReleaseDC( pDC );
// Check that this window is active and
// that the cursor is within bounds of the clipping rect
if( this == GetActiveWindow() &&
pt.x >= 0 && pt.x < rect.Width() && pt.y >= 0 && pt.y < rect.Height() )
{
sprintf( pszText, "Image(%dx%d) Cursor(%d,%d) RGB(%u,%u,%u)",
iWidth,
iHeight,
pt.x + iSBOffsetX,
pt.y + iSBOffsetY,
cr & 0xFF,
(cr & 0xFF00) >> 8,
(cr & 0xFF0000) >> 16 );
}
示例10: rect
void CMainDlg::DrawPhoto()
{
if (m_BitmapEx.IsValid())
{
//CBitmapEx m_PhotoBitmapEx;
//int tX,tY;
CDC *pDC = m_ctl_photo.GetDC();
CDC memDC;
memDC.CreateCompatibleDC(pDC);
CBitmap bmp;
bmp.CreateCompatibleBitmap(pDC, m_PhotoBitmapEx.GetWidth(), m_PhotoBitmapEx.GetHeight());
memDC.SelectObject(bmp);
CRect rect(0,0,m_PhotoBitmapEx.GetWidth(),m_PhotoBitmapEx.GetHeight());
CBrush bBlack(GetSysColor(COLOR_3DFACE));
memDC.FillRect(&rect, &bBlack);
m_PhotoBitmapEx.Draw(memDC);
pDC->FillRect(&m_PhotoRect, &bBlack);
pDC->SetStretchBltMode(HALFTONE);
pDC->StretchBlt(0,0,m_PhotoRect.Width(), m_PhotoRect.Height(),
&memDC,
0,0,
m_CutRect.Width(), m_CutRect.Height(),
SRCCOPY);
/*CDC *pDC = m_ctl_photo.GetDC();
CDC memDC;
memDC.CreateCompatibleDC(pDC);
CBitmap bmp;
bmp.CreateCompatibleBitmap(pDC, m_PhotoBitmapEx.GetWidth(), m_PhotoBitmapEx.GetHeight());
memDC.SelectObject(bmp);
CRect rect(0,0,m_PhotoBitmapEx.GetWidth(),m_PhotoBitmapEx.GetHeight());
CBrush bBlack(GetSysColor(COLOR_3DFACE));
memDC.FillRect(&rect, &bBlack);
m_PhotoBitmapEx.Draw(memDC);
pDC->FillRect(&m_PhotoRect, &bBlack);
pDC->SetStretchBltMode(HALFTONE);
pDC->StretchBlt(0,0,m_PhotoRect.Width(), m_PhotoRect.Height(),
&memDC,
0,0,
m_PhotoBitmapEx.GetWidth(), m_PhotoBitmapEx.GetHeight(),
SRCCOPY);*/
memDC.DeleteDC();
ReleaseDC(pDC);
}
else
{
CDC *pDC = m_ctl_photo.GetDC();
CBrush bBlack(GetSysColor(COLOR_3DFACE));
pDC->FillRect(m_PhotoRect,&bBlack);
}
}
示例11: dc
void CMyHeaderCtrl::OnPaint()
{
CPaintDC dc(this);
CRect rect,rectItem;
GetClientRect(&rect);
CDC hdcMem;
hdcMem.CreateCompatibleDC(NULL);
CBitmap hBitmap;
hBitmap.CreateCompatibleBitmap(&dc,rect.Width(),rect.Height());
hdcMem.SelectObject(&hBitmap);
//CMemDC memDC(&dc, rect);
int nItems = GetItemCount();
if( m_pBitmapBk != NULL )
{
m_pBitmapBk->SetCDibRect( rect );
m_pBitmapBk->Draw( &hdcMem,FALSE );
}
CFont* def_font;
CFont font;
LOGFONT lf;
memset(&lf, 0, sizeof(LOGFONT));
lf.lfHeight = 12;
strcpy(lf.lfFaceName, "宋体");
font.CreateFontIndirect(&lf);
def_font = hdcMem.SelectObject(&font);
hdcMem.SetBkMode(TRANSPARENT);
hdcMem.SetTextColor(m_fontColor) ;
for(int i = 0; i <nItems; i++)
{
TCHAR buf1[256];
HD_ITEM hditem1;
hditem1.mask = HDI_TEXT | HDI_FORMAT | HDI_ORDER;
hditem1.pszText = buf1;
hditem1.cchTextMax = 255;
GetItem( i, &hditem1 );
GetItemRect(i, &rect);
if( m_nHoverItem == i )
{
if(this->m_bLButtonDown)
{
m_pBitmapBkDown->SetCDibRect( rect );
m_pBitmapBkDown->Draw( &hdcMem,FALSE );
}
else
{
m_pBitmapBkOver->SetCDibRect( rect );
m_pBitmapBkOver->Draw( &hdcMem,FALSE );
}
}
if( m_pBitmapMidLine != NULL )
{
if(m_nHoverItem == i)
{
m_pBitmapMidLineOver->SetCDibRect(CRect(rect.BottomRight().x-1,rect.TopLeft().y,rect.BottomRight().x,rect.BottomRight().y));
m_pBitmapMidLineOver->Draw(&hdcMem,FALSE);
// int start = rect.TopLeft().x == 0 ? 0 : rect.TopLeft().x - 1;
// m_pBitmapMidLineOver->SetCDibRect(CRect(start ,rect.TopLeft().y,start + 1,rect.BottomRight().y));
// m_pBitmapMidLineOver->Draw(&hdcMem,FALSE);
}
else
{
// m_pBitmapMidLine->SetCDibRect(CRect(rect.BottomRight().x-1,rect.TopLeft().y,rect.BottomRight().x+2,rect.BottomRight().y));
// m_pBitmapMidLine->Draw(&hdcMem,FALSE);
m_pBitmapMidLineOver->SetCDibRect(CRect(rect.BottomRight().x-1,rect.TopLeft().y,rect.BottomRight().x,rect.BottomRight().y));
m_pBitmapMidLineOver->Draw(&hdcMem,FALSE);
}
}
GetItemRect(i, &rectItem);
//DRAWITEMSTRUCT DrawItemStruct;
//
//DrawItemStruct.CtlType = ODT_HEADER;
//DrawItemStruct.hDC = dc.GetSafeHdc();
//DrawItemStruct.itemAction = ODA_DRAWENTIRE;
//DrawItemStruct.hwndItem = GetSafeHwnd();
//DrawItemStruct.rcItem = rectItem;
//DrawItemStruct.itemID = i;*/
//// DrawItem(&DrawItemStruct);
UINT uFormat = DT_SINGLELINE | DT_NOPREFIX | DT_TOP |DT_CENTER | DT_END_ELLIPSIS | DT_VCENTER;
rectItem.DeflateRect(2,2,2,2);
TCHAR buf[256];
HD_ITEM hditem;
hditem.mask = HDI_TEXT | HDI_FORMAT | HDI_ORDER ;
hditem.pszText = buf;
hditem.cchTextMax = 255;
//.........这里部分代码省略.........
示例12: bBlack
void CMainDlg::DrawPicture()
{
int tX,tY;
if (m_SBitmapEx.IsValid())
{
m_BitmapEx.Create(m_SBitmapEx.GetWidth(),m_SBitmapEx.GetHeight());
m_BitmapEx.Draw(0,0,m_SBitmapEx.GetWidth(),m_SBitmapEx.GetHeight(),m_SBitmapEx,0,0);
m_BitmapEx.Scale(m_nScale,m_nScale);
CDC *pDC = m_ctl_image.GetDC();
CDC memDC,memDC1;
memDC.CreateCompatibleDC(pDC);
memDC1.CreateCompatibleDC(pDC);
CBitmap bmp;
bmp.CreateCompatibleBitmap(pDC, m_BitmapEx.GetWidth(), m_BitmapEx.GetHeight());
memDC.SelectObject(bmp);
m_BitmapEx.Draw(memDC);
CBitmap bmp1;
bmp1.CreateCompatibleBitmap(pDC, m_ImageRect.Width(), m_ImageRect.Height());
memDC1.SelectObject(bmp1);
CPen pen;
CPen* pOldPen;
CFont wFont,wFont1;
CFont *pOldFont;
CString title;
//清除背景
CRgn rgn;
rgn.CreateRectRgn(0,0,m_ImageRect.Width(),m_ImageRect.Height());
CBrush bBlack(GetSysColor(COLOR_3DFACE));
memDC1.FillRgn(&rgn, &bBlack);
//memDC1.SetStretchBltMode(HALFTONE);
tX = (m_ImageRect.Width() - m_BitmapEx.GetWidth())/2;
tY = (m_ImageRect.Height() - m_BitmapEx.GetHeight())/2;
memDC1.BitBlt(tX,tY,m_BitmapEx.GetWidth(),m_BitmapEx.GetHeight(),&memDC,m_pLeft,m_pTop,SRCCOPY);
pen.CreatePen(PS_SOLID, 1, RGB (255, 0, 0));
pOldPen = memDC1.SelectObject (&pen);
memDC1.MoveTo(m_CutRect.left,m_CutRect.top);
memDC1.LineTo(m_CutRect.right,m_CutRect.top);
memDC1.LineTo(m_CutRect.right,m_CutRect.bottom);
memDC1.LineTo(m_CutRect.left,m_CutRect.bottom);
memDC1.LineTo(m_CutRect.left,m_CutRect.top);
memDC1.SelectObject (pOldPen);
/*
if (m_PicEditStatus)
{
//清除背景
if (m_DrawRect.left > 0)
{
CRgn rGap1,rGap2,rGap3,rGap4;
rGap1.CreateRectRgn(0, 0, m_DrawRect.left+10,m_ImageRect.Height());
rGap2.CreateRectRgn(m_DrawRect.right-10, 0, m_ImageRect.right,m_ImageRect.Height());
rGap3.CreateRectRgn(0, 0, m_ImageRect.Width(),m_DrawRect.top+10);
rGap4.CreateRectRgn(0, m_DrawRect.bottom-10, m_ImageRect.Width(),m_ImageRect.bottom);
rGap1.CombineRgn(&rGap1,&rGap2,RGN_OR);
rGap1.CombineRgn(&rGap1,&rGap3,RGN_OR);
rGap1.CombineRgn(&rGap1,&rGap4,RGN_OR);
CBrush bBlack(GetSysColor(COLOR_3DFACE));
memDC1.FillRgn(&rGap1, &bBlack);
}
memDC1.SetStretchBltMode(HALFTONE);
if (m_Factor>=0)
{
memDC1.StretchBlt(0,0,m_ImageRect.Width(), m_ImageRect.Height(),
&memDC,
(m_BitmapEx.GetWidth())*m_Factor/2,(m_BitmapEx.GetHeight())*m_Factor/2
,(m_BitmapEx.GetWidth())*(1-m_Factor), (m_BitmapEx.GetHeight())*(1-m_Factor)
,SRCCOPY);
m_DrawRect = m_ImageRect;
}
else
{
memDC1.StretchBlt((m_ImageRect.Width())*(-m_Factor)/2,(m_ImageRect.Height())*(-m_Factor)/2
,(m_ImageRect.Width())*(1+m_Factor), (m_ImageRect.Height())*(1+m_Factor)
,&memDC,
0,0,m_BitmapEx.GetWidth(),m_BitmapEx.GetHeight()
,SRCCOPY);
m_DrawRect.left = (m_ImageRect.Width())*(-m_Factor)/2;
m_DrawRect.top = (m_ImageRect.Height())*(-m_Factor)/2;
m_DrawRect.right =
(m_ImageRect.Width())*(-m_Factor)/2 + (m_ImageRect.Width())*(1+m_Factor) - 1;
m_DrawRect.bottom =
(m_ImageRect.Height())*(-m_Factor)/2 + (m_ImageRect.Height())*(1+m_Factor) - 1;
}
//.........这里部分代码省略.........
示例13: DrawItem
void CListBoxST::DrawItem(LPDRAWITEMSTRUCT pDIStruct)
{
CDC* pDC = CDC::FromHandle(pDIStruct->hDC);
BOOL bIsSelected = FALSE;
BOOL bIsFocused = FALSE;
BOOL bIsDisabled = FALSE;
COLORREF crNormal = GetSysColor(COLOR_WINDOW);
COLORREF crSelected = GetSysColor(COLOR_HIGHLIGHT);
COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
COLORREF crColor = RGB(0, 0, 0);
CString sText; // List box item text
STRUCT_LBDATA* lpLBData = NULL;
lpLBData = (STRUCT_LBDATA*)CListBox::GetItemDataPtr(pDIStruct->itemID);
if (lpLBData == NULL || lpLBData == (LPVOID)-1L) return;
bIsSelected = (pDIStruct->itemState & ODS_SELECTED);
bIsFocused = (pDIStruct->itemState & ODS_FOCUS);
bIsDisabled = ((pDIStruct->itemState & ODS_DISABLED) || ((lpLBData->dwFlags & TEST_BIT0) == TEST_BIT0));
CRect rcItem = pDIStruct->rcItem;
CRect rcIcon = pDIStruct->rcItem;
CRect rcText = pDIStruct->rcItem;
CRect rcCenteredText = pDIStruct->rcItem;
pDC->SetBkMode(TRANSPARENT);
// ONLY FOR DEBUG
CBrush brBtnShadow(RGB(0, 0, 255));
// pDC->FrameRect(&rcItem, &brBtnShadow);
// pDC->Rectangle(&rcItem);
// Calculate rcIcon
if (m_pImageList)
{
rcIcon.right = rcIcon.left + m_szImage.cx + CX_BORDER*3;
rcIcon.bottom = rcIcon.top + m_szImage.cy + CY_BORDER*3;
} // if
else rcIcon.SetRect(0, 0, 0, 0);
// Calculate rcText
rcText.left = rcIcon.right;
// Calculate rcCenteredText
// Get list box item text
CListBox::GetText(pDIStruct->itemID, sText);
rcCenteredText = rcText;
pDC->DrawText(sText, -1, rcCenteredText, DT_WORDBREAK | DT_EXPANDTABS| DT_CALCRECT | lpLBData->nFormat);
rcCenteredText.OffsetRect(0, (rcText.Height() - rcCenteredText.Height())/2);
// Draw rcIcon background
if (m_pImageList)
{
if (bIsSelected && (m_byRowSelect == ST_FULLROWSELECT) && !bIsDisabled)
crColor = crSelected;
else
crColor = crNormal;
OnDrawIconBackground(pDIStruct->itemID, pDC, &rcItem, &rcIcon, bIsDisabled, bIsSelected, crColor);
} // if
// Draw rcText/rcCenteredText background
if (bIsDisabled)
{
pDC->SetTextColor(GetSysColor(COLOR_GRAYTEXT));
crColor = crNormal;
} // if
else
{
if (bIsSelected)
{
pDC->SetTextColor(0x00FFFFFF & ~crText);
crColor = crSelected;
} // if
else
{
pDC->SetTextColor(crText);
crColor = crNormal;
} // else
} // else
if (m_byRowSelect == ST_TEXTSELECT)
//pDC->FillSolidRect(&rcCenteredText, crColor);
OnDrawTextBackground(pDIStruct->itemID, pDC, &rcItem, &rcCenteredText, bIsDisabled, bIsSelected, crColor);
else
//pDC->FillSolidRect(&rcText, crColor);
OnDrawTextBackground(pDIStruct->itemID, pDC, &rcItem, &rcText, bIsDisabled, bIsSelected, crColor);
// Draw the icon (if any)
if (m_pImageList)
OnDrawIcon(pDIStruct->itemID, pDC, &rcItem, &rcIcon, lpLBData->nImage, bIsDisabled, bIsSelected);
// Draw text
pDC->DrawText(sText, -1, rcCenteredText, DT_WORDBREAK | DT_EXPANDTABS | lpLBData->nFormat);
// Draw focus rectangle
if (bIsFocused && !bIsDisabled)
{
switch (m_byRowSelect)
{
//.........这里部分代码省略.........
示例14: pDC
void COBDPNDDlgConfigNowFCC::OnPaint()
{
if (m_memdcBkBmp != NULL)
{
CClientDC pDC(this);
CRect rect;
CDC memDC;
GetWindowRect(&rect);
memDC.CreateCompatibleDC(&pDC);
CBitmap* pOldMemBmp = NULL;
pOldMemBmp = memDC.SelectObject(&m_cBitmapBkBmp);
memDC.BitBlt(0,0,rect.Width(),rect.Height(),&m_memdcBkBmp,0,0,SRCCOPY);
memDC.SetBkMode(TRANSPARENT);
fDrawTitleText(&memDC);
memDC.SelectObject(m_fontText);
memDC.SetTextColor(theMainDlg->m_clrTitle);
CString strText;
DWORD dwCurrVss = theMainDlg->fGetDataStreamValueF(0x00000D00);
if (dwCurrVss == INVALID_DATASTREAM_VALUE)
dwCurrVss = 0;
strText.Format(_T("%s%d"),m_strText[0],dwCurrVss);
memDC.DrawText(strText, -1, &m_rectList[0], DT_LEFT);
float fValue = theMainDlg->fGetDataStreamValueF(0xFF010001);
if (fValue == INVALID_DATASTREAM_VALUE)
fValue = 0;
strText.Format(_T("%s%0.1f"),fValue);
memDC.DrawText(strText, -1, &m_rectList[1], DT_LEFT);
CPen pen(PS_SOLID,2,RGB(255,255,255));
CPen *oldPen = memDC.SelectObject(&pen);
memDC.MoveTo(30, m_rectList[1].bottom + (m_rectList[2].top - m_rectList[1].bottom)/2);
memDC.LineTo(theMainDlg->m_rectWin.right-30, m_rectList[1].bottom + (m_rectList[2].top - m_rectList[1].bottom)/2);
memDC.SelectObject(m_fontText3);
if (dwCurrVss > 0 && dwCurrVss > m_wSetupSpeed-2 && dwCurrVss < m_wSetupSpeed+2)
{
strText.Format(_T("%s[%d]"),m_strText[3],8-m_wCountTime);
if (!m_bCountDown)
{
SetTimer(1,1000,NULL);
m_bCountDown = TRUE;
m_wCountTime = 0;
}
}
else
{
strText.Format(_T("%s"),m_strText[2]);
KillTimer(1);
m_bCountDown = FALSE;
m_wCountTime = 0;
}
memDC.DrawText(strText, -1, &m_rectList[2],DT_CENTER ); //DT_LEFT|DT_EDITCONTROL|DT_WORDBREAK
fDrawFootText(&memDC);
//将背景位图复制到窗口客户区
pDC.BitBlt(0,0,rect.Width(),rect.Height(),&memDC,0,0,SRCCOPY);
if(pOldMemBmp)
memDC.SelectObject(pOldMemBmp);
DeleteObject(pOldMemBmp);
DeleteDC(memDC);
}
CDialog::OnPaint();
}
示例15: iTextPosition
//.........这里部分代码省略.........
if (iBold != 0)
ierrorcode += 2;
if (bNestedItalic)
ierrorcode += 4;
if (iItalic != 0)
ierrorcode += 8;
if (bNestedUnderline)
ierrorcode += 16;
if (iUnderline != 0)
ierrorcode += 32;
if (bNestedAnchor)
ierrorcode += 64;
if (iAnchor != 0)
ierrorcode += 128;
if (iFont != 0)
ierrorcode += 256;
if (bOverlapped)
ierrorcode +=512;
iError = ierrorcode;
if (ierrorcode != 0) {
return L"";
}
// Now really process the HTML
NONCLIENTMETRICS ncm ={0};
ncm.cbSize = sizeof(NONCLIENTMETRICS);
SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
sizeof(NONCLIENTMETRICS), &ncm, NULL);
CWnd *pWndDesk = GetDesktopWindow();
CDC *pDCDesk = pWndDesk->GetWindowDC();
int logPixY = pDCDesk->GetDeviceCaps(LOGPIXELSY);
pWndDesk->ReleaseDC(pDCDesk);
iDefaultFontPointSize = MulDiv(ncm.lfMessageFont.lfHeight, 72, logPixY);
iCurrentFontPointSize = iDefaultFontPointSize;
iDefaultFontSize = ConvertPointsToSize(iCurrentFontPointSize);
iCurrentFontSize = iDefaultFontSize;
curPos = 0;
oldPos = 0;
csToken = csHTML.Tokenize(L"<>", curPos);
while (csToken != L"" && curPos != -1) {
oldPos = curPos - csToken.GetLength() - 1;
CString a = csHTML.Mid(oldPos - 1, 1);
CString b = csHTML.Mid(curPos - 1, 1);
if (csHTML.Mid(oldPos - 1, 1) == L"<" &&
csHTML.Mid(curPos - 1, 1) == L">") {
bHTMLTag = true;
} else
bHTMLTag = false;
if (!bHTMLTag && iAnchor != 0)
goto next;
if (bHTMLTag) {
// Must be a HTML Tag
csHTMLTag = csToken;
csHTMLTag.MakeLower();
if (csHTMLTag == L"b") {
this_format.entrytype = Bold;
this_format.iStart = iTextPosition;