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.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to get the title bar text display length in pixels?

Solved!
Go to solution

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:

q.PNG

 

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.

0 Kudos
Message 1 of 4
(3,069 Views)
Solution
Accepted by topic author tstanley

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.

0 Kudos
Message 2 of 4
(3,066 Views)

I suppose this native (easier) method can be applied to window title too. You don't need  WinSDK to use it.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 3 of 4
(3,054 Views)

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!

0 Kudos
Message 4 of 4
(3,040 Views)