Reputation: 2655
I'm trying to create a menu and draw it with GDI.
I have a MENU TITLE, unchangable. I have an array of items.
If I want the title to be "MAIN MENU" how do I calculate the width and height of the Text? If I set SetBkColor() just before TextOut() to a different color than the HDC Background I see that it's rendered as a Rectangle - but how do I get the size of this rectangle and before writing out the Text on the screen?
Also, I set CreateFont() and SelectObject(HDC, Font) beforehand so I can write "bigger" text for the Menu.
Anyone with suggestions?
Haven't found a working solution for this with native GDI and not using newer Graphics objects in .NET.
Upvotes: 2
Views: 1243
Reputation: 4769
The easiest way is probably DrawText()
with DT_CALCRECT
.
You can also measure text yourself with GetTextExtentPoint32()
.
Upvotes: 4