2

I have several large toolbars in an MFC application for Window 8.1. Right now I am using the following code to replace the image of each button using current DPI scaling when the application is moved to a monitor with different DPI settings.

const auto& toolbars = m_cToolBarManager.GetToolbar();
for (const auto& toolbar : toolbars)
{
    CMFCToolBarImages* images = toolbar->GetImages();
    for (int index = 0; index < toolbar->GetCount(); ++index)
    {
        CMFCToolBarButton* button = (CMFCToolBarButton*)toolbar->GetButton(index);
        TRY_POINTER(button);
        if (button->m_nStyle & TBBS_SEPARATOR)
        {
            continue;
        }
        images->AddIcon(LoadScaledIcon(button->m_nID));
    }
}

Each time the application is moved to a different monitor hundreds of images have to be loaded and set for the buttons. Moreover, due to a large number of images embedded as resources, the application executable becomes larger.

Is there more efficient way to do this?

Liton
  • 1,398
  • 2
  • 14
  • 27
  • MFC currently does not listen for WM_DPICHANGED do there's nothing built-in to make this simple. If you don't want to support this code then just don't write it, DWM scaling is not the end of the world and few users have the setup. – Hans Passant Nov 05 '14 at 13:28
  • Maybe it's a good opportunity to rethink your UI. Hundreds of toolbar buttons does not sound that useful to me. – Jonathan Potter Nov 05 '14 at 19:58
  • @JonathanPotter - We develop scientific applications for sophisticated engineers. Not all buttons are shown at once. How many buttons are there in Word, Excel or Blender? – Liton Nov 06 '14 at 07:59
  • @HansPassant we are implementing DPI because our high-valued clients are paying for that. I know myself several ways to implement the concept and rewrite the code. My question here is to find others who might have already done it in a better way. – Liton Nov 06 '14 at 08:02
  • @Liton: did you find any way to do this? And if you have non-button controls in the toolbar (e.g.: ComboBox), how would one scale the width of the combo box so that it doesn't look very small at 200% text size? – Edward Clements Nov 20 '15 at 16:48

0 Answers0