Click here to Skip to main content
15,883,915 members
Articles / Programming Languages / C++

CPU Load Control

Rate me:
Please Sign up or sign in to vote.
3.90/5 (13 votes)
22 Feb 2007CPOL1 min read 77.3K   2.5K   33  
Demonstration to control the amount of CPU load used by your computer
// LoadControlDlg.h : header file
//

#pragma once
#include "afxwin.h"
#include "afxcmn.h"
#include <pdh.h>

 
// CLoadControlDlg dialog
class CLoadControlDlg : public CDialog
{
// Construction
public:
	CLoadControlDlg(CWnd* pParent = NULL);	// standard constructor

// Dialog Data
	enum { IDD = IDD_LOADCONTROL_DIALOG };

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support


// Implementation
public:
	HICON m_hIcon;

	UINT_PTR m_nTimer;

	ULONG ulCpuCycles;
	ULONG ulCpuCount;

	HQUERY hQuery;
	HCOUNTER hCounter;
	bool bCounterInit;
	long m_desiredLoad;	

	// Generated message map functions
	virtual BOOL OnInitDialog();
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	DECLARE_MESSAGE_MAP()
public:
	afx_msg void OnNMCustomdrawProgress1(NMHDR *pNMHDR, LRESULT *pResult);
public:
	afx_msg void OnEnChangeEdit1();
	static LONG GetCPUCycle(HQUERY query, HCOUNTER counter);
	void OnTimer(UINT nIDEvent);
public:
	CEdit m_desired;
public:
	CProgressCtrl m_load;
public:
	CStatic m_loadText;
public:
	afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
public:
	afx_msg void OnDestroy();
};

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions