Professional UI Solutions
Site Map   /  Register
 
 
 

TSELLC ProfUIS Tech Bulletin

May 23, 2016 /  TSELLC ProfUIS Tech Bulletin 05/23/2016

Introduction

There are important changes in the ProfUIS MFC Library and in the accompanying Samples to fully accommodate 100 – 200 DPI scaling. You can review these functions and variables in the library and the samples. There is a brief description of them in this Bulletin.  But if you have any questions send an email to Service@tsellc.com
  1. In the ProfUIS library the tabs, groups, captions, fonts ... and so on are automatically adjusted (scaled) to DPI resolution.
  2. In the samples, the bitmaps/icons from resources are scaled correctly. We use a new function for this described later under Resource Scaling.  These scaled resources are used mainly in the ribbon samples.
  3. For better images you can provide icons/bitmaps with the correct scaling for different resolution. When the Apps are initialized the ribbon code can question the value of m_nDpiAwareValue from CPaintManager and use the corresponding icon/bitmap.

Registry Sample Key

We are recommending that the Registry Keys contain the DPI Aware value. In this way new Keys are created for the various scaled values. Using these keys allows the software to load the right resources for that particular scaling. Here is a samples key for our Bitmap Editor at 100 percent scaling or 96 DPI.

HKEY_CURRENT_USER\Software\Foss\BitmapEditor 3.30 (96x96 DPI)

The Code for creating these keys is detailed under “Samples Apps Main Page InitInstance” below.

Resource Scaling

Much of the work in scaling is done by our scaling function. This scaling function is a vast improvement over the stretchbit function. It uses advanced filtering to improve the final image. But scaling up images has its limitation. The function for scaling resources in Apps is:

bmp.LoadBMP_Resource_Scale(MAKEINTRESOURCE(nID);

This function will scale the resource to the size in the DPI Aware variable. In Applications
Use LoadBMP_Resource_Scale (MAKEINTRESOURCE(nID))); in place of the LoadBMP_Resource(MAKEINTRESOURCE(nID));

Here is an example:
VERIFY(_bmp.LoadBMP_Resource_Scale(MAKEINTRESOURCE(nID)));

Here is an example of scaling an integer, 64 in this example, used in the display of an App.
static const INT nItemWidth = g_PaintManager->UiScalingDo(64, CExtPaintManager::__EUIST_X);

Setting up Scaling

A key in the registry for one of our samples would look like this.
HKEY_CURRENT_USER\Software\Foss\BitmapEditor 3.30 (96x96 DPI)
Notice the DPI Aware value. If the DPI Aware is not included when the user changes DPI values, the program will crash. You can use the older key but you will need to start the ProfUIS Library every time the program loads. This is not a big delay but it is noticeable.

Samples Apps Main Page InitInstance

The Edit start and Edit stops statements outline the area of major change code snippet below.

BOOL CRibbonBarApp::InitInstance()
{
    VERIFY( ::AfxOleInit() );
    srand( (unsigned)time( NULL ) );
    InitCommonControls();
    AfxEnableControlContainer();
    CExtPaintManager::g_bAutoScaleIcons = true;

    // Edit starts
    SetRegistryKey(_T("Foss"));
    CString pszVersion;
    pszVersion.Format(_T("%d.%d%d"), ( ( __PROF_UIS_VERSION_DWORD >> 24 ) & 0XFF ), ( ( __PROF_UIS_VERSION_DWORD >> 16 ) & 0XFF ), ( ( __PROF_UIS_VERSION_DWORD >> 8 ) & 0XFF ));
    CString pszAppName;
    pszAppName.Format(_T("%s %s (%dx%d DPI)"), m_pszAppName, pszVersion, g_PaintManager.m_nLPX, g_PaintManager.m_nLPY);
    free(( void* ) m_pszAppName);
    m_pszAppName = _tcsdup(pszAppName);
    ASSERT(m_pszAppName != NULL);
    if ( m_pszProfileName != NULL )
        free(( void* ) m_pszProfileName);
    m_pszProfileName = _tcsdup(pszAppName);
    ASSERT(m_pszProfileName != NULL);
    // Edit Stops

CMainFrame * pFrame = new CMainFrame;
    m_pMainWnd = pFrame;
    if( ! pFrame->LoadFrame(
            IDR_MAINFRAME,
            WS_OVERLAPPEDWINDOW|FWS_ADDTOTITLE,
            NULL,
            NULL
            )
        )
    {
        m_pMainWnd = NULL;
        return FALSE;
    }
    pFrame->ActivateFrame( SW_SHOW );
    return TRUE;
}

App Image Scaling by Selection

You will see this code appearing in the Ribbon Samples.  It allows the selection of images by DPI Aware size. This allows the use of images for different scaling of the App. Please see the Ribbon sample for a full explanation.
#define __GetResID(nID, nDpiAwareValue, Res)\
{\
    switch ( nDpiAwareValue )\
    {\
        case CExtPaintManager::CExtPaintManagerAutoPtr::__PROFUISDPI_SIZEMEDIUM:\
            nID = Res##_120;\
        case CExtPaintManager::CExtPaintManagerAutoPtr::__PROFUISDPI_SIZELARGE:\
            nID = Res##_150;\
        case CExtPaintManager::CExtPaintManagerAutoPtr::__PROFUISDPI_SIZEEXLARGE:\
            nID = Res##_200;\
        case CExtPaintManager::CExtPaintManagerAutoPtr::__PROFUISDPI_SIZENOSCREEN:\
        case CExtPaintManager::CExtPaintManagerAutoPtr::__PROFUISDPI_SIZENORMAL:\
        default:\
            nID = Res;\
    }\
}

Status Bar Scaling

Status bars are normally 16 pixels and scale automatically, but in our samples there are some that are set to 20 pixels. In order to correctly scale them, this function is used.

m_wndStatusBar.GetStatusBarCtrl().SetMinHeight(g_PaintManager->UiScalingDo(20, CExtPaintManager::__EUIST_Y));

Conclusion

We reviewed the samples at all resolutions and with Windows 7, 8.1, and 10. We used Visual Studio 2010 – 2015 for generating the samples.

If you find some scaling implementation that is not correct or you have a better solution let us know. If we agree and it is practical, we will include it in the next release.

We use our samples as a unit test of the scaling process. If you find that we need to add additional items to our testing process, let us know.

Thanks
The TSELLC Development Team.
Service@tsellc.com

 

 

 

Prof-UIS a Foss Software Inc. development Web www.prof-uis.com Email: Sales@Prof-UIS.com