本文整理汇总了C++中CClientDC::GetTextMetrics方法的典型用法代码示例。如果您正苦于以下问题:C++ CClientDC::GetTextMetrics方法的具体用法?C++ CClientDC::GetTextMetrics怎么用?C++ CClientDC::GetTextMetrics使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CClientDC
的用法示例。
在下文中一共展示了CClientDC::GetTextMetrics方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SetRowHeight
//*********************************************************************
void CCxNDArrayDimGrid::SetRowHeight ()
{
if (m_bIsPrinting)
{
ASSERT_VALID (m_pPrintDC);
// map to printer metrics
HDC hDCFrom = ::GetDC(NULL);
int nYMul = m_pPrintDC->GetDeviceCaps(LOGPIXELSY); // pixels in print dc
int nYDiv = ::GetDeviceCaps(hDCFrom, LOGPIXELSY); // pixels in screen dc
::ReleaseDC(NULL, hDCFrom);
TEXTMETRIC tm;
m_pPrintDC->GetTextMetrics (&tm);
m_PrintParams.m_nRowHeight = tm.tmHeight + ::MulDiv (2 * TEXT_VMARGIN, nYMul, nYDiv);
m_PrintParams.m_nLargeRowHeight = m_PrintParams.m_nRowHeight;
}
else
{
CClientDC dc (this);
HFONT hfontOld = SetCurrFont (&dc);
TEXTMETRIC tm;
dc.GetTextMetrics (&tm);
m_nRowHeight = tm.tmHeight + 2 * TEXT_VMARGIN;
m_nLargeRowHeight = m_nRowHeight;
::SelectObject (dc.GetSafeHdc (), hfontOld);
}
}
示例2: CenterText
void CBigIcon::CenterText(CClientDC &dc, LPCSTR lpszStatus, int top)
{
int nMargin;
CRect rect;
TEXTMETRIC tm;
// Leave a horizontal margin equal to the widest character
VERIFY(dc.GetTextMetrics(&tm));
nMargin = tm.tmMaxCharWidth;
// Compute the opaque rect
rect.left = nMargin;
rect.right = m_sizeBitmap.cx - nMargin;
rect.top = top;
rect.bottom = rect.top + tm.tmHeight;
// We need to compute where to draw the text so it is centered
// horizontally
int x = rect.left;
CSize extent = CIntlWin::GetTextExtent(0, dc.m_hDC, lpszStatus, XP_STRLEN(lpszStatus));
if (extent.cx < rect.Width())
x += (rect.Width() - extent.cx) / 2;
// Draw opaquely so we can avoid erasing the old text
dc.ExtTextOut(x, rect.top, ETO_OPAQUE, &rect, lpszStatus, strlen(lpszStatus), NULL);
}
示例3: MeasureItem
//******************************************************************************
void CBCGPRibbonCommandsListBox::MeasureItem(LPMEASUREITEMSTRUCT lpMIS)
{
ASSERT (lpMIS != NULL);
CClientDC dc (this);
CFont* pOldFont = (CFont*) dc.SelectStockObject (DEFAULT_GUI_FONT);
ASSERT_VALID (pOldFont);
TEXTMETRIC tm;
dc.GetTextMetrics (&tm);
lpMIS->itemHeight = tm.tmHeight + 6;
dc.SelectObject (pOldFont);
}
示例4: OnCreate
int myframe::OnCreate(LPCREATESTRUCT lp)
{
if (CWnd::OnCreate (lp) == -1)
return -1;
CClientDC dc (this);
CButton *but;
but=new CButton;
but->Create("Show fonts",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,CRect(10,10,100,50),this,10);
fonttitle.Create("",WS_VISIBLE | WS_CHILD,CRect(50,100,500,500),this);
TEXTMETRIC tm;
dc.GetTextMetrics (&tm);
m_cxChar = tm.tmAveCharWidth;
m_cyChar = tm.tmHeight + tm.tmExternalLeading;
return 0;
}
示例5: OnInitDialog
BOOL CDlgCalcDlg::OnInitDialog()
{
CDialog::OnInitDialog();
//
// Set the application's icon.
//
SetIcon(m_hIcon, TRUE);
SetIcon(m_hIcon, FALSE);
//
// Remove the Size and Maximize commands from the system menu.
//
CMenu* pMenu = GetSystemMenu (FALSE);
pMenu->DeleteMenu (SC_SIZE, MF_BYCOMMAND);
pMenu->DeleteMenu (SC_MAXIMIZE, MF_BYCOMMAND);
//
// Initialize m_rect with the coordinates of the control representing
// the calculator's output window. Then destroy the control.
//
CWnd* pWnd = GetDlgItem (IDC_DISPLAYRECT);
pWnd->GetWindowRect (&m_rect);
pWnd->DestroyWindow ();
ScreenToClient (&m_rect);
//
// Initialize m_cxChar and m_cyChar with the average character width
// and height.
//
TEXTMETRIC tm;
CClientDC dc (this);
dc.GetTextMetrics (&tm);
m_cxChar = tm.tmAveCharWidth;
m_cyChar = tm.tmHeight - tm.tmDescent;
//
// Initialize the calculator's output window and return.
//
DisplayXRegister ();
return TRUE;
}
示例6: OnCreate
int CUndoBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CBCGPPopupMenuBar::OnCreate(lpCreateStruct) == -1)
return -1;
CFont* pMenuFont = (CFont*) &CBCGPMenuBar::GetMenuFont ();
//------------------
// Set label height:
//------------------
CClientDC dc (this);
CFont* pOldFont = dc.SelectObject (pMenuFont);
TEXTMETRIC tm;
dc.GetTextMetrics (&tm);
m_nLabelHeight = tm.tmHeight + 2;
dc.SelectObject (pOldFont);
CRect rectDummy (0, 0, 0, 0);
m_wndList.Create (WS_VISIBLE | WS_CHILD | LBS_NOINTEGRALHEIGHT | LBS_NOTIFY | WS_VSCROLL | LBS_MULTIPLESEL,
rectDummy, this, ID_LIST);
m_wndList.ModifyStyleEx (0, WS_EX_CLIENTEDGE);
m_wndList.SetFont (pMenuFont);
CUndoButton* pUndoButton = GetParentButton ();
ASSERT_VALID (pUndoButton);
for (POSITION pos = pUndoButton->m_lstActions.GetHeadPosition (); pos != NULL;)
{
m_wndList.AddString (pUndoButton->m_lstActions.GetNext (pos));
}
return 0;
}
示例7: OnCreate
int CMainWindow::OnCreate (LPCREATESTRUCT lpcs)
{
if (CWnd::OnCreate (lpcs) == -1)
return -1;
//
// Create an 8-point MS Sans Serif font to use in the controls.
//
m_fontMain.CreatePointFont (80, _T ("MS Sans Serif"));
//
// Compute the average width and height of a character in the font.
//
CClientDC dc (this);
CFont* pOldFont = dc.SelectObject (&m_fontMain);
TEXTMETRIC tm;
dc.GetTextMetrics (&tm);
m_cxChar = tm.tmAveCharWidth;
m_cyChar = tm.tmHeight + tm.tmExternalLeading;
dc.SelectObject (pOldFont);
//
// Create the controls that will appear in the FontView window.
//
CRect rect (m_cxChar * 2, m_cyChar, m_cxChar * 48, m_cyChar * 2);
m_wndLBTitle.Create (_T ("Typefaces"), WS_CHILD | WS_VISIBLE | SS_LEFT,
rect, this);
rect.SetRect (m_cxChar * 2, m_cyChar * 2, m_cxChar * 48,
m_cyChar * 18);
m_wndListBox.CreateEx (WS_EX_CLIENTEDGE, _T ("listbox"), NULL,
WS_CHILD | WS_VISIBLE | LBS_STANDARD, rect, this, IDC_LISTBOX);
rect.SetRect (m_cxChar * 2, m_cyChar * 19, m_cxChar * 48,
m_cyChar * 20);
m_wndCheckBox.Create (_T ("Show TrueType fonts only"), WS_CHILD |
WS_VISIBLE | BS_AUTOCHECKBOX, rect, this, IDC_CHECKBOX);
rect.SetRect (m_cxChar * 2, m_cyChar * 21, m_cxChar * 66,
m_cyChar * 25);
m_wndGroupBox.Create (_T ("Sample"), WS_CHILD | WS_VISIBLE | BS_GROUPBOX,
rect, this, (UINT) -1);
rect.SetRect (m_cxChar * 4, m_cyChar * 22, m_cxChar * 64,
(m_cyChar * 99) / 4);
m_wndSampleText.Create (_T (""), WS_CHILD | WS_VISIBLE | SS_CENTER, rect,
this, IDC_SAMPLE);
rect.SetRect (m_cxChar * 50, m_cyChar * 2, m_cxChar * 66,
m_cyChar * 4);
m_wndPushButton.Create (_T ("Print Sample"), WS_CHILD | WS_VISIBLE |
WS_DISABLED | BS_PUSHBUTTON, rect, this, IDC_PRINT);
//
// Set each control's font to 8-point MS Sans Serif.
//
m_wndLBTitle.SetFont (&m_fontMain, FALSE);
m_wndListBox.SetFont (&m_fontMain, FALSE);
m_wndCheckBox.SetFont (&m_fontMain, FALSE);
m_wndGroupBox.SetFont (&m_fontMain, FALSE);
m_wndPushButton.SetFont (&m_fontMain, FALSE);
//
// Fill the list box with typeface names and return.
//
FillListBox ();
return 0;
}
示例8: AdjustControl
//************************************************************************************************
void CBCGPDateTimeCtrl::AdjustControl (CRect rectClient)
{
if (GetSafeHwnd () == NULL)
{
return;
}
CClientDC dc (this);
CFont* pPrevFont = m_hFont == NULL ?
(CFont*) dc.SelectStockObject (DEFAULT_GUI_FONT) :
dc.SelectObject (CFont::FromHandle (m_hFont));
if (m_WidestDate == COleDateTime ())
{
BuidWidestDate (&dc);
}
SetPartsOrder ();
m_iPartNum = m_bCheckBoxIsAvailable ? 1 : 0;
m_CurrPartType = m_arPartsOrder [m_iPartNum];
m_rectText = rectClient;
m_rectText.InflateRect (0, -2);
if (m_bAutoResize)
{
// Calculate text size:
TEXTMETRIC tm;
dc.GetTextMetrics (&tm);
m_iControlHeight = tm.tmHeight + 6;
}
else
{
m_iControlHeight = rectClient.Height ();
}
if (m_bCheckBoxIsAvailable)
{
m_rectCheck = CRect (rectClient.left + 1, rectClient.top + 1,
rectClient.left + m_iControlHeight - 1, rectClient.bottom - 1);
m_rectText.left = m_rectCheck.right + 2;
}
m_rectText.top = rectClient.top;
m_rectText.bottom = rectClient.top + m_iControlHeight;
// Calculate parts:
CalcPartRects (&dc);
// Adjust control size:
m_rectText.right = m_arPartRects [m_iPartsNumber - 1].right + 2;
m_iControlWidth = m_rectText.right;
if (m_spinButton)
{
m_iControlWidth += iSpinWidth;
}
if (!m_bAutoResize)
{
m_iControlWidth = rectClient.Width ();
m_iControlHeight = rectClient.Height ();
}
if (m_dropCalendar && m_showDate)
{
if (m_bAutoResize)
{
m_iControlWidth += iDropButtonWidth;
}
int iDropStart = rectClient.left + m_iControlWidth - iDropButtonWidth - 1;
if (m_spinButton)
{
iDropStart -= iSpinWidth + 1;
}
m_rectDropButton = CRect ( iDropStart,
rectClient.top,
iDropStart + iDropButtonWidth,
rectClient.top + m_iControlHeight - 2);
}
if (m_bAutoResize)
{
SetWindowPos (NULL, -1, -1, m_iControlWidth + 2, m_iControlHeight + 2,
SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOMOVE);
}
// Adjust spin button:
if (m_spinButton)
{
if (m_wndSpin.GetSafeHwnd () == NULL)
{
m_wndSpin.Create (WS_CHILD | WS_VISIBLE | UDS_ALIGNRIGHT | UDS_AUTOBUDDY,
//.........这里部分代码省略.........
示例9: RecalcLayout
//*****************************************************************************
void CBCGPCaptionBar::RecalcLayout ()
{
CClientDC dc (NULL);
CFont* pOldFont = dc.SelectObject (
m_hFont == NULL ? &globalData.fontRegular : CFont::FromHandle (m_hFont));
ASSERT (pOldFont != NULL);
TEXTMETRIC tm;
dc.GetTextMetrics (&tm);
int nTextHeight = tm.tmHeight + 2;
CSize sizeImage = GetImageSize ();
const int nButtonVertMargin = CBCGPVisualManager::GetInstance()->GetMessageBarMargin();
const int nBorderSize = m_bIsMessageBarMode ? 0 : m_nBorderSize;
//-------------------------------------------------------------------
// the height is set to the default (provided by the user in Create)
// or calculated if it is -1
//-------------------------------------------------------------------
if (m_nDefaultHeight != -1)
{
m_nCurrentHeight = m_nDefaultHeight;
}
else
{
if (!m_strBtnText.IsEmpty () && m_bIsMessageBarMode)
{
nTextHeight += 2 * nButtonVertMargin;
}
m_nCurrentHeight = max (nTextHeight, sizeImage.cy) +
m_nMargin * 2 + nBorderSize;
}
if (m_bIsMessageBarMode)
{
m_nCurrentHeight += CBCGPVisualManager::GetInstance()->GetMessageBarMargin() * 2;
}
// for left and center alignment: icon, button, text
// for right alignment: text, button, icon
CRect rectClient;
GetClientRect (rectClient);
if (rectClient.IsRectEmpty ())
{
return;
}
if (m_bIsMessageBarMode)
{
CSize sizeImage = CBCGPMenuImages::Size ();
const int nCloseButtonMargin = 4;
sizeImage.cx += 2 * nCloseButtonMargin;
sizeImage.cy += 2 * nCloseButtonMargin;
m_rectClose = CRect (
CPoint (rectClient.right - sizeImage.cx, rectClient.top + nCloseButtonMargin),
sizeImage);
m_rectClose.right--;
rectClient.DeflateRect (nCloseButtonMargin, nCloseButtonMargin);
rectClient.right -= m_rectClose.Width ();
}
else
{
m_rectClose.SetRectEmpty();
}
BOOL bButtonLeftOfIcon = FALSE;
BOOL bTextLeftOfButton = FALSE;
BOOL bTextLeftOfIcon = FALSE;
BOOL bIconCenter = FALSE;
BOOL bButtonCenter = FALSE;
BOOL bButtonAfterText = FALSE;
BOOL bTextCenter = FALSE;
// differs from the current height, because the border size is non-client area
int nBaseLine = rectClient.CenterPoint ().y;
int nCenterOffset = rectClient.CenterPoint ().x;
int nNextXOffsetLeft = rectClient.left + m_nMargin;
int nNextXOffsetRight = rectClient.right - m_nMargin;
int nNextXOffsetCenter = nCenterOffset;
if (IsImageSet ())
{
if (sizeImage.cy < rectClient.Height () || m_bIsMessageBarMode)
{
// center the icon if its height lesser than client area height
m_rectImage.top = nBaseLine - sizeImage.cy / 2;
}
else
{
//.........这里部分代码省略.........