如何在窗口服务应用程序中找到ActiveWindow

如何在窗口服务应用程序中找到ActiveWindow

本文介绍了如何在窗口服务应用程序中找到ActiveWindow的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI,
我正在创建一个窗口服务应用程序,在其中我必须找出哪个是当前活动窗口(具有键盘焦点).我已经这样做了,但这总是返回空值.



I am creating a window service application in which I have to findout out which is current active window(which have keyboard focus).I have done like this but this is returning null values always.


[DllImport("user32.dll")]
        static extern IntPtr GetForegroundWindow();

const int nChars = 256;
            IntPtr handle = IntPtr.Zero;
            StringBuilder Buff = new StringBuilder(nChars);
            handle = GetForegroundWindow();
            if (GetWindowText(handle, Buff, nChars) > 0)
            {
                Log.WriteLine(Buff.ToString());
                return Buff.ToString();
            }
            Log.WriteLine("Returning  Null");
            return null;



但是我在控制台应用程序中尝试了Same逻辑,但是在那方面工作得很好.还有其他方法可以在窗口服务中找出活动窗口吗?
请帮帮我.

问候,
Manushi



But I have tried Same logic in console application but its working fine in that.Is there any other way to findout out active window in window service?
Kindly help me out.

Regards,
Manushi

推荐答案


这篇关于如何在窗口服务应用程序中找到ActiveWindow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 04:16