?、、

解决方案 »

  1.   

    一。关于硬盘操作的函数:
     diskfree:返回磁盘的自由空间。
     disksize:返回指定磁盘的大小。
    函数返回值为int64类型。如果返回-1表示 指定的driver无效。
    其参数都是driver:byte;其中0, 表示当前目录。
    1:A。
    2:B。
    3:C.... and so on.二关于内存举列说明:
    procedure Tform1.timer1timer(sender:Tobject);
    var
      TMS:TMemoryStatus;
    begin
      TMS.dwLength:=sizeof(TMS);
      GlobalMemorystatus(TMS);
      gauge1.progress:=TMS.dwMemoryLoad;
      gauge1.progress:=(100*TMS.dwAvailphys) div TMS.dwtotalphys;
      gauge1.progress:=(100*TMS.dwavailpagefile)div tms.dwtotalpagefile;
    end; 
    TMS结构说明:
      dwlength  该结构的长度
      dwmemoryload   内存使用百分比
      dwtotalphys   实际内存总字节数
      dwavailphys   用的实际内存总字节数
      dwtotalpagefile  分页文件总字节数
      dwavailpagefile  分页文件可用字节数
      dwtotalvirtual   虚拟内存的总字节数。
      dwavailvirtual  可用的虚拟内存字节数三。关于 cpu 速度我也从别人那里抄来的一个例子:(测pentium级以上cpu)
    unction GetCPUSpeed: Double;
    const
      DelayTime = 500; // measure time in ms
    var
      TimerHi, TimerLo: DWORD;
      PriorityClass, Priority: Integer;
    begin
        PriorityClass := GetPriorityClass(GetCurrentProcess);
       Priority := GetThreadPriority(GetCurrentThread);
       SetPriorityClass(GetCurrentProcess, REALTIME_PRIORITY_CLASS);
       SetThreadPriority(GetCurrentThread, THREAD_PRIORITY_TIME_CRITICAL);  Sleep(10);//暂停线索.
      asm
        dw 310Fh // rdtsc
        mov TimerLo, eax
        mov TimerHi, edx
      end;
      Sleep(DelayTime);
      asm
        dw 310Fh // rdtsc
        sub eax, TimerLo
        sbb edx, TimerHi
        mov TimerLo, eax
        mov TimerHi, edx
      end;  SetThreadPriority(GetCurrentThread, Priority);
      SetPriorityClass(GetCurrentProcess, PriorityClass);  Result := TimerLo / (1000.0 * DelayTime);
    end;
      
    四。关于用光驱,软驱。
      我一般是用disksize(driver:byte):int64来读取其大小如果返回值为-1 则证明驱动器无盘或不可用. 
      

  2.   

    感谢您使用微软产品!
    使用PDH函数查询几个performance counters.比如以下代码(在Win2k下我测试过):HQUERY hQuery;
    HCOUNTER *pCounterHandle;void CCpuPerformanceDlg::OnStop() 
    {
        if(hQuery!=NULL)
    PdhCloseQuery(hQuery); 
    BOOL bRet=this->KillTimer (10);  // the timer ID is 10
    if(!bRet) AfxMessageBox("Error occurs when stopping...");
        m_Start.EnableWindow (true);
    m_Stop.EnableWindow (false);
    }void CCpuPerformanceDlg::OnTimer(UINT nIDEvent) 
    {
             PDH_STATUS pdhStatus; 
    DWORD ctrType; 
    PDH_FMT_COUNTERVALUE fmtValue[3]; 
    pdhStatus = PdhCollectQueryData(hQuery); 
    ERROR_EXIT(pdhStatus,ERROR_SUCCESS); 
    pdhStatus = PdhGetFormattedCounterValue( pCounterHandle[0], PDH_FMT_DOUBLE, &ctrType, &fmtValue[0] );   
    pdhStatus = PdhGetFormattedCounterValue( pCounterHandle[1], PDH_FMT_DOUBLE, &ctrType, &fmtValue[1] );   
    pdhStatus = PdhGetFormattedCounterValue( pCounterHandle[2], PDH_FMT_DOUBLE, &ctrType, &fmtValue[2] );   
    //ERROR_EXIT(pdhStatus,ERROR_SUCCESS); 
    double dPercentCPU = fmtValue[0].doubleValue;  
    double dPercentUTime = fmtValue[1].doubleValue;  
        double dPercentPTime = fmtValue[2].doubleValue;  
    this->m_CPU =dPercentCPU;
    this->m_UTime =dPercentUTime;
    this->m_PTime =dPercentPTime;
    this->m_PUTime =dPercentUTime+dPercentPTime; UpdateData(false);
    CDialog::OnTimer(nIDEvent);
    }void CCpuPerformanceDlg::OnStart() 
    {
    PDH_STATUS pdhStatus; 
    char szCounter[256];   this->BeginWaitCursor (); pdhStatus = PdhOpenQuery(NULL, 0, &hQuery );  // NULL for the realtime query
    ERROR_EXIT(pdhStatus,ERROR_SUCCESS); 
     
        pCounterHandle = (HCOUNTER *)GlobalAlloc(GPTR, sizeof(HCOUNTER)*3);   // we need 3 counters
    if(pCounterHandle==NULL) return; 

    wsprintf( szCounter, TEXT("\\Processor(_Total)\\%% Processor Time"));  
    //wsprintf( szCounter, TEXT("\\system\\% Total Processor Time"));  

    pdhStatus = PdhAddCounter(hQuery, szCounter, 0, &pCounterHandle[0]);
        ERROR_EXIT(pdhStatus,ERROR_SUCCESS);     wsprintf( szCounter, TEXT("\\Processor(_Total)\\%% User Time")); 
    pdhStatus = PdhAddCounter(hQuery, szCounter, 0, &pCounterHandle[1]);
        ERROR_EXIT(pdhStatus,ERROR_SUCCESS); 
    wsprintf( szCounter, TEXT("\\Processor(_Total)\\%% Privileged Time")); 
    pdhStatus = PdhAddCounter(hQuery, szCounter, 0, &pCounterHandle[2]);
        ERROR_EXIT(pdhStatus,ERROR_SUCCESS); 
    this->SetTimer (10,1000,NULL); // 1 seconds, the timer ID=10
    m_Start.EnableWindow (false);
    m_Stop.EnableWindow (true);

    this->EndWaitCursor();

    AfxMessageBox("Start successfully!");
    }
    - 微软全球技术中心 VC技术支持 本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款 
    (http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。 
    为了为您创建更好的讨论环境,请参加我们的用户满意度调查 
    (http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。
      

  3.   

    double CSLProcessorInfo::getProcessorSpeed()
    {
    DWORD dwRet;
    LPBYTE  byProcSpeed;
    DWORD dwBuffer;
    HKEY hKey;
    // first,try to get the CPuSpeed through accessing the register 
    if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", 0, KEY_READ, &hKey))
    {
    byProcSpeed=0;
    dwBuffer=sizeof(byProcSpeed);
    dwRet=RegQueryValueEx(hKey,"~MHz",NULL,NULL,(LPBYTE)&byProcSpeed,&dwBuffer);
    if(dwRet==ERROR_SUCCESS)
    {
    return (long)byProcSpeed;
    }
    }
    //if the way of the above failed,we use 
    else
    {
    unsigned __int64  m_start;
    unsigned __int64  m_overhead=0;
    double fTicks;
    m_start=theCycleCount();
    m_overhead=theCycleCount()-m_start;
    m_start=theCycleCount();
    Sleep(1000); 
    unsigned CpuSpeed = (unsigned)((theCycleCount()-m_start-m_overhead)/10000);
    fTicks=CpuSpeed/100.00;
    return fTicks;
    }
    }
      

  4.   

    inline unsigned __int64 CSLProcessorInfo::theCycleCount(void)
    {
    _asm    _emit 0x0F 
    _asm    _emit 0x31
    };//上面是我的处理器信息类的一部分,绝对可行,提供了两种方法,如果你的系统是WinNt或Win2k以上操作系统,直接访问注册表即可。否则通过另外一种方法可以获取更准确的频率.