Example #1
0
        protected void PollActiveWindow()
        {
            while (!exiting)
            {
                IntPtr currentActiveWindow = Win32API.GetForegroundWindow();
                if (currentActiveWindow != IntPtr.Zero)
                {
                    if (lastActiveWindow != currentActiveWindow)
                    {
                        lastActiveWindow = currentActiveWindow;

                        uint threadId = Win32API.GetWindowThreadProcessId(lastActiveWindow, IntPtr.Zero);
                        FireWindowActivated(lastActiveWindow, threadId);
                    }
                    else if (lastActiveWindow != IntPtr.Zero)
                    {
                        uint threadId = Win32API.GetWindowThreadProcessId(lastActiveWindow, IntPtr.Zero);
                        Win32API.GUITHREADINFO threadInfo = new Win32API.GUITHREADINFO();
                        threadInfo.cbSize = Marshal.SizeOf(threadId);
                        if (Win32API.GetGUIThreadInfo(threadId, out threadInfo))
                        {
                            IntPtr hwndActive = new IntPtr(threadInfo.hwndActive);
                            if (lastActiveControl != hwndActive)
                            {
                                lastActiveControl = hwndActive;
                                FireWindowControlFocussed(lastActiveWindow, lastActiveControl);
                            }
                        }
                    }
                }

                Thread.Sleep(POLL_SLEEP_INTERVAL_MS);
            }
        }
Example #2
0
 public static IntPtr GetActiveControl(uint threadId)
 {
     Win32API.GUITHREADINFO threadInfo = new Win32API.GUITHREADINFO();
     threadInfo.cbSize = Marshal.SizeOf(threadInfo);
     if (Win32API.GetGUIThreadInfo(threadId, out threadInfo))
     {
         return(new IntPtr(threadInfo.hwndActive));
     }
     return(IntPtr.Zero);
 }