Sign in to follow this  

Owner-drawn menus

Recommended Posts

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
	SIZE				size;
	HDC					hDC;

	hDC = GetDC( hWnd );

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

Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this