How to measure width of title bar available for text?

I am trying to customize the title bar of my main window to show as much as possible of the file name that can be placed in the title bar. So, I expect to calculate the width of the area marked here in the red rectangle:

enter image description here

Now, I would ideally like to have code that can use any system metrics, and thereby avoid getting into various platform / theme / dpi variations that may exist.

How can this be done if it is really possible?

+4
source share
2 answers

Like andlabs in the comments , WM_GETTITLEBARINFOEXcan be used to get the required information.

, TITLEBARINFOEX struct , . - , .

0

GetTitleBarInfo, TITLEBARINFO:

TITLEBARINFO tbi;
GetTitleBarInfo(hwnd, &tbi);

tbi.rcTitlebar.right - tbi.rcTitlebar.left. (Close, Minimize Maximize). GetSystemMetrics(SM_CXSIZE),

(tbi.rcTitlebar.right - tbi.rcTitlebar.left) - (3 * GetSystemMetrics(SM_CXSIZE))

, Windows,

-1

Source: https://habr.com/ru/post/1616627/


All Articles