public FileOperationDialog()
        {
            this.DataContext = this;
            Contents = new ObservableCollection<FileOperation>();
            Contents.CollectionChanged += Contents_CollectionChanged;
            InitializeComponent();

            var Name = Environment.OSVersion.Version.ToString().StartsWith("6.1") ? "Windows 7" : "Windows 8";
            Background = Name == "Windows 7" ? Brushes.WhiteSmoke : Brushes.White;
            //Background = Theme.Background;

            //ensure win32 handle is created
            var handle = new WindowInteropHelper(this).EnsureHandle();

            //set window background
            /*var result =*/
            SetClassLong(handle, GCL_HBRBACKGROUND, GetSysColorBrush(COLOR_WINDOW));

            if (!IsShown)
            {
                if (LoadTimer == null)
                {
                    LoadTimer = new DispatcherTimer();
                    LoadTimer.Interval = TimeSpan.FromMilliseconds(1500);
                    LoadTimer.Tick += LoadTimer_Tick;
                    LoadTimer.Start();
                }
            }
        }
Пример #2
0
        public WindowImpl(string title)
        {
            Background = Brushes.HotPink;
            UseLayoutRounding = true;
            Title = title;            

            Grid = new Grid()
            {
                UseLayoutRounding = true,
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment = VerticalAlignment.Stretch,
            };
            
            this.AddChild(Grid);

            KeyDownEvents = Observable.FromEvent<KeyEventArgs>(this, "KeyDown").Select(e => e.EventArgs);
            KeyUpEvents = Observable.FromEvent<KeyEventArgs>(this, "KeyUp").Select(e => e.EventArgs);
            MouseMoveEvents = Observable.FromEvent<MouseEventArgs>(this, "MouseMove").Select(e => e.EventArgs.GetPosition(Grid).ToXna());
            MouseDownEvents = Observable.FromEvent<MouseButtonEventArgs>(this, "MouseDown").Select(e => e.EventArgs.GetPosition(Grid).ToXna());
            MouseUpEvents = Observable.FromEvent<MouseButtonEventArgs>(this, "MouseUp").Select(e => e.EventArgs.GetPosition(Grid).ToXna());

            KeyDownEvents.Where(e => e.Key == Key.F).Subscribe(ie => this.Fullscreen = this.Fullscreen == null ? Screen.PrimaryScreen : null);
            
            MaybeFullscreen = null;
            Hwnd = new WindowInteropHelper(this).EnsureHandle();            
            Show();
        }
Пример #3
0
 private void SetWindowStyle()
 {
     var helper = new WindowInteropHelper(this);
     const int gwlExstyle = -20;
     const int wsExNoactivate = 0x08000000;
     NativeWin32.SetWindowLong(helper.Handle, gwlExstyle, (IntPtr)(wsExNoactivate | wsExNoactivate));
 }
Пример #4
0
        private void SwitchPreviewPanel(bool bOn)
        {
            var _linphone = ServiceManager.Instance.LinphoneService;
            if (_linphone == null)
                return;
            if (!bOn)
            {
                if (ResetNativePreviewHandle)
                    _linphone.SetVideoPreviewWindowHandle(IntPtr.Zero, true);
            }
            else
            {
                _linphone.SetPreviewVideoSizeByName("cif");
                var source = GetWindow(this);
                if (source != null)
                {
                    var wih = new WindowInteropHelper(source);
                    if (wih.Handle != IntPtr.Zero)
                    {
                        IntPtr hWnd = wih.EnsureHandle();

                        if (hWnd != IntPtr.Zero)
                        {
                            _linphone.SetVideoPreviewWindowHandle(hWnd);
                        }
                    }
                }
                ResetNativePreviewHandle = true;
            }
        }
Пример #5
0
 void OnLoaded(object sender, RoutedEventArgs e)
 {
     // Hide Maximize & Size on the system context menu
     var hwnd = new WindowInteropHelper(this).Handle;
     NativeMethods.SetWindowLong(hwnd, NativeMethods.GWL_STYLE,
         NativeMethods.GetWindowLong(hwnd, NativeMethods.GWL_STYLE)  & ~NativeMethods.WS_SYSMENU);
 }
Пример #6
0
 public static void Activatable(this Window window, bool isActivatable)
 {
     // フォーカスを受け取らないようにする
     IntPtr hwnd = new WindowInteropHelper(window).Handle;
     int extendedStyle = NativeMethods.GetWindowLong(hwnd, NativeMethods.GWL_EXSTYLE);
     NativeMethods.SetWindowLong(hwnd, NativeMethods.GWL_EXSTYLE, isActivatable ? extendedStyle ^ NativeMethods.WS_EX_NOACTIVATE : extendedStyle | NativeMethods.WS_EX_NOACTIVATE);
 }
Пример #7
0
 void LoginDialog_Loaded(object sender, RoutedEventArgs e)
 {
     Handle = new WindowInteropHelper(this).Handle;
     Presenter.Initialise(this);
     wb.Navigating += wb_Navigating;
     wb.Navigated += wb_Navigated;
 }
Пример #8
0
    /// <summary>
    /// The actual method that makes API calls to drop the shadow to the window
    /// </summary>
    /// <param name="window">Window to which the shadow will be applied</param>
    /// <returns>True if the method succeeded, false if not</returns>
    private static bool DropShadow(Window window)
    {
        try
        {
            WindowInteropHelper helper = new WindowInteropHelper(window);
            int val = 2;
            int ret1 = DwmSetWindowAttribute(helper.Handle, 2, ref val, 4);

            if (ret1 == 0)
            {
                Margins m = new Margins { Bottom = 0, Left = 0, Right = 0, Top = 0 };
                int ret2 = DwmExtendFrameIntoClientArea(helper.Handle, ref m);
                return ret2 == 0;
            }
            else
            {
                return false;
            }
        }
        catch (Exception ex)
        {
            // Probably dwmapi.dll not found (incompatible OS)
            return false;
        }
    }
