Determine the width of the thumbnail bar in the Windows Desktop Preview

Klicke hier für den deutschen Artikel.

Introduction

Often, it is necessary to dynamically adjust the width of the thumbnail bar in the Windows Desktop Preview to accommodate different window sizes, screen resolutions, or desired thumbnail dimensions. This ensures that either more space is available for the preview or for the thumbnail bar, depending on the requirements.

C#

In C#, the ListLabelPreviewControl can be used to display reports. The width of the thumbnail bar can be set either directly via the Visual Studio Property:

Or, for more flexibility, dynamically in the code at runtime:

partial class Form1
{
   private System.ComponentModel.IContainer components = null;
   private void InitializeComponent()
   {
	this.components = new System.ComponentModel.Container();
	this.PreviewControl = new combit.Reporting.ListLabelPreviewControl(this.components); 
    this.PreviewControl.ThumbnailWidth = 90; // desired width in pixel
   }
 }

C++

To set the thumbnail bar width in C++, the message LS_VIEWERCONTROL_SET_OPTION is sent to the window handle using the Windows function ::SendMessage, with the parameter LS_OPTION_NAVIGATIONBARWIDTH and the desired width.
The Windows function ::FindWindowExW() is used to retrieve the correct window handle by passing the window class name "LlStgsysViewerControl31W" as a string:

CViewerView* pView = dynamic_cast<CViewerView*>(GetActiveView());
if (pView != nullptr && ::IsWindow(pView->m_LlView.GetSafeHwnd()))
{
    HWND hwndParentControl = pView->m_LlView.GetSafeHwnd();
    HWND hwndViewerControl = ::FindWindowExW(hwndParentControl, NULL, L"LlStgsysViewerControl31W", NULL);
    if (hwndViewerControl != NULL)
    {
            ::SendMessage(
                    hwndViewerControl,
                    LS_VIEWERCONTROL_SET_OPTION,
                    LS_OPTION_NAVIGATIONBARWIDTH,
                    90      // desired width in pixel
            );
    }
}

The window class name includes the version number of the List & Label version used, which can also be retrieved via the LlGetVersion(LL_VERSION_MAJOR) function call, see API Reference / Function Reference / LlGetVersion.

To make the example version-independent, the string must be constructed dynamically. Here, wstring is used to comply with the Windows API standard:

CViewerView* pView = dynamic_cast<CViewerView*>(GetActiveView());
if (pView != nullptr && ::IsWindow(pView->m_LlView.GetSafeHwnd()))
{
    std::wstring versionNumber = std::to_wstring(LlGetVersion(1));
    std::wstring windowClassName;
    windowClassName.append(L"LlStgsysViewerControl").append(versionNumber).append(L"W");
    HWND hwndParentControl = pView->m_LlView.GetSafeHwnd();
    HWND hwndViewerControl = ::FindWindowExW(hwndParentControl, NULL, windowClassName.c_str(), NULL);
    if (hwndViewerControl != NULL)
    {
            ::SendMessage(
                    hwndViewerControl,
                    LS_VIEWERCONTROL_SET_OPTION,
                    LS_OPTION_NAVIGATIONBARWIDTH,
                    90      // desired width in pixel
            );
    }
}

Note

The value must be greater than 0 and must not exceed half the width of the Preview Control in pixels. Otherwise, the thumbnail bar width will automatically be corrected to 200 pixels.