本文整理汇总了C++中CDC::DrawText方法的典型用法代码示例。如果您正苦于以下问题:C++ CDC::DrawText方法的具体用法?C++ CDC::DrawText怎么用?C++ CDC::DrawText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CDC
的用法示例。
在下文中一共展示了CDC::DrawText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pen
void CPlotWindow:: DrawAxis(CDC &MemDC)
{
CString str;
// CBrush br,*oldbr;
// br.CreateSolidBrush(backcolor);
// oldbr = MemDC.SelectObject(&br);
// // MemDC.Rectangle(X1,Y2,X2,Y1);
// MemDC.SelectObject(oldbr);
// br.DeleteObject();
MemDC.FillSolidRect(X1,Y2,X2,Y1,backcolor);
// MemDC.Rectangle(X1,Y2,X2,Y1);
// MemDC.SetBkColor(backcolor);
// MemDC.SelectPalette()
COLORREF color_text=RGB(255,255,255);
CPen pen(PS_DASH,1,color_text);
CPen* pOldPen = MemDC.SelectObject(&pen);
MemDC.SetTextColor(color_text);
//Draw X Axis
MemDC.MoveTo(X1,Y2-2);
MemDC.LineTo(X2,Y2-2);
CPen pen1(PS_SOLID,1,color_text);
MemDC.SelectObject(&pen1);
if(y1<0 && y2>0)
{
int b;
b= static_cast<int>(((Y1-10)*y2-(Y2+20)*y1)/(y2-y1));
//Draw Y Axis
MemDC.MoveTo(X1+Xoffset,Y1-10);
MemDC.LineTo(X1+Xoffset,Y2+2);
//Draw Arrow;
MemDC.MoveTo(X1+Xoffset-arrowsize,Y2+2+arrowsize);
MemDC.LineTo(X1+Xoffset,Y2+2);
MemDC.LineTo(X1+Xoffset+arrowsize,Y2+2+arrowsize);
//Draw X Axis
MemDC.MoveTo(X1+Xoffset,b);
MemDC.LineTo(X2-2,b);
//Draw Arrow;
MemDC.MoveTo(X2-2-arrowsize,b+arrowsize);
MemDC.LineTo(X2-2,b);
MemDC.LineTo(X2-2-arrowsize,b-arrowsize);
CRect rect_text(X1,b-15,X1+Xoffset-4,b+5);
str.Format(_T("%ld"),0);
MemDC.DrawText(str,rect_text,DT_RIGHT|DT_SINGLELINE|DT_VCENTER);
CRect rect_text1(X1+Xoffset+10,Y2+10,X1+Xoffset+100,Y2+30);
str.Format(_T("%ld"),y2);
MemDC.DrawText(str,rect_text1,DT_LEFT|DT_SINGLELINE|DT_VCENTER);
CRect rect_text2(X1+Xoffset+10,Y1-10,X1+Xoffset+100,Y1-30);
str.Format(_T("%ld"),y1);
MemDC.DrawText(str,rect_text2,DT_LEFT|DT_SINGLELINE|DT_VCENTER);
str.Format(_T("%d"),x_range-1);
CRect rect_text3(X2-100,b+4,X2-10,b+24);
MemDC.DrawText(str,rect_text3,DT_RIGHT|DT_SINGLELINE|DT_VCENTER);
MemDC.MoveTo(X1+Xoffset,Y2+20);
MemDC.LineTo(X1+Xoffset+6,Y2+20);
MemDC.MoveTo(X1+Xoffset,Y1-15);
MemDC.LineTo(X1+Xoffset+6,Y1-15);
MemDC.MoveTo(X2-20,b);
MemDC.LineTo(X2-20,b-6);
Axis_X1 = X1+Xoffset;
Axis_X2 = X2-20;
Axis_Y1 = Y1-15;
Axis_Y2 = Y2+20;
}
else
{
//XÖáÔÚ×îÏÂÃæ
CRect rect_text1(X1+Xoffset+10,Y2+10,X1+Xoffset+200,Y2+30);
str.Format(_T("%ld"),y2);
MemDC.DrawText(str,rect_text1,DT_LEFT|DT_SINGLELINE|DT_VCENTER);
CRect rect_text2(X1+Xoffset+10,Y1-Yoffset,X1+Xoffset+200,Y1-Yoffset+20);
str.Format(_T("%ld"),y1);
MemDC.DrawText(str,rect_text2,DT_LEFT|DT_SINGLELINE|DT_VCENTER);
//Draw Y Axis
MemDC.MoveTo(X1+Xoffset,Y1-Yoffset);
MemDC.LineTo(X1+Xoffset,Y2+2);
//Draw Arrow;
MemDC.MoveTo(X1+Xoffset-arrowsize,Y2+2+arrowsize);
MemDC.LineTo(X1+Xoffset,Y2+2);
MemDC.LineTo(X1+Xoffset+arrowsize,Y2+2+arrowsize);
//Draw X Axis
MemDC.LineTo(X1+Xoffset+arrowsize,Y2+2+arrowsize);
MemDC.MoveTo(X1+Xoffset,Y1-Yoffset);
MemDC.LineTo(X2-2,Y1-Yoffset);
//Draw Arrow;
MemDC.MoveTo(X2-2-arrowsize,Y1-Yoffset+arrowsize);
MemDC.LineTo(X2-2,Y1-Yoffset);
MemDC.LineTo(X2-2-arrowsize,Y1-Yoffset-arrowsize);
str.Format(_T("%d"),x_range-1);
CRect rect_text3(X2-100,Y1-Yoffset+4,X2-10,Y1-Yoffset+24);
MemDC.DrawText(str,rect_text3,DT_RIGHT|DT_SINGLELINE|DT_VCENTER);
MemDC.MoveTo(X1+Xoffset,Y2+20);
MemDC.LineTo(X1+Xoffset+6,Y2+20);
MemDC.MoveTo(X2-20,Y1-Yoffset);
MemDC.LineTo(X2-20,Y1-Yoffset-6);
Axis_X1 = X1+Xoffset;
Axis_X2 = X2-20;
Axis_Y1 = Y1-Yoffset;
Axis_Y2 = Y2+20;
}
MemDC.SelectObject(pOldPen);
//.........这里部分代码省略.........
示例2: 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(255, 0, 0));
//pDC->FrameRect(&rcItem, &brBtnShadow);
// Calculate rcIcon
if (m_pImageList)
{
rcIcon.right = rcIcon.left + m_szImage.cx + LBST_CX_BORDER*2;
rcIcon.bottom = rcIcon.top + m_szImage.cy + LBST_CY_BORDER*2;
} // 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)
{
case ST_FULLROWSELECT:
//.........这里部分代码省略.........
示例3: OnDrawItem
void CHotGamePanel::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDis)
{
if (lpDis->CtlType != ODT_MENU)
{
CDialog::OnDrawItem(nIDCtl, lpDis);
return ;
}
CDC* pDC = CDC::FromHandle(lpDis->hDC);
pDC->SetBkMode(1);
CRect rc(lpDis->rcItem);
I8SkinCtrl_ns::I8_DrawImage(pDC, TEXT("Skin/Menu/背景_1px.png"), rc);
tagMenuItemEx* pItem = (tagMenuItemEx*)lpDis->itemData;
if (pItem->dwGid < 0)
{
CRect rx = rc;
rx.DeflateRect(0, 1, 0, 1);
I8SkinCtrl_ns::I8_DrawImage(pDC, TEXT("Skin/Menu/背景_分割线.png"), rx);
}
else if (pItem->dwGid > 0)
{
int nItem = m_lstGame.GetNextItem(-1, LVIS_SELECTED);
if (nItem != -1)
{
tagGameInfo* pGame = m_GameInfo[nItem];
CRect rx = rc;
rx.top = rc.top + (rc.Height() - 32)/2;
rx.bottom = rx.top + 32;
rx.left = 4; rx.right = rx.left + 32;
m_ilLstCtrl.Draw(pDC, nItem, rx.TopLeft(), ILD_TRANSPARENT);
LOGFONT lf = {0};
GetObject(GetStockObject(DEFAULT_GUI_FONT), sizeof(lf), &lf);
lf.lfWeight = FW_BOLD;
CFont font;
font.CreateFontIndirect(&lf);
rx = rc;
rx.left = 48;
pDC->SetTextColor(0xB56226);
CFont* pOldFont = pDC->SelectObject(&font);
pDC->DrawText(pGame->Name, -1, &rx, DT_SINGLELINE|DT_LEFT|DT_VCENTER);
pDC->SelectObject(pOldFont);
}
}
else
{
if (lpDis->itemState & ODS_SELECTED)
pDC->SetTextColor(RGB(255, 255, 255));
else
pDC->SetTextColor(RGB(0, 0, 0));
CRect rcImg = rc;
rcImg.DeflateRect(4, 1, 4, 1);
if (lpDis->itemState & ODS_SELECTED)
I8SkinCtrl_ns::I8_DrawImage(pDC, TEXT("Skin/Menu/背景_按钮_鼠标经过.png"), rcImg);
else
I8SkinCtrl_ns::I8_DrawImage(pDC, TEXT("Skin/Menu/背景_按钮_默认状态.png"), rcImg);
CRect rx = rc;
rx.left = 40;
rx.right = rc.right - 10;
pDC->DrawText(pItem->szText, &rx, DT_SINGLELINE|DT_LEFT|DT_VCENTER);
}
}
示例4: PrintPiecesThread
//.........这里部分代码省略.........
bool DrawNames = 1;//(PrintOptions & PRINT_NAMES) != 0;
bool Horizontal = 1;//(PrintOptions & PRINT_HORIZONTAL) != 0;
pMemDC->SetTextColor(0x000000);
pMemDC->SetBkMode(TRANSPARENT);
// lf.lfHeight = -MulDiv(40, GetDeviceCaps(pMemDC->m_hDC, LOGPIXELSY), 72);
// lf.lfWeight = FW_BOLD;
HFONT CatalogFont = CreateFontIndirect(&lf);
lf.lfHeight = -MulDiv(80, GetDeviceCaps(pMemDC->m_hDC, LOGPIXELSY), 72);
HFONT CountFont = CreateFontIndirect(&lf);
HFONT OldMemFont = (HFONT)SelectObject(pMemDC->m_hDC, CatalogFont);
HPEN hpOld = (HPEN)SelectObject(pMemDC->m_hDC, GetStockObject(BLACK_PEN));
for (UINT CurPage = StartPage; CurPage != EndPage; CurPage += StepPage)
{
TCHAR szBuf[80];
wsprintf(szBuf, strTemp, CurPage);
dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_PAGENUM, szBuf);
if (::StartPage(PD.m_pd.hDC) < 0)
{
bError = TRUE;
break;
}
// Draw header and footer.
SelectObject(PD.m_pd.hDC, HeaderFont);
CString Header;
UINT Align;
FormatHeader(Header, Align, AfxGetApp()->GetProfileString("Default", "Catalog Header", ""), project->m_strTitle, project->m_strAuthor, project->m_strDescription, CurPage, TotalPages);
Align |= DT_TOP|DT_SINGLELINE;
DrawText(PD.m_pd.hDC, (LPCTSTR)Header, Header.GetLength(), HeaderRect, Align);
FormatHeader(Header, Align, AfxGetApp()->GetProfileString("Default", "Catalog Footer", "Page &P"), project->m_strTitle, project->m_strAuthor, project->m_strDescription, CurPage, TotalPages);
Align |= DT_BOTTOM|DT_SINGLELINE;
DrawText(PD.m_pd.hDC, (LPCTSTR)Header, Header.GetLength(), HeaderRect, Align);
int StartPiece = (CurPage - 1) * RowsPerPage * ColsPerPage;
int EndPiece = lcMin(StartPiece + RowsPerPage * ColsPerPage, PiecesUsed.GetSize());
for (int CurPiece = StartPiece; CurPiece < EndPiece; CurPiece++)
{
FillRect(pMemDC->m_hDC, CRect(0, PicHeight, PicWidth, 0), (HBRUSH)GetStockObject(WHITE_BRUSH));
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
PieceInfo* pInfo = PiecesUsed[CurPiece].Info;
pInfo->ZoomExtents(30.0f, Aspect);
pInfo->RenderPiece(PiecesUsed[CurPiece].ColorIndex);
glFinish();
// Draw description text at the bottom.
CRect TextRect(0, 0, PicWidth, PicHeight);
if (DrawNames)
{
SelectObject(pMemDC->m_hDC, CatalogFont);
pMemDC->DrawText(pInfo->m_strDescription, strlen(pInfo->m_strDescription), TextRect, DT_CALCRECT | DT_WORDBREAK);
TextRect.OffsetRect(0, PicHeight - TextRect.Height() - 5);
pMemDC->DrawText(pInfo->m_strDescription, strlen(pInfo->m_strDescription), TextRect, DT_WORDBREAK);
}
示例5: OnCustomdrawList
//.........这里部分代码省略.........
{
strSymbols = csText.Left(nSymEnd);
csText = csText.Mid(nSymEnd+1);
}
// set firstTenNum to the first ten number (1-10) corresponding to
// the current nItem.
// -1 means that nItem is not in the FirstTen block.
int firstTenNum = GetFirstTenNum(nItem);
if( m_bShowTextForFirstTenHotKeys && firstTenNum > 0 )
{
rcText.left += 12;
}
// if we are inside a group, don't display the "in group" flag
if( theApp.m_GroupID > 0 )
{
int nFlag = strSymbols.Find(_T("!"));
if( nFlag >= 0 )
strSymbols.Delete(nFlag);
}
DrawBitMap(nItem, rcText, pDC, csText);
// draw the symbol box
if( strSymbols.GetLength() > 0 )
{
strSymbols = " " + strSymbols + " "; // leave space for box
// add spaces to leave room for the symbols
CRect rectSym(rcText.left, rcText.top+1, rcText.left, rcText.top+1);
CRect rectSpace(0,0,0,0);
//Get text bounds
pDC->DrawText(" ", &rectSpace, DT_VCENTER | DT_EXPANDTABS | DT_CALCRECT);
pDC->DrawText(strSymbols, &rectSym, DT_VCENTER | DT_EXPANDTABS | DT_CALCRECT);
VERIFY( rectSpace.Width() > 0 );
// int numSpaces = rectSym.Width() / rectSpace.Width();
// numSpaces++;
// csText = CString(' ',numSpaces) + csText;
// draw the symbols
pDC->FillSolidRect( rectSym, GetSysColor(COLOR_ACTIVECAPTION) );
//pDC->FillSolidRect( rectSym, RGB(0,255,255) );
pDC->Draw3dRect(rectSym, GetSysColor(COLOR_3DLIGHT), GetSysColor(COLOR_3DDKSHADOW));
// COLORREF crOld = pDC->SetTextColor(GetSysColor(COLOR_INFOTEXT));
COLORREF crOld = pDC->SetTextColor(RGB(255, 255, 255));
pDC->DrawText(strSymbols, rectSym, DT_VCENTER|DT_EXPANDTABS|DT_NOPREFIX);
pDC->SetTextColor(crOld);
rcText.left += rectSym.Width() + 2;
}
if(DrawRtfText(nItem, rcText, pDC) == FALSE)
{
pDC->DrawText(csText, rcText, DT_VCENTER|DT_EXPANDTABS|DT_NOPREFIX);
}
// Draw a focus rect around the item if necessary.
if(bListHasFocus && (rItem.state & LVIS_FOCUSED))
pDC->DrawFocusRect(rcItem);
if( m_bShowTextForFirstTenHotKeys && firstTenNum > 0 )
{
CString cs;
if( firstTenNum == 10 )
示例6: DrawItem
//.........这里部分代码省略.........
}
for (int i = 0; i < uDrawCound; i++)
{
pszText[i] = pItem->arryItemText.GetAt(i).szItemText;
CListCtrl::GetSubItemRect(
lpDrawItemStruct->itemID, i, LVIR_BOUNDS, pRect[i]
);
}
if (CString(pszText[0]) == "FK")
{
int a = 0;
a++;
}
(*pRect).left += rcItem.Height() * pItem->nTitleLever;
for (int i = 0; i < uDrawCound ; i++)
{
if (!i)
{
LPKGLISTITEM pParent = pItem;
while (pParent->pPerantItem)
pParent = pParent->pPerantItem;
int nTitleLever = pParent->nTitleLever;
while (pParent && pParent->nTitleLever < pItem->nTitleLever)
{
CRect rect = rcItem;
rect.left += rcItem.Height() * pParent->nTitleLever;
pDC->FillRect(
&rect, &CBrush(pParent->arryItemText.GetAt(i).colorBack)
);
CPen pen(PS_SOLID, 1, pParent->arryItemText.GetAt(i).colorFrame);
CPen* pPenSave = pDC->SelectObject(&pen);
pDC->MoveTo(rect.left, rect.top);
pDC->LineTo(rect.left, rect.bottom);
pDC->SelectObject(pPenSave);
pParent = FindJunior(pParent);
if (pItem->pPerantItem && pItem->pPerantItem->nTitleLever == pParent->nTitleLever)
pParent = pItem->pPerantItem;
//pParent = pParent->pFirstChildItem;
//nTitleLever++;
}
}
if (bIsSelected)
{
colorExpandFrame = pItem->arryItemText.GetAt(i).colorExpandRectFrameSel;
colorExpandBack = pItem->arryItemText.GetAt(i).colorExpandRectBackSel;
colorBack = pItem->arryItemText.GetAt(i).colorBackSel;
colorFrame = pItem->arryItemText.GetAt(i).colorFrameSel;
colorText = pItem->arryItemText.GetAt(i).colorTextSel;
}
else
{
colorExpandFrame = pItem->arryItemText.GetAt(i).colorExpandRectFrame;
colorExpandBack = pItem->arryItemText.GetAt(i).colorExpandRectBack;
colorText = pItem->arryItemText.GetAt(i).colorText;
colorFrame = pItem->arryItemText.GetAt(i).colorFrame;
colorBack = pItem->arryItemText.GetAt(i).colorBack;
}
if (!i && !pItem->pFirstChildItem)
pRect[i].left += 1;
pDC->FillRect(pRect[i], &CBrush(colorBack));
CPen pen(PS_SOLID, 1, colorFrame);
CPen* pPenSave = pDC->SelectObject(&pen);
pDC->MoveTo(pRect[i].left, pRect[i].bottom);
pDC->LineTo(pRect[i].left, pRect[i].top);
pDC->LineTo(pRect[i].right, pRect[i].top);
pDC->SelectObject(pPenSave);
if (m_listDataTree.IsTitle(pItem))//(uDrawCound == 1)
{
CRect rect = (*pRect);
rect.left += 5;
rect.top += 3;
rect.bottom -= 4;
rect.right = rect.left + (rect.bottom - rect.top);
rcItem.left = (*pRect).left;
(*pRect).left += rcItem.Height() + 4;
DrawRect(
pDC, &rect, colorExpandFrame, colorExpandBack, !pItem->nItemState
);
}
else
{
pRect[i].left += 12;
}
pDC->SetTextColor(colorText);
pDC->DrawText(
pszText[i], -1, pRect[i], DT_LEFT | DT_SINGLELINE | DT_VCENTER
);
}
Exit0:
SAFE_DELETE_ARRAY(pRect);
SAFE_DELETE_ARRAY(pszText);
}
示例7: SetAllButtonsWidth
void CMuleToolbarCtrl::SetAllButtonsWidth()
{
if (GetButtonCount() == 0)
return;
if (m_eLabelType == LabelsBelow)
{
CDC *pDC = GetDC();
CFont *pFnt = GetFont();
CFont *pOldFnt = pDC->SelectObject(pFnt);
CRect r(0,0,0,0);
// calculate the max. possible button-size
int iCalcSize = 0;
for (int i = 0; i < m_buttoncount ; i++)
{
if (!IsButtonHidden(IDC_TOOLBARBUTTON + i))
{
pDC->DrawText(TBStrings[i], -1, r, DT_SINGLELINE | DT_CALCRECT);
if (r.Width() > iCalcSize)
iCalcSize = r.Width();
}
}
iCalcSize += 10;
pDC->SelectObject(pOldFnt);
ReleaseDC(pDC);
if (!thePrefs.GetUseReBarToolbar())
{
GetClientRect(&r);
int bc = GetButtonCount();
if (bc == 0)
bc = 1;
int iMaxPossible = r.Width() / bc;
// if the buttons are to big, reduze their size
if (iCalcSize > iMaxPossible)
iCalcSize = iMaxPossible;
}
else
{
if (iCalcSize < 56)
iCalcSize = 56;
else if (iCalcSize > 72)
iCalcSize = 72;
}
SetButtonWidth(iCalcSize, iCalcSize);
}
else
{
int iSmallIconsButtonHeight;
if (theApp.m_ullComCtrlVer < MAKEDLLVERULL(6, 0, 0, 0)) {
// Win98,WinME,Win2000: Comtrl32 prior to 6.0 cannot make a toolbar smaller than 22 pixels
// in height and if it gets larger than 22 pixels the icons do not get centered vertically.
iSmallIconsButtonHeight = 22;
}
else
iSmallIconsButtonHeight = GetSystemMetrics(SM_CYSCREEN) <= 600 ? 16 : 28;
if (m_eLabelType == NoLabels)
{
DWORD dwSize = GetButtonSize();
int iFixedButtonWidth;
int iFixedButtonHeight = HIWORD(dwSize);
if (m_sizBtnBmp.cx == 16)
{
iFixedButtonWidth = 28;
iFixedButtonHeight = iSmallIconsButtonHeight;
}
else
{
iFixedButtonWidth = 56;
}
// it seems that the control updates itself more properly, if 'SetButtonWidth' id called *before* 'SetButtonSize'
SetButtonWidth(iFixedButtonWidth, iFixedButtonWidth);
SetButtonSize(CSize(iFixedButtonWidth, iFixedButtonHeight));
}
else
{
int iFixedButtonHeight = 0;
if (m_sizBtnBmp.cx == 16)
iFixedButtonHeight = iSmallIconsButtonHeight;
// it seems that the control updates itself more properly, if 'SetButtonWidth' id called *before* 'SetButtonSize'
SetButtonWidth(0, 0);
SetButtonSize(CSize(0, iFixedButtonHeight));
}
}
}
示例8: OnNMCustomDraw
//.........这里部分代码省略.........
int iTextHeight = 0;
int iMaxCol1Width = 0;
int iMaxCol2Width = 0;
int iMaxSingleLineWidth = 0;
CSize sizText(0);
int iPos = 0;
while (iPos != -1)
{
CString strLine = GetNextString(strText, _T('\n'), iPos);
int iColon = strLine.Find(_T(':'));
if (iColon != -1) {
CFont* pOldFont = m_bCol1Bold ? pdc->SelectObject(&m_fontBold) : NULL;
CSize siz = pdc->GetTextExtent(strLine, iColon + 1);
if (pOldFont)
pdc->SelectObject(pOldFont);
iMaxCol1Width = max(iMaxCol1Width, siz.cx);
iTextHeight = siz.cy; // update height with 'col1' string, because 'col2' string might be empty and therefore has no height
sizText.cy += siz.cy;
LPCTSTR pszCol2 = (LPCTSTR)strLine + iColon + 1;
while (_istspace(*pszCol2))
pszCol2++;
if (*pszCol2 != _T('\0')) {
siz = pdc->GetTextExtent(pszCol2, ((LPCTSTR)strLine + strLine.GetLength()) - pszCol2);
iMaxCol2Width = max(iMaxCol2Width, siz.cx);
}
}
else if (!strLine.IsEmpty()) {
CSize siz = pdc->GetTextExtent(strLine);
iMaxSingleLineWidth = max(iMaxSingleLineWidth, siz.cx);
sizText.cy += siz.cy;
}
else {
CSize siz = pdc->GetTextExtent(_T(" "), 1);
sizText.cy += siz.cy;
}
}
iMaxCol1Width = min(m_iScreenWidth4, iMaxCol1Width);
iMaxCol2Width = min(m_iScreenWidth4*2, iMaxCol2Width);
const int iMiddleMargin = 6;
iMaxSingleLineWidth = max(iMaxSingleLineWidth, iMaxCol1Width + iMiddleMargin + iMaxCol2Width);
sizText.cx = iMaxSingleLineWidth;
rcWnd.right = rcWnd.left + rcBorder.left + sizText.cx + rcBorder.right;
rcWnd.bottom = rcWnd.top + rcBorder.top + sizText.cy + rcBorder.bottom;
if (rcWnd.left >= m_rcScreen.left) {
if (rcWnd.right > m_rcScreen.right && rcWnd.Width() <= m_rcScreen.Width())
rcWnd.OffsetRect(-(rcWnd.right - m_rcScreen.right), 0);
}
if (rcWnd.top >= m_rcScreen.top) {
if (rcWnd.bottom > m_rcScreen.bottom && rcWnd.Height() <= m_rcScreen.Height())
rcWnd.OffsetRect(0, -(rcWnd.bottom - m_rcScreen.bottom));
}
pwnd->MoveWindow(&rcWnd);
pwnd->ScreenToClient(&rcWnd);
pdc->FillSolidRect(&rcWnd, m_crTooltipBkColor);
CPoint ptText(pNMCD->nmcd.rc.left, pNMCD->nmcd.rc.top);
iPos = 0;
while (iPos != -1)
{
CString strLine = GetNextString(strText, _T('\n'), iPos);
int iColon = strLine.Find(_T(':'));
if (iColon != -1) {
CRect rcDT(ptText.x, ptText.y, ptText.x + iMaxCol1Width, ptText.y + iTextHeight);
// don't draw empty <col1> strings (they are still handy to use for skipping the <col1> space)
if (iColon > 0) {
CFont* pOldFont = m_bCol1Bold ? pdc->SelectObject(&m_fontBold) : NULL;
pdc->DrawText(strLine, iColon + 1, &rcDT, m_dwCol1DrawTextFlags);
if (pOldFont)
pdc->SelectObject(pOldFont);
}
LPCTSTR pszCol2 = (LPCTSTR)strLine + iColon + 1;
while (_istspace(*pszCol2))
pszCol2++;
if (*pszCol2 != _T('\0')) {
rcDT.left = ptText.x + iMaxCol1Width + iMiddleMargin;
rcDT.right = rcDT.left + iMaxCol2Width;
pdc->DrawText(pszCol2, ((LPCTSTR)strLine + strLine.GetLength()) - pszCol2, &rcDT, m_dwCol2DrawTextFlags);
}
ptText.y += iTextHeight;
}
else {
CSize siz = pdc->TabbedTextOut(ptText.x, ptText.y, strLine, 0, NULL, 0);
ptText.y += siz.cy;
}
}
*pResult = CDRF_SKIPDEFAULT;
return;
}
*pResult = CDRF_DODEFAULT;
}
示例9: DrawItem
void CGfxPopupMenu::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
// CRect rcItem(lpDrawItemStruct->rcItem);
// pDC->FillSolidRect(rcItem, RGB(255,0,0));
if (lpDrawItemStruct->CtlType == ODT_MENU)
{
UINT id = lpDrawItemStruct->itemID;
UINT state = lpDrawItemStruct->itemState;
bool bEnab = !(state & ODS_DISABLED);
bool bSelect = (state & ODS_SELECTED) ? true : false;
bool bChecked = (state & ODS_CHECKED) ? true : false;
// David 08/04/98 - start - bold font handling
bool bBold = (state & ODS_DEFAULT) ? true : false;
// David 08/04/98 - end - bold font handling
SpawnItem * pItem = (SpawnItem *) lpDrawItemStruct->itemData;
if (pItem)
{
CDC * pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
CFont * pft;
// David 08/04/98 - start - bold font handling
if (!bBold) pft = CFont::FromHandle((HFONT) hMenuFont ? hMenuFont : hGuiFont);
else pft = CFont::FromHandle((HFONT) hMenuBoldFont ? hMenuBoldFont : hGuiFont);
// David 08/04/98 - end - bold font handling
CFont * of = pDC->SelectObject(pft);
CRect rc(lpDrawItemStruct->rcItem);
CRect rcImage(rc), rcText(rc);
rcImage.right = rcImage.left + rc.Height();
rcImage.bottom = rc.bottom;
if (pItem->iCmd == -3) // is a separator
{
CPen pnDk(PS_SOLID,1,cr3dShadow);
CPen pnLt(PS_SOLID,1,cr3dHilight);
CPen * opn = pDC->SelectObject(&pnDk);
pDC->MoveTo(rc.left + 2, rc.top + 2);
pDC->LineTo(rc.right - 2, rc.top + 2);
pDC->SelectObject(&pnLt);
pDC->MoveTo(rc.left + 2, rc.top + 3);
pDC->LineTo(rc.right - 2, rc.top + 3);
pDC->SelectObject(opn);
}
else if (pItem->iCmd == -4) // is a title item
{
CString cs(pItem->cText), cs1;
CRect rcBdr(rcText);
if (bSelect && bEnab)
{
rcText.top ++;
rcText.left += 2;
}
pDC->FillSolidRect(rcText, crMenu);
pDC->DrawText(cs, rcText, DT_VCENTER|DT_CENTER|DT_SINGLELINE);
if (bSelect && bEnab) pDC->Draw3dRect(rcBdr,cr3dShadow,cr3dHilight);
}
else
{
rcText.left += rcImage.right + 1;
int obk = pDC->SetBkMode(TRANSPARENT);
COLORREF ocr;
if (bSelect)
{
if (pItem->iImageIdx >= 0 || (state & ODS_CHECKED))
pDC->FillSolidRect(rcText, crHighlight);
else
pDC->FillSolidRect(rc, crHighlight);
ocr = pDC->SetTextColor(crMenuTextSel);
}
else
{
if (pItem->iImageIdx >= 0 || (state & ODS_CHECKED))
pDC->FillSolidRect(rcText, crMenu);
else
pDC->FillSolidRect(rc/*rcText*/, crMenu);
ocr = pDC->SetTextColor(crMenuText);
}
if (pItem->iImageIdx >= 0)
{
int ay = (rcImage.Height() - szImage.cy) / 2;
int ax = (rcImage.Width() - szImage.cx) / 2;
if (bSelect && bEnab)
pDC->Draw3dRect(rcImage,cr3dHilight,cr3dShadow);
else
{
pDC->Draw3dRect(rcImage,crMenu,crMenu);
}
if (bEnab)
{
ilList.Draw(pDC, pItem->iImageIdx, CPoint(rcImage.left + ax, rcImage.top +ay), ILD_NORMAL);
}
//.........这里部分代码省略.........
示例10: OnPaint
void CMultiPicWnd::OnPaint()
{
CPaintDC dc(this); // device context for painting
CRect rc;
GetClientRect(&rc);
m_ff.SetTargetDC(dc);
if (m_bMemDCInvalidated)
{
m_picDrawer.Draw(m_ff.GetMemDC(), rc);
if (m_curPic>=0 && m_frames[m_curPic].title.size() > 0)
{
CDC* pDC = &m_ff.GetMemDC();
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(RGB(255,255,255));
CFont* pOldFont = NULL;
if (m_pTitleFont != NULL)
pOldFont = pDC->SelectObject(m_pTitleFont);
CRect titleRC(rc);
titleRC.DeflateRect(10,10);
pDC->DrawText(m_frames[m_curPic].title.c_str(), -1, &titleRC, DT_LEFT | DT_WORDBREAK | DT_NOPREFIX | DT_EXPANDTABS | DT_CALCRECT);
int titHeight = titleRC.Height();
titleRC.top = rc.bottom - titHeight - 10;
titleRC.bottom = titleRC.top + titHeight;
CRect borderRC(titleRC);
borderRC.InflateRect(5,2);
m_AlphaDrawer.SetColor(RGB(0,0,0));
m_AlphaDrawer.Draw(*pDC, borderRC, 100);
pDC->DrawText(m_frames[m_curPic].title.c_str(), -1, &titleRC, DT_LEFT | DT_WORDBREAK | DT_NOPREFIX | DT_EXPANDTABS);
if (pOldFont != NULL)
pDC->SelectObject(pOldFont);
}
m_bMemDCInvalidated = FALSE;
m_bTransitioning = TRUE;
m_curFadeStep = 0;
}
if (m_bTemporaryDisableTransitioning)//Do not transition the first time
{
m_bTransitioning = FALSE;
m_bTemporaryDisableTransitioning = FALSE;
}
if (m_bTransitioning)
{
if (m_curFadeStep < m_totalFadeSteps)
{
//TRACE(_T("CFadePicWnd: Fading: %d/%d\r\n"), m_curFadeStep, m_totalFadeSteps);
BLENDFUNCTION bf;
bf.BlendOp=AC_SRC_OVER;
bf.BlendFlags = 0;
bf.SourceConstantAlpha = (255 * m_curFadeStep) / ( 2 * m_totalFadeSteps + 1);//v1 Increasing
bf.AlphaFormat = 0;//AC_SRC_ALPHA ;
dc.AlphaBlend(rc.left, rc.top, rc.Width(), rc.Height(), &m_ff.GetMemDC(), 0, 0, rc.Width(), rc.Height(), bf);
SetTimer(TIMER_FADE_REFRESH, TIMER_FADE_DELAY, NULL);
m_curFadeStep++;
}
else
{
//TRACE(_T("CFadePicWnd: Fading Finished: Blitting\r\n"));
m_ff.Draw();
}
m_bTransitioning = FALSE;
}
else
{
m_ff.Draw();
}
}
示例11: EdgeSize
//=============================================================================
CXProgressWnd& CXProgressWnd::SetWindowSize(int nNumTextLines, int nWindowWidth /*=390*/)
//=============================================================================
{
int nWidth = nWindowWidth;
int nMargin = 10;
CSize EdgeSize(::GetSystemMetrics(SM_CXEDGE), ::GetSystemMetrics(SM_CYEDGE));
CSize CancelSize;
CRect CancelRect, ProgressRect, AviRect;
AviRect.SetRectEmpty();
if (IsWindow(m_avi.m_hWnd))
{
// we'll adjust the width later
AviRect.SetRect(nMargin, nMargin,
nMargin + m_nAviHeight, nMargin + m_nAviHeight);
}
// set up a default size for the text area in case things go wrong
m_TextRect.SetRect(nMargin, AviRect.bottom+nMargin,
nWindowWidth-2*nMargin, AviRect.bottom+100+2*nMargin);
m_TimeLeftRect.SetRectEmpty();
// get DrawText to tell us how tall the text area will be (while we're at
// it, we'll see how big the word "Cancel" is)
CDC* pDC = GetDC();
if (pDC)
{
CFont *pOldFont = pDC->SelectObject(&m_font);
CString str = _T("M");
for (int i = 0; i < nNumTextLines-1; i++)
str += _T("\nM");
pDC->DrawText(str, m_TextRect, DT_CALCRECT|DT_NOCLIP|DT_NOPREFIX);
if (m_bTimeLeft)
pDC->DrawText(_T("M"), 1, m_TimeLeftRect,
DT_CALCRECT|DT_NOCLIP|DT_NOPREFIX);
nWidth = max(nWindowWidth, m_TextRect.Width()+2*nMargin);
m_TextRect.right = nWidth - nMargin;
CancelSize = pDC->GetTextExtent(m_strCancelLabel + _T(" "));
CancelSize += CSize(EdgeSize.cx*11, EdgeSize.cy*5);
pDC->SelectObject(pOldFont);
ReleaseDC(pDC);
}
AviRect.right = m_TextRect.right;
// Work out how big (and where) the progress control should be
ProgressRect.SetRect(m_TextRect.left, m_TextRect.bottom + nMargin,
m_TextRect.right, m_TextRect.bottom + nMargin + CancelSize.cy);
if (m_bTimeLeft)
{
// Work out how big (and where) the time left text should be
int h = m_TimeLeftRect.Height();
m_TimeLeftRect.SetRect(m_TextRect.left, ProgressRect.bottom + nMargin,
m_TextRect.right, ProgressRect.bottom + nMargin + h);
}
else
{
m_TimeLeftRect = ProgressRect;
}
// work out how big (and where) the cancel button should be
CancelRect.SetRect(ProgressRect.right - CancelSize.cx, m_TimeLeftRect.bottom + nMargin,
ProgressRect.right, m_TimeLeftRect.bottom + nMargin + CancelSize.cy);
// resize the main window to fit the controls
CSize ClientSize(nWidth, nMargin + CancelRect.bottom);
CRect WndRect, ClientRect;
GetWindowRect(WndRect);
GetClientRect(ClientRect);
WndRect.right = WndRect.left + WndRect.Width() - ClientRect.Width() + ClientSize.cx;
WndRect.bottom = WndRect.top + WndRect.Height() - ClientRect.Height() + ClientSize.cy;
MoveWindow(WndRect);
// now reposition the controls...
if (IsWindow(m_avi.m_hWnd))
m_avi.MoveWindow(AviRect);
// start modified code: added to allow dialog with only a message
if (m_bEnableProgressBar)
// end modified code
m_wndProgress.MoveWindow(ProgressRect);
// start modified code: added to allow dialog with only a message
if (m_bEnableCancel)
// end modified code
m_CancelButton.MoveWindow(CancelRect);
return *this;
}
示例12: SetIcon
void CIconStatic::SetIcon(LPCTSTR pszIconID)
{
m_strIconID = pszIconID;
// If this function is called for the first time and we did not yet call 'SetWindowText', we take
// the window label which is already specified for the window (the label which comes from the resource)
CString strText;
CStatic::GetWindowText(strText);
CStatic::SetWindowText(_T(""));
if (!strText.IsEmpty() && m_strText.IsEmpty())
m_strText = strText;
CRect rRect;
GetClientRect(rRect);
CDC *pDC = GetDC();
CDC MemDC;
CBitmap *pOldBMP;
VERIFY( MemDC.CreateCompatibleDC(pDC) );
CFont *pOldFont = MemDC.SelectObject(GetFont());
CRect rCaption(0,0,0,0);
MemDC.DrawText(m_strText, rCaption, DT_CALCRECT);
ASSERT( rCaption.Width() >= 0 );
ASSERT( rCaption.Height() >= 0 );
if (rCaption.Height() < 16)
rCaption.bottom = rCaption.top + 16;
rCaption.right += 25;
if (rRect.Width() >= 16 && rCaption.Width() > rRect.Width() - 16)
rCaption.right = rCaption.left + rRect.Width() - 16;
if (m_MemBMP.m_hObject)
VERIFY( m_MemBMP.DeleteObject() );
VERIFY( m_MemBMP.CreateCompatibleBitmap(pDC, rCaption.Width(), rCaption.Height()) );
pOldBMP = MemDC.SelectObject(&m_MemBMP);
// Get the background color from the parent window. This way the controls which are
// embedded in a dialog window can get painted with the same background color as
// the dialog window.
HBRUSH hbr = (HBRUSH)GetParent()->SendMessage(WM_CTLCOLORSTATIC, (WPARAM)MemDC.m_hDC, (LPARAM)m_hWnd);
FillRect(MemDC, &rCaption, hbr);
if (!m_strIconID.IsEmpty())
VERIFY( DrawState( MemDC.m_hDC, NULL, NULL, (LPARAM)(HICON)CTempIconLoader(m_strIconID, 16, 16), NULL, 3, 0, 16, 16, DST_ICON | DSS_NORMAL) );
// clear all alpha channel data
BITMAP bmMem;
if (m_MemBMP.GetObject(sizeof bmMem, &bmMem) >= sizeof bmMem && bmMem.bmBitsPixel == 32)
{
DWORD dwSize = m_MemBMP.GetBitmapBits(0, NULL);
if (dwSize)
{
LPBYTE pPixels = (LPBYTE)malloc(dwSize);
if (pPixels)
{
if (m_MemBMP.GetBitmapBits(dwSize, pPixels) == dwSize)
{
LPBYTE pLine = pPixels;
int iLines = bmMem.bmHeight;
while (iLines-- > 0)
{
LPDWORD pdwPixel = (LPDWORD)pLine;
for (int x = 0; x < bmMem.bmWidth; x++)
*pdwPixel++ &= 0x00FFFFFF;
pLine += bmMem.bmWidthBytes;
}
m_MemBMP.SetBitmapBits(dwSize, pPixels);
}
free(pPixels);
}
}
}
rCaption.left += 22;
if(IsThemeActive() && IsAppThemed())
{
HTHEME hTheme = OpenThemeData(NULL, L"BUTTON");
DrawThemeText(hTheme, MemDC.m_hDC, BP_GROUPBOX, GBS_NORMAL, m_strText, m_strText.GetLength(),
DT_WORDBREAK | DT_CENTER | DT_WORD_ELLIPSIS, NULL, &rCaption);
CloseThemeData(hTheme);
}
else
{
MemDC.SetTextColor(GetSysColor(COLOR_WINDOWTEXT));
MemDC.DrawText(m_strText, rCaption, DT_SINGLELINE | DT_LEFT | DT_END_ELLIPSIS);
}
ReleaseDC(pDC);
MemDC.SelectObject(pOldBMP);
MemDC.SelectObject(pOldFont);
if (m_wndPicture.m_hWnd == NULL)
m_wndPicture.Create(NULL, WS_CHILD | WS_VISIBLE | SS_BITMAP, CRect(0,0,0,0), this);
m_wndPicture.SetWindowPos(NULL, rRect.left+8, rRect.top, rCaption.Width()+22, rCaption.Height(), SWP_SHOWWINDOW);
m_wndPicture.SetBitmap(m_MemBMP);
//.........这里部分代码省略.........
示例13: DrawItem
void CSkinListBox::DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct )
{
//没有节点就不用继续执行了
if( GetCount()==0 ) return;
//变量定义
CRect rcItem=lpDrawItemStruct->rcItem;
CDC * pDCControl=CDC::FromHandle(lpDrawItemStruct->hDC);
//创建缓冲
CDC BufferDC;
CBitmap ImageBuffer;
BufferDC.CreateCompatibleDC(pDCControl);
ImageBuffer.CreateCompatibleBitmap(pDCControl,rcItem.Width(),rcItem.Height());
//设置环境
BufferDC.SelectObject(&ImageBuffer);
BufferDC.SelectObject(GetCtrlFont());
//获取字符
CString strString;
GetText(lpDrawItemStruct->itemID,strString);
//计算位置
CRect rcString;
rcString.SetRect(4,0,rcItem.Width()-8,rcItem.Height());
//颜色定义
COLORREF crTextColor=((lpDrawItemStruct->itemState&ODS_SELECTED)!=0)?m_colSelectText:m_colNormalText;
//绘画背景
BufferDC.FillSolidRect(0,0,rcItem.Width(),rcItem.Height(),m_colBack);
//节点选中
if ( (lpDrawItemStruct->itemState&ODS_SELECTED) != 0 )
{
if ( m_pSelectImg!= NULL && !m_pSelectImg->IsNull() )
{
m_pSelectImg->Draw(&BufferDC,CRect(0,0,rcItem.Width(),rcItem.Height()));
}
}
//节点高亮
else if ( m_nHovenItem == lpDrawItemStruct->itemID )
{
if ( m_pBackImgH!= NULL && !m_pBackImgH->IsNull() )
{
m_pBackImgH->Draw(&BufferDC,CRect(0,0,rcItem.Width(),rcItem.Height()));
}
}
//绘画字符
BufferDC.SetBkMode(TRANSPARENT);
BufferDC.SetTextColor(crTextColor);
BufferDC.DrawText(strString,&rcString,DT_VCENTER|DT_SINGLELINE);
//绘画界面
pDCControl->BitBlt(rcItem.left,rcItem.top,rcItem.Width(),rcItem.Height(),&BufferDC,0,0,SRCCOPY);
//清理资源
BufferDC.DeleteDC();
ImageBuffer.DeleteObject();
}
示例14: DrawCaption
void COFSNcDlg::DrawCaption(CDC &dc,const CRect &m_Rect)
{
if(m_Rect.Width()==0||m_Rect.Height()==0) return;
switch(m_CaptionMode)
{
case CAP_NONE:
case CAP_COLOR:
{
CFont m_font;
CBrush m_br;
CRect m_TextRect = m_Rect;
if(m_bActive)
m_br.CreateSolidBrush(m_ActiveColor);
else
m_br.CreateSolidBrush(m_InactiveColor);
dc.FillRect(m_Rect,&m_br);
CString str;
GetWindowText(str);
m_font.Attach(GetStockObject(DEFAULT_GUI_FONT));
dc.SelectObject(&m_font);
dc.SetTextColor(RGB(255,255,255));
dc.SetBkMode(TRANSPARENT);
m_TextRect.right -= 80;
dc.DrawText(str,(LPRECT)&m_TextRect ,DT_LEFT|DT_VCENTER|DT_END_ELLIPSIS|DT_SINGLELINE);
}
break;
case CAP_BITMAP_1:
{
CDC dcT;
dcT.CreateCompatibleDC(&dc);
dcT.SelectObject(pActiveBMP);
dc.BitBlt(m_Rect.left,m_Rect.top,m_Rect.Width(),m_Rect.Height(),&dcT,0,0,SRCCOPY);
}
break;
case CAP_BITMAP_1_ZOOM:
{
CDC dcT;
dcT.CreateCompatibleDC(&dc);
dcT.SelectObject(pActiveBMP);
dc.StretchBlt(m_Rect.left,m_Rect.top,m_Rect.Width(),m_Rect.Height(),&dcT,0,0,m_ActiveBMPSize.cx,m_ActiveBMPSize.cy,SRCCOPY);
// dc.BitBlt(m_Rect.left,m_Rect.top,m_Rect.Width(),m_Rect.Height(),&dcT,0,0,SRCCOPY);
}
break;
case CAP_BITMAP_2:
{
CDC dcT;
dcT.CreateCompatibleDC(&dc);
if(m_bActive)
dcT.SelectObject(pActiveBMP);
else
dcT.SelectObject(pInactiveBMP);
dc.BitBlt(m_Rect.left,m_Rect.top,m_Rect.Width(),m_Rect.Height(),&dcT,0,0,SRCCOPY);
}
break;
case CAP_BITMAP_2_ZOOM:
{
CDC dcT;
dcT.CreateCompatibleDC(&dc);
if(m_bActive)
{
dcT.SelectObject(pActiveBMP);
dc.StretchBlt(m_Rect.left,m_Rect.top,m_Rect.Width(),m_Rect.Height(),&dcT,0,0,m_ActiveBMPSize.cx,m_ActiveBMPSize.cy,SRCCOPY);
}
else
{
dcT.SelectObject(pInactiveBMP);
dc.StretchBlt(m_Rect.left,m_Rect.top,m_Rect.Width(),m_Rect.Height(),&dcT,0,0,m_InactiveBMPSize.cx,m_InactiveBMPSize.cy,SRCCOPY);
}
}
break;
}
DWORD dwStyle = GetStyle();
CRect m_ButtonRect;
m_ButtonRect.SetRect(m_Rect.right - CaptionH +2 ,m_Rect.top + 4,
m_Rect.right - 2,m_Rect.bottom - 2);
if(dwStyle&WS_SYSMENU)
dc.DrawFrameControl(&m_ButtonRect,DFC_CAPTION,DFCS_CAPTIONCLOSE);
if (dwStyle & WS_MAXIMIZEBOX)
{
m_ButtonRect-=CPoint(CaptionH-2,0);
dc.DrawFrameControl(&m_ButtonRect, DFC_CAPTION, IsZoomed()?DFCS_CAPTIONRESTORE:DFCS_CAPTIONMAX);
}
if (dwStyle & WS_MINIMIZEBOX)
{
m_ButtonRect-=CPoint(CaptionH-2,0);
dc.DrawFrameControl(&m_ButtonRect, DFC_CAPTION ,DFCS_CAPTIONMIN);
}
}
示例15: MakeCaptionBitmap
void CSAPrefsStatic::MakeCaptionBitmap()
{
if (m_bm.m_hObject)
return; // already have bitmap; return
CRect cr;
GetClientRect(cr);
int w = cr.Width();
int h = cr.Height();
// Create bitmap same size as caption area and select into memory DC
//
CWindowDC dcWin(this);
CDC dc;
dc.CreateCompatibleDC(&dcWin);
m_bm.DeleteObject();
m_bm.CreateCompatibleBitmap(&dcWin, w, h);
CBitmap* pOldBitmap = dc.SelectObject(&m_bm);
COLORREF clrBG = ::GetSysColor(COLOR_3DFACE); // background color
int r = GetRValue(clrBG); // red..
int g = GetGValue(clrBG); // ..green
int b = GetBValue(clrBG); // ..blue color vals
int x = 8*cr.right/8; // start 5/6 of the way right
int w1 = x - cr.left; // width of area to shade
int NCOLORSHADES = 128; // this many shades in gradient
int xDelta= max( w / NCOLORSHADES , 1); // width of one shade band
PaintRect(dc, x, 0, cr.right-x, h, clrBG);
while (x > xDelta)
{ // paint bands right to left
x -= xDelta; // next band
int wmx2 = (w1-x)*(w1-x); // w minus x squared
int w2 = w1*w1; // w squared
PaintRect(dc, x, 0, xDelta, h,
RGB(r-(r*wmx2)/w2, g-(g*wmx2)/w2, b-(b*wmx2)/w2));
}
PaintRect(dc,0,0,x,h,RGB(0,0,0)); // whatever's left ==> black
// draw the 'constant' text
// create a font, if we need to
if (m_nameFont.GetSafeHandle()==NULL)
{
m_nameFont.CreateFont( 18, 0, 0, 0, FW_BOLD,
0, 0, 0, ANSI_CHARSET,
OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,
FF_MODERN,
m_csFontName);
}
CFont * OldFont = dc.SelectObject(&m_nameFont);
// back up a little
cr.right-=5;
// draw text in DC
dc.SetBkMode(TRANSPARENT);
dc.SetTextColor( ::GetSysColor( COLOR_3DHILIGHT));
dc.DrawText( m_csConstantText, cr + CPoint(1,1), DT_SINGLELINE | DT_RIGHT | DT_VCENTER);
dc.SetTextColor( ::GetSysColor( COLOR_3DSHADOW));
dc.DrawText( m_csConstantText, cr, DT_SINGLELINE | DT_RIGHT | DT_VCENTER);
// restore old font
dc.SelectObject(OldFont);
// Restore DC
dc.SelectObject(pOldBitmap);
}