Пример #9
0
        public void AfterEngineInit()
        {
            // Basics.
            {
                var deviceDesc = new Device.Descriptor {DebugDevice = true};
                renderDevice = new ClearSight.RendererDX12.Device(ref deviceDesc,
                    ClearSight.RendererDX12.Device.FeatureLevel.Level_11_0);

                var descCQ = new CommandQueue.Descriptor() {Type = CommandListType.Graphics};
                commandQueue = renderDevice.Create(ref descCQ);

                var wih = new WindowInteropHelper(window);
                var swapChainDesc = new SwapChain.Descriptor()
                {
                    AssociatedGraphicsQueue = commandQueue,

                    MaxFramesInFlight = 3,
                    BufferCount = 3,

                    Width = (uint) window.Width,
                    Height = (uint) window.Height,
                    Format = Format.R8G8B8A8_UNorm,

                    SampleCount = 1,
                    SampleQuality = 0,

                    WindowHandle = wih.Handle,
                    Fullscreen = false
                };
                swapChain = renderDevice.Create(ref swapChainDesc);

                var commandListDesc = new CommandList.Descriptor()
                {
                    Type = CommandListType.Graphics,
                    AllocationPolicy = new CommandListInFlightFrameAllocationPolicy(CommandListType.Graphics, swapChain)
                };
                commandList = renderDevice.Create(ref commandListDesc);
            }

            // Render targets.
            {
                var descHeapDesc = new DescriptorHeap.Descriptor()
                {
                    Type = DescriptorHeap.Descriptor.ResourceDescriptorType.RenderTarget,
                    NumResourceDescriptors = swapChain.Desc.BufferCount
                };
                descHeapRenderTargets = renderDevice.Create(ref descHeapDesc);

                var rtvViewDesc = new RenderTargetViewDescription()
                {
                    Format = swapChain.Desc.Format,
                    Dimension = Dimension.Texture2D,
                    Texture = new TextureSubresourceDesc(mipSlice: 0)
                };
                for (uint i = 0; i < swapChain.Desc.BufferCount; ++i)
                {
                    renderDevice.CreateRenderTargetView(descHeapRenderTargets, i, swapChain.BackbufferResources[i], ref rtvViewDesc);
                }
            }
        }
Пример #10
0
 public static CustomMessageBoxResult ShowDialog(Form owner, string caption, string message)
 {
     VersionPickDialog messageBox = new VersionPickDialog();
     var helper = new WindowInteropHelper(messageBox);
     helper.Owner = owner.Handle;
     return messageBox.ShowDialogInternal(caption, message);
 }
Пример #11
0
 private void button1_Click(object sender, EventArgs e)
 {
     MyWPFControlLibrary.CalculatorWindow calc = new MyWPFControlLibrary.CalculatorWindow();
     WindowInteropHelper helper = new WindowInteropHelper(calc);
     helper.Owner = this.Handle;
     calc.Show();
 }
Пример #12
0
        private void PostInitializeWindow()
        {
            Activate();
            Focus();

            // Set the name of the inspected app to the title
            var process = Process.GetCurrentProcess();
            string processName = process.MainWindowTitle ?? process.ProcessName;
            Title += " -  " + processName;

            try
            {
                var interopHelper = new WindowInteropHelper(this);
                _handle = interopHelper.Handle;
                NativeMethods.SetForegroundWindow(_handle);
            }
            catch (Exception)
            {
            }

            if( _viewModel.ShowUsageHint)
            {
                var usageHintWindow = new UsageHintWindow();
                usageHintWindow.Owner = this;
                usageHintWindow.ShowDialog();
            }

            // Initialize this service
            ServiceLocator.Resolve<MouseElementService>();
        }
Пример #13
0
        public static bool ExtendGlassFrame(Window window, Thickness margin)
        {
            if (!Native.DwmIsCompositionEnabled())
                return false;

            try
            {
                IntPtr hwnd = new WindowInteropHelper(window).Handle;

                if (hwnd == IntPtr.Zero)
                    throw new InvalidOperationException("The Window must be shown before extending glass.");

                // Set the background to transparent from both the WPF and Win32 perspectives
                window.Background = Brushes.Transparent;
                HwndSource.FromHwnd(hwnd).CompositionTarget.BackgroundColor = Colors.Transparent;

                Native.MARGINS margins = new Native.MARGINS(margin);
                Native.DwmExtendFrameIntoClientArea(hwnd, ref margins);

                return true;
            }
            catch (Exception ex)
            {
                LogWriter.Log(ex, "Error • Glass");
            }

            return false;
        }
Пример #14
0
 public static WpfScreen GetScreenFrom(Window window)
 {
     var windowInteropHelper = new WindowInteropHelper(window);
     Screen screen = Screen.FromHandle(windowInteropHelper.Handle);
     WpfScreen wpfScreen = new WpfScreen(screen);
     return wpfScreen;
 }
Пример #15
0
        public static bool ExtendGlassFrame(Window window, Thickness margin)
        {
            try
            {
                // desktop window manader must be enabled if it isn't don't bother trying to add glass
                if (!DwmIsCompositionEnabled())
                {
                    return false;
                }

                IntPtr hwnd = new WindowInteropHelper(window).Handle;

                if (hwnd == IntPtr.Zero)
                {
                    throw new InvalidOperationException("The Window must be shown before extending glass.");
                }

                // Set the background to transparent from both the WPF and Win32 perspectives
                //window.Background = Brushes.Transparent;
                HwndSource.FromHwnd(hwnd).CompositionTarget.BackgroundColor = Colors.Transparent;

                MARGINS margins = new MARGINS(margin);
                DwmExtendFrameIntoClientArea(hwnd, ref margins);
                return true;
            }
            catch
            {
                return false;
            }
        }
