webkiller 发表于 2011-12-26 15:41:41

如何获取键盘类型

Keyboard.cpp

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop
//---------------------------------------------------------------------------
USEFORM("MainForm.cpp", Form1);
//---------------------------------------------------------------------------
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
      try
      {
               Application->Initialize();
               Application->CreateForm(__classid(TForm1), &Form1);
               Application->Run();
      }
      catch (Exception &exception)
      {
               Application->ShowException(&exception);
      }
      catch (...)
      {
               try
               {
                         throw Exception("");
               }
               catch (Exception &exception)
               {
                         Application->ShowException(&exception);
               }
      }
      return 0;
}
//---------------------------------------------------------------------------




MainForm.cpp



//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "MainForm.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
      : TForm(Owner)
{
   this->Edit1->Text="";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn2Click(TObject *Sender)
{
   this->Close();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
   int iType=GetKeyboardType(0);
   switch(iType)
   {
   case 1:
       this->Edit1->Text="IBM PC/XT or compatible (83-key) keyboard";
       break;
   case 2:
       this->Edit1->Text="Olivetti 'ICO' (102-key) keyboard";
       break;
   case 3:
       this->Edit1->Text="IBM PC/AT (84-key) or similar keyboard";
       break;
   case 4:
       this->Edit1->Text="IBM enhanced (101- or 102-key) keyboard";
       break;
   case 5:
       this->Edit1->Text="Nokia 1050 and similar keyboards";
       break;
   case 6:
       this->Edit1->Text="Nokia 9140 and similar keyboards";
       break;
   case 7:
       this->Edit1->Text="Japanese keyboard";
       break;
   }
}
//---------------------------------------------------------------------------

MainForm.h


//---------------------------------------------------------------------------

#ifndef MainFormH
#define MainFormH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <Buttons.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:    // IDE-managed Components
      TLabel *Label1;
      TEdit *Edit1;
      TBitBtn *BitBtn1;
      TBitBtn *BitBtn2;
      void __fastcall BitBtn2Click(TObject *Sender);
      void __fastcall BitBtn1Click(TObject *Sender);
private:    // User declarations
public:      // User declarations
      __fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif


页: [1]
查看完整版本: 如何获取键盘类型