1.实现监听全局的鼠标和键盘事件,2分钟不动则关机
2.实现计算机基本信息和性能信息的获取,比如C盘利用率,CPU利用率,内存利用率等等
3.开辟新的线程
完整代码如下:
#include <windows.h>
#include <time.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <tchar.h>
#define GB(x) (((x).HighPart << 2) + ((DWORD)(x).LowPart) / 1024.0 / 1024.0 / 1024.0)
typedef long long int64_t;
typedef unsigned long long uint64_t;
HWND hgWnd;
HHOOK myhook;
HHOOK myhookForKeyboard;
long time0=0,time1=0;
//MSG Msg;
/*int get_io_bytes(uint64_t* read_bytes, uint64_t* write_bytes)
{
IO_COUNTERS io_counter;
if(GetProcessIoCounters(GetCurrentProcess(), &io_counter))
{
if(read_bytes) *read_bytes = io_counter.ReadTransferCount;
if(write_bytes) *write_bytes = io_counter.WriteTransferCount;
return 0;
}
return -1;
} */
/*char* GetUserName(void)
{
const int nBufSize = 30;
char chBuf[nBufSize];
ZeroMemory(chBuf,nBufSize);
//获取当前登录用户的名称
DWORD dwRet = nBufSize;
if (::GetUserName(chBuf,&dwRet))
{
//
OutputDebugString(chBuf);
}
else
{
OutputDebugString(_T("获取登录用户名称出错!"));
}
OutputDebugString(_T("/r/n"));
return chBuf;
}*/
/*void TcharToChar (const TCHAR * tchar, char * _char)
{
int iLength ;
//获取字节长度
iLength = WideCharToMultiByte(CP_ACP, 0, tchar, -1, NULL, 0, NULL, NULL);
//将tchar值赋给_char
WideCharToMultiByte(CP_ACP, 0, tchar, -1, _char, iLength, NULL, NULL);
}
char* GetPCName()
{
const int nBufSize = MAX_COMPUTERNAME_LENGTH + 1;
TCHAR chBuf[nBufSize];
ZeroMemory(chBuf,nBufSize);
//获取当前计算机的名称
DWORD dwRet = nBufSize;
GetComputerName(chBuf,&dwRet);
char charBuf[nBufSize];
TcharToChar(chBuf,charBuf);
return charBuf;
}*/
/*//获取实时网速
int WIN_GetIfTable(WIN_IfTable& lstIf)
{
// GetAdaptersAddresses
// 网口信息, 准备1个足够大的buf
struct
{
DWORD dwNumEntries;
MIB_IFROW table[8];
}myIfTable;
memset(&myIfTable, 0, sizeof(myIfTable));
// DWORD nNumOfIf = 0;
// DWORD ret = GetNumberOfInterfaces(&nNumOfIf);
ULONG nBufSize = sizeof(myIfTable);
DWORD ret = GetIfTable((MIB_IFTABLE*)&myIfTable, &nBufSize, TRUE);
if( ret == 0)
{
for(int i=0; i<myIfTable.dwNumEntries; i++)
{
WIN_IfEntry entry;
MIB_IFROW* pRow = &myIfTable.table[i];
strcpy(entry.strName, "");
strcpy(entry.strDescr, (char*)pRow->bDescr);
entry.nIndex = pRow->dwIndex;
entry.nType = pRow->dwType;
entry.nInOctets = pRow->dwInOctets; //pRow->dwInUcastPkts + pRow->dwInNUcastPkts;
entry.nOutOctes = pRow->dwOutOctets; //pRow->dwOutUcastPkts + pRow->dwOutNUcastPkts;
entry.nAdminStatus = pRow->dwAdminStatus;
entry.nSpeed = pRow->dwSpeed;
if(pRow->dwType == 6)
lstIf.push_back(entry);
}
}
return 0;
} */
/// 获得CPU的核数
int get_processor_number(/*int& dwNumberOfProcessors,*/)
{
SYSTEM_INFO info;
GetSystemInfo(&info);
//info.dwProcessorType; CPU类型
//
//info.wProcessorLevel
//info.wProcessorRevision
//info.dwPageSize
return (int)info.dwNumberOfProcessors;
}
//CPU利用率
__int64 CompareFileTime2(FILETIME time1, FILETIME time2)
{
//memcpy(<__int64>, &FILETIME, 8);
__int64 a = time1.dwHighDateTime << 32 | time1.dwLowDateTime;
__int64 b = time2.dwHighDateTime << 32 | time2.dw