/*
Name: automatic_proc_freq_switch.cpp
Author: cLx - http://clx.freeshell.org/
Date: 04/10/11 19:37
08/06/05 14:44 (based on get_winamp_title.cpp, same author)
Description: On my laptop, the cpu freq. switching is making a noise into
the audio output. So I dont want it to switch when I'm playing
a movie or a song !
*/
#include <windows.h>
#define BUFLENGTH 1000
typedef enum {
DEFAULT = 0,
LOWPOWER,
HIGHPOWER
} tstate;
int isplaying(void){
HWND hWnd;
char buf[BUFLENGTH + 1];
hWnd = FindWindow("MPlayer - The Movie Player", NULL);
if (hWnd){
return 1;
}
hWnd = FindWindow("Winamp v1.x", NULL);
if (hWnd) {
GetWindowText(hWnd, buf, BUFLENGTH);
if (strstr(buf, "- Winamp [Stopped]")) { return 0; }
if (strstr(buf, "- Winamp [Paused]")) { return 0; }
if (!strstr(buf, "- Winamp")) { return 0; }
return 1;
}
return 0;
}
#define CPUCTRLEXE "C:\\Program Files\\Notebook Hardware Control\\nhcmsg.exe"
#define LP_COMMAND "-cpu_dynamic"
#define HP_COMMAND "-cpu_performance"
int execute_command(const char *opt){
return (int)ShellExecute( 0, "open", CPUCTRLEXE, opt, NULL, SW_NORMAL);
}
int main(void){
tstate state = DEFAULT;
for(;;){
switch(state){
case DEFAULT:
if (isplaying()){ state = HIGHPOWER; }
else { state = LOWPOWER; }
break;
case LOWPOWER:
if (isplaying()){
execute_command(HP_COMMAND);
state = HIGHPOWER;
}
break;
case HIGHPOWER:
if (!isplaying()){
execute_command(LP_COMMAND);
state = LOWPOWER;
}
break;
}
Sleep(5000);
}
return 0;
}