コード例 #1
0
        protected override void ProcessRecord()
        {
            if (hWnd == IntPtr.Zero)
            {
                hWnd = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle;
            }


            WindowInformation result = new WindowInformation();

            Rectangle rect = GetWindowRectangle(hWnd);

            result.X      = rect.X;
            result.Y      = rect.Y;
            result.Height = rect.Height;
            result.Width  = rect.Width;

            if (USER32.IsIconic(hWnd))
            {
                result.State = WindowState.Minimized;
            }
            else if (USER32.IsZoomed(hWnd))
            {
                result.State = WindowState.Maximized;
            }


            WriteObject(result);
        }
コード例 #2
0
        private void FillInformation(WindowInformation windowInformation)
        {
            gvInformation.Rows.Clear();
            gvInformation.Tag = null;

            var indexHeader = gvInformation.Rows.Add();
            var rowHeader   = gvInformation.Rows[indexHeader];

            rowHeader.Cells[0].Value           = "Window Information";
            rowHeader.Cells[0].Style.BackColor = Color.LightGray;
            rowHeader.Cells[1].Style.BackColor = Color.LightGray;

            foreach (var windowDetailKey in windowInformation.WindowDetails.Keys)
            {
                var index = gvInformation.Rows.Add();
                var row   = gvInformation.Rows[index];
                row.Cells[0].Value = windowDetailKey;
                row.Cells[1].Value = windowInformation.WindowDetails[windowDetailKey];
            }

            indexHeader = gvInformation.Rows.Add();
            rowHeader   = gvInformation.Rows[indexHeader];
            rowHeader.Cells[0].Value           = "Process Information";
            rowHeader.Cells[0].Style.BackColor = Color.LightGray;
            rowHeader.Cells[1].Style.BackColor = Color.LightGray;

            foreach (var processDetailKey in windowInformation.ProcessDetails.Keys)
            {
                var index = gvInformation.Rows.Add();
                var row   = gvInformation.Rows[index];
                row.Cells[0].Value = processDetailKey;
                row.Cells[1].Value = windowInformation.ProcessDetails[processDetailKey];
            }
            gvInformation.Tag = windowInformation;
        }
コード例 #3
0
ファイル: HandleService.cs プロジェクト: pe1a0/DolphinD3-1
        public void UpdateHandle(string processName)
        {
            var hwnd          = WindowHelper.GetHWND(processName);
            var currentHandle = GetHandle(processName);

            var processId  = WindowHelper.GetWindowThreadProcessId(hwnd);
            var clientRect = WindowHelper.GetClientRect(hwnd);

            if (currentHandle == default ||
                currentHandle.Handle != hwnd ||
                currentHandle.ProcessId != processId ||
                currentHandle.ClientRectangle != clientRect)
            {
                var rect = WindowHelper.GetClientRect(hwnd);
                //var bitmap = new Bitmap(rect.Width - rect.X, rect.Height - rect.Y, PixelFormat.Format24bppRgb);
                //var graphics = Graphics.FromImage(bitmap);

                var handle = new WindowInformation
                {
                    ClientRectangle = rect,
                    Handle          = hwnd,
                    ProcessId       = WindowHelper.GetWindowThreadProcessId(hwnd),
                    ProcessName     = processName,
                    //WindowBitmap = bitmap,
                    //Graphics = graphics,
                    //GraphicsHdc = graphics.GetHdc()
                };
                handles[processName] = handle;

                HandleStatusChanged?.Invoke(this, new HandleChangedEventArgs {
                    ProcessName = processName, NewHandle = handle
                });
                logService.AddEntry(this, $"Handle information changed [{processName}][{hwnd}][{clientRect}]");
            }
        }
コード例 #4
0
        private static bool EnumChildWindowsCallback(IntPtr windowHandle, WindowFinderEnumChildWindowsProcContext context)
        {
            var classNameResult = MatchClassName(context, windowHandle);

            if (classNameResult == null)
            {
                return(true);
            }

            var windowTextResult = MatchWindowText(context, windowHandle);

            if (windowTextResult == null)
            {
                return(true);
            }

            var windowInformation = new WindowInformation(
                context.ParentWindow.ProcessID,
                windowHandle,
                classNameResult.Value,
                windowTextResult.Value,
                context.ParentWindow);

            if (classNameResult.IsMatch && windowTextResult.IsMatch)
            {
                context.Windows.Add(windowInformation);
            }

            return(true);
        }
