#include <windows.h>
#include <QString>
int getRecommendedWidthWin32
( const QString* titleText,
int totalSystemButtons
) {
// const QString* titleText = The desired caption text for the title bar.
// int totalSystemButtons = The amount of system buttons in the title bar (i.e close button, minimise button etc.).
// Query the operating system metrics.
int finalWidth = 0;
NONCLIENTMETRICS metrics;
ZeroMemory( &metrics, sizeof( NONCLIENTMETRICS ) );
metrics.cbSize = sizeof( NONCLIENTMETRICS );
if ( SystemParametersInfo( SPI_GETNONCLIENTMETRICS, 0, &metrics, 0 ) != 0 )
{
// Add the width of caption buttons.
// Buttons have at least this total width or less.
finalWidth += metrics.iCaptionWidth * totalSystemButtons;
// Add the width of the frame border (left and right, so twice).
// This is commented out as it seems redundant.
//finalWidth += metrics.iBorderWidth * 2;
// Add the 'estimated' width of the caption text.
HFONT tempFont = CreateFontIndirect( &metrics.lfCaptionFont );
HDC hDC = GetDC( NULL ); // Device context for the whole screen.
SelectObject( hDC, tempFont );
SIZE textPixelSize;
GetTextExtentPoint32( hDC, reinterpret_cast< LPCWSTR >( titleText->utf16() ), titleText->size(), &textPixelSize );
ReleaseDC( NULL, hDC );
DeleteObject( tempFont );
finalWidth += textPixelSize.cx;
}
return finalWidth;
}
#include <windows.h>
#include <QString>
int getRecommendedWidthWin32( const QString* titleText, int totalSystemButtons )
{
// const QString* titleText = The desired caption text for the title bar.
// int totalSystemButtons = The amount of system buttons in the title bar (i.e close button, minimise button etc.).
// Query the operating system metrics.
int finalWidth = 0;
NONCLIENTMETRICS metrics;
ZeroMemory( &metrics, sizeof( NONCLIENTMETRICS ) );
metrics.cbSize = sizeof( NONCLIENTMETRICS );
if ( SystemParametersInfo( SPI_GETNONCLIENTMETRICS, 0, &metrics, 0 ) != 0 )
{
// Add the width of caption buttons.
// Buttons have at least this total width or less.
finalWidth += metrics.iCaptionWidth * totalSystemButtons;
// Add the width of the frame border (left and right, so twice).
// This is commented out as it seems redundant.
//finalWidth += metrics.iBorderWidth * 2;
// Add the 'estimated' width of the caption text.
HFONT tempFont = CreateFontIndirect( &metrics.lfCaptionFont );
HDC hDC = GetDC( NULL ); // Device context for the whole screen.
SelectObject( hDC, tempFont );
SIZE textPixelSize;
GetTextExtentPoint32( hDC, reinterpret_cast< LPCWSTR >( titleText->utf16() ), titleText->size(), &textPixelSize );
ReleaseDC( NULL, hDC );
DeleteObject( tempFont );
finalWidth += textPixelSize.cx;
}
return finalWidth;
}
To copy to clipboard, switch view to plain text mode
For that dialog, the call was this:
Bookmarks