SetForegroundWindow() private method

private SetForegroundWindow ( IntPtr hwnd ) : int
hwnd System.IntPtr
return int
Ejemplo n.º 1
0
        static void StartMonitoringTaskbarForUAC()
        {
            Win32.RECT?taskbarLastItemRectangle = null;
#pragma warning disable 8321
            bool ChechForUACTaskbarItem()
            {
                Bitmap image = Win32.GetWindowBitmap(Win32.GetTaskbarWindow());

                var rect = Win32.GetTaskbarRect();

                int item_size = image.Height; // it's roughly square

                int item_right        = image.ContentHEnd();
                int item_left_offset  = item_right - item_size;
                int item_right_offset = image.Width - item_right;

                image = image.HCrop(item_left_offset, item_right_offset);

                rect.Left  += item_left_offset;
                rect.Right -= item_right_offset;

                if (taskbarLastItemRectangle.HasValue)
                {
                    if (Math.Abs(rect.Left - taskbarLastItemRectangle.Value.Left) >= item_size)
                    {
                        // new item has appeared on the taskbar

                        var half_size = item_size / 2;

                        // MessageBox.Show("Please activate the UAC prompt on the taskbar.");
                        Win32.FireMouseClick(rect.Left + half_size, rect.Top + half_size);

                        return(true);
                    }
                }

                taskbarLastItemRectangle = rect;
                return(false);
            }

            ThreadPool.QueueUserWorkItem(x =>
            {
                bool done = false;
                while (!done)
                {
                    // if (ChechForUACTaskbarItem())
                    //     break;
                    Thread.Sleep(1000);
                    Win32.SetForegroundWindow(Win32.GetTaskbarWindow());
                }
            });
        }
Ejemplo n.º 2
0
        IntPtr GetMsiForegroundWindow()
        {
            var proc = Process.GetProcessesByName("msiexec").Where(p => p.MainWindowHandle != IntPtr.Zero).FirstOrDefault();

            if (proc != null)
            {
                Win32.ShowWindow(proc.MainWindowHandle, Win32.SW_RESTORE);
                Win32.SetForegroundWindow(proc.MainWindowHandle);
                return(proc.MainWindowHandle);
            }
            else
            {
                return(IntPtr.Zero);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the msi foreground window.
        /// </summary>
        /// <returns></returns>
        protected virtual IntPtr GetMsiForegroundWindow()
        {
            Process proc = null;

            var bundleUI = Environment.GetEnvironmentVariable("WIXSHARP_SILENT_BA_PROC_ID");

            if (bundleUI != null)
            {
                int id = 0;
                if (int.TryParse(bundleUI, out id))
                {
                    proc = Process.GetProcessById(id);
                }
            }

            var bundlePath = session["WIXBUNDLEORIGINALSOURCE"];

            if (bundlePath.IsNotEmpty())
            {
                try
                {
                    proc = Process.GetProcessesByName(Path.GetFileNameWithoutExtension(bundlePath)).Where(p => p.MainWindowHandle != IntPtr.Zero).FirstOrDefault();
                }
                catch { }
            }

            if (proc == null)
            {
                proc = Process.GetProcessesByName("msiexec").Where(p => p.MainWindowHandle != IntPtr.Zero).FirstOrDefault();
            }

            if (proc != null)
            {
                //IntPtr handle = proc.MainWindowHandle; //old algorithm

                IntPtr handle = MsiWindowFinder.GetMsiDialog(proc.Id);

                Win32.ShowWindow(handle, Win32.SW_RESTORE);
                Win32.SetForegroundWindow(handle);

                return(handle);
            }
            else
            {
                return(IntPtr.Zero);
            }
        }