コード例 #5
0
        private void RelocateWindow(WindowInformation item)
        {
            var placement = new WindowInformation(new WindowInteropHelper(this).Handle).GetPlacement();
            item?.Relocate(placement.Left, placement.Top);

            this.Close();
        }
コード例 #6
0
        private void RelocateWindow(WindowInformation item)
        {
            var placement = new WindowInformation(new WindowInteropHelper(this).Handle).GetPlacement();

            item?.Relocate(placement.Left, placement.Top);

            this.Close();
        }
コード例 #7
0
 public void UpdateData(WindowInformation windowInformation)
 {
     X      = windowInformation.X;
     Y      = windowInformation.Y;
     Height = windowInformation.Height;
     Width  = windowInformation.Width;
     Title  = windowInformation.Title;
 }
コード例 #8
0
 public void ApplyWindowInformation(WindowInformation windowInformation)
 {
     WindowInformation.Title  = windowInformation.Title;
     WindowInformation.Width  = windowInformation.Width;
     WindowInformation.Height = windowInformation.Height;
     WindowInformation.X      = windowInformation.X;
     WindowInformation.Y      = windowInformation.Y;
 }
コード例 #9
0
 public WindowFinderEnumChildWindowsProcContext(
     IWin32WindowsNativeMethods nativeMethods,
     Regex classNameConstraint,
     Regex windowTextConstraint,
     WindowInformation parentWindow)
     : base(nativeMethods, classNameConstraint, windowTextConstraint)
 {
     _parentWindow = parentWindow;
 }
コード例 #10
0
        public void Init(Config.Config config, WindowInformation windowInformation)
        {
            ClearItems();

            foreach (var marker in config.Markers)
            {
                var navigationalMarker = new NavigationalItem(config, marker, config.TimeoutInSeconds, windowInformation);
                _navigationalItems.Add(navigationalMarker);
            }
        }
コード例 #11
0
 static void FindWindowsByClass(string className, WindowInformation root, ref List <WindowInformation> matchingWindows)
 {
     if (root._className == className)
     {
         matchingWindows.Add(root);
     }
     foreach (var child in root._children)
     {
         FindWindowsByClass(className, child, ref matchingWindows);
     }
 }
コード例 #12
0
        /// <remarks>Must be static because the delegate is passed to unmanaged code.</remarks>>
        private static bool EnumWindowsCallback(IntPtr windowHandle, WindowFinderEnumWindowsProcContext context)
        {
            int processID = context.NativeMethods.GetWindowThreadProcessID(windowHandle);

            if (processID == 0)
            {
                return(true);
            }

            if (context.OwnProcessIDConstraint.HasValue && processID == context.OwnProcessIDConstraint.Value)
            {
                return(true);
            }

            if (context.ProcessIDConstraint.HasValue && processID != context.ProcessIDConstraint.Value)
            {
                return(true);
            }

            var classNameResult = MatchClassName(context, windowHandle);

            if (classNameResult == null)
            {
                return(true);
            }

            var windowTextResult = MatchWindowText(context, windowHandle);

            if (windowTextResult == null)
            {
                return(true);
            }

            var windowInformation = new WindowInformation(
                processID,
                windowHandle,
                classNameResult.Value,
                windowTextResult.Value,
                null);

            if (classNameResult.IsMatch && windowTextResult.IsMatch)
            {
                context.Windows.Add(windowInformation);
            }

            if (context.IncludeChildWindows)
            {
                FindChildWindows(windowHandle, context, windowInformation);
            }

            return(true);
        }