Пример #16
0
		/// <summary>
		/// 在窗口背后启用模糊效果
		/// </summary>
		/// <param name="window">目标窗口</param>
		/// <returns>成功与否</returns>
		public static bool EnableBlurBehindWindow(Window window)
		{
			if (!AeroGlassCompositionEnabled)
				return false;

			IntPtr hwnd = new WindowInteropHelper(window).Handle;
			if (hwnd == IntPtr.Zero)
				throw new InvalidOperationException("在启用Aero效果前窗口必须已显示");

			//创建DWM_BLURBEHIND结构
			DWM_BLURBEHIND bb = new DWM_BLURBEHIND();
			bb.dwFlags = DWM_BLURBEHIND.DWM_BB_ENABLE | DWM_BLURBEHIND.DWM_BB_BLURREGION;
			bb.fEnable = true;
			bb.hRegionBlur = NativeMethods.CreateRectRgn(0, 0, (int)window.ActualWidth, (int)window.ActualHeight);

			try
			{
				NativeMethods.DwmEnableBlurBehindWindow(hwnd, ref bb);
			}
			catch { }
			//回收句柄
			NativeMethods.DeleteObject(bb.hRegionBlur);
			
			return true;
		}
Пример #17
0
        public PagedViewModel(BaseModel baseModel)
        {
            BaseModel = baseModel;

            Logger.Verbose("Initializing engine window");
            View = new PagedView { DataContext = this };
            ViewWindowHandle = new WindowInteropHelper(View).EnsureHandle();

            _bottomButtonsModel = new ButtonPanelModel(this);
            _contentPanelModel = new ContentPanelModel(this);

            Logger.Verbose("Initializing engine events");
            BaseModel.Bootstrapper.DetectBegin += DetectBegin;
            BaseModel.Bootstrapper.DetectRelatedBundle += DetectedRelatedBundle;
            BaseModel.Bootstrapper.DetectComplete += DetectComplete;
            BaseModel.Bootstrapper.PlanPackageBegin += PlanPackageBegin;
            BaseModel.Bootstrapper.PlanComplete += PlanComplete;
            BaseModel.Bootstrapper.ApplyBegin += ApplyBegin;
            BaseModel.Bootstrapper.ExecuteProgress += ExecuteProgressHandler;
            BaseModel.Bootstrapper.ExecutePackageBegin += ExecutePackageBegin;
            BaseModel.Bootstrapper.ExecutePackageComplete += ExecutePackageComplete;
            BaseModel.Bootstrapper.Error += ExecuteError;
            BaseModel.Bootstrapper.ResolveSource += ResolveSource;
            BaseModel.Bootstrapper.ApplyComplete += ApplyComplete;
            BaseModel.Bootstrapper.Progress += ProgressHandler;
            BaseModel.Bootstrapper.DetectUpdateComplete += DetectUpdateCompleteHandler;
            BaseModel.Bootstrapper.DetectPriorBundle += DetectPriorBundleHandler;
            BaseModel.Bootstrapper.DetectRelatedMsiPackage += DetectRelatedMsiPackageHandler;
        }
Пример #18
0
        public static void ShowMenu(Window targetWindow, Point menuLocation)
        {
            if (targetWindow == null)
                throw new ArgumentNullException("TargetWindow is null.");

            int x, y;

            try
            {
                x = Convert.ToInt32(menuLocation.X);
                y = Convert.ToInt32(menuLocation.Y);
            }
            catch (OverflowException)
            {
                x = 0;
                y = 0;
            }

            uint WM_SYSCOMMAND = 0x112, TPM_LEFTALIGN = 0x0000, TPM_RETURNCMD = 0x0100;           

            IntPtr window = new WindowInteropHelper(targetWindow).Handle;

            IntPtr wMenu = NativeMethods.GetSystemMenu(window, false);

            int command = NativeMethods.TrackPopupMenuEx(wMenu, TPM_LEFTALIGN | TPM_RETURNCMD, x, y, window, IntPtr.Zero);

            if (command == 0)
                return;

            NativeMethods.PostMessage(window, WM_SYSCOMMAND, new IntPtr(command), IntPtr.Zero);
        }
 private void OnShowDialog(object sender, EventArgs e)
 {
     var application = (DTE)GetService(typeof(SDTE));
     if (application.Solution == null || !application.Solution.IsOpen)
         MessageBox.Show("Please open a solution first. ", "No solution");
     else
     {
         if (application.Solution.IsDirty) // solution must be saved otherwise adding/removing projects will raise errors
         {
             MessageBox.Show("Please save your solution first. \n" +
                             "Select the solution in the Solution Explorer and press Ctrl-S. ",
                             "Solution not saved");
         }
         else if (application.Solution.Projects.OfType<Project>().Any(p => p.IsDirty))
         {
             MessageBox.Show("Please save your projects first. \n" +
                             "Select the project in the Solution Explorer and press Ctrl-S. ",
                             "Project not saved");
         }
         else
         {
             var window = new MainDialog(application, GetType().Assembly);
             var helper = new WindowInteropHelper(window);
             helper.Owner = (IntPtr)application.MainWindow.HWnd;
             window.ShowDialog();
         }
     }
 }
Пример #20
0
        protected override void OnSourceInitialized(EventArgs e)
        {
            base.OnSourceInitialized(e);

            IntPtr handle = new WindowInteropHelper(this).Handle;
            HwndSource.FromHwnd(handle).AddHook(WindowProc);
        }
Пример #21
0
        static void wnd_Loaded(object sender, RoutedEventArgs e)
        {
            Window wnd = (Window)sender;
            Brush originalBackground = wnd.Background;
            wnd.Background = Brushes.Transparent;
            try
            {
                IntPtr mainWindowPtr = new WindowInteropHelper(wnd).Handle;
                HwndSource mainWindowSrc = HwndSource.FromHwnd(mainWindowPtr);
                mainWindowSrc.CompositionTarget.BackgroundColor = Color.FromArgb(0, 0, 0, 0);

                //System.Drawing.Graphics desktop = System.Drawing.Graphics.FromHwnd(mainWindowPtr);
                //float DesktopDpiX = desktop.DpiX;
                //float DesktopDpiY = desktop.DpiY;

                MARGINS margins = new MARGINS();
                margins.cxLeftWidth = -1;
                margins.cxRightWidth = -1;
                margins.cyTopHeight = -1;
                margins.cyBottomHeight = -1;

                //DwmExtendFrameIntoClientArea(mainWindowSrc.Handle, ref margins);
            }
            catch (DllNotFoundException)
            {
                wnd.Background = originalBackground;
            }
        }
