如何在窗口中接管Tab键,用setwindowlong,接管窗口默认处理函数,但是都拿不到,有无别的办法

解决方案 »

  1.   

    需要处理WM_GETDLGCODE消息,这是我回答别人的问题,跟你的类似,你看看。
    http://community.csdn.net/Expert/topic/4501/4501019.xml?temp=.8360865
      

  2.   

    procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    begin
    case key of
        VK_UP:showmessage('up key');
        VK_DOWN:showmessage('down key');
        VK_LEFT:showmessage('left');
        VK_RIGHT:showmessage('right');
        VK_TAB:;//加上TAb的处理
    end;end;
    form的keypreview设为true,
    这个问题需要截获 WM_GETDLGCODE 消息,如下:
    procedure WMGetDlgCode(var Message: TWMGetDlgCode); message WM_GETDLGCODE;
    procedure TMyControl.WMGetDlgCode(var Message: TWMGetDlgCode);
    begin
      inherited;
      Message.Result := Message.Result or DLGC_WANTTAB;
    end;WM_GETDLGCODE
      The WM_GETDLGCODE message is sent to the dialog box procedure associated with a 
    control. Normally, Windows handles all arrow-key and TAB-key input to the control. 
    By responding to the WM_GETDLGCODE message, an application can take control of a 
    particular type of input and process the input itself. 下面是参数列表:
    DLGC_BUTTON Button.
    DLGC_DEFPUSHBUTTON Default push button.
    DLGC_HASSETSEL EM_SETSEL messages.
    DLGC_RADIOBUTTON Radio button.
    DLGC_STATIC Static control.
    DLGC_UNDEFPUSHBUTTON Nondefault push button.
    <font color = #ff0000><strong>DLGC_WANTALLKEYS</font></strong> All keyboard input.
    DLGC_WANTARROWS Direction keys.
    DLGC_WANTCHARS WM_CHAR messages.
    DLGC_WANTMESSAGE All keyboard input (the application passes this message on to a control).
    DLGC_WANTTAB TAB key.