コード例 #13
0
 protected void AssertWindowInformation(
     WindowInformation actualWindowInformation,
     IntPtr expectedWindowHandle,
     int expectedProcessID,
     string expectedClassName,
     string expectedWindowText)
 {
     Assert.That(actualWindowInformation.WindowHandle, Is.EqualTo(expectedWindowHandle));
     Assert.That(actualWindowInformation.ProcessID, Is.EqualTo(expectedProcessID));
     Assert.That(actualWindowInformation.ClassName, Is.EqualTo(expectedClassName));
     Assert.That(actualWindowInformation.WindowText, Is.EqualTo(expectedWindowText));
     Assert.That(actualWindowInformation.ParentWindow, Is.Null);
 }
コード例 #14
0
 private ICommand Initialize_PlaceAppOnTopCommand()
 {
     return(new DelegateCommand(() =>
     {
         if (selectedwindow != null)
         {
             lastWindowOnTop = selectedwindow;
             selectedwindow.OnTop = true;
             WindowsService.Focus(selectedwindow.HWnd);
             WindowsService.SetOnTop(selectedwindow.HWnd);
         }
     }));
 }
コード例 #15
0
        //private UserProcessState _UserProcessState = UserProcessState.Processing ;
        ///// <summary>
        ///// 用户选择状态
        ///// </summary>
        //public virtual UserProcessState UserProcessState
        //{
        //    get { return _UserProcessState; }
        //    set { _UserProcessState = value; }
        //}

        //private UserProcessState _DefaultUserProcessState = UserProcessState.Accept;
        ///// <summary>
        ///// 默认的选择状态
        ///// </summary>
        //public virtual UserProcessState DefaultUserProcessState
        //{
        //    get { return _DefaultUserProcessState; }
        //    set { _DefaultUserProcessState = value; }
        //}

        /// <summary>
        /// 等待用户的选择操作,本函数将不返回直到用户确定选择或取消选择
        /// </summary>
        /// <remarks>本函数向当前应用程序添加自定义的消息过滤器,并开始循环处理当前应用程序的消息,若用户确定或取消的选择操作则退出循环处理</remarks>
        /// <returns>用户是否选择的某个项目</returns>
        public virtual void WaitUserSelected()
        {
            //Win32.NativeMSG msg = new Win32.NativeMSG();
            // Process messages until exit condition recognised
            bolExitLoop   = false;
            bolUserAccept = false;

            MessageFilter.ExcludePaintMessageFilter.Enabled = true;
            Win32Message.ClearMessage();
            //System.Windows.Forms.Application.DoEvents();
            MessageFilter.ExcludePaintMessageFilter.Enabled = false;

            System.Windows.Forms.Application.AddMessageFilter(this);
            //this.UserProcessState = WinForms.UserProcessState.Processing;
            UserProcessState  state = UserProcessState.Processing;
            WindowInformation info  = new WindowInformation(this);

            while (Win32Message.Wait())
            {
                //User32.GetMessage(ref msg, 0, 0, 0);
                //				Windows32.User32.GetMessage( ref msg , 0 , 0 , 0 );
                //				Windows32.User32.TranslateMessage( ref msg );
                //				Windows32.User32.DispatchMessage( ref msg );
                System.Windows.Forms.Application.DoEvents();
                //state = this.UserProcessState ;
                if (this.Visible == false)
                {
                    break;
                }
                if (state == UserProcessState.Accept ||
                    state == UserProcessState.Cancel)
                {
                    break;
                }
                if (bolExitLoop)
                {
                    break;
                }
            }//while
            System.Windows.Forms.Application.RemoveMessageFilter(this);
            Win32Message.ClearMessage();
            //if (state == UserProcessState.Processing)
            //{
            //    state = this.DefaultUserProcessState;
            //}
            if (this.AutoClose)
            {
                this.Hide();
            }
            //return state == UserProcessState.Accept ;
        }
コード例 #16
0
        public static bool EnumChildWindowsCallback(IntPtr hWnd, IntPtr lParam)
        {
            StringBuilder className = new StringBuilder(256);

            GetClassName(hWnd, className, className.Capacity);
            var windowInformation = new WindowInformation(hWnd, lParam, className.ToString());

            _windowLookupMap[hWnd] = windowInformation;
            if (lParam != IntPtr.Zero)
            {
                _windowLookupMap[lParam]._children.Add(windowInformation);
            }
            EnumChildWindows(hWnd, EnumChildWindowsCallback, hWnd);
            return(true);
        }
