Chinaunix首页 | 论坛 | 博客
  • 博客访问: 14417868
  • 博文数量: 5645
  • 博客积分: 9880
  • 博客等级: 中将
  • 技术积分: 68081
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-28 13:35
文章分类

全部博文(5645)

文章存档

2008年(5645)

我的朋友

分类:

2008-04-28 21:23:55

下载本文示例代码
  CPU的速度随温度和电压的变化而变化,如何随时查看CPU的速度?下面我们通过编程实现。在这个过程中,要用到汇编语言的知识。  第一步:生成一个基于对话框的工程CPUSpeed。其他选项我们可以都取其默认值。  第二步:在对话框上添加一个按钮,名称为"测试CPU速度",双击此按钮生成此按钮的处理函数,OnButton1。  第三步:在CPUSpeedDlg.cpp文件中定义类Ctime,在OnButton1中添加处理代码,最后文件CPUSpeedDlg.cpp变成如下: // CPUSpeedDlg.cpp : implementation file// #include "stdafx.h"#include "CPUSpeed.h"#include "CPUSpeedDlg.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif///////////////////////////////////////////////// CAboutDlg dialog used for App Aboutinline unsigned __int64 theCycleCount(void){ _asm _emit 0x0F _asm _emit 0x31 /// this causes a compiler warning as there is no return statement /// however the _emits return a __int64 value}class CTimer{ unsigned __int64 m_start; public:  unsigned __int64 m_overhead; CTimer(void) {  m_overhead = 0;  Start(); /// we get the start cycle  m_overhead = Stop();  // then we get the stop cycle catching the overhead time } void Start(void) {  m_start = theCycleCount(); } unsigned __int64 Stop(void) {  /// with the stop cycle we remove the overhead's time  return theCycleCount()-m_start-m_overhead; }};void CCPUSpeedDlg::OnButton1() { // TODO: Add your control notification handler code here CString strRawClockFrequency;  CTimer timer; long tickslong; long tickslongextra; timer.Start();  Sleep(1000);  unsigned cpuspeed100 = (unsigned)(timer.Stop()/10000); tickslong = cpuspeed100/100; tickslongextra = cpuspeed100-(tickslong*100); strRawClockFrequency.Format("%d.%d MHZ estimate ", tickslong,tickslongextra ); AfxMessageBox("CPU速度为" strRawClockFrequency); } class CAboutDlg : public CDialog { ……以下为编程环境生成时自动生成的代码。  好了,现在点击按钮"测试CPU速度"就可以弹出对话框告诉我们CPU的速度了。   CPU的速度随温度和电压的变化而变化,如何随时查看CPU的速度?下面我们通过编程实现。在这个过程中,要用到汇编语言的知识。  第一步:生成一个基于对话框的工程CPUSpeed。其他选项我们可以都取其默认值。  第二步:在对话框上添加一个按钮,名称为"测试CPU速度",双击此按钮生成此按钮的处理函数,OnButton1。  第三步:在CPUSpeedDlg.cpp文件中定义类Ctime,在OnButton1中添加处理代码,最后文件CPUSpeedDlg.cpp变成如下: // CPUSpeedDlg.cpp : implementation file// #include "stdafx.h"#include "CPUSpeed.h"#include "CPUSpeedDlg.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif///////////////////////////////////////////////// CAboutDlg dialog used for App Aboutinline unsigned __int64 theCycleCount(void){ _asm _emit 0x0F _asm _emit 0x31 /// this causes a compiler warning as there is no return statement /// however the _emits return a __int64 value}class CTimer{ unsigned __int64 m_start; public:  unsigned __int64 m_overhead; CTimer(void) {  m_overhead = 0;  Start(); /// we get the start cycle  m_overhead = Stop();  // then we get the stop cycle catching the overhead time } void Start(void) {  m_start = theCycleCount(); } unsigned __int64 Stop(void) {  /// with the stop cycle we remove the overhead's time  return theCycleCount()-m_start-m_overhead; }};void CCPUSpeedDlg::OnButton1() { // TODO: Add your control notification handler code here CString strRawClockFrequency;  CTimer timer; long tickslong; long tickslongextra; timer.Start();  Sleep(1000);  unsigned cpuspeed100 = (unsigned)(timer.Stop()/10000); tickslong = cpuspeed100/100; tickslongextra = cpuspeed100-(tickslong*100); strRawClockFrequency.Format("%d.%d MHZ estimate ", tickslong,tickslongextra ); AfxMessageBox("CPU速度为" strRawClockFrequency); } class CAboutDlg : public CDialog { ……以下为编程环境生成时自动生成的代码。  好了,现在点击按钮"测试CPU速度"就可以弹出对话框告诉我们CPU的速度了。 下载本文示例代码


编程实现测试CPU的速度编程实现测试CPU的速度编程实现测试CPU的速度编程实现测试CPU的速度编程实现测试CPU的速度编程实现测试CPU的速度编程实现测试CPU的速度编程实现测试CPU的速度编程实现测试CPU的速度编程实现测试CPU的速度编程实现测试CPU的速度编程实现测试CPU的速度编程实现测试CPU的速度编程实现测试CPU的速度编程实现测试CPU的速度
阅读(154) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~