getevent.cpp

来自「《C Builder 5技术内幕》程序源代码」· C++ 代码 · 共 77 行

CPP
77
字号
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "GetEvent.h"
#include "VirtKey.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormCapturingEvents *FormCapturingEvents;
//---------------------------------------------------------------------------
__fastcall TFormCapturingEvents::TFormCapturingEvents(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TFormCapturingEvents::FormPaint(TObject *Sender)
{
  MemoInfo->Font->Name = "Times New Roman";
  MemoInfo->Font->Size = 10;
  MemoInfo->Lines->Clear();
  MemoInfo->Lines->Add( AnsiString( "Font: " ) + MemoInfo->Font->Name );
}
//---------------------------------------------------------------------------
void __fastcall TFormCapturingEvents::FormResize(TObject *Sender)
{
  AnsiString asInfo = AnsiString( "Current width is" )
                    + AnsiString( Width )
                    + AnsiString( ". Current height is" )
                    + AnsiString( Height );
  MemoInfo->Lines->Add( asInfo );
}
//---------------------------------------------------------------------------
void __fastcall TFormCapturingEvents::FormKeyDown(TObject *Sender,
      WORD &Key, TShiftState Shift)
{
  AnsiString asInfo = "Key Down: " + GetKey( Key ) + " " + GetShift( Shift );
  MemoInfo->Lines->Add( asInfo );
}
//---------------------------------------------------------------------------
void __fastcall TFormCapturingEvents::FormKeyUp(TObject *Sender, WORD &Key,
      TShiftState Shift)
{
  AnsiString asInfo = "Key Up: " + GetKey( Key ) + " " + GetShift( Shift );
  MemoInfo->Lines->Add( asInfo );
}
//---------------------------------------------------------------------------
void __fastcall TFormCapturingEvents::FormMouseDown(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
  MemoInfo->Lines->Add( "Mouse Down:" );
  AnsiString asInfo = GetShift( Shift );
  MemoInfo->Lines->Add( asInfo );
}
//---------------------------------------------------------------------------
void __fastcall TFormCapturingEvents::FormMouseMove(TObject *Sender,
      TShiftState Shift, int X, int Y)
{
  MemoInfo->Lines->Add( "Mouse Move:" );
  AnsiString asInfo = "X: " + IntToStr( X ) + ", Y: " + IntToStr( Y ) + " " + GetShift( Shift );
  MemoInfo->Lines->Add( asInfo );
}
//---------------------------------------------------------------------------
void __fastcall TFormCapturingEvents::FormMouseUp(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
  MemoInfo->Lines->Add( "Mouse Up:" );
  AnsiString asInfo = "X: " + IntToStr( X ) + ", Y: " + IntToStr( Y ) + " " + GetShift( Shift );
  MemoInfo->Lines->Add( asInfo );
}
//---------------------------------------------------------------------------
void TFormCapturingEvents::NewMouseMove(TWMMouse &Message)
{
  TForm::Dispatch( &Message );
  StatusBarInfo->SimpleText = "X: " + IntToStr( Message.XPos ) + ", Y: " + IntToStr( Message.YPos );
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?