コード例 #17
0
ファイル: Presenter.cs プロジェクト: Roolen/FlyExplorer
        /// <summary>
        /// Создает новое окно свойств и заполняет его данными.
        /// </summary>
        /// <param name="pathFile">Путь файла</param>
        /// <param name="type">Тип файла</param>
        /// <returns></returns>
        private static WindowInformation CreateNewWindowInformation(string pathFile, TypeContentElement type)
        {
            WindowInformation window = new WindowInformation();

            if (type == TypeContentElement.folder)
            {
                DirectoryInfo directory     = new DirectoryInfo(pathFile);
                Stack <long>  infoDirectory = CalculateWeightOfFolder(pathFile);

                window.Icon.Source = new BitmapImage(new Uri("ControlElements/Images/FolderV3.png", UriKind.Relative));

                window.InfoName.Text = directory.Name;

                window.InfoTypeFile.Text = "Folder";

                window.InfoDescription.Text = "No description";

                window.InfoPath.Text = directory.FullName;

                window.InfoSize.Text = $"{FormatFileSize(infoDirectory.Pop())} ({infoDirectory.Pop()} files; {infoDirectory.Pop()} folders;)";

                window.InfoCreate.Text = directory.CreationTimeUtc.ToString();

                window.InfoChange.Text = directory.LastWriteTimeUtc.ToString();
            }
            if (type == TypeContentElement.file)
            {
                FileInfo file = new FileInfo(pathFile);

                window.Icon.Source = GetIconForFile(file.Extension, pathFile);

                window.InfoName.Text = file.Name;

                window.InfoTypeFile.Text = FormattingOfTypeFile(file.Extension);

                window.InfoDescription.Text = "No description";

                window.InfoPath.Text = file.FullName;

                window.InfoSize.Text = FormatFileSize(file.Length);

                window.InfoCreate.Text = file.CreationTimeUtc.ToString();

                window.InfoChange.Text = file.LastWriteTimeUtc.ToString();
            }

            return(window);
        }
コード例 #18
0
ファイル: WindowService.cs プロジェクト: y497068561/matisco
        private Window CreateWindow(Type type, WindowKey windowKey, Action <IResultDataCollection> onWindowClosedAction, WindowKey parentWindowKey, IRegionManager regionManager)
        {
            Window window;

            if (regionManager != null)
            {
                Debug.WriteLine($"view regionmanager: {regionManager.GetHashCode()}");
                SetCurrentRegionManager(regionManager);

                window = _container.Resolve(type, new TypedParameter(typeof(IRegionManager), regionManager)) as Window;
                RegionManager.SetRegionManager(window, regionManager);
            }
            else
            {
                window = _container.Resolve(type) as Window;
            }

            if (ReferenceEquals(window, null))
            {
                return(null);
            }

            var windowInformation = new WindowInformation(windowKey, parentWindowKey, window, onWindowClosedAction);

            if (ReferenceEquals(parentWindowKey, null))
            {
                window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            }
            else
            {
                var parent = _concurrentWindowCollection.Get(parentWindowKey);
                window.Owner = parent.Window;
                window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
            }

            _concurrentWindowCollection.Add(windowInformation);

            window.Closing         += WindowClosingCallback;
            window.Closed          += WindowClosedCallback;
            window.Activated       += WindowActivateCallback;
            window.Deactivated     += WindowDeactivatedCallback;
            window.SizeChanged     += WindowSizeChangedCallback;
            window.LocationChanged += WindowLocationChangedCallback;

            return(window);
        }
