Delphi 应用程序失去焦点

发布于 2024-11-01 04:46:00 字数 321 浏览 0 评论 0原文

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

关于如何重新关注表单和/或应用程序有什么想法吗?

谢谢

I implement this chevron tool bar in my application and it works perfectly great; however, when I clicked on any items on the menu, my application loses focus. Even if I move my mouse over the the corner of the form, the cursor doesn't change to the resize handle. I need to click on the form or application in order to regain focus which I would not like to have to do. Calling MainForm.Setfocus after calling the menu item doesn't help. I would like to have the focus be automatically on my application so my users don't need to click on the form before doing the things they need to do.

Any idea on how to regain focus on the form and/or application?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

念三年u 2024-11-08 04:46:00

拦截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;

Intercept the WM_KillFocus message.

pseudo code
don't have Delphi on this terminal, will fill in the blanks when home.

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文