调整屏幕的分辨率

调整屏幕的分辨率,在开始的时候进行调整并记录原始的分辨率,在程序退出的时候再调整到原始的状态

 

 结束时调整:
 if ( m_bChangeDisplay )
 {
  DEVMODE dm;

  memset( &dm, 0, sizeof(DEVMODE) );
  dm.dmSize = sizeof(DEVMODE);
  dm.dmFields = DM_PELSHEIGHT | DM_PELSWIDTH | DM_DISPLAYFREQUENCY;
  dm.dmPelsHeight = m_iSysHeight;
  dm.dmPelsWidth  = m_iSysWidth;
  dm.dmDisplayFrequency = m_iFrequency;

  ChangeDisplaySettings( &dm, CDS_UPDATEREGISTRY );
 }


启动时调整:
 // 调整分辩率
 m_iSysWidth  = GetSystemMetrics( SM_CXSCREEN );
 m_iSysHeight = GetSystemMetrics( SM_CYSCREEN );
 if ( m_iSysWidth != SYSCR_WIDTH || m_iSysHeight != SYSCR_HEIGHT )
 //if ( false )
 {
  DEVMODE dm;
  long lRet;

  memset( &dm, 0, sizeof(DEVMODE) );
  dm.dmSize = sizeof(DEVMODE);
  dm.dmFields = DM_PELSHEIGHT | DM_PELSWIDTH | DM_DISPLAYFREQUENCY;
  EnumDisplaySettings( NULL, ENUM_CURRENT_SETTINGS, &dm );
  m_iFrequency = dm.dmDisplayFrequency;

  dm.dmPelsHeight = SYSCR_HEIGHT;
  dm.dmPelsWidth  = SYSCR_WIDTH;

  lRet = ChangeDisplaySettings( &dm, CDS_TEST );
  if ( lRet != DISP_CHANGE_SUCCESSFUL )
  {
   if ( dm.dmDisplayFrequency <= 60 )
    bRet = false;
   else
   {
    dm.dmDisplayFrequency = 60;
    lRet = ChangeDisplaySettings( &dm, CDS_TEST );
    if ( lRet != DISP_CHANGE_SUCCESSFUL )
     bRet = false;
    else
    {
     lRet = ChangeDisplaySettings( &dm, CDS_UPDATEREGISTRY );
     if ( lRet != DISP_CHANGE_SUCCESSFUL )
      bRet = false;
     else
      m_bChangeDisplay = true;
    }
   }
  }
  else
  {
   lRet = ChangeDisplaySettings( &dm, CDS_UPDATEREGISTRY );
   if ( lRet != DISP_CHANGE_SUCCESSFUL )
    bRet = false;
   else
    m_bChangeDisplay = true;
  }
 }

你可能感兴趣的:(null)