コード例 #19
0
ファイル: Utils.cs プロジェクト: ywscr/CSharpWriter
        public static ApplicationStyle GetApplicationStyle(System.Windows.Forms.Control ctl)
        {
            int layer = 0;
            //string txt = "";
            Control parent = ctl;

            while (parent != null)
            {
                //txt = txt + Environment.NewLine + ctl.GetType().FullName;
                if (parent is System.Windows.Forms.Form)
                {
                    return(ApplicationStyle.WinForm);
                }
                else if (parent.GetType().FullName == "System.Windows.Forms.Integration.WinFormsAdapter")
                {
                    return(ApplicationStyle.WPF);
                }

                parent = parent.Parent;
                layer++;
            }
            WindowInformation info = new WindowInformation(ctl.Handle);

            while (info != null)
            {
                string cn = info.ClassName;
                if (cn != null &&
                    cn.IndexOf(
                        "Internet Explorer",
                        StringComparison.CurrentCultureIgnoreCase) >= 0)
                {
                    // 运行在IE浏览器中
                    return(ApplicationStyle.IEHost);
                }
                info = info.Parent;
            }
            if (layer == 1)
            {
                return(ApplicationStyle.SmartClient);
            }
            //System.Windows.Forms.MessageBox.Show(txt);
            return(ApplicationStyle.UnKnow);
        }
コード例 #20
0
        private static WindowInformation GetWindowInformation(IntPtr hWnd)
        {
            var caption   = new StringBuilder(1024);
            var className = new StringBuilder(1024);

            NativeMethods.GetWindowText(hWnd, caption, caption.Capacity);
            NativeMethods.GetClassName(hWnd, className, className.Capacity);
            var wi = new WindowInformation
            {
                Handle    = (long)hWnd,
                ClassName = className.ToString(),
                IsVisible = NativeMethods.IsWindowVisible(hWnd)
            };

            if (!string.IsNullOrEmpty(caption.ToString()))
            {
                wi.Caption = caption.ToString();
            }
            else
            {
                caption =
                    new StringBuilder(
                        (int)NativeMethods.SendMessage(hWnd, (uint)WM.GETTEXTLENGTH, IntPtr.Zero, IntPtr.Zero) + 1);

                NativeMethods.SendMessage(hWnd, (uint)WM.GETTEXT, (IntPtr)caption.Capacity, caption);
                wi.Caption = caption.ToString();
            }

            try
            {
                uint processId;
                NativeMethods.GetWindowThreadProcessId(hWnd, out processId); //returns thread id
                var process = Process.GetProcessById((int)processId);
                wi.ProcessId   = process.Id;
                wi.ProcessName = process.ProcessName;
            }
            catch (Exception)
            {
                // ignored
            }

            return(wi);
        }
コード例 #21
0
ファイル: WindowService.cs プロジェクト: y497068561/matisco
        private void AskToSaveChanges(WindowInformation windowInformation)
        {
            var navigationParameters = new NavigationParameters
            {
                { nameof(ModalViewModel.Title), "Save" },
                { nameof(ModalViewModel.Message), "There are unsaved changes. Do you want to close this window?" },
                { nameof(ModalButtonEnum), new ModalButtonEnum[] { ModalButtonEnum.Yes, ModalButtonEnum.No } },
                { nameof(ModalIconEnum), ModalIconEnum.Warning }
            };

            OpenDialog(windowInformation.Window, nameof(ModalView), navigationParameters, args =>
            {
                var result = (ModalButtonEnum)args.GetResults().First().Results[0];

                if (result == ModalButtonEnum.Yes)
                {
                    windowInformation.IsClosingByForce = true;
                    windowInformation.Window.Close();
                }
            });
        }
コード例 #22
0
 /// <summary>
 /// 位置とサイズを保存
 /// </summary>
 /// <param name="window"></param>
 /// <param name="key"></param>
 public void Store(Window window, string key)
 {
     var placement = new WindowInformation(new WindowInteropHelper(window).Handle).GetPlacement();
     this.WindowPlacements[key] = placement;
 }
コード例 #23
0
ファイル: DebugToolsUI.cs プロジェクト: zengfr/Neutronium
 /// <summary>
 /// Build a DebugToolsUI with corresponding about and debug UI.
 /// </summary>
 /// <param name="debugToolbar"></param>
 /// <param name="about"></param>
 public DebugToolsUI(WindowInformation debugToolbar, WindowInformation about)
 {
     DebugToolbar = debugToolbar;
     About = about;
 }