Пример #22
0
        public static void ToFullscreen(this Window window)
        {
            if (window.IsFullscreen())
            { 
                return; 
            }
   
            _windowState = window.WindowState;
            _windowStyle = window.WindowStyle;
            _windowTopMost = window.Topmost;
            _windowResizeMode = window.ResizeMode;
            _windowRect.X = window.Left;
            _windowRect.Y = window.Top;
            _windowRect.Width = window.Width;
            _windowRect.Height = window.Height;

            window.WindowState = WindowState.Normal; 
            window.WindowStyle = WindowStyle.None;
            window.ResizeMode = ResizeMode.NoResize;
            window.Topmost = true; 

          
            var handle = new WindowInteropHelper(window).Handle; 
            Screen screen = Screen.FromHandle(handle); 
            window.MaxWidth = screen.Bounds.Width;
            window.MaxHeight = screen.Bounds.Height;
            window.WindowState = WindowState.Maximized;
             
            window.Activated += new EventHandler(window_Activated);
            window.Deactivated += new EventHandler(window_Deactivated); 
            _fullWindow = window;
        }
Пример #23
0
        internal static void ShowMinimizeAndMaximizeButtons(Window window)
        {
            var hwnd = new WindowInteropHelper(window).Handle;
            var currentStyle = UnsafeNativeMethods.GetWindowLong(hwnd, GWL_STYLE);

            UnsafeNativeMethods.SetWindowLong(hwnd, GWL_STYLE, (currentStyle | (int)WS_MAXIMIZEBOX | (int)WS_MINIMIZEBOX));
        }
Пример #24
0
        private void AddInstanceButton_Click(object sender, RoutedEventArgs e)
        {
            NewEnemyInstanceWindow instWindow = new NewEnemyInstanceWindow(this.NewEnemyElement);
            var helper = new WindowInteropHelper(instWindow);
            helper.Owner = new WindowInteropHelper(this).Handle;
            bool? res = instWindow.ShowDialog();
            if (res != null && (bool)res)
            {

            }
            else
            {
               // MessageBox.Show("Did not add new enemy instance");
            }
            /*
             * NewEnemyWindow eneWindow = new NewEnemyWindow();
            var helper = new WindowInteropHelper(eneWindow);
            helper.Owner = new WindowInteropHelper(this).Handle;
            bool? res = eneWindow.ShowDialog();
            if (res != null && (bool)res)
            {
            }
            else
            {
                MessageBox.Show("Did not add new enemy");
            }
             */
        }
        protected override void OnSourceInitialized(EventArgs e)
        {
            base.OnSourceInitialized(e);

            var helper = new WindowInteropHelper(this);
            SetWindowLong(helper.Handle, GWL_EXSTYLE, GetWindowLong(helper.Handle, GWL_EXSTYLE) | WS_EX_NOACTIVATE);
        }
        private void TestNameDialog_SourceInitialized(object sender, EventArgs e)
        {
            var wih = new WindowInteropHelper(this);
            var style = GetWindowLong(wih.Handle, GWL_STYLE);
            SetWindowLong(wih.Handle, GWL_STYLE, style & ~WS_SYSMENU);

        }
        public void Show(Int32Rect rpRect)
        {
            var rMainWindowHandle = new WindowInteropHelper(App.Current.MainWindow).Handle;

            if (r_HwndSource == null)
            {
                var rParam = new HwndSourceParameters(nameof(ScreenshotToolOverlayWindow))
                {
                    Width = 0,
                    Height = 0,
                    PositionX = 0,
                    PositionY = 0,
                    WindowStyle = 0,
                    UsesPerPixelOpacity = true,
                    HwndSourceHook = WndProc,
                    ParentWindow = rMainWindowHandle,
                };

                r_HwndSource = new HwndSource(rParam) { SizeToContent = SizeToContent.Manual, RootVisual = this };
            }

            var rBrowserWindowHandle = ServiceManager.GetService<IBrowserService>().Handle;

            NativeStructs.RECT rBrowserWindowRect;
            NativeMethods.User32.GetWindowRect(rBrowserWindowHandle, out rBrowserWindowRect);

            var rHorizontalRatio = rBrowserWindowRect.Width / GameConstants.GameWidth;
            var rVerticalRatio = rBrowserWindowRect.Height / GameConstants.GameHeight;
            rpRect.X = (int)(rpRect.X * rHorizontalRatio);
            rpRect.Y = (int)(rpRect.Y * rVerticalRatio);
            rpRect.Width = (int)(rpRect.Width * rHorizontalRatio);
            rpRect.Height = (int)(rpRect.Height * rVerticalRatio);

            NativeMethods.User32.SetWindowPos(r_HwndSource.Handle, IntPtr.Zero, rBrowserWindowRect.Left + rpRect.X, rBrowserWindowRect.Top + rpRect.Y, rpRect.Width, rpRect.Height, NativeEnums.SetWindowPosition.SWP_NOZORDER | NativeEnums.SetWindowPosition.SWP_NOACTIVATE | NativeEnums.SetWindowPosition.SWP_SHOWWINDOW);
        }
Пример #28
0
        public static bool ExtendGlassFrame(Window window, Thickness margin)
        {
            // Get the Operating System From Environment Class
            OperatingSystem os = Environment.OSVersion;

            // Get the version information
            Version vs = os.Version;

            if (vs.Major < 6)
                return false;

            if (!DwmIsCompositionEnabled())
                return false;

            IntPtr hwnd = new WindowInteropHelper(window).Handle;
            if (hwnd == IntPtr.Zero)
                throw new InvalidOperationException("Glass cannot be extended before the window is shown.");

            // Set the background to transparent from both the WPF and Win32 perspectives
            window.Background = Brushes.Transparent;
            HwndSource.FromHwnd(hwnd).CompositionTarget.BackgroundColor = Colors.Transparent;

            MARGINS margins = new MARGINS(margin);
            DwmExtendFrameIntoClientArea(hwnd, ref margins);

            return true;
        }
