某些VCL如TTRACKBAR有自己默认的
快捷键(pagedown,pageup等),但是
在我的程序中这些键都有其他用处了。
怎么屏蔽掉VCL的快捷键?

解决方案 »

  1.   

    //那些不是vcl默认的,是windows标准组件默认的。
    //给你个进程内热键类:
    unit HotKey3_San;interface
    uses
    windows,sysutils,messages,classes,controls;type  //WNDPROC_SAN=function(wndhandle:hwnd;msg:cardinal;wParam:integer;lParam:integer):integer;stdcall;
    ////////////////////
      THotKey3Rec=class
      public
        Active:boolean;
        Key:cardinal;
        Modifiers:cardinal;
        EventProc:TNotifyEvent;
        PassOn:boolean;
        HK_HWnd:cardinal;
      end;////////////////////
      THotKey3_San=class
      private
        List:TList;
        FHandle:cardinal;
        newproc:pointer;
        oldproc:pointer;
        procedure NewProcedure(var msg:tmessage);
        function FindItem(Key,Modifiers:cardinal):THotKey3Rec;
        procedure DeleteAll;
      public
        constructor Create(AWinControl:TWinControl);
        destructor Destroy;override;
        function DeleteHotKey(Key,Modifiers:cardinal):boolean;
        function AddHotKey(Key,Modifiers:cardinal;EventProc:TNotifyEvent;PassOn:boolean=true):THotKey3Rec;
      end;implementation
    uses
    common_san;
    { THotKey3_San }function THotKey3_San.AddHotKey(Key,Modifiers:cardinal;EventProc:TNotifyEvent;PassOn:boolean=true):THotKey3Rec;
    begin
      result:=thotkey3rec.Create;
      result.Active:=true;
      result.Key:=key;
      result.Modifiers:=modifiers;
      result.EventProc:=eventproc;
      result.PassOn:=passon;
      result.HK_HWnd:=0;
      list.Add(result);
    end;constructor THotKey3_San.Create(AWinControl: TWinControl);
    begin
      fhandle:=awincontrol.handle;
      if not iswindow(fhandle) then
        raise exception.Create(classname+':  Invalid Window Handle!');
      list:=tlist.Create;
      oldproc:=pointer(getwindowlong(fHandle,GWL_WNDPROC));
      newproc:=classes.MakeObjectInstance(newprocedure);
      if setwindowlong(fHandle,GWL_WNDPROC,integer(newproc))=0 then
        raise exception.create(self.classname+':  Cannot Set New Window Proc!');
    end;procedure THotKey3_San.DeleteAll;
    var
    i:integer;
    p:thotkey3rec;
    begin
      for i:=0 to list.Count-1 do
      begin
        p:=list.Items[i];
        p.Free;
      end;
    end;function THotKey3_San.DeleteHotKey(Key, Modifiers: cardinal):boolean;
    var
    p:thotkey3rec;
    i:integer;
    begin
      result:=false;
      p:=finditem(key,modifiers);
      if (p<>nil) then
      begin
        i:=list.IndexOf(p);
        if (i >=0) and (i<list.count) then
        begin
          p.Free;
          list.Delete(i);
          result:=true;
        end;
      end;
    end;destructor THotKey3_San.Destroy;
    begin
      if Assigned(OldProc) then
        SetWindowLong(FHandle, GWL_WNDPROC, integer(OldProc));
      if Assigned(NewProc) then
        Classes.FreeObjectInstance(NewProc);
      NewProc := nil;
      OldProc := nil;
      deleteall;
      list.Free;
      inherited;
    end;function THotKey3_San.FindItem(Key,Modifiers:cardinal): THotKey3Rec;
    var
    i:integer;
    p:thotkey3rec;
    begin
      result:=nil;  for i:=0 to list.Count-1 do
      begin
        p:=list.items[i];
        if (p.Modifiers=modifiers) and (p.Key=key) then
        begin
          result:=p;
          break;
        end;
      end;
      
    end;procedure THotKey3_San.NewProcedure(var msg: tmessage);
    var
    hkrec:thotkey3rec;
    begin
      if msg.Msg=wm_keydown then
      begin
      hkrec:=finditem(cardinal(msg.lParam),msg.wParam);
      if hkrec=nil then
      begin
        //msg1;
        if oldproc<>nil then
          CallWindowProc(OldProc, FHandle,Msg.Msg, Msg.wParam, Msg.lParam);
      end
      else
      begin    if assigned(hkrec.EventProc) then
          hkrec.EventProc(hkrec);
        if (hkrec.passon)and(oldproc<>nil) then
          CallWindowProc(OldProc, FHandle,Msg.Msg, Msg.wParam, Msg.lParam);
      end;
      end
      else
      begin
    //  beep;
        if oldproc<>nil then
          CallWindowProc(OldProc, FHandle,Msg.Msg, Msg.wParam, Msg.lParam);  end;
     // beep;end;end.
      

  2.   

    to  stanely(俺是邢她汉子) :
    我怎么屏蔽掉它们?能说详细点么?
      

  3.   


    1、将自己的键盘事件处理程序放到onKeyUP或者onKeyPress中。
    2、在窗体上放一个TApplicationEvents组件,在onShortCut事件
    里写入handled := true;