コード例 #24
0
        private static void FindChildWindows(IntPtr windowHandle, WindowFinderEnumWindowsProcContext context, WindowInformation windowInformation)
        {
            var childWindowContext = new WindowFinderEnumChildWindowsProcContext(
                context.NativeMethods,
                context.ClassNameConstraint,
                context.WindowTextConstraint,
                windowInformation);

            context.NativeMethods.EnumChildWindows(windowHandle, EnumChildWindowsCallback, childWindowContext);
            context.Windows.AddRange(childWindowContext.Windows);
        }
コード例 #25
0
        /// <summary>
        /// 本函数实现 System.Windows.Forms.IMessageFilter接口的PreFilterMessage函数,用于对当前应用程序的消息进行预处理
        /// </summary>
        /// <remarks>本过滤器处理了鼠标按钮按下时间和键盘事件以及鼠标滚轮事件,
        /// 若鼠标在本列表边框外部按下则表示认为用户想要关闭列表,此时立即关闭本列表窗体
        /// 此外本函数还处理汉语拼音辅助定位列表元素
        /// 用户可用上下光标键或者上下翻页键来滚动列表,用空格或回车来进行选择</remarks>
        /// <param name="m">当前消息队列中的消息对象</param>
        /// <returns>true 当前消息其他程序不可处理(本消息被吃掉了) false本消息还可被其他程序处理</returns>
        public virtual bool PreFilterMessage(ref System.Windows.Forms.Message m)
        {
            bool eatMessage = false;

            if (this.IsDisposed || this.Disposing || this.Visible == false)
            {
                // 若对象被销毁了或列表不显示则删除本消息过滤器
                System.Windows.Forms.Application.RemoveMessageFilter(this);
                return(false);
            }

            Win32Message msg = new Win32Message(m);

            // 获得窗体的绝对位置和大小
            System.Drawing.Rectangle BoundsRect = this.Bounds;

            // 鼠标在客户区的按键按下消息
            // Mouse was pressed in a window of this application
            if (msg.IsMouseDownMessage)
            {
                if (msg.Msg == (int)Msgs.WM_LBUTTONDOWN ||
                    msg.Msg == (int)Msgs.WM_MBUTTONDOWN ||
                    msg.Msg == (int)Msgs.WM_RBUTTONDOWN ||
                    msg.Msg == (int)Msgs.WM_XBUTTONDOWN)
                {
                    System.Drawing.Point mousePos = msg.ScreenMousePosition;
                    bolExitLoop = !BoundsRect.Contains(mousePos);
                    msgBack     = m;
                    eatMessage  = bolExitLoop;
                    if (bolExitLoop)
                    {
                        if (IsChildWindow(m.HWnd))
                        {
                            bolExitLoop = false;
                        }
                        WindowInformation info = new WindowInformation(this.Handle);
                        if (info.Enabled == false)
                        {
                            // 窗体不可用,很可能正在显示对话框使得本窗体暂时不可用
                            bolExitLoop = false;
                        }
                        //else
                        //{
                        //    this.UserProcessState = WinForms.UserProcessState.Accept;
                        //}
                        return(true);
                    }
                }
            }
            // 鼠标在非客户区的按键按下消息
            // Mouse was pressed in a window of this application
            if ((m.Msg == (int)Msgs.WM_NCLBUTTONDOWN) ||
                (m.Msg == (int)Msgs.WM_NCMBUTTONDOWN) ||
                (m.Msg == (int)Msgs.WM_NCRBUTTONDOWN) ||
                (m.Msg == (int)Msgs.WM_NCXBUTTONDOWN))
            {
                System.Drawing.Point mousePos = msg.MousePosition;
                bolExitLoop = !BoundsRect.Contains(mousePos);
                //eatMessage = true;
                msgBack    = m;
                eatMessage = bolExitLoop;
                if (bolExitLoop)
                {
                    if (IsChildWindow(m.HWnd))
                    {
                        bolExitLoop = false;
                    }
                    WindowInformation info = new WindowInformation(this.Handle);
                    if (info.Enabled == false)
                    {
                        // 窗体不可用,很可能正在显示对话框使得本窗体暂时不可用
                        bolExitLoop = false;
                    }
                    //else
                    //{
                    //    this.UserProcessState = WinForms.UserProcessState.Accept;
                    //}
                    return(true);
                }
            }
            if (this.RuntimeContentControl is IMessageFilter)
            {
                WindowInformation info = new WindowInformation(this.Handle);
                //if (info.Enabled)
                {
                    IMessageFilter mf = (IMessageFilter)this.RuntimeContentControl;
                    return(mf.PreFilterMessage(ref m));
                }
            }
            return(eatMessage);
        }
