修改系统菜单字体和大小

 

 

#ifndef _tcscpy_s
#define _tcscpy_s _tcscpy
#endif //_tcscpy_s

BOOL SetMenuFont(LPCTSTR szFontName, long PointSize)
{
  NONCLIENTMETRICS cs={sizeof(NONCLIENTMETRICS )};

  if( SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(cs), &cs, 0) )
  {
    if(szFontName)
    {
      _tcscpy_s(cs.lfMenuFont.lfFaceName, szFontName);
    }

    HDC hDC = CreateDC(_T("DISPLAY"), NULL, NULL, NULL);
    cs.lfMenuFont.lfHeight =  -MulDiv(PointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72);

    SIZE extSize={0, 0};
    GetTextExtentPoint(hDC, _T("TEST"), _tcslen(_T("TEST")), &extSize);

    cs.iMenuHeight = extSize.cy;

    DeleteDC(hDC);

    if(SystemParametersInfo(SPI_SETNONCLIENTMETRICS, sizeof(cs), &cs, SPIF_SENDCHANGE))
    {
      return TRUE;
    }
  }

  return FALSE;
}

你可能感兴趣的:(null)