要求:按回车后系统在Grid模拟按 Tab 键procedure Tfmzs_NewMen.DBGrid1KeyPress(Sender: TObject; var Key: Char);
begin
  inherited;
   If Key=#13 then
  Begin
    Key:=#0;
    SendKeys('{TAB}');
  end;
End;但是,当我把窗体封装在dll中,程序总是不能发送tab键(跟踪发现,程序已进入了if 语句),不封装时,却能成功发送!
试过 postmessage, 和
        keybd_event(9,0,0,0);    //tab
       keybd_event(9,0,KEYEVENTF_KEYUP,0);    //tab,用15,16都试过
都不成功.甚至,人工在表格Grid中按 Tab 键时,系统也没有把光标移动到下一个单元格,为什么?

解决方案 »

  1.   

    SendKeys
    這個函數是不是你自己寫得
    我在delphi找不到這個函數
      

  2.   

    procedure SendKeys(H: THandle; sSend: string); 
    var 
     i: integer; 
     ch: byte; 
    begin 
     SetFocus(H); 
     if H = 0 then Exit; 
     i := 1; 
     while i <= Length(sSend) do begin 
       ch := byte(sSend[i]); //send string 
       if Windows.IsDBCSLeadByte(ch) then begin 
         Inc(i); 
         SendMessage(H, WM_IME_CHAR, MakeWord(byte(sSend[i]), ch), 0); 
       end 
       else 
         SendMessage(H, WM_IME_CHAR, word(ch), 0); 
       Inc(i); 
     end; 
    end; 這個拿去試一下
      

  3.   

    一样的不行!
    什么 KeyPreview, TabStop...都设置了,没用。