Пример #29
0
        public static void GoFullScreen(this Window window)
        {
            if (IsFullScreen(window))
            {
                return;
            }

            windowState = window.WindowState;
            windowStyle = window.WindowStyle;
            windowTopmost = window.Topmost;
            windowResizeMode = window.ResizeMode;
            windowRect.X = window.Left;
            windowRect.Y = window.Top;
            windowRect.Width = window.Width;
            windowRect.Height = window.Height;

            window.WindowState = WindowState.Maximized;
            window.WindowStyle = WindowStyle.None;
            windowTopmost = false;
            windowResizeMode = ResizeMode.NoResize;
            IntPtr handle = new WindowInteropHelper(window).Handle;
            Screen screen = Screen.FromHandle(handle);
            window.Width = screen.Bounds.Width;
            window.Height = screen.Bounds.Height;

            fullWindow = window;
        }
Пример #30
0
        public Window1()
        {
            InitializeComponent();

            helper = new WindowInteropHelper(this);

        }
Пример #31
0
        internal static void DisableButtons(this Window window)
        {
            const int GWL_STYLE  = -16;
            const int WS_SYSMENU = 0x80000;
            IntPtr    hwnd       = new System.Windows.Interop.WindowInteropHelper(window).Handle;
            int       value      = User32.GetWindowLong(hwnd, GWL_STYLE);

            User32.SetWindowLong(hwnd, GWL_STYLE, value & ~WS_SYSMENU);
        }
Пример #32
0
        private static void Target_SourceInitialized(object sender, EventArgs e)
        {
            Window target = sender as Window;

            target.SourceInitialized -= Target_SourceInitialized;
            System.IntPtr handle = new WinInterop.WindowInteropHelper(target).Handle;
            WinInterop.HwndSource.FromHwnd(handle).AddHook(new WinInterop.HwndSourceHook(WindowProc));
            SetHwndPointer(target, handle);
        }
Пример #33
0
        protected override void OnSourceInitialized(EventArgs e)
        {
            IntPtr hwnd = new System.Windows.Interop.WindowInteropHelper(this).Handle;

            SetWindowLong(hwnd, GWL_STYLE,
                          GetWindowLong(hwnd, GWL_STYLE) & (0xFFFFFFFF ^ WS_SYSMENU));

            base.OnSourceInitialized(e);
        }
Пример #34
0
        void RemoveCloseCmd()
        {
            var    hwnd          = new System.Windows.Interop.WindowInteropHelper(this).Handle;
            IntPtr hMenu         = GetSystemMenu(hwnd, false);
            int    menuItemCount = GetMenuItemCount(hMenu);

            //RemoveMenu(hMenu, menuItemCount - 1, MF_BYPOSITION);
            RemoveMenu(hMenu, SC_CLOSE, MF_BYCOMMAND);
        }
Пример #35
0
        private void AddSpeckleMenu(object sender, ElapsedEventArgs e)
        {
            if (Grasshopper.Instances.DocumentEditor == null)
            {
                return;
            }

            if (MenuHasBeenAdded)
            {
                loadTimer.Stop();
                return;
            }

            var speckleMenu = new ToolStripMenuItem("Speckle");

            speckleMenu.DropDown.Items.Add("Speckle Account Manager", null, (s, a) =>
            {
                var signInWindow = new SpecklePopup.SignInWindow(false);
                var helper       = new System.Windows.Interop.WindowInteropHelper(signInWindow);
                helper.Owner     = Rhino.RhinoApp.MainWindowHandle();
                signInWindow.Show();
            });

            speckleMenu.DropDown.Items.Add(new ToolStripSeparator());

            speckleMenu.DropDown.Items.Add("Speckle Home", null, (s, a) =>
            {
                Process.Start(@"https://speckle.works");
            });

            speckleMenu.DropDown.Items.Add("Speckle Documentation", null, (s, a) =>
            {
                Process.Start(@"https://speckle.works/docs/essentials/start");
            });

            speckleMenu.DropDown.Items.Add("Speckle Forum", null, (s, a) =>
            {
                Process.Start(@"https://discourse.speckle.works");
            });

            try
            {
                var mainMenu = Grasshopper.Instances.DocumentEditor.MainMenuStrip;
                Grasshopper.Instances.DocumentEditor.Invoke(new Action(() =>
                {
                    mainMenu.Items.Insert(mainMenu.Items.Count - 2, speckleMenu);
                }));
                MenuHasBeenAdded = true;
                loadTimer.Stop();
            }
            catch (Exception err)
            {
                Debug.WriteLine(err.Message);
            }
        }
		protected override void OnSourceInitialized(EventArgs e)
		{
			base.OnSourceInitialized(e);
			IntPtr hwnd = new System.Windows.Interop.WindowInteropHelper(this).Handle;
			uint styles = GetWindowLong(hwnd, GWL_STYLE);
			styles = GetWindowLong(hwnd, GWL_EXSTYLE);
			styles |= WS_EX_CONTEXTHELP;
			SetWindowLong(hwnd, GWL_EXSTYLE, styles);
			SetWindowPos(hwnd, IntPtr.Zero, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
			((HwndSource)PresentationSource.FromVisual(this)).AddHook(HelpHook);
		}
Пример #37
0
        //protected override void OnSourceInitialized(EventArgs e)
        public static void OnInitHideIcon(this Window w, EventArgs e)
        {
            IntPtr hwnd = new System.Windows.Interop.WindowInteropHelper(w).Handle;
            // int newStyle = (int)( GetWindowLong(hwnd, GWL_STYLE) & (0xFFFFFFFF ^ WS_SYSMENU));
            // SetWindowLong(hwnd, GWL_STYLE, newStyle);
            int extendedStyle = GetWindowLong(hwnd, GWL_EXSTYLE);

            SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle | WS_EX_DLGMODALFRAME);
            SetWindowPos(hwnd, IntPtr.Zero, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
            // base.OnSourceInitialized(e);
        }
Пример #38
0
        void DeleteAltMenuWindow_SourceInitialized(object sender, EventArgs e)
        {
            IntPtr handle = new System.Windows.Interop.WindowInteropHelper(this).Handle;
            IntPtr hmenu  = GetSystemMenu(handle, 0);
            int    cnt    = GetMenuItemCount(hmenu);

            for (int i = cnt - 1; i >= 0; i--)
            {
                RemoveMenu(hmenu, i, MF_DISABLED | MF_BYPOSITION);
            }
        }
Пример #39
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            //去掉图标和最大化关闭按钮
            var hwnd = new System.Windows.Interop.WindowInteropHelper(this).Handle;

            SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_SYSMENU);
            //ImageDealer.Width = image.Width;
            //ImageDealer.Height = image.Height;
            photoName             = getPhotoName();
            ImageDealer.BitSource = image;
        }
