首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 计算机考试 > 等级考试 > 复习指导 >

C++基础解析十三

2008-11-24 
C++GetSystemInfo-获取系统信息;GetKeyboardType-获取键盘的类型信息

    一、C++GetSystemInfo-获取系统信息

    //声明:GetSystemInfo(
  var lpSystemInfo: TSystemInfo {}
  );
  //TSystemInfo 是 _SYSTEM_INFO 结构的重定义:
  _SYSTEM_INFO = record
  case Integer of
  0: (
  dwOemId: DWORD); {返回计算机标识符, 已废弃}
  1: (
  wProcessorArchitecture: Word;    {处理器的体系结构}
  wReserved: Word;           {保留}
  dwPageSize: DWORD;          {分页大小}
  lpMinimumApplicationAddress: Pointer;{最小寻址空间}
  lpMaximumApplicationAddress: Pointer;{最大寻址空间}
  dwActiveProcessorMask: DWORD;    {处理器掩码; 0..31 表示不同的处理器}
  dwNumberOfProcessors: DWORD;     {处理器数目}
  dwProcessorType: DWORD;       {处理器类型}
  dwAllocationGranularity: DWORD;   {虚拟内存空间的粒度}
  wProcessorLevel: Word;        {处理器等级}
  wProcessorRevision: Word);      {处理器版本}
  end;//举例:procedure TForm1.FormCreate(Sender: TObject);
  var
  SI: TSystemInfo;
  begin
  GetSystemInfo(SI);
  Memo1.Clear;
  with Memo1.Lines do
  begin
  Add(Format('OEMID:' + #9#9 + '%d', [SI.dwOemId]));
  Add(Format('处理器体系结构:' + #9 + '%d',

[SI.wProcessorArchitecture]));
  Add(Format('分页大小:' + #9 + '%d', [SI.dwPageSize]));
  Add(Format('最小寻址空间:' + #9 + '%d', [Integer

(SI.lpMinimumApplicationAddress)]));
  Add(Format('最大寻址空间:' + #9 + '%d', [Integer

(SI.lpMaximumApplicationAddress)]));
  Add(Format('处理器掩码:' + #9 + '%d',

[SI.dwActiveProcessorMask]));
  Add(Format('处理器数目:' + #9 + '%d',

[SI.dwNumberOfProcessors]));
  Add(Format('处理器类型:' + #9 + '%d',

[SI.dwProcessorType]));
  Add(Format('虚拟内存粒度:' + #9 + '%d',

[SI.dwAllocationGranularity]));
  Add(Format('处理器等级:' + #9 + '%d',

[SI.wProcessorLevel]));
  Add(Format('处理器版本:' + #9 + '%d',

[SI.wProcessorRevision]));
  end;
  end;//效果图:

二、GetKeyboardType-获取键盘的类型信息

//声明:
  GetKeyboardType(
  nTypeFlag: Integer {0:键盘类型; 1:键盘子类型; 2:功能键数量}
  ): Integer;
  //举例:
  procedure TForm1.FormCreate(Sender: TObject);
  var
  i: Integer;
  List: TStringList;
  begin
  List := TStringList.Create;
  List.Add('IBM PC/XT or compatible (83-key) keyboard');
  List.Add('Olivetti "ICO" (102-key) keyboard');
  List.Add('IBM PC/AT (84-key) or similar keyboard');
  List.Add('IBM enhanced (101/102-key) keyboard');
  List.Add('Nokia 1050 and similar keyboards');
  List.Add('Nokia 9140 and similar keyboards');
  List.Add('Japanese keyboard');
  i := GetKeyboardType(0);
  ShowMessage(List[i-1]);  {这里返回: IBM enhanced (101/102-key) keyboard}
  i := GetKeyboardType(1);
  ShowMessage(IntToStr(i)); {这是厂商自定义数据, 这里返回: 0}
  i := GetKeyboardType(2);
  ShowMessage(IntToStr(i)); {返回: 12; 就是指 F1..F12}
  List.Free;
  end;

 

3COME考试频道为您精心整理,希望对您有所帮助,更多信息在http://www.reader8.com/exam/

热点排行