[Home] [Puzzles & Projects] [Delphi Techniques] [Math topics] [Library] [Utilities]
|
| Here's a little routine, MakeCaption, that solves the problem of justifying titlebar caption information, I wanted to add a copyright notice to the right side of the titlebar for some simple programs where an About box seemed like overkill. So here's the plan - we'll just determine the width in pixels of the titlebar caption area, determine the width of the text we want to insert, then calculate how many space characters to stick in between the left and right halves. Like this: NbrSpaces:=(CaptionAreaWidth-LeftTextWidth-RightTextWidth) div SpaceWidth; Caption:=LeftText+StringofChar(' ',NbrSpaces)+RightText; As usual, things are not so simple. The TextWidth function will return the width in pixels for a particular canvas. The value depends on the font characteristics of the canvas. And there's the complication. Titlebar characteristics are uniform for the entire Windows system and are defined by the Control Panel or by right-clicking on your desktop and then the Appearance tab. Retrieving this information in the program requires a call to the SystemParametersInfo function with a SPI_GetNonCLientMetrics parameter. A little messy - you can view the code for the details. Once we get the width of the borders, the size of the icon in the top left corner and the size of the max/min/close boxes, we can subtract those from the client rectangle width to get the width of the caption area. I defined a temporary bitmap just to get a canvas and assigned the titlebar font properties to it. Then using the TextWidth function for that canvas gives us the other numbers we need to complete the NbrSpaces calculation. And it works! You can download the source (MakeCaption and a the test project) to view the rest of the details.
Modified 05/12/2018 08:57 |
[Feedback] [Newsletters (subscribe/view)] [About me]Copyright © 2000-2018, Gary Darby All rights reserved. |