Exemple #1
0
        void changeWindow(object sender, EventArgs e)
        {
            if (e is ChangeActiveWindowsEvent)
            {
                ChangeActiveWindowsEvent ev = e as ChangeActiveWindowsEvent;
                bool isWindow = false;

                AppList.ForEach(x => {
                    if (x.WindowName == ev.windowsname)
                    {
                        if (nowWindow != x.WindowName)
                        {
                            server.all_send(x.url);
                            isWindow  = true;
                            nowWindow = x.WindowName;
                        }
                    }
                });

                if (isWindow == false && nowWindow != "default.html")
                {
                    AppList.ForEach(x =>
                    {
                        if (x.WindowName == "$default$")
                        {
                            server.all_send(x.url);
                        }
                        nowWindow = "default.html";
                    });
                }
            }
            else
            {
                return;
            }
        }
        async Task GetActiveWindows()
        {
            StringBuilder sb = new StringBuilder(65535);
            await Task.Run(() =>
            {
                while (true)
                {
                    IntPtr hWnd = GetForegroundWindow();
                    int id;
                    GetWindowThreadProcessId(hWnd, out id);
                    string prosessname = Process.GetProcessById(id).ProcessName;

                    if (ActiveWindowName != prosessname)
                    {
                        ChangeActiveWindowsEvent chgEvent = new ChangeActiveWindowsEvent();
                        chgEvent.windowsname = prosessname;
                        ChangeActiveWindow?.Invoke(this, chgEvent);
                        ActiveWindowName = prosessname;
                        Console.WriteLine("Window:{0}", ActiveWindowName);
                    }
                    Thread.Sleep(100);
                }
            });
        }