【问题标题】:Delphi Application Loses FocusDelphi 应用程序失去焦点
【发布时间】:2011-08-05 06:19:30
【问题描述】:

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

知道如何重新关注表单和/或应用程序吗?

谢谢

【问题讨论】:

    标签: delphi menu setfocus


    【解决方案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;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-06
      • 2013-08-07
      • 1970-01-01
      • 2020-10-02
      相关资源
      最近更新 更多