Пример #40
0
        private void ForceActiveWindow()
        {
            var helper = new System.Windows.Interop.WindowInteropHelper(this);

            // タスクバーが点滅しフォーカスはあるのに入力できない状態になるため
            for (int i = 0; i < 3; i++)
            {
                if (ForceActive(helper.Handle))
                {
                    break;
                }
            }
        }
Пример #41
0
        protected override void OnSourceInitialized(EventArgs e)
        {
            base.OnSourceInitialized(e);

            //快捷键相关
            IntPtr whandle = new System.Windows.Interop.WindowInteropHelper(this).Handle;

            RegisterHotKey(whandle, 101, KeyModifiers.Ctrl | KeyModifiers.Alt, Keys.O);
            RegisterHotKey(whandle, 102, KeyModifiers.Ctrl | KeyModifiers.Alt, Keys.P);
            HwndSource source = PresentationSource.FromVisual(this) as HwndSource;

            source.AddHook(WndProc);
            //SetWindowLong(whandle, -16, 0);
        }
Пример #42
0
        public bool Register(System.Windows.Window windowControl)
        {
            // Check that we have not registered
            if (this.registered)
            {
                throw new NotSupportedException("You cannot register a hotkey that is already registered");
            }

            // We can't register an empty hotkey
            if (this.Empty)
            {
                throw new NotSupportedException("You cannot register an empty hotkey");
            }

            // Get an ID for the hotkey and increase current ID
            this.id          = Hotkey.currentID;
            Hotkey.currentID = Hotkey.currentID + 1 % Hotkey.maximumID;

            // Translate modifier keys into unmanaged version
            uint modifiers = (this.Alt ? Hotkey.MOD_ALT : 0) | (this.Control ? Hotkey.MOD_CONTROL : 0) |
                             (this.Shift ? Hotkey.MOD_SHIFT : 0) | (this.Windows ? Hotkey.MOD_WIN : 0);


            System.Windows.Interop.WindowInteropHelper h = new System.Windows.Interop.WindowInteropHelper(windowControl);
            // Register the hotkey
            if (Hotkey.RegisterHotKey(h.Handle, this.id, modifiers, keyCode) == 0)
            {
                // Is the error that the hotkey is registered?
                if (Marshal.GetLastWin32Error() == ERROR_HOTKEY_ALREADY_REGISTERED)
                {
                    return(false);
                }
                else
                {
                    throw new Win32Exception();
                }
            }

            // Save the control reference and register state
            this.registered    = true;
            this.windowControl = windowControl;


            // Register us as a message filter
            ComponentDispatcher.ThreadFilterMessage += ComponentDispatcher_ThreadFilterMessage;

            // We successfully registered
            return(true);
        }
Пример #43
0
        public override void AddedToDocument(GH_Document document)
        {
            base.AddedToDocument(document);

            ready = false;

            if (serialisedSender != null)
            {
                mySender = new SpeckleSender(serialisedSender, new GhRhConveter(true, true));
            }
            else
            {
                var myForm = new SpecklePopup.MainWindow();

                var some = new System.Windows.Interop.WindowInteropHelper(myForm);
                some.Owner = Rhino.RhinoApp.MainWindowHandle();

                myForm.ShowDialog();

                if (myForm.restApi != null && myForm.apitoken != null)
                {
                    mySender = new SpeckleSender(myForm.restApi, myForm.apitoken, new GhRhConveter(true, true));
                }
            }

            if (mySender == null)
            {
                return;
            }

            mySender.OnError += OnError;

            mySender.OnReady += OnReady;

            mySender.OnDataSent += OnDataSent;

            mySender.OnMessage += OnVolatileMessage;

            mySender.OnBroadcast += OnBroadcast;

            expireComponentAction = () => this.ExpireSolution(true);

            this.ObjectChanged += (sender, e) => updateMetadata();

            foreach (var param in Params.Input)
            {
                param.ObjectChanged += (sender, e) => updateMetadata();
            }
        }
Пример #44
0
        internal static void HideMinimizeAndMaximizeButtons(this Window window,
                                                            bool hideMaximize = true,
                                                            bool hideMinimize = true)
        {
            window.SourceInitialized += (s, e) =>
            {
                var hwnd           = new System.Windows.Interop.WindowInteropHelper(window).Handle;
                var currentStyle   = GetWindowLong(hwnd, GWL_STYLE);
                var currentStyleM  = currentStyle & ((hideMaximize == true)? ~WS_MAXIMIZEBOX : ~0);
                var currentStyleMm = currentStyleM & ((hideMinimize == true)? ~WS_MINIMIZEBOX : ~0);


                SetWindowLong(hwnd, GWL_STYLE, (currentStyleMm));
            };
        }
Пример #45
0
        public static void RemoveIcon(this Window window)
        {
            IntPtr hwnd = new System.Windows.Interop.WindowInteropHelper(window).Handle;

            // Change the extended window style to not show a window icon
            int extendedStyle = GetWindowLong(hwnd, GWL_EXSTYLE);

            SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle | WS_EX_DLGMODALFRAME);

            // Update the window's non-client area to reflect the changes
            SetWindowPos(hwnd, IntPtr.Zero, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);

            SendMessage(hwnd, WM_SETICON, new IntPtr(1), IntPtr.Zero);
            SendMessage(hwnd, WM_SETICON, IntPtr.Zero, IntPtr.Zero);
        }