コード例 #26
0
        public WindowUpdate GetWindowUpdate(long windowHandle, out IDataInfo windowRenderData)
        {
            Desktop.SetCurrent(Desktop);

            List <Window> windows;

            try
            {
                //get all windows
                windows = Desktop.GetWindows().Where(x => NativeMethods.IsWindowVisible(x.Handle)).ToList();
            }
            catch (Exception)
            {
                windowRenderData = null;
                return(null);
            }

            var windowUpdate = new WindowUpdate {
                AllWindows = windows.Select(x => x.Handle.ToInt64()).ToList()
            };

            const int maxWindowNameLength = 100;
            var       ptr = Marshal.AllocHGlobal(maxWindowNameLength);

            try
            {
                foreach (var window in windows)
                {
                    RECT rect;
                    NativeMethods.GetWindowRect(window.Handle, out rect);
                    NativeMethods.GetWindowText(window.Handle, ptr, maxWindowNameLength);

                    var windowInformation = new WindowInformation
                    {
                        Handle = (int)window.Handle,
                        Height = rect.Height,
                        Width  = rect.Width,
                        X      = rect.X,
                        Y      = rect.Y,
                        Title  = Marshal.PtrToStringAnsi(ptr)
                    };

                    var existingRenderWindow =
                        _renderWindows.FirstOrDefault(x => x.WindowInformation.Handle == window.Handle.ToInt64());

                    if (existingRenderWindow == null)
                    {
                        windowUpdate.NewWindows.Add(windowInformation);
                        _renderWindows.Add(new RenderWindow(windowInformation, window.Handle));
                    }
                    else
                    {
                        if (existingRenderWindow.WindowInformation.Equals(windowInformation))
                        {
                            continue;
                        }

                        windowUpdate.UpdatedWindows.Add(windowInformation);
                        existingRenderWindow.ApplyWindowInformation(windowInformation);
                    }
                }
            }
            finally
            {
                Marshal.FreeHGlobal(ptr);
            }

            var windowToRender = _renderWindows.FirstOrDefault(x => x.Handle.ToInt64() == windowHandle) ??
                                 _renderWindows.FirstOrDefault();

            //in case that _renderWindows is empty
            if (windowToRender != null)
            {
                windowRenderData = windowToRender.Render();
                windowUpdate.RenderedWindowHandle = windowToRender.Handle.ToInt64();
            }
            else
            {
                windowRenderData = null;
            }

            return(windowUpdate);
        }
コード例 #27
0
 /// <summary> Обработчик нажания ссылки о программе </summary>
 private void HyperlinkAbout_Click(object sender, RoutedEventArgs e)
 {
     WindowInformation.ShowAbout();
 }
コード例 #28
0
 /// <summary> Обработчик нажания ссылки известные проблемы </summary>
 private void HyperlinkProblems_Click(object sender, RoutedEventArgs e)
 {
     WindowInformation.ShowProblems();
 }
コード例 #29
0
 public RenderWindow(WindowInformation windowInformation, IntPtr handle)
 {
     WindowInformation = windowInformation;
     Handle            = handle;
 }
コード例 #30
0
 public WindowRenderInfo(WindowInformation windowInformation)
 {
     UpdateData(windowInformation);
     Handle = windowInformation.Handle;
 }
