获取硬件信息

Getting Hardware Information

The following examples get or set hardware information.

Example 1

 

The following example uses the GetSystemInfo function to obtain hardware information such as the OEM identifier, processor type, page size, and so on. The example displays the information in the console.

 

#include <windows.h>
#include <stdio.h>

void main()
{
   SYSTEM_INFO siSysInfo;
 
   // Copy the hardware information to the SYSTEM_INFO structure. 
 
   GetSystemInfo(&siSysInfo); 
 
   // Display the contents of the SYSTEM_INFO structure. 

   printf("Hardware information: /n");  
   printf("  OEM ID: %u/n", siSysInfo.dwOemId);
   printf("  Number of processors: %u/n", 
      siSysInfo.dwNumberOfProcessors); 
   printf("  Page size: %u/n", siSysInfo.dwPageSize); 
   printf("  Processor type: %u/n", siSysInfo.dwProcessorType); 
   printf("  Minimum application address: %lx/n", 
      siSysInfo.lpMinimumApplicationAddress); 
   printf("  Maximum application address: %lx/n", 
      siSysInfo.lpMaximumApplicationAddress); 
   printf("  Active processor mask: %u/n", 
      siSysInfo.dwActiveProcessorMask); 
}

 

Example 2

 

The following example uses the GetSystemMetrics function to determine whether a mouse is installed and whether the mouse buttons are swapped. The example also uses the SystemParametersInfo function to retrieve the mouse threshold and speed. It displays the information in the console.

 

#include <windows.h>
#include <stdio.h>

void main()
{
   BOOL fResult;
   int aMouseInfo[3];
 
   fResult = GetSystemMetrics(SM_MOUSEPRESENT); 
 
   if (fResult == 0) 
      printf("No mouse installed./n"); 
   else 
   { 
      printf("Mouse installed./n");

      // Determine whether the buttons are swapped. 

      fResult = GetSystemMetrics(SM_SWAPBUTTON); 
 
      if (fResult == 0) 
         printf("Buttons not swapped./n"); 
      else printf("Buttons swapped./n");
 
      // Get the mouse speed and the threshold values. 
 
      fResult = SystemParametersInfo(
         SPI_GETMOUSE,  // get mouse information 
         0,             // not used 
         &aMouseInfo,   // holds mouse information 
         0);            // not used 

      if( fResult )
      { 
         printf("Speed: %d/n", aMouseInfo[2]); 
         printf("Threshold (x,y): %d,%d/n", 
            aMouseInfo[0], aMouseInfo[1]); 
      }
   } 
}

 

Example 3

 

The following example uses SystemParametersInfo to double the mouse speed.

 

#include <windows.h>
#include <stdio.h>

void main()
{
   BOOL fResult;
   int aMouseInfo[3];       // array for mouse information
 
   // Get the current mouse speed. 
 
   fResult = SystemParametersInfo(
      SPI_GETMOUSE,   // get mouse information 
      0,              // not used 
      &aMouseInfo,    // holds mouse information
      0);             // not used 
   
   // Double it. 
 
   if( fResult )
   {
      aMouseInfo[2] = 2 * aMouseInfo[2]; 
 
      // Change the mouse speed to the new value. 
 
      SystemParametersInfo(
         SPI_SETMOUSE,      // set mouse information
         0,                 // not used 
         aMouseInfo,        // mouse information 
         SPIF_SENDCHANGE);  // update win.ini 
   }
}
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值