Owner-drawn menus

Started by
1 comment, last by sakky 19 years, 6 months ago
I have a problem with my owner drawn menus. I’ve made the menus myself. I’ve set the owner-draw flags and overridden the WM_MEASUREITEM and WM_DRAWITEM messages. My problem is I still have left-over padding from the menus. My guess is I’m not calculating the menu size right. I’m calculating the menu size vie character size * string size. This is my code for WM_MEASUREITEM

VOID OnMeasureItem( HWND hWnd, LPMEASUREITEMSTRUCT lpMIS )
{
	SIZE				size;
	HDC					hDC;

	hDC = GetDC( hWnd );

	GetTextExtentPoint32( hDC, ( LPCTSTR )lpMIS->itemData, 
							   lstrlen( ( LPCTSTR )lpMIS->itemData ), 
							   &size );
	
	lpMIS->itemWidth	= size.cx + 20;
	lpMIS->itemHeight	= size.cy + 4;
}

Take back the internet with the most awsome browser around, FireFox
Advertisement
See MSDN, about halfway down the page, for detailed info and sample code relating to owner-drawn menus. One error I see is that you're getting a DC in that function but never releasing it. I doubt that's the problem, but it is a memory leak (at least until your program terminates). Put in a call to ReleaseDC(hDC) at the end of the function.

How come you're adding 20 and 4 to the item dimensions? In the sample code at MSDN, they don't do that. That's probably what's giving you extra padding.
Yes, I forgot to release the DC. I was adding those numbers to the item dimensions so that their would be room for the icon.

[EDIT] Removeingthe numbers doesn't do anything except cram things together.
Take back the internet with the most awsome browser around, FireFox

This topic is closed to new replies.

Advertisement