Пример #46
0
 public static System.Drawing.Rectangle GetWindowRectangle(this Window w)
 {
     if (w.WindowState == WindowState.Maximized)
     {
         var handle = new System.Windows.Interop.WindowInteropHelper(w).Handle;
         var screen = System.Windows.Forms.Screen.FromHandle(handle);
         return(screen.WorkingArea);
     }
     else
     {
         return(new System.Drawing.Rectangle(
                    (int)w.Left, (int)w.Top,
                    (int)w.ActualWidth, (int)w.ActualHeight));
     }
 }
Пример #47
0
        private static IntPtr GetWindowPointer(Window target)
        {
            IntPtr result = GetHwndPointer(target);

            if (result != IntPtr.Zero)
            {
                return(GetHwndPointer(target));
            }
            else
            {
                System.IntPtr handle = new WinInterop.WindowInteropHelper(target).Handle;
                SetHwndPointer(target, handle);
                result = GetHwndPointer(target);
            }
            return(result);
        }
Пример #48
0
        /// <summary>
        /// 加载窗口
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            CmdCapsLock.Tag = CapsLockStatus.ToString();

            IntPtr a    = new System.Windows.Interop.WindowInteropHelper(this).Handle;
            int    temp = GetWindowLong(a, -20);

            SetWindowLong(a, -20, temp | 0x08000000);
            HwndSource.FromHwnd(a).AddHook(new HwndSourceHook(WndProc));
            double height = System.Windows.SystemParameters.PrimaryScreenHeight;
            double width  = System.Windows.SystemParameters.PrimaryScreenWidth;

            this.Left = (width - 990) / 2;
            this.Top  = height - 350;
            this.WindowStartupLocation = WindowStartupLocation.Manual;
            this.ShowInTaskbar         = false;
        }
Пример #49
0
        public WTSSessionHelper(System.Windows.Window window)
        {
            if (window == null)
            {
                return;
            }
            var wih = new System.Windows.Interop.WindowInteropHelper(window);

            _hwnd = wih.Handle;
            var mainWindowHwndSource = System.Windows.PresentationSource.FromVisual(window) as HwndSource;

            if (mainWindowHwndSource != null)
            {
                mainWindowHwndSource.AddHook(new HwndSourceHook(WindowHwndMessageFilter));
            }
            WTSRegisterSessionNotification(_hwnd, NOTIFY_FOR_THIS_SESSION);
        }
Пример #50
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            IntPtr a    = new System.Windows.Interop.WindowInteropHelper(this).Handle;
            int    temp = GetWindowLong(a, -20);

            SetWindowLong(a, -20, temp | 0x08000000);
            HwndSource.FromHwnd(a).AddHook(new HwndSourceHook(WndProc));
            double height = Screen.PrimaryScreen.Bounds.Height;
            double width  = Screen.PrimaryScreen.Bounds.Width;

            this.Left = (width - 960) / 2; this.Top = height - 400;
            this.WindowStartupLocation = WindowStartupLocation.Manual;
            this.ShowInTaskbar         = false;
            int x = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Size.Width - 210;
            int y = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Size.Height - 300;

            this.Left = x;
            this.Top  = y;
        }
Пример #51
0
 public bool InstallHotKeyHook(Window window)
 {
     if (window == null)
     {
         return(false);
     }
     System.Windows.Interop.WindowInteropHelper helper = new System.Windows.Interop.WindowInteropHelper(window);
     if (IntPtr.Zero == helper.Handle)
     {
         return(false);
     }
     System.Windows.Interop.HwndSource source = System.Windows.Interop.HwndSource.FromHwnd(helper.Handle);
     if (source == null)
     {
         return(false);
     }
     source.AddHook(this.HotKeyHook);
     return(true);
 }
Пример #52
0
        public static void RemoveIcon(Window window)
        {
            // Get this window's handle
            ///IntPtr hwnd = new WindowInteropHelper(window).Handle;

            // Change the extended window style to not show a window icon
            //int extendedStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
            //SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle | WS_EX_DLGMODALFRAME);

            // Update the window's non-client area to reflect the changes
            //SetWindowPos(hwnd, IntPtr.Zero, 0, 0, 0, 0, SWP_NOMOVE |
            //      SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);

            IntPtr hwnd = new System.Windows.Interop.WindowInteropHelper(window).Handle;

            SetWindowLong(hwnd, GWL_STYLE,
                          GetWindowLong(hwnd, GWL_STYLE) & (0xFFFFFFFF ^ WS_SYSMENU));

            // base.OnSourceInitialized(e);
        }
Пример #53
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (CapsLockStatus == true)
            {
                checkImage.Visibility = Visibility.Visible;
            }
            else
            {
                checkImage.Visibility = Visibility.Hidden;
            }
            IntPtr a    = new System.Windows.Interop.WindowInteropHelper(this).Handle;
            int    temp = GetWindowLong(a, -20);

            SetWindowLong(a, -20, temp | 0x08000000);
            // HwndSource.FromHwnd(a).AddHook(new HwndSourceHook(WndProc));
            // double height = Screen.PrimaryScreen.Bounds.Height;
            // double width = Screen.PrimaryScreen.Bounds.Width;
            //  this.Left = (width-960)/2; this.Top = height - 400;
            // this.WindowStartupLocation = WindowStartupLocation.Manual;
            this.ShowInTaskbar = false;
        }
