禁止用键盘左右箭头,去切换PageControl页签

unit Unit1;



interface



uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, ComCtrls;



type

  TForm1 = class(TForm)

    PageControl1: TPageControl;

    TabSheet1: TTabSheet;

    TabSheet2: TTabSheet;

    procedure FormCreate(Sender: TObject);

  private

    { Private declarations }

    procedure EditWndProc(var Message: TMessage);

  public

    { Public declarations }

  end;



var

  Form1: TForm1;

  EditHandle: THandle;

  EditPointer:Pointer;

  



implementation



{$R *.dfm}



procedure TForm1.EditWndProc(var Message: TMessage);

begin

  case Message.Msg of

      WM_KEYDOWN  :                          //如果是按键消息

      begin

        if Message.WParam in [37,39] then   //如果是左右箭头

          Exit;

      end;

   end;

   Message.Result:=CallWindowProc(EditPointer, EditHandle, Message.Msg, Message.WParam, Message.LParam);

end;



procedure TForm1.FormCreate(Sender: TObject);

Var P:Pointer;

begin

  EditHandle:=PageControl1.Handle;

  if EditHandle<>0 then

  begin

    EditPointer := Pointer(GetWindowLong(EditHandle, GWL_WNDPROC));

    P := Classes.MakeObjectInstance(EditWndProc);

    SetWindowLong(EditHandle, GWL_WNDPROC, Longint(P));

  end;

end;





end.
View Code

 

你可能感兴趣的:(page)