.net – 确定表单被停用时激活的位置

.net – 确定表单被停用时激活的位置,第1张

概述有没有人知道在停用表单时确定哪个窗口将获得焦点的方法? 我找到了答案.在WndProc中处理 WM_ACTIVATE消息(用于激活和取消激活),而不是订阅激活和取消激活事件.由于它报告窗口的句柄被激活,我可以将该句柄与我的表单的句柄进行比较,并确定焦点是否正在改变它们中的任何一个. const int WM_ACTIVATE = 0x0006;const int WA_INACTIVE = 0; 有没有人知道在停用表单时确定哪个窗口将获得焦点的方法?解决方法 我找到了答案.在WndProc中处理 WM_ACTIVATE消息(用于激活和取消激活),而不是订阅激活和取消激活事件.由于它报告窗口的句柄被激活,我可以将该句柄与我的表单的句柄进行比较,并确定焦点是否正在改变它们中的任何一个.

const int WM_ACTIVATE = 0x0006;const int WA_INACTIVE = 0;const int WA_ACTIVE = 1;  const int WA_CliCKACTIVE = 2;  protected overrIDe voID WndProc(ref Message m)  {      if (m.Msg == WM_ACTIVATE)      {           // When m.WParam is WA_INACTIVE,the window is being deactivated and         // m.LParam is the handle of the window that will be activated.         // When m.WParam is WA_ACTIVE or WA_CliCKACTIVE,the window is being          // activated and m.LParam is the handle of the window that has been          // deactivated.    }      base.WndProc(ref m);  }

编辑:此方法可以在其应用的窗口之外使用(例如,在d出窗口外部).

您可以使用NativeWindow根据其句柄附加到任何窗口并查看其消息循环.请参阅以下代码示例:

public class Popup : Form{    const int WM_ACTIVATE = 0x0006;    const int WA_INACTIVE = 0;    private ParentwindowIntercept parentwindowIntercept;    public Popup(IntPtr hWndParent)    {        this.parentwindowIntercept = new ParentwindowIntercept(hWndParent);    }    private class ParentwindowIntercept : NativeWindow    {        public ParentwindowIntercept(IntPtr hWnd)        {            this.AssignHandle(hWnd);        }        protected overrIDe voID WndProc(ref Message m)        {            if (m.Msg == WM_ACTIVATE)            {                if ((int)m.WParam == WA_INACTIVE)                {                    IntPtr windowFocusGoingTo = m.LParam;                    // Compare handles here                }            }            base.WndProc(ref m);        }     }}
总结

以上是内存溢出为你收集整理的.net – 确定表单被停用时激活的位置全部内容,希望文章能够帮你解决.net – 确定表单被停用时激活的位置所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1071417.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-26
下一篇2022-05-26

发表评论

登录后才能评论

评论列表(0条)

    保存