コード例 #31
0
        /// <summary>
        /// 弹出下拉列表
        /// </summary>
        /// <param name="control">要显示的数据内容控件</param>
        /// <returns>用户是否确认数据编辑操作</returns>
        public void DropDownControl(Control control)
        {
            _UserAccept = false;
            if (control == null)
            {
                throw new ArgumentNullException("control");
            }
            if (_PopupForm == null)
            {
                _PopupForm = new XPopupForm();
                _PopupForm.OwnerControl = this._EditControl;
                //_PopupForm.ControlBox = true;
            }
            Size size = control.GetPreferredSize(new Size(0, 300));    // .Size;

            _PopupForm.ClientSize = new Size(
                size.Width + 5 + PopupFormSizeFix.Width,
                size.Height + 5 + PopupFormSizeFix.Height);

            WindowInformation info   = new WindowInformation(_PopupForm.Handle);
            Rectangle         rect2  = info.Bounds;
            Rectangle         crect2 = info.ClientBounds;

            _PopupForm.Controls.Clear();
            _PopupForm.Controls.Add(control);
            control.Dock = DockStyle.Fill;


            if (_PopupForm.ClientSize.Width < control.Width)
            {
            }
            _PopupForm.AutoClose = true;
            //_PopupForm.CanGetFocus = true;
            //_PopupForm.Visible = true;
            //_PopupForm.Show();
            ImeMode back = ImeMode.NoControl;

            if (this._EditControl != null &&
                _EditControl.IsHandleCreated &&
                _EditControl.IsDisposed == false &&
                _ElementInstance != null)
            {
                _PopupForm.Owner   = this._EditControl.FindForm();
                _PopupForm.TopMost = (_PopupForm.Owner != null);

                if (this._ElementInstance is DomElement)
                {
                    DomElement element = (DomElement)this._ElementInstance;
                    if (!(element is DomParagraphFlagElement))
                    {
                        element = element.FirstContentElement;
                    }
                    if (element == null)
                    {
                        goto EndFunction;
                    }
                    Rectangle rect = this._EditControl.GetCompositionRect(
                        element.AbsLeft,
                        element.AbsTop,
                        element.Height);
                    _PopupForm.CompositionRect = rect;
                    _PopupForm.UpdateComposition();
                }
                _PopupForm.Show();
                if (control is MonthCalendar)
                {
                    MonthCalendar mc = (MonthCalendar)control;
                    size = mc.Size;
                    _PopupForm.ClientSize = new Size(
                        size.Width + PopupFormSizeFix.Width,
                        size.Height + PopupFormSizeFix.Height);
                }
                else if (control is DateTimeSelectControl)
                {
                    DateTimeSelectControl dtc = (DateTimeSelectControl)control;
                    size = dtc.GetPreferredSize(Size.Empty);
                    _PopupForm.ClientSize = new Size(
                        size.Width + PopupFormSizeFix.Width,
                        size.Height + PopupFormSizeFix.Height);
                }
                if (_PopupForm.CanGetFocus == false)
                {
                    if (ForceFousePopupControl)
                    {
                        this._EditControl.Focus();
                    }
                }
                back = _EditControl.ImeMode;
                _EditControl.ImeMode = ImeMode.Disable;
            }//if
            _PopupForm.WaitUserSelected();
EndFunction:
            _PopupForm.CloseList();
            if (_PopupForm != null)
            {
                _PopupForm.Controls.Clear();
            }
            if (control != null)
            {
                control.Dispose();
            }
            if (_EditControl != null)
            {
                _EditControl.ImeMode = back;
                _EditControl.Focus();
            }

            //_UserAccept = ( _PopupForm.UserProcessState == UserProcessState.Accept );
        }
コード例 #32
0
        /// <summary>
        /// 位置とサイズを保存
        /// </summary>
        /// <param name="window"></param>
        /// <param name="key"></param>
        public void Store(Window window, string key)
        {
            var placement = new WindowInformation(new WindowInteropHelper(window).Handle).GetPlacement();

            this.WindowPlacements[key] = placement;
        }