
Need Help with OwnerDraw Menu, GetTextExtentPoint32 & Menu Fonts
To get a right text extention you should select a right
font into DC.
As far as I understand (you don't mention this), you are
talking about Win95 or WinNT 4.0.
Your WM_MEASUREITEM handler should look somth. like this:
void CMenuOwner::OnMeasureItem(int id, MEASUREITEMSTRUCT* pmis)
{
NONCLIENTMETRICS ncm;
ncm.cbSize = sizeof(NONCLIENTMETRICS);
SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
sizeof(NONCLIENTMETRICS),
&ncm,
0);
CFont font;
font.CreateFontIndirect(&ncm.lfMenuFont);
CDC dc;
dc.CreateCompatibleDC(NULL);
CFont* pOldFont = (CFont*)dc.SelectObject(&font);
// Now get text extention:
CString sText = _T("Your menu item text");
CSize size = dc.GetTextExtent(sText);
dc.SelectObject(pOldFont);
font.DeleteObject();
dc.DeleteDC();
pmis->itemWidth = size.cx;
pmis->itemHeight = size.cy;
CMenuOwnerBase::OnMeasureItem(id, pmis);
Quote:
}
--
__ __ __ AbirNet, Ltd.
| |_| |_| | Active Network Protection
\ / __ __ __ __ __
| |__| |__| |__| |__| |__| |
| |
| <http://www.AbirNet.com> |
|______________________________________|
The Next Generation in Internet and Intranet Protection.
--------------------------------------------------------------------
AbirNet provides Windows 95 and NT-based software that lets you know
how your network is being used while protecting it from intrusions
and abuse using no network overhead see-it-all filtering, blocking,
alerting, logging, and scanning technologies.
--------------------------------------------------------------------
Get an EVALUATION COPY at <http://www.AbirNet.com>
--------------------------------------------------------------------
Quote:
> Here's a code fragment from my OnMeasureItem procedure which is called
for
> my ownerdraw pop-up menu:
> ...
> SIZE size;
> HDC dc = GetDC(hWnd);
> GetTextExtentPoint32(dc, mi->s, lstrlen(mi->s), &size);
> ...
> This works for typical menu font sizes, but if I increase the menu font
> size, GetTextExtentPoint32 still returns the same 'size' (i.e. no matter
> what size the menu font is, the menu item height and width stay the
same.)
> The result is a popup menu with text running off the sides of the menu.
> I suspect the problem is getting the device context. The window handle
> (hWnd) used to retrieve the device context *should* be the handle to the
> menu, right? Well, how do I get an HWND from a CMenu object? Since I
> don't know how to do this, I've been using the HWND from the window that
> owns the popup. Does anyone know what to do here?
> Thanks in advance.