织梦CMS - 轻松建站从此开始!

罗索

当前位置: 主页>杂项技术>VC(MFC)>

Visual C++ 系统及硬件编程-硬件篇

落鹤生 发布于 2010-05-30 15:58 点击:次 
CPU的速度随温度和电压的变化而变化,如何随时查看CPU的速度?下面我们通过编程实现。在这个过程中,要用到汇编语言的知识。
TAG:

编程实现测试CPU的速度
CPU的速度随温度和电压的变化而变化,如何随时查看CPU的速度?下面我们通过编程实现。在这个过程中,要用到汇编语言的知识。

第一步:生成一个基于对话框的工程CPUSpeed。其他选项我们可以都取其默认值。

第二步:在对话框上添加一个按钮,名称为"测试CPU速度",双击此按钮生成此按钮的处理函数,OnButton1。

第三步:在CPUSpeedDlg.cpp文件中定义类Ctime,在OnButton1中添加处理代码,最后文件CPUSpeedDlg.cpp变成如下:

  1. // CPUSpeedDlg.cpp : implementation file 
  2. // 
  3. #include "stdafx.h" 
  4. #include "CPUSpeed.h" 
  5. #include "CPUSpeedDlg.h" 
  6.  
  7. #ifdef _DEBUG 
  8. #define new DEBUG_NEW 
  9. #undef THIS_FILE 
  10. static char THIS_FILE[] = __FILE__; 
  11. #endif 
  12.  
  13. /////////////////////////////////////////////// 
  14. // CAboutDlg dialog used for App About 
  15. inline unsigned __int64 theCycleCount(void
  16.  
  17.  _asm _emit 0x0F 
  18.  _asm _emit 0x31 
  19.  
  20.   /// this causes a compiler warning as there is no return statement 
  21.  /// however the _emits return a __int64 value 
  22.  
  23. class CTimer 
  24.   unsigned __int64 m_start; 
  25.  
  26.  public
  27.  
  28.   unsigned __int64 m_overhead; 
  29.  
  30.  CTimer(void
  31.  { 
  32.   m_overhead = 0; 
  33.    Start(); /// we get the start cycle 
  34.   m_overhead = Stop(); 
  35.   // then we get the stop cycle catching the overhead time 
  36.  } 
  37.  
  38.  void Start(void
  39.  { 
  40.    m_start = theCycleCount(); 
  41.  } 
  42.  
  43.  unsigned __int64 Stop(void
  44.  { 
  45.    /// with the stop cycle we remove the overhead's time 
  46.   return theCycleCount()-m_start-m_overhead; 
  47.  } 
  48. }; 
  49.  
  50. void CCPUSpeedDlg::OnButton1() 
  51.  // TODO: Add your control notification handler code here 
  52.  CString strRawClockFrequency; 
  53.   
  54.  CTimer timer; 
  55.  
  56.  long tickslong; 
  57.  long tickslongextra; 
  58.   timer.Start(); 
  59.  Sleep(1000); 
  60.  unsigned cpuspeed100 = (unsigned)(timer.Stop()/10000); 
  61.  
  62.  
  63.  tickslong = cpuspeed100/100; 
  64.  tickslongextra = cpuspeed100-(tickslong*100); 
  65.  strRawClockFrequency.Format("%d.%d MHZ estimate ", tickslong,tickslongextra ); 
  66.  AfxMessageBox("CPU速度为"+strRawClockFrequency); 
  67.  } 
  68.  class CAboutDlg : public CDialog 
  69.  { 
  70.  ……以下为编程环境生成时自动生成的代码。 

  好了,现在点击按钮"测试CPU速度"就可以弹出对话框告诉我们CPU的速度了。


程序中使用自定义的鼠标

?建立工程与一个资源档

用Image Editor编辑一个鼠游标

(Fild | New | Resource File)

新建一个 CURSOR_1 的 CURSOR, 设定好它的 Hot Spot

(Cursor | Set Hot Spot)

存档时注意要和建立的Project存在同一个目录在本例我们先假定为 MyCursor.res

二. 程序部分

定义一个常数crMyCursor, 这个常数您必须设成大於零的任何整数, 以 LoadCursor() 函数将自订的鼠标资源 load 进来, 以下为源代码:

  1. // unit.pas 
  2. unit Unit1; 
  3. interface 
  4. uses 
  5. SysUtils, WinTypes, WinProcs, Messages, Classes, 
  6. Graphics, Controls, Forms, Dialogs; 
  7.  
  8. const crMyCursor = 1; (* 宣告一个常数 *) 
  9. type 
  10. TForm1 = class(TForm) 
  11. procedure FormCreate(Sender: TObject); 
  12. private 
  13. { Private declarations } 
  14. public 
  15. { Public declarations } 
  16. end; 
  17. var 
  18.  
  19. Form1: TForm1; 
  20. {$R mycursor.res}//这行$R不可少, 否则自订的鼠游标就出不来 
  21. implementation 
  22. {$R *.DFM} 
  23.  
  24. procedure TForm1.FormCreate(Sender: TObject); 
  25. begin 
  26. //将鼠标资源 load 进来 
  27. Screen.Cursors[crMyCursor] := LoadCursor 
  28. (hInstance,CURSOR_1); 
  29. Cursor := crMyCursor;//指定 form1 的 cursor 自订鼠标 
  30. Button1.Cursor := crMyCursor;//指定Button1的cursor为自订标 
  31. end; 
  32. end. 
(wiseman)
本站文章除注明转载外,均为本站原创或编译欢迎任何形式的转载,但请务必注明出处,尊重他人劳动,同学习共成长。转载请注明:文章转载自:罗索实验室 [http://www.rosoo.net/a/201005/9541.html]
本文出处:博客园 作者:wiseman
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
相关文章
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:点击我更换图片
栏目列表
将本文分享到微信
织梦二维码生成器
推荐内容