From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
12-17-2012 09:45 AM
Hi,
Does anyone know how to obtain the display length (in pixels) of the title bar text? To make things clear, this is what I'm looking for:
I don't see a CVI function for this. The ATTR_TITLE_FONT attribute for GetPanelAttribute(...) is only valid for child panels which precludes me from using GetTextDisplaySize(...) to get the size. Diving into the Windows SDK I can't even find an answer there. Any ideas? Thanks.
Solved! Go to Solution.
12-17-2012 10:58 AM
Figured out how to do this. You have to go into the SDK to get the font properties - how this is done is kind of non-obvious. But once you have the font properties you can create a meta font in CVI, with the properties, and once you have the meta font you can use GetTextDisplaySize(...) to get the size. For future reference:
//define a NONCLIENTMETRICS structure
NONCLIENTMETRICS ncmtest;
//We have to set the cbSize parameter to the size of the passed structure before retrieving it ncmtest.cbSize = sizeof(NONCLIENTMETRICS); //Get NONCLIENTMETRICS structure result = SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &ncmtest, 0); //copy the title font name to a c-string while(ncmtest.lfCaptionFont.lfFaceName[i] != 0) { thefont[i] = (char)ncmtest.lfCaptionFont.lfFaceName[i]; ++i; } //null terminate thefont[i] = '\0'; //create meta font with title font properties. lfWeight & 0x700 indicates bold. CreateMetaFontWithCharacterSet() doesn't recognize DEFAULT_CHARSET so we replace it with VAL_NATIVE_CHARSET(?). uir_status = CreateMetaFontWithCharacterSet ("TheTitleFont", thefont, abs(ncmtest.lfCaptionFont.lfHeight), ncmtest.lfCaptionFont.lfWeight & 0x700 ? 1 : 0, ncmtest.lfCaptionFont.lfItalic, ncmtest.lfCaptionFont.lfUnderline, ncmtest.lfCaptionFont.lfStrikeOut, 0, ncmtest.lfCaptionFont.lfCharSet == DEFAULT_CHARSET ? VAL_NATIVE_CHARSET : ncmtest.lfCaptionFont.lfCharSet); //get titlebar text uir_status = GetPanelAttribute (panelhandle, ATTR_TITLE, thetext); //get title bar length uir_status = GetTextDisplaySize (thetext, "TheTitleFont", &height, &width);
I get 79 for the length from the screenshot above.
12-17-2012 05:38 PM - edited 12-17-2012 05:38 PM
I suppose this native (easier) method can be applied to window title too. You don't need WinSDK to use it.
12-18-2012 07:36 AM
Hi,
I'm actually using GetTextDisplaySize(..). The problem is that I need the font used on the title bar and its properties, and I couldn't find a way to get the font properties of the title bar of a top-level (non-child) window through CVI. If I'm wrong please let me know!