大悟还俗

邮箱 key_ok@qq.com 我的收集 http://pan.baidu.com/share/home?uk=1177427271
posts - 236, comments - 8, trackbacks - 0, articles - 0
  新随笔 :: 联系 :: 订阅 订阅 :: 管理

公告

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

Posted on 2013-11-18 10:29 大悟还俗 阅读(...) 评论(...) 编辑 收藏
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