[VC(Visual C++) ]- 70_偵測CPU和記憶體使用率_並分別記錄到檔案中

[VC(Visual C++) ]- 70_偵測CPU和記憶體使用率_並分別記錄到檔案中

[VC(Visual C++) ]- 70_偵測CPU和記憶體使用率_並分別記錄到檔案中

本篇分享70_偵測CPU和記憶體使用率_並分別記錄到檔案中範例,有興趣的(C/P)同好,歡迎來http://yfdisk.com/file/jashliao/75532da8/索取,因為我不會上傳檔案分享哈哈 ^ ^

主要程式碼

001    // CNetControlDlg.cpp : implementation file                
002    //                
003                    
004    #include "stdafx.h"                
005    #include "CNetControl.h"                
006    #include "CNetControlDlg.h"                
007                    
008    #ifdef _DEBUG                
009    #definenew DEBUG_NEW                
010    #undef THIS_FILE                
011    staticchar THIS_FILE[] = __FILE__;                
012    #endif                
013                    
014    /////////////////////////////////////////////////////////////////////////////                
015    // CAboutDlg dialog used for App About                
016                    
017    class CAboutDlg : public CDialog                
018    {                
019    public:                
020        CAboutDlg();            
021                    
022    // Dialog Data                
023        //{{AFX_DATA(CAboutDlg)            
024        enum { IDD = IDD_ABOUTBOX };            
025        //}}AFX_DATA            
026                    
027        // ClassWizard generated virtual function overrides            
028        //{{AFX_VIRTUAL(CAboutDlg)            
029        protected:            
030        virtualvoid DoDataExchange(CDataExchange* pDX);    // DDX/DDV support            
031        //}}AFX_VIRTUAL            
032                    
033    // Implementation                
034    protected:                
035        //{{AFX_MSG(CAboutDlg)            
036        //}}AFX_MSG            
037        DECLARE_MESSAGE_MAP()            
038    };                
039                    
040    CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)                
041    {                
042        //{{AFX_DATA_INIT(CAboutDlg)            
043        //}}AFX_DATA_INIT            
044    }                
045                    
046    void CAboutDlg::DoDataExchange(CDataExchange* pDX)                
047    {                
048        CDialog::DoDataExchange(pDX);            
049        //{{AFX_DATA_MAP(CAboutDlg)            
050        //}}AFX_DATA_MAP            
051    }                
052                    
053    BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)                
054        //{{AFX_MSG_MAP(CAboutDlg)            
055            // No message handlers        
056        //}}AFX_MSG_MAP            
057    END_MESSAGE_MAP()                
058                    
059    /////////////////////////////////////////////////////////////////////////////                
060    // CCNetControlDlg dialog                
061                    
062    CCNetControlDlg::CCNetControlDlg(CWnd* pParent /*=NULL*/)                
063        : CDialog(CCNetControlDlg::IDD, pParent)            
064    {                
065        //{{AFX_DATA_INIT(CCNetControlDlg)            
066        //}}AFX_DATA_INIT            
067        // Note that LoadIcon does not require a subsequent DestroyIcon in Win32            
068        m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);            
069    }                
070                    
071    void CCNetControlDlg::DoDataExchange(CDataExchange* pDX)                
072    {                
073        CDialog::DoDataExchange(pDX);            
074        //{{AFX_DATA_MAP(CCNetControlDlg)            
075        //}}AFX_DATA_MAP            
076    }                
077                    
078    BEGIN_MESSAGE_MAP(CCNetControlDlg, CDialog)                
079        //{{AFX_MSG_MAP(CCNetControlDlg)            
080        ON_WM_SYSCOMMAND()            
081        ON_WM_PAINT()            
082        ON_WM_QUERYDRAGICON()            
083        ON_WM_CREATE()            
084        //}}AFX_MSG_MAP            
085    END_MESSAGE_MAP()                
086                    
087    /////////////////////////////////////////////////////////////////////////////                
088    // CCNetControlDlg message handlers                
089                    
090    BOOL CCNetControlDlg::OnInitDialog()                
091    {                
092        CDialog::OnInitDialog();            
093                    
094        // Add "About..." menu item to system menu.            
095                    
096        // IDM_ABOUTBOX must be in the system command range.            
097        ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);            
098        ASSERT(IDM_ABOUTBOX < 0xF000);            
099                    
100        CMenu* pSysMenu = GetSystemMenu(FALSE);            
101        if (pSysMenu != NULL)            
102        {            
103            CString strAboutMenu;        
104            strAboutMenu.LoadString(IDS_ABOUTBOX);        
105            if (!strAboutMenu.IsEmpty())        
106            {        
107                pSysMenu->AppendMenu(MF_SEPARATOR);    
108                pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);    
109            }        
110        }            
111                    
112        // Set the icon for this dialog.  The framework does this automatically            
113        //  when the application's main window is not a dialog            
114        SetIcon(m_hIcon, TRUE);            // Set big icon
115        SetIcon(m_hIcon, FALSE);        // Set small icon    
116                    
117        m_MyCpuCtrl.SetRefreshInterval(1000);            
118        m_MyMemCtrl.SetRefreshInterval(1000);            
119        return TRUE;  // return TRUE  unless you set the focus to a control            
120    }                
121                    
122    void CCNetControlDlg::OnSysCommand(UINT nID, LPARAM lParam)                
123    {                
124        if ((nID & 0xFFF0) == IDM_ABOUTBOX)            
125        {            
126            CAboutDlg dlgAbout;        
127            dlgAbout.DoModal();        
128        }            
129        else            
130        {            
131            CDialog::OnSysCommand(nID, lParam);        
132        }            
133    }                
134                    
135    // If you add a minimize button to your dialog, you will need the code below                
136    //  to draw the icon.  For MFC applications using the document/view model,                
137    //  this is automatically done for you by the framework.                
138                    
139    void CCNetControlDlg::OnPaint()                 
140    {                
141        if (IsIconic())            
142        {            
143            CPaintDC dc(this); // device context for painting        
144                    
145            SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);        
146                    
147            // Center icon in client rectangle        
148            int cxIcon = GetSystemMetrics(SM_CXICON);        
149            int cyIcon = GetSystemMetrics(SM_CYICON);        
150            CRect rect;        
151            GetClientRect(&rect);        
152            int x = (rect.Width() - cxIcon + 1) / 2;        
153            int y = (rect.Height() - cyIcon + 1) / 2;        
154                    
155            // Draw the icon        
156            dc.DrawIcon(x, y, m_hIcon);        
157        }            
158        else            
159        {            
160            CDialog::OnPaint();        
161        }            
162    }                
163                    
164    // The system calls this to obtain the cursor to display while the user drags                
165    //  the minimized window.                
166    HCURSOR CCNetControlDlg::OnQueryDragIcon()                
167    {                
168        return (HCURSOR) m_hIcon;            
169    }                
170                    
171    int CCNetControlDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)                 
172    {                
173        CRect rect;            
174        if (CDialog::OnCreate(lpCreateStruct) == -1)            
175            return -1;        
176                    
177        rect.left        = lpCreateStruct->x + 20;    
178        rect.top        = lpCreateStruct->y + 25;    
179        rect.bottom        = lpCreateStruct->y + (lpCreateStruct->cy / 52) * 52 - 25;         
180        rect.right        = lpCreateStruct->x + lpCreateStruct->cx / 2 - 25;    
181                    
182                    
183        if(!m_MyCpuCtrl.Create(WS_CHILD | WS_VISIBLE,                
184                    
185                    
186         )            
187        {            
188            TRACE0("Create m_MyCtrl Failed!");        
189            return 0;        
190        }            
191                    
192        rect.left   = rect.right + 20;            
193        rect.right += lpCreateStruct->cx / 2;            
194                    
195        if(!m_MyMemCtrl.Create(WS_CHILD | WS_VISIBLE,            
196                    
197                    
198         )            
199        {            
200            TRACE0("Create m_MyCtrl Failed!");        
201            return 0;        
202        }            
203        return 0;            
204    }                

 

 

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *