本文整理汇总了C++中CGridCtrl::ReleaseDC方法的典型用法代码示例。如果您正苦于以下问题:C++ CGridCtrl::ReleaseDC方法的具体用法?C++ CGridCtrl::ReleaseDC怎么用?C++ CGridCtrl::ReleaseDC使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CGridCtrl
的用法示例。
在下文中一共展示了CGridCtrl::ReleaseDC方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetTextExtentEx
// This hack allows you to determine the height that a cell should be in order to display
// stuff properly in the given width.
CSize CGridCellMultiLine::GetTextExtentEx(int width, LPCTSTR szText, CDC* pDC /*= NULL*/)
{
CGridCtrl* pGrid = GetGrid();
ASSERT(pGrid);
BOOL bReleaseDC = FALSE;
if (pDC == NULL)
{
pDC = pGrid->GetDC();
if (!pDC)
{
CGridDefaultCell* pDefCell = (CGridDefaultCell*) GetDefaultCell();
ASSERT(pDefCell);
return CSize(pDefCell->GetWidth(), pDefCell->GetHeight());
}
bReleaseDC = TRUE;
}
CFont *pOldFont = NULL,
*pFont = GetFontObject();
if (pFont)
pOldFont = pDC->SelectObject(pFont);
CSize size;
int nFormat = GetFormat();
TEXTMETRIC tm;
pDC->GetTextMetrics(&tm);
int textWidth = width - (4*GetMargin ());
// corrects the bug if resizing column gives a text width smaller than (4*Getmargin())
if (textWidth <= 0)
{
textWidth = 1;
}
// If the cell is a multiline cell, then use the width of the cell
// to get the height
if ((nFormat & DT_WORDBREAK) && !(nFormat & DT_SINGLELINE))
{
CRect rect;
rect.SetRect(0, 0, textWidth, 0);
pDC->DrawText(szText, -1, rect, nFormat | DT_CALCRECT);
size.cx = rect.Width ();
size.cy = rect.Height ();
}
else
size = pDC->GetTextExtent(szText, _tcslen(szText));
size.cx += (tm.tmOverhang);
if (pOldFont)
pDC->SelectObject(pOldFont);
size += CSize(4*GetMargin(), 2*GetMargin());
// Kludge for vertical text
LOGFONT *pLF = GetFont();
if (pLF->lfEscapement == 900 || pLF->lfEscapement == -900)
{
int nTemp = size.cx;
size.cx = size.cy;
size.cy = nTemp;
size += CSize(0, 4*GetMargin());
}
if (bReleaseDC)
pGrid->ReleaseDC(pDC);
return size;
}