2

我在我的应用程序中实现了这个chevron 工具栏,它工作得非常好;但是,当我单击菜单上的任何项目时,我的应用程序会失去焦点。即使我将鼠标移到窗体的角上,光标也不会变为调整大小手柄。我需要单击表格或应用程序以重新获得我不想做的焦点。调用菜单项后调用 MainForm.Setfocus 无济于事。我希望将焦点自动放在我的应用程序上,这样我的用户在做他们需要做的事情之前不需要点击表单。

关于如何重新关注表单和/或应用程序的任何想法?

谢谢

4

1 回答 1

-1

拦截 WM_KillFocus 消息。

伪代码
在这个终端上没有Delphi,回家后会填空。

type
  TForm1 = class(TForm)
  ...
  protected
    procedure WMKillFocus(message: TWM_Killfocus); message WM_KillFocus;
  ...

procedure TForm1.WMKillFocus(message: TWM_Killfocus);
begin
  //do stuff to prevent the focus from shifting.
  //do *NOT* call SetFocus, it confuses Windows/Delphi and leads to suffering
  //Call PostMessage or handle the KillFocus message
  //From MSDN
  //While processing this message, do not make any function calls that display
  //or activate a window. This causes the thread to yield control and can
  //cause the application to stop responding to messages. For more information 
  //see Message Deadlocks. 
  //Also don't use SendMessage, PostMessage is OK though.        

  //Suggestion:
  PostMessage(Self.handle, WM_SETFOCUS, 0, 0); 
end;
于 2011-04-14T13:49:16.820 回答