人人做人人澡人人爽欧美,国产主播一区二区,久久久精品五月天,羞羞视频在线观看免费

當前位置:蘿卜系統下載站 > 技術開發教程 > 詳細頁面

VC++設計圖形顯示CPU內存運用率程序

VC++設計圖形顯示CPU內存運用率程序

更新時間:2022-09-05 文章作者:未知 信息來源:網絡 閱讀次數:

[文章導讀]

本程序分兩種情況來獲取CPU的利用率,NT下利用ntdll.dll中沒有公開的API: NtQuerySystemInformation

[正文]   


  下載本文源代碼
http://www.yesky.com/imagesnew/software//0410/31/ccpumemctl.rar 

  程序思想與要點:

  1)、本程序分兩種情況來獲取CPU的利用率,NT下利用ntdll.dll中沒有公開的API: NtQuerySystemInformation, 9x下利用注冊表來獲取CPU的利用率

  code:NT

typedef LONG (WINAPI *PROCNTQSI)(UINT,PVOID,ULONG,PULONG);
PROCNTQSI NtQuerySystemInformation;

NtQuerySystemInformation = (PROCNTQSI)GetProcAddress(
 GetModuleHandle("ntdll"),
 "NtQuerySystemInformation"
);
if (!NtQuerySystemInformation)
{
 return;
}

// get number of processors in the system
status = NtQuerySystemInformation(SystemBasicInformation,
&SysBaseInfo,sizeof(SysBaseInfo),NULL);
if (status != NO_ERROR)
{
 return;
}
status = NtQuerySystemInformation(SystemTimeInformation,
&SysTimeInfo,sizeof(SysTimeInfo),0);
if (status!=NO_ERROR)
{
 return;
}
// get new CPU''s idle time
status = NtQuerySystemInformation(SystemPerformanceInformation,
&SysPerfInfo,sizeof(SysPerfInfo),NULL);
if (status != NO_ERROR)
{
 return;
}
// if it''s a first call - skip it
if (m_liOldIdleTime.QuadPart != 0)
{
 // CurrentValue = NewValue - OldValue
 dbIdleTime = Li2Double(SysPerfInfo.liIdleTime) - Li2Double(m_liOldIdleTime);
 dbSystemTime = Li2Double(SysTimeInfo.liKeSystemTime) - Li2Double(m_liOldSystemTime);

 // CurrentCpuIdle = IdleTime / SystemTime
 dbIdleTime = dbIdleTime / dbSystemTime;

 // CurrentCpuUsage% = 100 - (CurrentCpuIdle * 100) / NumberOfProcessors
 dbIdleTime = 100.0 - dbIdleTime * 100.0 / (double)SysBaseInfo.bKeNumberProcessors + 0.5;

 m_fNewUsges = (UINT)dbIdleTime;
}

  2)、 通過 GlobalMemoryStatus來獲取內存的使用情況

  code:

MEMORYSTATUS MemStat;
MemStat.dwLength = sizeof(MEMORYSTATUS);
GlobalMemoryStatus(&MemStat);
m_ulNewUsges = MemStat.dwMemoryLoad;

  3)、 程序中封裝了兩個類 CcpuUsgesCtl和CmemUsgesCtl,使用這兩這個類可以實現CPU,內存利用率的定時讀取,并以圖形化的形式顯示出來

  使用

  有兩種使用方法,不過要先把這個類的文件 add to project

  1).聲明一個這兩類的對象,并用create來動態生成

such as:CMemUsgesCtl m_ MyMemCtrl;
CCpuUsgesCtl m_ MyCpuCtrl;
…………
if(!m_MyCpuCtrl.Create(WS_CHILD | WS_VISIBLE, rect, this, IDC_CPUCTL))
{
 TRACE0("Create m_MyCtrl Failed!");
 return 0;
}

 rect.left = rect.right + 20;
 rect.right += lpCreateStruct->cx / 2;

 if(!m_MyMemCtrl.Create(WS_CHILD | WS_VISIBLE,rect, this, IDC_MEMCTL))
 {
  TRACE0("Create m_MyCtrl Failed!");
  return 0;
 }


  2) 插入一個static控件,并從類向導中為其生成control形變量,最后將變量的類型換為我們就行了

  效果圖:



  結束語

  控件利用內存來繪圖,實現了無閃爍顯示,歡迎指教!

溫馨提示:喜歡本站的話,請收藏一下本站!

本類教程下載

系統下載排行

網站地圖xml | 網站地圖html
主站蜘蛛池模板: 桑植县| 舞阳县| 洛川县| 岚皋县| 芜湖市| 孝昌县| 呼图壁县| 浦江县| 康平县| 辽阳市| 大厂| 紫金县| 和平县| 兴和县| 堆龙德庆县| 望奎县| 天峻县| 文昌市| 吴桥县| 临江市| 甘孜县| 常州市| 临武县| 大姚县| 山西省| 乌恰县| 潍坊市| 遂宁市| 鲜城| 太原市| 乌鲁木齐县| 河南省| 卫辉市| 东阿县| 德保县| 菏泽市| 涞源县| 韩城市| 昌都县| 长葛市| 仲巴县|