twzheng's cppblog

『站在风口浪尖紧握住鼠标旋转!』 http://www.cnblogs.com/twzheng

  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  136 随笔 :: 78 文章 :: 353 评论 :: 0 Trackbacks

GetSystemInfo

GetSystemInfo,Win32 API 函数。

函数说明:
         GetSystemInfo返回关于当前系统的信息。


函数原型:

void GetSystemInfo(
  LPSYSTEM_INFO lpSystemInfo
);


参数表:
lpSystemInfo 
         [out] 指向一个供函数返回信息的SYSTEM_INFO结构体。

返回值:

         这个函数不返回任何值。

必备条件:

Client Requires Windows XP, Windows 2000 Professional, Windows NT Workstation, Windows Me, Windows 98, or Windows 95.
Server Requires Windows Server 2003, Windows 2000 Server, or Windows NT Server.
Header

Declared in Winbase.h; include Windows.h.

Library

Link to Kernel32.lib.

DLL Requires Kernel32.dll.

其他:

SYSTEM_INFO 结构体介绍

示例代码:

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 
   }

}



参考MSDN.
posted on 2007-06-02 22:34 谭文政 阅读(8485) 评论(3)  编辑 收藏 引用 所属分类: 网络编程

评论

# re: GetSystemInfo函数介绍 2007-06-04 13:56 picasa
很有价值的代码  回复  更多评论
  

# re: GetSystemInfo函数介绍 2007-06-04 18:16 Bin
VOID GetSystemInfo(
LPSYSTEM_INFO lpSystemInfo // address of system information structure
);

说明
在一个SYSTEM_INFO结构中载入与底层硬件平台有关的信息

参数表
参数 类型及说明

lpSystemInfo
SYSTEM_INFO,指定一个结构,用于装载适当的系统信息



typedef struct _SYSTEM_INFO { // sinf
union {
DWORD dwOemId;
struct {
WORD wProcessorArchitecture;
WORD wReserved;
};
};
DWORD dwPageSize;
LPVOID lpMinimumApplicationAddress;
LPVOID lpMaximumApplicationAddress;
DWORD dwActiveProcessorMask;
DWORD dwNumberOfProcessors;
DWORD dwProcessorType;
DWORD dwAllocationGranularity;
WORD wProcessorLevel;
WORD wProcessorRevision;
} SYSTEM_INFO;  回复  更多评论
  

# re: GetSystemInfo函数介绍 2008-11-16 15:51 安永辉
很有代表性 和说明性  回复  更多评论
  


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理