简体   繁体   中英

Don't change the font of dialog with respect to windows dpi in mfc?

I have a dialog which is of (355,99) dimensions it only have a menu and task bar so it is of small size. its display is fine in 100% dpi but on 125 % dpi some controls on task cut out. how to scale them according to dpi in the following function

void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
{
   CMDIFrameWnd::OnGetMinMaxInfo(lpMMI);
   lpMMI->ptMinTrackSize = CPoint(355,99); // set minimum size  
}

I found the solution by my own so i am posting it for helping others. for my problem i have find the dpi of system and set the dialog size accordingly. here is my code:

  void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)  
  {
      CMDIFrameWnd::OnGetMinMaxInfo(lpMMI);
      HDC hdcScreen = ::GetDC(NULL);
      int iDPI = -1; // assume failure
      if (hdcScreen) 
      {
          iDPI = ::GetDeviceCaps(hdcScreen, LOGPIXELSX);
          ::ReleaseDC(NULL, hdcScreen);
       }
       switch(iDPI)
       {
          case 96:
              lpMMI->ptMinTrackSize = CPoint(355,99);
              break;
          case 120:
              lpMMI->ptMinTrackSize = CPoint(360,115);
              break;
          case 144:
            lpMMI->ptMinTrackSize = CPoint(365,134);
            break;
           case 196:
             lpMMI->ptMinTrackSize = CPoint(370,150);
             break;
            default:
              lpMMI->ptMinTrackSize = CPoint(355,99);
              break;

        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM