本文整理汇总了C++中CClientDC::GetTextExtent方法的典型用法代码示例。如果您正苦于以下问题:C++ CClientDC::GetTextExtent方法的具体用法?C++ CClientDC::GetTextExtent怎么用?C++ CClientDC::GetTextExtent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CClientDC
的用法示例。
在下文中一共展示了CClientDC::GetTextExtent方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MeasureItem
void CaImMenu::MeasureItem (LPMEASUREITEMSTRUCT lpMeasureItemStruct) {
MENUITEMINFO iInfo;
GetMenuItemInfo (lpMeasureItemStruct->CtlID, &iInfo);
CaImMenuItem* pItem = (CaImMenuItem*)lpMeasureItemStruct->itemData;
CFont fntDef;
LOGFONT lfDef;
CClientDC dc (0);
CFont* pFont = (CFont *)dc.SelectStockObject (ANSI_VAR_FONT);
if (pItem->CheckStyle (AMIS_DEFAULT)) {
CFont* pFnt = dc.GetCurrentFont ();
pFnt->GetLogFont (&lfDef);
lfDef.lfWeight = FW_BOLD;
fntDef.CreateFontIndirect (&lfDef);
dc.SelectObject (&fntDef);
}
if (pItem->CheckStyle (AMIS_BAR))
lpMeasureItemStruct->itemHeight = 4;
else
lpMeasureItemStruct->itemHeight = m_dwHeight;
lpMeasureItemStruct->itemWidth = 25 + 8 + 8 + 2 + dc.GetTextExtent (pItem->GetText ()).cx;
dc.SelectObject (pFont);
if (pItem->CheckStyle (AMIS_DEFAULT))
fntDef.DeleteObject ();
}
示例2: OnMeasureItem
//*****************************************************************************************
void CIconCombo::OnMeasureItem(int /*nIDCtl*/, LPMEASUREITEMSTRUCT lpMeasureItemStruct)
{
int nTextWidth = 0;
int nTextHeight = 0;
if (!m_lstIconNames.IsEmpty ())
{
nTextHeight = globalData.GetTextHeight ();
CClientDC dc (this);
CFont* pOldFont = dc.SelectObject (&globalData.fontRegular);
for (POSITION pos = m_lstIconNames.GetHeadPosition (); pos != NULL;)
{
CString str = m_lstIconNames.GetNext (pos);
nTextWidth = max (nTextWidth, dc.GetTextExtent (str).cx + nIconMargin);
}
dc.SelectObject (pOldFont);
}
lpMeasureItemStruct->itemWidth = m_imageListIcons.GetImageSize ().cx + nTextWidth + 3 * nIconMargin;
lpMeasureItemStruct->itemHeight = max (nTextHeight, m_imageListIcons.GetImageSize ().cy + 2 * nIconMargin);
}
示例3: OnShowPopupMenu
void CRibbonListButton::OnShowPopupMenu ()
{
ASSERT_VALID (this);
CBCGPBaseRibbonElement::OnShowPopupMenu ();
if (m_sizeMaxText == CSize (0, 0))
{
CBCGPRibbonBar* pRibbonBar = GetTopLevelRibbonBar ();
ASSERT_VALID (pRibbonBar);
CClientDC dc (pRibbonBar);
CFont* pOldFont = dc.SelectObject (pRibbonBar->GetFont ());
ASSERT (pOldFont != NULL);
int i = 0;
for (i = 0; i < m_arLabels.GetSize (); i++)
{
CSize szText = dc.GetTextExtent (m_arLabels [i]);
m_sizeMaxText.cx = max (m_sizeMaxText.cx, szText.cx);
m_sizeMaxText.cy = max (m_sizeMaxText.cy, szText.cy);
}
const int cxImage = m_listImages.GetImageSize ().cx;
for (i = 0; i < m_arSubItems.GetSize (); i++)
{
CBCGPBaseRibbonElement* pButton = m_arSubItems [i];
ASSERT_VALID (pButton);
CString strText = pButton->GetText ();
CSize szText = dc.GetTextExtent (strText);
m_sizeMaxText.cx = max (m_sizeMaxText.cx, szText.cx - cxImage);
}
dc.SelectObject (pOldFont);
}
CBCGPRibbonPaletteButton::OnShowPopupMenu ();
}
示例4: OnSize
void CCGuiFlatTabbedViewView::OnSize(UINT nType, int cx, int cy)
{
CGuiViewWorkTab::OnSize(nType, cx, cy);
CClientDC dc (this);
CString strItem;
m_wndEdit.GetText (90, strItem);
int cxExtentMax = 0;
cxExtentMax = dc.GetTextExtent (strItem).cx;
m_wndEdit.SetHorizontalExtent (cxExtentMax);
// TODO: Add your message handler code here
}
示例5: UpdateDisplay
void CDlgCalcDlg::UpdateDisplay(LPCTSTR pszDisplay)
{
CClientDC dc (this);
CFont* pOldFont = dc.SelectObject (GetFont ());
CSize size = dc.GetTextExtent (pszDisplay);
CRect rect = m_rect;
rect.InflateRect (-2, -2);
int x = rect.right - size.cx - m_cxChar;
int y = rect.top + ((rect.Height () - m_cyChar) / 2);
dc.ExtTextOut (x, y, ETO_OPAQUE, rect, pszDisplay, NULL);
dc.SelectObject (pOldFont);
}
示例6: SetColumnsWidth
//*************************************************************************************
void CBCGPKeyMapDlg::SetColumnsWidth ()
{
CRect rectList;
m_KeymapList.GetClientRect (rectList);
CClientDC dc (this);
CFont* pOldFont = dc.SelectObject (m_KeymapList.GetFont ());
ASSERT_VALID (pOldFont);
int nKeyColumWidth = dc.GetTextExtent (CString (_T("Ctrl+Shift+W"))).cx + 10;
dc.SelectObject (pOldFont);
int nRestOfWidth = rectList.Width () - nKeyColumWidth - ::GetSystemMetrics (SM_CXHSCROLL);
m_KeymapList.SetColumnWidth (iColumnCommand, nRestOfWidth / 3);
m_KeymapList.SetColumnWidth (iColumnKeys, nKeyColumWidth);
m_KeymapList.SetColumnWidth (iColumnDescr, nRestOfWidth * 2 / 3);
}
示例7: ComputeSize
// determine size of a given cell based on actual font settings
CSize CMiniCalendarCtrl::ComputeSize()
{
const int iXDaysSpaceFromBorder = 15;
const int iHeaderSpaceForBorder = 15;
const int iHeaderYSpaceForBorder = 3;
const int iDaysXSpacing = 5;
const int iDaysYSpacing = 2;
CSize szReturn(0, 0);
int iWidthByDays = 0;
int iWidthByDaysOfWeekIndividual = 0;
int iWidthByHeader = 0;
int iHeaderHeight = 0;
int iDaysHeight = 0;
int iX;
// allocate a DC to use when testing sizes, etc
CClientDC* pDC = NULL;
if (::IsWindow(GetSafeHwnd()))
pDC = new CClientDC(this);
else
pDC = new CClientDC(AfxGetMainWnd());
ASSERT(pDC);
if (!pDC)
throw (new CMemoryException());
// get current font and save for later restoration
CFont* pOldFont = pDC->GetCurrentFont();
// first, use days to determine width
// NOTE: typically, most fonts use the same pixel sizes for all numbers,
// but this is not mandatory and many "fancy" fonts change this. To deal
// with this, I am calculating the width of all possible dates the control will display
pDC->SelectObject(m_pFont);
for (iX = 1; iX <= 31; iX++)
{
CString strTemp = "00";
strTemp += CCalendarUtils::LongToString(iX);
strTemp = strTemp.Right(2);
CSize szTemp = pDC->GetTextExtent(strTemp);
if (szTemp.cx > iWidthByDays)
iWidthByDays = szTemp.cx;
if (szTemp.cy > iDaysHeight)
iDaysHeight = szTemp.cy;
}
// make sure we also try it with the special days font
pDC->SelectObject(m_pFontBold);
for (iX = 1; iX <= 31; iX++)
{
CString strTemp = "00";
strTemp += CCalendarUtils::LongToString(iX);
strTemp = strTemp.Right(2);
CSize szTemp = pDC->GetTextExtent(strTemp);
if (szTemp.cx > iWidthByDays)
iWidthByDays = szTemp.cx;
if (szTemp.cy > iDaysHeight)
iDaysHeight = szTemp.cy;
}
// finish computation
m_iDaysHeight = iDaysHeight;
m_iIndividualDayWidth = iWidthByDays;
iWidthByDays = (iWidthByDays * 7) + (iDaysXSpacing*6) + (iXDaysSpaceFromBorder*2);
iDaysHeight = (iDaysHeight * 6) + (iDaysYSpacing*6);
// next use days of week to determine width and height. here again, we test each variant
pDC->SelectObject(m_pFont);
int iWidthByDaysOfWeek = pDC->GetTextExtent("S").cx;
if (pDC->GetTextExtent("M").cx > iWidthByDaysOfWeek)
iWidthByDaysOfWeek = pDC->GetTextExtent("M").cx;
if (pDC->GetTextExtent("T").cx > iWidthByDaysOfWeek)
iWidthByDaysOfWeek = pDC->GetTextExtent("T").cx;
if (pDC->GetTextExtent("W").cx > iWidthByDaysOfWeek)
iWidthByDaysOfWeek = pDC->GetTextExtent("W").cx;
if (pDC->GetTextExtent("F").cx > iWidthByDaysOfWeek)
iWidthByDaysOfWeek = pDC->GetTextExtent("F").cx;
int iDaysOfWeekHeight = pDC->GetTextExtent("S").cy;
if (pDC->GetTextExtent("M").cy > iDaysOfWeekHeight)
iDaysOfWeekHeight = pDC->GetTextExtent("M").cy;
if (pDC->GetTextExtent("T").cy > iDaysOfWeekHeight)
iDaysOfWeekHeight = pDC->GetTextExtent("T").cy;
if (pDC->GetTextExtent("W").cy > iDaysOfWeekHeight)
iDaysOfWeekHeight = pDC->GetTextExtent("W").cy;
if (pDC->GetTextExtent("F").cy > iDaysOfWeekHeight)
iDaysOfWeekHeight = pDC->GetTextExtent("F").cy;
// finish computation
iWidthByDaysOfWeekIndividual = iWidthByDaysOfWeek;
iWidthByDaysOfWeek = (iWidthByDaysOfWeek * 7) + (iDaysXSpacing*6) + (iXDaysSpaceFromBorder*2);
if (iWidthByDaysOfWeekIndividual > m_iIndividualDayWidth)
m_iIndividualDayWidth = iWidthByDaysOfWeekIndividual;
//.........这里部分代码省略.........
示例8: Track
//*******************************************************************************************
void CLoginBarToolTipCtrl::Track (CRect rect, const CString& strText)
{
if (GetSafeHwnd () == NULL)
{
return;
}
if (m_rectLast == rect && m_strText == strText)
{
return;
}
ASSERT_VALID (m_pWndParent);
m_rectLast = rect;
m_strText = strText;
CClientDC dc (this);
//ASSERT_VALID(m_pFont);
CFont* pPrevFont = m_pFont == NULL ?
(CFont*) dc.SelectStockObject (DEFAULT_GUI_FONT) :
dc.SelectObject (&theApp.m_font);
ASSERT (pPrevFont != NULL);
int nTextHeight = rect.Height () ;
int nTextWidth = rect.Width ();
if (m_strText.FindOneOf (_T("\n")) != -1) // multi-line tooltip
{
const int nDefaultHeight = globalData.GetTextHeight () ;
const int nDefaultWidth = 200;
CRect rectText (0, 0, nDefaultWidth, nDefaultHeight);
nTextHeight = dc.DrawText (m_strText, rectText, DT_LEFT | /*DT_WORDBREAK | */DT_CALCRECT | DT_NOPREFIX);
nTextWidth = rectText.Width ();
nTextHeight += 2 * m_nTextMargin ;
nTextWidth += 2 * m_nTextMargin;
nTextHeight += (GetLineCount(m_strText) - 1) * m_nTextMargin; //加上行间距
}
else
{
nTextWidth = dc.GetTextExtent (m_strText).cx + 2 * m_nTextMargin;
}
dc.SelectObject (pPrevFont);
if (m_pWndParent->GetExStyle () & WS_EX_LAYOUTRTL)
{
rect.left = rect.right - nTextWidth;
}
else
{
rect.right = rect.left + nTextWidth;
}
rect.bottom = rect.top + nTextHeight;
if (rect.Height () < m_rectLast.Height ())
{
rect.top = m_rectLast.top;
rect.bottom = m_rectLast.bottom;
}
MONITORINFO mi;
mi.cbSize = sizeof (MONITORINFO);
CRect rectScreen;
if (GetMonitorInfo (MonitorFromPoint (rect.TopLeft (), MONITOR_DEFAULTTONEAREST), &mi))
{
rectScreen = mi.rcWork;
}
else
{
::SystemParametersInfo (SPI_GETWORKAREA, 0, &rectScreen, 0);
}
if (rect.Width () > rectScreen.Width ())
{
rect.left = rectScreen.left;
rect.right = rectScreen.right;
}
else if (rect.right > rectScreen.right)
{
rect.OffsetRect( rectScreen.right - rect.right, 0 );
//rect.right = rectScreen.right;
//rect.left = rect.right - nTextWidth;
}
else if (rect.left < rectScreen.left)
{
rect.OffsetRect( rectScreen.left - rect.left, 0 );
//rect.left = rectScreen.left;
//rect.right = rect.left + nTextWidth;
}
if (rect.Height () > rectScreen.Height ())
{
rect.top = rectScreen.top;
rect.bottom = rectScreen.bottom;
}
else if (rect.bottom > rectScreen.bottom)
//.........这里部分代码省略.........
示例9: OnSelchangeCategory
//******************************************************************
void CBCGPKeyboardPage::OnSelchangeCategory()
{
UpdateData ();
int iIndex = m_wndCategoryList.GetCurSel ();
if (iIndex == LB_ERR)
{
ASSERT (FALSE);
return;
}
m_wndCommandsList.ResetContent ();
m_wndCurrentKeysList.ResetContent ();
CObList* pCategoryButtonsList =
(CObList*) m_wndCategoryList.GetItemData (iIndex);
ASSERT_VALID (pCategoryButtonsList);
CString strCategory;
m_wndCategoryList.GetLBText (iIndex, strCategory);
BOOL bAllCommands = (strCategory == m_strAllCategory);
CClientDC dcCommands (&m_wndCommandsList);
CFont* pOldFont = dcCommands.SelectObject (m_wndCommandsList.GetFont ());
ASSERT (pOldFont != NULL);
CBCGPToolbarCustomize* pWndParent = DYNAMIC_DOWNCAST (CBCGPToolbarCustomize, GetParent ());
ASSERT (pWndParent != NULL);
int cxCommandsExtentMax = 0;
for (POSITION pos = pCategoryButtonsList->GetHeadPosition (); pos != NULL;)
{
CBCGPToolbarButton* pButton = (CBCGPToolbarButton*) pCategoryButtonsList->GetNext (pos);
ASSERT (pButton != NULL);
if (pButton->m_nID > 0 && pButton->m_nID != (UINT) -1)
{
CString strText = pButton->m_strText;
if (!pButton->m_strTextCustom.IsEmpty () &&
(bAllCommands || pWndParent->GetCountInCategory (strText, *pCategoryButtonsList) > 1))
{
strText = pButton->m_strTextCustom;
}
int iIndex = m_wndCommandsList.AddString (strText);
m_wndCommandsList.SetItemData (iIndex, (DWORD_PTR) pButton);
cxCommandsExtentMax = max (cxCommandsExtentMax, dcCommands.GetTextExtent (strText).cx);
}
}
m_wndCommandsList.SetHorizontalExtent (cxCommandsExtentMax + ::GetSystemMetrics (SM_CXHSCROLL));
dcCommands.SelectObject (pOldFont);
m_wndNewKey.EnableWindow (FALSE);
m_wndCommandsList.SetCurSel (0);
OnSelchangeCommandsList ();
}
示例10: FillWindowList
// Refresh windows list
void CBCGPWindowsManagerDlg::FillWindowList(void)
{
m_wndList.SetRedraw(FALSE);
m_wndList.ResetContent();
int cxExtent = 0;
CClientDC dcList (&m_wndList);
CFont* pOldFont = dcList.SelectObject (GetFont ());
ASSERT_VALID (pOldFont);
m_bMDIActions = TRUE;
m_lstCloseDisabled.RemoveAll ();
m_lstSaveDisabled.RemoveAll ();
HWND hwndT = ::GetWindow(m_pMDIFrame->m_hWndMDIClient, GW_CHILD);
while (hwndT != NULL)
{
CBCGPMDIChildWnd* pFrame = DYNAMIC_DOWNCAST (CBCGPMDIChildWnd,
CWnd::FromHandle (hwndT));
if (pFrame == NULL)
{
hwndT = ::GetWindow(hwndT,GW_HWNDNEXT);
continue;
}
if (!pFrame->CanShowOnWindowsList ())
{
hwndT = ::GetWindow(hwndT,GW_HWNDNEXT);
continue;
}
TCHAR szWndTitle[256];
::GetWindowText(hwndT,szWndTitle,sizeof(szWndTitle)/sizeof(szWndTitle[0]));
int index = m_wndList.AddString(szWndTitle);
int cxCurr = dcList.GetTextExtent (szWndTitle).cx;
cxExtent = max (cxExtent, cxCurr);
m_wndList.SetItemData(index,(DWORD_PTR) hwndT);
if (pFrame != NULL && pFrame->IsReadOnly ())
{
m_lstSaveDisabled.AddTail (hwndT);
}
DWORD dwStyle = ::GetWindowLong (hwndT, GWL_STYLE);
if ((dwStyle & WS_SYSMENU) == 0)
{
m_bMDIActions = FALSE;
}
else
{
HMENU hSysMenu = ::GetSystemMenu (hwndT, FALSE);
if (hSysMenu == NULL)
{
m_bMDIActions = FALSE;
}
else
{
MENUITEMINFO menuInfo;
ZeroMemory(&menuInfo,sizeof(MENUITEMINFO));
menuInfo.cbSize = sizeof(MENUITEMINFO);
menuInfo.fMask = MIIM_STATE;
if (!::GetMenuItemInfo(hSysMenu, SC_CLOSE, FALSE, &menuInfo) ||
(menuInfo.fState & MFS_GRAYED) ||
(menuInfo.fState & MFS_DISABLED))
{
m_lstCloseDisabled.AddTail (hwndT);
}
}
}
hwndT = ::GetWindow(hwndT,GW_HWNDNEXT);
}
m_wndList.SetHorizontalExtent (cxExtent + ::GetSystemMetrics (SM_CXHSCROLL) + 30);
dcList.SelectObject (pOldFont);
m_Icons.DeleteImageList();
m_Icons.Create(globalData.m_sizeSmallIcon.cx, globalData.m_sizeSmallIcon.cy, ILC_COLOR32 | ILC_MASK, 0, 10);
for (int i = 0; i < m_wndList.GetCount(); i++)
{
HWND hwnd = (HWND)m_wndList.GetItemData(i);
HICON hIcon = NULL;
if ((hIcon = (HICON)::SendMessage(hwnd, WM_GETICON, FALSE, 0)) == NULL)
{
hIcon = (HICON)(LONG_PTR)GetClassLongPtr(hwnd, GCLP_HICONSM);
}
if (hIcon != NULL)
{
m_Icons.Add(hIcon);
m_wndList.SetItemImage(i, m_Icons.GetImageCount() - 1);
}
//.........这里部分代码省略.........
示例11: RecalcLayout
//.........这里部分代码省略.........
// only in this case button and text is at the left side of the icon
bButtonLeftOfIcon = TRUE;
bTextLeftOfIcon = TRUE;
break;
case ALIGN_CENTER:
bIconCenter = TRUE;
nNextXOffsetCenter -= sizeImage.cx / 2;
if (m_btnAlignnment == ALIGN_LEFT)
{
bButtonLeftOfIcon = TRUE;
}
if (m_textAlignment == ALIGN_LEFT)
{
bTextLeftOfIcon = TRUE;
}
break;
default:
ASSERT (FALSE);
}
}
else
{
m_rectImage.SetRectEmpty();
}
int nButtonWidth = 0;
if (!m_strBtnText.IsEmpty ())
{
nButtonWidth = dc.GetTextExtent (m_strBtnText).cx + 2 * m_nHorzElementOffset;
if (m_bIsMessageBarMode)
{
nButtonWidth += 2 * nButtonHorzMargin;
}
if (m_uiBtnID != 0 && m_bBtnEnabled && m_bBtnHasDropDownArrow)
{
nButtonWidth += nMenuArrowWidth;
}
// the button always has a height equivalent to the bar's height
m_rectButton.top = rectClient.top;
m_rectButton.bottom = rectClient.bottom;
if (m_bIsMessageBarMode)
{
m_rectButton.DeflateRect (0, nButtonVertMargin);
}
switch (m_btnAlignnment)
{
case ALIGN_LEFT:
if (!m_bIsMessageBarMode || m_textAlignment != ALIGN_LEFT)
{
m_rectButton.left = nNextXOffsetLeft;
if (nNextXOffsetLeft == rectClient.left + m_nMargin)
{
m_rectButton.left = rectClient.left + m_nMargin;
}