home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2005 March / PCpro_2005_03.ISO / files / systools / speedswitchxp / sswitchxp14.exe / Typical / CPUOptions.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2005-01-14  |  10.7 KB  |  276 lines

  1. /*
  2.    SpeedswitchXP V1.4
  3.    - Windows XP CPU Frequency Control for Notebooks -
  4.  
  5.    Copyright(c) 2002-2004 Christian Diefer
  6.  
  7.    This program is free software; you can redistribute it and/or modify
  8.    it under the terms of the GNU General Public License version 2 as 
  9.    published by the Free Software Foundation.
  10.  
  11.    This program is distributed in the hope that it will be useful,
  12.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.    GNU General Public License for more details.
  15.    
  16.    You should have received a copy of the GNU General Public License
  17.    along with this program; if not, write to the Free Software
  18.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20.  
  21. #include "stdafx.h"
  22. #include "SpeedswitchXP.h"
  23. #include "CPUOptions.h"
  24. #include "speedswitch.h"
  25.  
  26. #define TOOLTIP_ID 1
  27.  
  28. // CCPUOptions dialog
  29.  
  30. IMPLEMENT_DYNAMIC(CCPUOptions, CDialog)
  31. CCPUOptions::CCPUOptions(CWnd* pParent /*=NULL*/)
  32.     : CDialog(CCPUOptions::IDD, pParent)
  33.   , m_iDynThrottleAC(0)
  34.   , m_iDynThrottleDC(0)
  35.   , m_iCStateConfig(0)
  36. {
  37.   m_iTimeCheck[0] = 0;
  38.   m_iTimeCheck[1] = 0;
  39.   m_iTimeCheck[2] = 0;
  40.   m_iDemoteLimit[0] = 0;
  41.   m_iDemoteLimit[1] = 0;
  42.   m_iDemoteLimit[2] = 0;
  43.   m_iPromoteLimit[0] = 0;
  44.   m_iPromoteLimit[1] = 0;
  45.   m_iPromoteLimit[2] = 0;
  46.   m_iDemotePercent[0] = 0;
  47.   m_iDemotePercent[1] = 0;
  48.   m_iDemotePercent[2] = 0;
  49.   m_iPromotePercent[0] = 0;
  50.   m_iPromotePercent[1] = 0;
  51.   m_iPromotePercent[2] = 0;
  52.   m_iAllowDemotion[0] = 1;
  53.   m_iAllowDemotion[1] = 1;
  54.   m_iAllowDemotion[2] = 1;
  55.   m_iAllowPromotion[0] = 1;
  56.   m_iAllowPromotion[1] = 1;
  57.   m_iAllowPromotion[2] = 1;
  58. }
  59.  
  60. CCPUOptions::~CCPUOptions()
  61. { }
  62.  
  63. void CCPUOptions::DoDataExchange(CDataExchange* pDX)
  64. {
  65.   CDialog::DoDataExchange(pDX);
  66.   DDX_CBIndex(pDX, IDC_COMBO1, m_iDynThrottleAC);
  67.   DDX_CBIndex(pDX, IDC_COMBO2, m_iDynThrottleDC);
  68.   DDX_CBIndex(pDX, IDC_COMBO3, m_iCStateConfig);
  69.   DDX_Text(pDX, IDC_EDIT1, m_iTimeCheck[0]);
  70.   DDX_Text(pDX, IDC_EDIT2, m_iTimeCheck[1]);
  71.   DDX_Text(pDX, IDC_EDIT3, m_iTimeCheck[2]);
  72.   DDX_Text(pDX, IDC_EDIT4, m_iDemoteLimit[0]);
  73.   DDX_Text(pDX, IDC_EDIT13, m_iDemoteLimit[1]);
  74.   DDX_Text(pDX, IDC_EDIT14, m_iDemoteLimit[2]);
  75.   DDX_Text(pDX, IDC_EDIT5, m_iPromoteLimit[0]);
  76.   DDX_Text(pDX, IDC_EDIT6, m_iPromoteLimit[1]);
  77.   DDX_Text(pDX, IDC_EDIT7, m_iPromoteLimit[2]);
  78.   DDX_Text(pDX, IDC_EDIT8, m_iDemotePercent[0]);
  79.   DDX_Text(pDX, IDC_EDIT15, m_iDemotePercent[1]);
  80.   DDX_Text(pDX, IDC_EDIT16, m_iDemotePercent[2]);
  81.   DDX_Text(pDX, IDC_EDIT9, m_iPromotePercent[0]);
  82.   DDX_Text(pDX, IDC_EDIT17, m_iPromotePercent[1]);
  83.   DDX_Text(pDX, IDC_EDIT18, m_iPromotePercent[2]);
  84.   DDX_CBIndex(pDX, IDC_COMBO9, m_iAllowDemotion[0]);
  85.   DDX_CBIndex(pDX, IDC_COMBO10, m_iAllowDemotion[1]);
  86.   DDX_CBIndex(pDX, IDC_COMBO11, m_iAllowDemotion[2]);
  87.   DDX_CBIndex(pDX, IDC_COMBO12, m_iAllowPromotion[0]);
  88.   DDX_CBIndex(pDX, IDC_COMBO13, m_iAllowPromotion[1]);
  89.   DDX_CBIndex(pDX, IDC_COMBO14, m_iAllowPromotion[2]);
  90. }
  91.  
  92. BOOL CCPUOptions::OnInitDialog()
  93. {
  94.     CDialog::OnInitDialog();
  95.  
  96.   fillCStateArray( m_iCStateConfig );
  97.  
  98.   addToolTip( 0, IDC_COMBO3, "Select AC or DC C-state configuration" );
  99.  
  100.   addToolTip( 1, IDC_EDIT1, "Time, in microseconds, that must expire before promotion or demotion is considered" );
  101.   addToolTip( 2, IDC_EDIT2, "Time, in microseconds, that must expire before promotion or demotion is considered" );
  102.   addToolTip( 3, IDC_EDIT3, "Time, in microseconds, that must expire before promotion or demotion is considered" );
  103.  
  104.   addToolTip( 4, IDC_EDIT4, "Minimum amount of time, in microseconds, that must be spent in the idle loop to avoid demotion" );
  105.   addToolTip( 5, IDC_EDIT13, "Minimum amount of time, in microseconds, that must be spent in the idle loop to avoid demotion" );
  106.   addToolTip( 6, IDC_EDIT14, "Minimum amount of time, in microseconds, that must be spent in the idle loop to avoid demotion" );
  107.  
  108.   addToolTip( 7, IDC_EDIT5, "Time, in microseconds, that must be exceeded to cause promotion to a deeper idle state" );
  109.   addToolTip( 8, IDC_EDIT6, "Time, in microseconds, that must be exceeded to cause promotion to a deeper idle state" );
  110.   addToolTip( 9, IDC_EDIT7, "Time, in microseconds, that must be exceeded to cause promotion to a deeper idle state" );
  111.  
  112.   addToolTip( 10, IDC_EDIT8, "Value (%) that scales the threshold at which the power policy manager decreases the performance of the processor" );
  113.   addToolTip( 11, IDC_EDIT15, "Value (%) that scales the threshold at which the power policy manager decreases the performance of the processor" );
  114.   addToolTip( 12, IDC_EDIT16, "Value (%) that scales the threshold at which the power policy manager decreases the performance of the processor" );
  115.  
  116.   addToolTip( 13, IDC_EDIT9, "Value (%) that scales the threshold at which the power policy manager increases the performance of the processor" );
  117.   addToolTip( 14, IDC_EDIT17, "Value (%) that scales the threshold at which the power policy manager increases the performance of the processor" );
  118.   addToolTip( 15, IDC_EDIT18, "Value (%) that scales the threshold at which the power policy manager increases the performance of the processor" );
  119.  
  120.   addToolTip( 16, IDC_COMBO9, "When set, allows the kernel power policy manager to demote from the current state" );
  121.   addToolTip( 17, IDC_COMBO10, "When set, allows the kernel power policy manager to demote from the current state" );
  122.   addToolTip( 18, IDC_COMBO11, "When set, allows the kernel power policy manager to demote from the current state" );
  123.  
  124.   addToolTip( 19, IDC_COMBO12, "When set, allows the kernel power policy manager to promote from the current state" );
  125.   addToolTip( 20, IDC_COMBO13, "When set, allows the kernel power policy manager to promote from the current state" );
  126.   addToolTip( 21, IDC_COMBO14, "When set, allows the kernel power policy manager to promote from the current state" );
  127.  
  128.   return TRUE;
  129. }
  130.  
  131. BOOL CCPUOptions::PreTranslateMessage( MSG* pMsg ) 
  132. {
  133.   for( int i=0; i<22; i++ )
  134.     m_tToolTip[i].RelayEvent( pMsg );
  135.  
  136.   return CDialog::PreTranslateMessage( pMsg );
  137. }
  138.  
  139.  
  140. BEGIN_MESSAGE_MAP(CCPUOptions, CDialog)
  141.   ON_CBN_SELCHANGE(IDC_COMBO3, OnCbnSelchangeCombo3)
  142. END_MESSAGE_MAP()
  143.  
  144.  
  145. // CCPUOptions message handlers
  146. void CCPUOptions::setVars()
  147. {
  148.   polAC = mach.ProcessorPolicyAc;
  149.   polDC = mach.ProcessorPolicyDc;
  150. //  polAC.PolicyCount = 2;
  151.   m_iCStateConfig = 0;
  152.   m_iDynThrottleAC = mach.ProcessorPolicyAc.DynamicThrottle;
  153.   m_iDynThrottleDC = mach.ProcessorPolicyDc.DynamicThrottle;
  154.   cpu = FALSE;
  155. }
  156.  
  157. void CCPUOptions::getVars()
  158. {
  159.   if( cpu )
  160.   {
  161.     mach.ProcessorPolicyAc = polAC;
  162.     mach.ProcessorPolicyDc = polDC;
  163.   }
  164. }
  165.  
  166.  
  167. void CCPUOptions::OnCbnSelchangeCombo3()
  168. {
  169.   UpdateData();
  170.   applyChanges( m_iCStateConfig==0 ? 1 : 0 );   // invertieren, da schon geΣndert
  171.   fillCStateArray( m_iCStateConfig );
  172.   UpdateData( FALSE );
  173. }
  174.  
  175. void CCPUOptions::fillCStateArray( int config )
  176. {
  177.   PROCESSOR_POWER_POLICY* pol;
  178.  
  179.   if( config == 0 )   // AC
  180.     pol = &polAC;
  181.   else
  182.     pol = &polDC;
  183.  
  184.   for( int i=0; i<(int)pol->PolicyCount; i++ )
  185.   {
  186.     m_iTimeCheck[i] = pol->Policy[i].TimeCheck;
  187.     m_iDemoteLimit[i] = pol->Policy[i].DemoteLimit;
  188.     m_iPromoteLimit[i] = pol->Policy[i].PromoteLimit;
  189.     m_iDemotePercent[i] = pol->Policy[i].DemotePercent;
  190.     m_iPromotePercent[i] = pol->Policy[i].PromotePercent;
  191.     m_iAllowDemotion[i] = pol->Policy[i].AllowDemotion ? 0 : 1;
  192.     m_iAllowPromotion[i] = pol->Policy[i].AllowPromotion ? 0 : 1;
  193.   }
  194.  
  195.   for( int i=pol->PolicyCount; i<3; i++ )
  196.   {
  197.     m_iTimeCheck[i] = 0;
  198.     m_iDemoteLimit[i] = 0;
  199.     m_iPromoteLimit[i] = 0;
  200.     m_iDemotePercent[i] = 0;
  201.     m_iPromotePercent[i] = 0;
  202.     m_iAllowDemotion[i] = 1;
  203.     m_iAllowPromotion[i] = 1;
  204.   }
  205.  
  206.   ((CWnd*)GetDlgItem(IDC_EDIT1))->EnableWindow( pol->PolicyCount>0 );
  207.   ((CWnd*)GetDlgItem(IDC_EDIT4))->EnableWindow( pol->PolicyCount>0 );
  208.   ((CWnd*)GetDlgItem(IDC_EDIT5))->EnableWindow( pol->PolicyCount>0 );
  209.   ((CWnd*)GetDlgItem(IDC_EDIT8))->EnableWindow( pol->PolicyCount>0 );
  210.   ((CWnd*)GetDlgItem(IDC_EDIT9))->EnableWindow( pol->PolicyCount>0 );
  211.   ((CWnd*)GetDlgItem(IDC_COMBO9))->EnableWindow( pol->PolicyCount>0 );
  212.   ((CWnd*)GetDlgItem(IDC_COMBO12))->EnableWindow( pol->PolicyCount>0 );
  213.  
  214.   ((CWnd*)GetDlgItem(IDC_EDIT2))->EnableWindow( pol->PolicyCount>1 );
  215.   ((CWnd*)GetDlgItem(IDC_EDIT13))->EnableWindow( pol->PolicyCount>1 );
  216.   ((CWnd*)GetDlgItem(IDC_EDIT6))->EnableWindow( pol->PolicyCount>1 );
  217.   ((CWnd*)GetDlgItem(IDC_EDIT15))->EnableWindow( pol->PolicyCount>1 );
  218.   ((CWnd*)GetDlgItem(IDC_EDIT17))->EnableWindow( pol->PolicyCount>1 );
  219.   ((CWnd*)GetDlgItem(IDC_COMBO10))->EnableWindow( pol->PolicyCount>1 );
  220.   ((CWnd*)GetDlgItem(IDC_COMBO13))->EnableWindow( pol->PolicyCount>1 );
  221.  
  222.   ((CWnd*)GetDlgItem(IDC_EDIT3))->EnableWindow( pol->PolicyCount>2 );
  223.   ((CWnd*)GetDlgItem(IDC_EDIT14))->EnableWindow( pol->PolicyCount>2 );
  224.   ((CWnd*)GetDlgItem(IDC_EDIT7))->EnableWindow( pol->PolicyCount>2 );
  225.   ((CWnd*)GetDlgItem(IDC_EDIT16))->EnableWindow( pol->PolicyCount>2 );
  226.   ((CWnd*)GetDlgItem(IDC_EDIT18))->EnableWindow( pol->PolicyCount>2 );
  227.   ((CWnd*)GetDlgItem(IDC_COMBO11))->EnableWindow( pol->PolicyCount>2 );
  228.   ((CWnd*)GetDlgItem(IDC_COMBO14))->EnableWindow( pol->PolicyCount>2 );
  229. }
  230.  
  231. void CCPUOptions::applyChanges( int config )
  232. {
  233.   PROCESSOR_POWER_POLICY* pol;
  234.  
  235.   if( config == 0 )   // AC
  236.     pol = &polAC;
  237.   else
  238.     pol = &polDC;
  239.  
  240.   for( int i=0; i<(int)pol->PolicyCount; i++ )
  241.   {
  242.     if( m_iDemotePercent[i]<0 || m_iDemotePercent[i]>100 )
  243.       m_iDemotePercent[i] = pol->Policy[i].DemotePercent;
  244.  
  245.     if( m_iPromotePercent[i]<0 || m_iPromotePercent[i]>100 )
  246.       m_iPromotePercent[i] = pol->Policy[i].PromotePercent;
  247.  
  248.     if( m_iTimeCheck[i] != pol->Policy[i].TimeCheck
  249.     ||  m_iDemoteLimit[i] != pol->Policy[i].DemoteLimit
  250.     ||  m_iPromoteLimit[i] != pol->Policy[i].PromoteLimit
  251.     ||  m_iDemotePercent[i] != pol->Policy[i].DemotePercent
  252.     ||  m_iPromotePercent[i] != pol->Policy[i].PromotePercent
  253.     ||  (m_iAllowDemotion[i]==0?1:0) != pol->Policy[i].AllowDemotion
  254.     ||  (m_iAllowPromotion[i]==0?1:0) != pol->Policy[i].AllowPromotion )
  255.     {
  256.       cpu = TRUE;
  257.       pol->Policy[i].TimeCheck = m_iTimeCheck[i];
  258.       pol->Policy[i].DemoteLimit = m_iDemoteLimit[i];
  259.       pol->Policy[i].PromoteLimit = m_iPromoteLimit[i];
  260.       pol->Policy[i].DemotePercent = m_iDemotePercent[i];
  261.       pol->Policy[i].PromotePercent = m_iPromotePercent[i];
  262.       pol->Policy[i].AllowDemotion = (m_iAllowDemotion[i]==0?1:0);
  263.       pol->Policy[i].AllowPromotion = (m_iAllowPromotion[i]==0?1:0);
  264.     }    
  265.   }
  266. }
  267.  
  268. void CCPUOptions::addToolTip( int no, int id, char* str )
  269. {
  270.   CWnd* wnd = GetDlgItem( id );
  271.   CRect rect; 
  272.   wnd->GetClientRect( rect );
  273.   m_tToolTip[no].Create( wnd );
  274.   m_tToolTip[no].AddTool( wnd, str, rect, TOOLTIP_ID );
  275.  
  276. }