Пример #54
0
        protected override void WndProc(ref System.Windows.Forms.Message m)
        {
            switch (m.Msg)
            {
            case WM_INPUT:
                RawInput.UpdateRawMouse(m.LParam);
                for (int i = 0; i <= Cursors.Count - 1; i++)
                {
                    System.Windows.Interop.WindowInteropHelper helper = new System.Windows.Interop.WindowInteropHelper((DeviceVisual)Cursors[i]);
                    RawMouse rm = (RawMouse)RawInput.Mice[i];
                    SetWindowPos(helper.Handle, IntPtr.Zero, rm.X, rm.Y, 0, 0, (uint)17693);
                    if (_MyInputEvent != null)
                    {
                        _MyInputEvent(helper.Handle.ToInt32(), rm.X, rm.Y, rm.Buttons);
                    }
                }

                System.Windows.Forms.Cursor.Position = new System.Drawing.Point(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height / 2);
                return;
            }
            base.WndProc(ref m);
        }
Пример #55
0
        protected override void OnSourceInitialized(EventArgs e)
        {
            base.OnSourceInitialized(e);

            IntPtr hwnd   = new System.Windows.Interop.WindowInteropHelper(this).Handle;
            uint   styles = GetWindowLong(hwnd, GWL_STYLE);

            styles &= 0xFFFFFFFF ^ (WS_MINIMIZEBOX | WS_MAXIMIZEBOX);
            SetWindowLong(hwnd, GWL_STYLE, styles);

            styles  = GetWindowLong(hwnd, GWL_EXSTYLE);
            styles |= WS_EX_CONTEXTHELP;
            SetWindowLong(hwnd, GWL_EXSTYLE, styles);

            styles  = GetWindowLong(hwnd, GWL_EXSTYLE);
            styles |= WS_EX_DLGMODALFRAME;
            SetWindowLong(hwnd, GWL_EXSTYLE, styles);

            SetWindowPos(hwnd, IntPtr.Zero, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
            ((HwndSource)PresentationSource.FromVisual(this)).AddHook((IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) =>
            {
                if (msg == WM_SYSCOMMAND && ((int)wParam & 0xFFF0) == SC_CONTEXTHELP)
                {
                    MessageBox.Show(
                        "You can use patterns to download multiple files from a single URL. For example, entering the following pattern" +
                        "\n\n" + "http://www.example.com/file[1:10].txt" +
                        "\n\n" + "will download the following ten files" +
                        "\n\n" + "file1.txt" + "\n" + "file2.txt" + "\n" + "..." + "\n\n" + "file10.txt",
                        "Help", MessageBoxButton.OK, MessageBoxImage.Information);
                    // Process.Start("explorer.exe", AppConstants.DocLink);
                    handled = true;
                }
                return(IntPtr.Zero);
            });

            SendMessage(hwnd, WM_SETICON, new IntPtr(1), IntPtr.Zero);
            SendMessage(hwnd, WM_SETICON, IntPtr.Zero, IntPtr.Zero);
        }
Пример #56
0
        private void WinSourceInitialized(object sender, EventArgs e)
        {
            var handle = new WinInterop.WindowInteropHelper(this).Handle;

            WinInterop.HwndSource.FromHwnd(handle)?.AddHook(WindowProc);
        }
Пример #57
0
        /// <summary>
        /// Remove icon from window header.
        /// </summary>
        public static void RemoveIconFrom(Window window)
        {
            IntPtr hwnd = new System.Windows.Interop.WindowInteropHelper(window).Handle;

            SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & (0xFFFFFFFF ^ WS_SYSMENU));
        }
Пример #58
0
        public override void AddedToDocument(GH_Document document)
        {
            base.AddedToDocument(document);
            Document = this.OnPingDocument();

            if (mySender == null)
            {
                this.NickName = "Initialising...";
                this.Locked   = true;

                var myForm = new SpecklePopup.MainWindow();

                var some = new System.Windows.Interop.WindowInteropHelper(myForm)
                {
                    Owner = Rhino.RhinoApp.MainWindowHandle()
                };

                myForm.ShowDialog();

                if (myForm.restApi != null && myForm.apitoken != null)
                {
                    mySender = new SpeckleApiClient(myForm.restApi);
                    RestApi  = myForm.restApi;
                    mySender.IntializeSender(myForm.apitoken, Document.DisplayName, "Grasshopper", Document.DocumentID.ToString()).ContinueWith(task =>
                    {
                        Rhino.RhinoApp.MainApplicationWindow.Invoke(ExpireComponentAction);
                    });
                }
                else
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Account selection failed");
                    return;
                }
            }
            else
            {
            }

            mySender.OnReady += (sender, e) =>
            {
                StreamId      = mySender.StreamId;
                this.Locked   = false;
                this.NickName = "Anonymous Stream";
                //this.UpdateMetadata();
                Rhino.RhinoApp.MainApplicationWindow.Invoke(ExpireComponentAction);
            };

            mySender.OnWsMessage += OnWsMessage;

            mySender.OnLogData += (sender, e) =>
            {
                this.Log += DateTime.Now.ToString("dd:HH:mm:ss ") + e.EventData + "\n";
            };

            mySender.OnError += (sender, e) =>
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, e.EventName + ": " + e.EventData);
                this.Log += DateTime.Now.ToString("dd:HH:mm:ss ") + e.EventData + "\n";
            };

            ExpireComponentAction = () => ExpireSolution(true);

            ObjectChanged += (sender, e) => UpdateMetadata();

            foreach (var param in Params.Input)
            {
                param.ObjectChanged += (sender, e) => UpdateMetadata();
            }

            MetadataSender = new System.Timers.Timer(1000)
            {
                AutoReset = false, Enabled = false
            };
            MetadataSender.Elapsed += MetadataSender_Elapsed;

            DataSender = new System.Timers.Timer(2000)
            {
                AutoReset = false, Enabled = false
            };
            DataSender.Elapsed += DataSender_Elapsed;

            ObjectCache = new Dictionary <string, SpeckleObject>();
        }
Пример #59
0
        public static void DisableMinMaxControls(this Window window)
        {
            IntPtr hwnd = new System.Windows.Interop.WindowInteropHelper(window).Handle;

            SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~(WS_MAXIMIZEBOX | WS_MINIMIZEBOX));
        }
        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            var hwnd = new System.Windows.Interop.WindowInteropHelper(AssociatedObject).Handle;

            SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_SYSMENU);
        }