Example #1
1
        public static bool IsFixedPitchFont(FontFamily font)
        {
            try
            {
                var family = new System.Drawing.FontFamily(font.Source);

                if (!family.IsStyleAvailable(FontStyle.Regular))
                    return false;

                var winHandle = new System.Windows.Interop.WindowInteropHelper(App.Current.MainWindow).Handle;

                using (Graphics gr = Graphics.FromHwnd(winHandle))
                using (Font fnt = new Font(family, 10, FontStyle.Regular))
                {
                    return gr.MeasureString("iii", fnt).Width == gr.MeasureString("WWW", fnt).Width;
                }
            }
            catch(Exception exp)
            {
                Console.WriteLine(font.Source);
                Console.WriteLine(exp);
                return false;
            }
        }
        public void LinePatternViewer()
        {
            LPMainWindow main_win = null;
            try
            {
                Document theDoc = this.ActiveUIDocument.Document;
                System.Collections.ObjectModel.ObservableCollection<LinePattern> data =
                    new System.Collections.ObjectModel.ObservableCollection<LinePattern>();

                //Collect all line pattern elements
                FilteredElementCollector collector = new FilteredElementCollector(theDoc);
                IList<Element> linepatternelements = collector.WherePasses(new ElementClassFilter(typeof(LinePatternElement))).ToElements();
                foreach (LinePatternElement lpe in linepatternelements)
                {
                    data.Add(lpe.GetLinePattern());
                }
                //start main window
                main_win = new LinePatternMacro.LPMainWindow(data);
                System.Windows.Interop.WindowInteropHelper x = new System.Windows.Interop.WindowInteropHelper(main_win);
                x.Owner = Process.GetCurrentProcess().MainWindowHandle;
                main_win.ShowDialog();
            }
            catch (Exception err)
            {
                Debug.WriteLine(new string('*', 100));
                Debug.WriteLine(err.ToString());
                Debug.WriteLine(new string('*', 100));
                if (main_win != null && main_win.IsActive)
                    main_win.Close();
            }
        }
Example #3
0
 private void ButtonBrowse_Click(object sender, RoutedEventArgs e)
 {
     IntPtr mainWindowPtr = new System.Windows.Interop.WindowInteropHelper(this).Handle; // 'this' means WPF Window
     var folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog();
     if (folderBrowserDialog.ShowDialog(new OldWindow(mainWindowPtr)) == System.Windows.Forms.DialogResult.OK)
         FolderPath.Text = folderBrowserDialog.SelectedPath;
 }
Example #4
0
        internal static void HideMinimizeAndMaximizeButtons(this Window window)
        {
            IntPtr hwnd = new System.Windows.Interop.WindowInteropHelper(window).Handle;
            var currentStyle = GetWindowLong(hwnd, GWL_STYLE);

            SetWindowLong(hwnd, GWL_STYLE, (currentStyle & ~WS_MAXIMIZEBOX & ~WS_MINIMIZEBOX));
        }
Example #5
0
        protected override void OnSourceInitialized(EventArgs e)
        {
            base.OnSourceInitialized(e);

            const int GWL_STYLE = -16;
            const int GWL_EXSTYLE = -20;
            const int WS_EX_DLGMODALFRAME = 0x0001;

            const int SWP_NOSIZE = 0x0001;
            const int SWP_NOMOVE = 0x0002;
            const int SWP_NOZORDER = 0x0004;
            const int SWP_FRAMECHANGED = 0x0020;

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

            int value = NativeMethods.GetWindowLong(hwnd, GWL_STYLE);
            NativeMethods.SetWindowLong(hwnd, GWL_STYLE, value & -131073 & -65537);

            int extendedStyle = NativeMethods.GetWindowLong(hwnd, GWL_EXSTYLE);
            NativeMethods.SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle | WS_EX_DLGMODALFRAME);

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

            if (!System.Diagnostics.Debugger.IsAttached)
            {
                NativeMethods.SendMessage(hwnd, NativeMethods.WM_SETICON, 0, (IntPtr)0);
                NativeMethods.SendMessage(hwnd, NativeMethods.WM_SETICON, 1, (IntPtr)0);
            }
        }
Example #6
0
 /// <summary>
 /// Sets the given WPF window as topmost or not topmost using a user32 pinvoke call
 /// </summary>
 /// <param name="window">The window to set as topmost</param>
 /// <param name="topMost">True to set window as topmost, false to remove topmost property</param>
 public static void SetTopMost(System.Windows.Window window, bool topMost)
 {
     var handle = new System.Windows.Interop.WindowInteropHelper(window).Handle;
     if (topMost)
         User32.SetWindowPos(handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOMOVE);
     else
         User32.SetWindowPos(handle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOMOVE);
 }
Example #7
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);
        }
    protected override void OnSourceInitialized(EventArgs e)
    {
      IntPtr hwnd = new System.Windows.Interop.WindowInteropHelper(this).Handle;
      SetWindowLong(hwnd, -16, 
        GetWindowLong(hwnd, -16) & (0xFFFFFFFF ^ 0x80000));

      base.OnSourceInitialized(e);
    }
        internal static void HideMinimizeAndMaximizeButtons(this Window window)
        {
            const int GWL_STYLE = -16;

            IntPtr hwnd = new System.Windows.Interop.WindowInteropHelper(window).Handle;
            long value = GetWindowLong(hwnd, GWL_STYLE);

            SetWindowLong(hwnd, GWL_STYLE, (int)(value & -131073 & -65537));
        }
Example #10
0
        protected override void OnSourceInitialized(EventArgs e)
        {
            base.OnSourceInitialized(e);
            // This can't be done any earlier than the SourceInitialized event:
            GlassHelper.ExtendGlassFrame(this, new Thickness(-1));

            //Hide system menu
            IntPtr hwnd = new System.Windows.Interop.WindowInteropHelper(this).Handle;
            SetWindowLong(hwnd, GWL_STYLE,
                GetWindowLong(hwnd, GWL_STYLE) & (0xFFFFFFFF ^ WS_SYSMENU));
        }
Example #11
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);

            //PicImage.Source = PicBitmapImage;
            //测试用
            PicImage.Source = new BitmapImage(new Uri(@"\view\Images\excel\1234.gif", UriKind.Relative));
            //PicImage.Source = PicBitmapImage = new BitmapImage(new Uri("view//Images//excel//1234.gif", UriKind.Relative));
        }
Example #12
0
        public void Show()
        {
            _wnd.Show();
            // Extract the window handle of the window we want to dock
            var mWindowHandle = new System.Windows.Interop.WindowInteropHelper(_wnd).Handle;

            // Dock it in Maya using the docking station
            _mI = new MDockingStation(mWindowHandle, true,
                                      MDockingStation.BottomDock | MDockingStation.TopDock | MDockingStation.LeftDock |
                                      MDockingStation.RightDock, MDockingStation.LeftDock);
        }
        /// <summary>
        /// Sets the window's close button visibility.
        /// </summary>
        /// <param name="window">The window to set.</param>
        /// <param name="showCloseButton"><c>true</c> to show the close button; otherwise, <c>false</c></param>
        public static void SetWindowCloseButtonVisibility(Window window, bool showCloseButton)
        {
            System.Windows.Interop.WindowInteropHelper wih = new System.Windows.Interop.WindowInteropHelper(window);
            
            int style = NativeMethods.GetWindowLong(wih.Handle, NativeMethods.GWL_STYLE);

            if (showCloseButton)
                NativeMethods.SetWindowLong(wih.Handle, NativeMethods.GWL_STYLE, style & NativeMethods.WS_SYSMENU);
            else
                NativeMethods.SetWindowLong(wih.Handle, NativeMethods.GWL_STYLE, style & ~NativeMethods.WS_SYSMENU);
        }
Example #14
0
        public override void doIt(MArgList args)
        {
            // Create the window to dock
            wnd = new wpfexamples.DAGExplorer();
            wnd.Show();

            // Extract the window handle of the window we want to dock
            IntPtr mWindowHandle = new System.Windows.Interop.WindowInteropHelper(wnd).Handle;

            // Dock it in Maya using the docking station
            mI = new MDockingStation(mWindowHandle, true, MDockingStation.BottomDock | MDockingStation.TopDock, MDockingStation.BottomDock);
        }
Example #15
0
        public AcadWindow(Autodesk.AutoCAD.Windows.Window win, Dock dockPos)
            : this()
        {
            _win         = win;
            DockPosition = dockPos;

            var helper = new System.Windows.Interop.WindowInteropHelper(this);

            helper.Owner = win.Handle;

            this.SizeChanged += OnSizeChanged;
        }
Example #16
0
        void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            var helper = new System.Windows.Interop.WindowInteropHelper(this);

            this.Load();

            this.filerUI1.ParentHandle = helper.Handle;
            this.filerUI1.ClearInitialize();

            this.filerUI2.ParentHandle = helper.Handle;
            this.filerUI2.ClearInitialize();
        }
Example #17
0
 private void onSourceInitialized(object sender, EventArgs e)
 {
     try {
         var STYLE = -16; // see winuser.h
         var hwnd  = new System.Windows.Interop.WindowInteropHelper(this).Handle;
         UnsafeNativeMethods.SetWindowLong(hwnd, STYLE,
                                           NativeMethods.GetWindowLong(hwnd, STYLE) & ~(0x10000 | 0x20000));
     } catch {
         // Ignore if we can't remove the buttons.
         SourceInitialized -= onSourceInitialized;
     }
 }
Example #18
0
        /// <summary>
        /// 获取WPF窗口句柄.
        /// </summary>
        /// <param name="main">The main.</param>
        /// <returns></returns>
        public static IntPtr GetHandle(this Window main)
        {
            var helper = new System.Windows.Interop.WindowInteropHelper(main);

#if !NET35
            if (helper.Handle == IntPtr.Zero)
            {
                return(helper.EnsureHandle());
            }
#endif
            return(helper.Handle);
        }
Example #19
0
 private void BtnBorderMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
 {
     try
     {
         var w   = new wSettings();
         var wih = new System.Windows.Interop.WindowInteropHelper(w);
         wih.Owner = (IntPtr)dApp.AppWindow.Handle;
         w.ShowDialog();
         LoadPresets();
     }
     catch (Exception ex) { MessageBox.Show(ex.ToString()); }
 }
Example #20
0
        /// <summary>
        /// Creates a bitmap with the iamge a user sees for a window.
        /// </summary>
        /// <param name="window">Window to capture.</param>
        /// <returns>The created bitmap.</returns>
        public static Bitmap CreateBitmapFromWindow(Window window)
        {
            if (window == null)
            {
                throw new ArgumentNullException("window");
            }

            System.Windows.Interop.WindowInteropHelper helper =
                new System.Windows.Interop.WindowInteropHelper(window);

            return(CreateBitmapFromWindowHandle(helper.Handle));
        }
 internal static void UpdateWindowOwner(Window w, FrameworkElement ownerObject)
 {
     if (!ViewModelBase.IsInDesignMode)
     {
         w.Owner = Window.GetWindow(ownerObject);
     }
     else
     {
         System.Windows.Interop.WindowInteropHelper windowInteropHelper = new System.Windows.Interop.WindowInteropHelper(w);
         windowInteropHelper.Owner = GetActiveWindow();
     }
 }
Example #22
0
        override public void doIt(MArgList args)
        {
            // Create the window to dock
            wnd = new wpfexamples.DAGExplorer();
            wnd.Show();

            // Extract the window handle of the window we want to dock
            IntPtr mWindowHandle = new System.Windows.Interop.WindowInteropHelper(wnd).Handle;

            // Dock it in Maya using the docking station
            mI = new MDockingStation(mWindowHandle, true, MDockingStation.BottomDock | MDockingStation.TopDock, MDockingStation.BottomDock);
        }
Example #23
0
 public static void Restore(System.Windows.Window window)
 {
     RunUI(window, () =>
     {
         if (window.WindowState == System.Windows.WindowState.Minimized)
         {
             window.Visibility = System.Windows.Visibility.Visible;
             IntPtr hWnd       = new System.Windows.Interop.WindowInteropHelper(window).Handle;
             Restore(hWnd);
         }
     });
 }
Example #24
0
 //"Неопределенный" прогресс для окна, так-же возвращает Handle этого окна
 public static void SetProgressIndeterminate(System.Windows.Window wnd, ref IntPtr Handle)
 {
     try
     {
         if (IsInitialized)
         {
             Handle = new System.Windows.Interop.WindowInteropHelper(wnd).Handle;
             SetProgressState(Handle, TBPF.INDETERMINATE);
         }
     }
     catch { }
 }
Example #25
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Document        doc             = commandData.Application.ActiveUIDocument.Document;
            BuiltInCategory builtInCategory = BuiltInCategory.OST_Doors;

            // Call WPF for user input
            using (NumberDoorsWPF customWindow = new NumberDoorsWPF(commandData))
            {
                // Revit application as window's owner
                System.Windows.Interop.WindowInteropHelper helper = new System.Windows.Interop.WindowInteropHelper(customWindow);
                helper.Owner = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle;

                customWindow.ShowDialog();

                // Retrieve user input
                Phase     phase     = customWindow.SelectedComboItemPhase.Tag as Phase;
                Parameter parameter = null;
                if (customWindow.SelectedComboItemParameters != null)
                {
                    parameter = customWindow.SelectedComboItemParameters.Tag as Parameter;
                }
                else
                {
                    TaskDialog.Show("Error", "Please create doors in the project first");
                    return(Result.Failed);
                }
                bool   numeric   = customWindow.optNumeric;
                string separator = customWindow.Separator;

                // Count doors renumbered
                int countInstances = 0;
                if (separator == null)
                {
                    return(Result.Cancelled);
                }
                else
                {
                    Helpers.Helpers.numberFamilyInstance(doc, phase, numeric, separator, builtInCategory, ref countInstances, parameter);
                }

                // Display result to user if any door was numbered
                if (countInstances > 0)
                {
                    TaskDialog.Show("Success", countInstances.ToString() + " doors numbered");
                    return(Result.Succeeded);
                }
                else
                {
                    TaskDialog.Show("Warning", "No doors numbered");
                    return(Result.Failed);
                }
            }
        }
Example #26
0
        public static (WindowInfo, ProgramInfo)? GetFromWpfWindow(System.Windows.Window window)
        {
            var handle = new System.Windows.Interop.WindowInteropHelper(window).Handle;

            if (handle == IntPtr.Zero)
            {
                return(null);
            }

            NativeMethods.GetWindowThreadProcessId(handle, out var processId);

            return(new WindowInfo(window.Title, window.Icon), new ProgramInfo(processId));
        }
Example #27
0
        public void Unregist(Window window)
        {
            var win  = new System.Windows.Interop.WindowInteropHelper(window);
            var hWnd = win.Handle;

            lock (_locker)
            {
                foreach (var pair in _dictHotKeyId2hWnd.Where(var => var.Value == hWnd).ToArray())
                {
                    Unregist(pair.Key);
                }
            }
        }
Example #28
0
 private void SetCurrentWindowToTop()
 {
     //目前除了让窗口置顶(TOP_MOST),只找到这种方法能让窗口前置
     if (IsHostBackground)
     {
         var handleCurrent    = new System.Windows.Interop.WindowInteropHelper(this).Handle;
         var handleHostWindow = new System.Windows.Interop.WindowInteropHelper(hostWindow).Handle;
         WinAPI.SetWindowOrder(handleCurrent, handleHostWindow);
         this.Visibility = Visibility.Hidden;
         this.Visibility = Visibility.Visible;
         this.Activate();
     }
 }
Example #29
0
        public MainWindow()
        {
            var vm = new MainWindowViewModel();

            InitializeComponent();
            DataContext   = vm;
            ShowInTaskbar = true;
            IntPtr hwnd     = new System.Windows.Interop.WindowInteropHelper(this).Handle;
            int    oldStyle = Win32Helper.GetWindowLong(hwnd, Win32Helper.GWL_STYLE);

            Win32Helper.SetWindowLong(hwnd, Win32Helper.GWL_STYLE, oldStyle & ~Win32Helper.WS_BORDER & ~Win32Helper.WS_CAPTION & ~Win32Helper.WS_DLGFRAME);
            initTaskbarIcon();
        }
Example #30
0
        private void Button_Click_Resize_Forms(object sender, RoutedEventArgs e)
        {
            Console.WriteLine("Button_Click_Forms");

            var    window = new System.Windows.Interop.WindowInteropHelper(this);
            IntPtr hWnd   = window.Handle;
            var    screen = System.Windows.Forms.Screen.FromHandle(hWnd);

            Left   = screen.WorkingArea.Left;
            Top    = screen.WorkingArea.Top;
            Width  = screen.WorkingArea.Width;
            Height = screen.WorkingArea.Height;
        }
Example #31
0
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Interop.WindowInteropHelper winHelper = new System.Windows.Interop.WindowInteropHelper(Application.Current.MainWindow);
            IntPtr mainWindowHandle = winHelper.Handle;

            SetWindowPos(Process.Start(@"C:\WINDOWS\system32\osk.exe").MainWindowHandle,
                         mainWindowHandle,
                         0,
                         0,
                         1000,
                         500,
                         SWP_NOACTIVATE);
        }
Example #32
0
        public static void ShowSystemMenu(Window window)
        {
            var hWnd = new System.Windows.Interop.WindowInteropHelper(window).Handle;

            GetWindowRect(hWnd, out var pos);
            var hMenu = GetSystemMenu(hWnd, false);
            var cmd   = TrackPopupMenu(hMenu, 0x100, pos.Left + 20, pos.Top + 20, 0, hWnd, IntPtr.Zero);

            if (cmd > 0)
            {
                SendMessage(hWnd, 0x112, (IntPtr)cmd, IntPtr.Zero);
            }
        }
 public static void SetOwnerToExcel(this Window window)
 {
     try
     {
         var app = ExcelUtil.Application;
         var helper = new System.Windows.Interop.WindowInteropHelper(window);
         helper.Owner = (IntPtr)app.Hwnd;
     }
     catch
     {
         // not fatal, just resume
     }
 }
Example #34
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            IntPtr handle   = new System.Windows.Interop.WindowInteropHelper(this).Handle;
            int    oldStyle = (int)(Win32API.GetWindowLong(handle, -20));

            //-20 GWL_EXSTYLE 窗口样式
            //0x00000080=WS_EX_TOOLWINDOW 小标题工具窗口 在Alt+tab中不会显示此窗口
            //0x08000000=WS_EX_NOACTIVATE 窗口不会变成前台
            //0x80000=WS_EX_LAYERED 窗口具有透眀属性 大概是没用
            //0x20=WS_EX_TRANSPARENT 窗口透明 这里其实是指的窗口不会捕获鼠标事件 鼠标可以穿过窗口点击到后面的东西
            //https://www.cnblogs.com/wangjixianyun/p/3427453.html
            Win32API.SetWindowLong(handle, -20, (IntPtr)(oldStyle | 0x00000080 | 0x08000000 | 0x80000 | 0x20));
        }
Example #35
0
 public override void ShowWindow(object rootModel, object context = null, IDictionary <string, object> settings = null)
 {
     System.Windows.Window window = CreateWindow(rootModel, true, context, settings);
     if (window != null)
     {
         System.Windows.Interop.WindowInteropHelper helper = new System.Windows.Interop.WindowInteropHelper(window);
         helper.Owner              = Autodesk.Windows.ComponentManager.ApplicationWindow;
         window.SourceInitialized += Window_SourceInitialized;
         window.SizeChanged       += Window_SizeChanged;
         window.LocationChanged   += Window_LocationChanged;
     }
     window.Show();
 }
Example #36
0
        /// <summary>
        /// Sets the given WPF window as topmost or not topmost using a user32 pinvoke call
        /// </summary>
        /// <param name="window">The window to set as topmost</param>
        /// <param name="topMost">True to set window as topmost, false to remove topmost property</param>
        public static void SetTopMost(System.Windows.Window window, bool topMost)
        {
            var handle = new System.Windows.Interop.WindowInteropHelper(window).Handle;

            if (topMost)
            {
                User32.SetWindowPos(handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOMOVE);
            }
            else
            {
                User32.SetWindowPos(handle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOMOVE);
            }
        }
Example #37
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            IntPtr handle = new System.Windows.Interop.WindowInteropHelper(this).Handle;

            if (!Api.RegisterHotKey(handle, REC_HOT_KEY_ID, 0, Keys.F6)) // 注册热键f6
            {
                TextBlock_Info.Text = "注册“录制”热键失败!";
            }
            if (!Api.RegisterHotKey(handle, EXE_HOT_KEY_ID, 0, Keys.F7)) // 注册热键f7
            {
                TextBlock_Info.Text = "注册“执行”热键失败!";
            }
        }
Example #38
0
        /// <summary>
        /// Helper method used to dock a Wpf window inside a Vst Window.
        /// All UI chrome is hidden away (borders, close/minimize/maximize buttons)
        /// and the window becomes embedded inside the parent window
        /// </summary>
        /// <param name="WpfWindow"></param>
        /// <param name="vstWindow"></param>
        public static void DockWpfWindow(System.Windows.Window WpfWindow, IntPtr vstWindow)
        {
            WpfWindow.Top           = 0;
            WpfWindow.Left          = 0;
            WpfWindow.ShowInTaskbar = false;
            WpfWindow.WindowStyle   = System.Windows.WindowStyle.None;
            WpfWindow.ResizeMode    = System.Windows.ResizeMode.NoResize;
            WpfWindow.Show();
            var    windowHwnd = new System.Windows.Interop.WindowInteropHelper(WpfWindow);
            IntPtr hWnd       = windowHwnd.Handle;

            SetParent(hWnd, vstWindow);
        }
Example #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);

            rdbSQL.IsChecked             = false;
            rdbWindows.IsChecked         = true;
            lblGebruikersnaam.Visibility = Visibility.Hidden;
            lblPaswoord.Visibility       = Visibility.Hidden;
            txtGebruikersnaam.Visibility = Visibility.Hidden;
            txtPaswoord.Visibility       = Visibility.Hidden;
        }
Example #40
0
        public static void RemoveWindowIcon(Window window)
        {
            IntPtr hWnd = new System.Windows.Interop.WindowInteropHelper(window).Handle;

            SendMessage(hWnd, WM_SETICON, new IntPtr(1), IntPtr.Zero);
            SendMessage(hWnd, WM_SETICON, IntPtr.Zero, IntPtr.Zero);

            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);
        }
Example #41
0
        public virtual void ShowAccountsPopup( )
        {
            Window.Dispatcher.Invoke(() =>
            {
                var signInWindow = new SpecklePopup.SignInWindow();

                var helper   = new System.Windows.Interop.WindowInteropHelper(signInWindow);
                helper.Owner = new System.Windows.Interop.WindowInteropHelper(Window).Handle;

                signInWindow.ShowDialog();
                DispatchStoreActionUi("getAccounts");
            });
        }
Example #42
0
 private void buttonConnect_Click(object sender, RoutedEventArgs e)
 {
     lock (buttonConnectLock)
     {
         this.Dispatcher.Invoke((Action) delegate()
         {
             IntPtr myWindowHandle = new System.Windows.Interop.WindowInteropHelper(this).Handle;
             if (myWindowHandle != IntPtr.Zero)
             {
                 IntPtr myInputQueue = IntPtr.Zero;
                 Mubox.Win32.Threads.GetWindowThreadProcessId(myWindowHandle, out myInputQueue);
                 if (myInputQueue != IntPtr.Zero)
                 {
                     Mubox.Control.Network.Client.MyInputQueue = myInputQueue;
                 }
                 else
                 {
                     Debug.WriteLine("GetWindowThreadProcessId Failed for " + this.ClientState.Settings.Name);
                 }
             }
             else
             {
                 Debug.WriteLine("WindowInteropHelper Failed for " + this.ClientState.Settings.Name);
             }
         });
         if (ClientState.NetworkClient == null)
         {
             try
             {
                 clientState_SetStatusText("Connecting...");
                 ClientState.NetworkClient = new Mubox.Control.Network.Client
                 {
                     DisplayName         = ClientState.Settings.Name,
                     WindowStationHandle = ClientState.WindowStationHandle,
                     WindowDesktopHandle = ClientState.WindowDesktopHandle,
                     WindowHandle        = ClientState.Settings.WindowHandle
                 };
                 ClientState.NetworkClient.Connected    += new EventHandler <EventArgs>(Client_Connected);
                 ClientState.NetworkClient.Disconnected += new EventHandler <EventArgs>(Client_Disconnected);
                 ClientState.NetworkClient.Connect(ClientState.Settings.ServerName, ClientState.Settings.ServerPortNumber);
                 tabControl1.SelectedItem  = tabGameSettings;
                 clientState_AutoReconnect = true;
             }
             catch (Exception ex)
             {
                 ClientState.NetworkClient = null;
                 clientState_SetStatusText("Connect Failed: " + ex.Message);
             }
         }
     }
 }
Example #43
0
        /// <summary>
        /// Sets the given WPF window as "transparent", which allows the mouse to "click-through" the window
        /// </summary>
        /// <param name="hwnd">The window to set as click-through transparent</param>
        public static void SetWindowExTransparent(System.Windows.Window window, bool isTransparent)
        {
            var handle = new System.Windows.Interop.WindowInteropHelper(window).Handle;
            var extendedStyle = GetWindowLong(handle, GWL_EXSTYLE);

            if (isTransparent)
            {
                SetWindowLong(handle, GWL_EXSTYLE, extendedStyle | WS_EX_TRANSPARENT);
            }
            else
            {
                SetWindowLong(handle, GWL_EXSTYLE, extendedStyle & ~WS_EX_TRANSPARENT);
            }
        }
Example #44
0
        public void ShowAccountPopup( )
        {
            RhinoApp.InvokeOnUiThread(new Action(() =>
                                                 //Window.Dispatcher.Invoke( ( ) =>
            {
                var signInWindow = new SpecklePopup.SignInWindow(true);

                var helper   = new System.Windows.Interop.WindowInteropHelper(signInWindow);
                helper.Owner = RhinoApp.MainWindowHandle();

                signInWindow.ShowDialog();
                NotifySpeckleFrame("refresh-accounts", "", "");
            }));
        }
Example #45
0
        public DXWavePlayer(int device, int BufferByteSize, DataRequestDelegate fillProc)
        {
            if (BufferByteSize < 1000)
            {
                throw new ArgumentOutOfRangeException("BufferByteSize", "minimal size of buffer is 1000 bytes");
            }

            _buffersize = BufferByteSize;
            _requestproc = fillProc;
            var devices = DirectSound.GetDevices();
            if (device <= 0 || device >= devices.Count)
            {
                device = 0;
            }

            _outputDevice = new DirectSound(devices[device].DriverGuid);

            System.Windows.Interop.WindowInteropHelper wh = new System.Windows.Interop.WindowInteropHelper(Application.Current.MainWindow);
            _outputDevice.SetCooperativeLevel(wh.Handle, CooperativeLevel.Priority);

            _buffDescription = new SoundBufferDescription();
            _buffDescription.Flags = BufferFlags.ControlPositionNotify | BufferFlags.ControlFrequency | BufferFlags.ControlEffects | BufferFlags.GlobalFocus | BufferFlags.GetCurrentPosition2;
            _buffDescription.BufferBytes = BufferByteSize * InternalBufferSizeMultiplier;

            WaveFormat format = new WaveFormat(16000, 16, 1);

            _buffDescription.Format = format;

            _soundBuffer = new SecondarySoundBuffer(_outputDevice, _buffDescription);
            _synchronizer = new AutoResetEvent(false);

            NotificationPosition[] nots = new NotificationPosition[InternalBufferSizeMultiplier];

            NotificationPosition not;
            int bytepos = 800;
            for (int i = 0; i < InternalBufferSizeMultiplier; i++)
            {
                not = new NotificationPosition();
                not.Offset = bytepos;
                not.WaitHandle = _synchronizer;
                nots[i] = not;
                bytepos += BufferByteSize;
            }

            _soundBuffer.SetNotificationPositions(nots);

            _waitThread = new Thread(new ThreadStart(DataRequestThread)) { Name = "MyWavePlayer.DataRequestThread" };
            _waitThread.Start();
        }
Example #46
0
 internal static void FlashWindow(Window window, int times = -1)
 {
     if ( Environment.OSVersion.Platform == PlatformID.Win32NT )
     {
         FLASHWINFO fInfo = new FLASHWINFO();
         var ptr = new System.Windows.Interop.WindowInteropHelper( window );
         fInfo.cbSize = Convert.ToUInt32( Marshal.SizeOf( fInfo ) );
         fInfo.hwnd = ptr.Handle;
         //fInfo.dwFlags = FLASHW_TIMERNOFG;
         fInfo.dwFlags = FLASHW_TRAY | 8;
         fInfo.uCount = (uint)( times <= 0 ? 3 : times );
         fInfo.dwTimeout = 0;
         FlashWindowEx( ref fInfo );
     }
 }
Example #47
0
        private void OnItemDoubleClicked(object sender, MouseEventArgs e)
        {
            var helper = new System.Windows.Interop.WindowInteropHelper(App.Current.MainWindow);
            var screen = System.Windows.Forms.Screen.FromHandle(helper.Handle);
            var height = screen.Bounds.Height;

            var path = this.lstPhoto.SelectedItem as Uri;
            var bmp = new BitmapImage();
            bmp.BeginInit();
            bmp.UriSource = path;
            bmp.DecodePixelHeight = height;
            bmp.EndInit();

            var image = new Image() { Source = bmp};
            LightBox.Show(this, image);
        }
Example #48
0
        public void Show(IWaitIndicatorAppearance appearance, double left, double top, double width, double height)
        {
            this.Left = left;
            this.Top = top;
            this.Width = width;
            this.Height = height;
            m_ViewModel.Appearance = appearance; // determine "appearance" yet before Show()

            var wih = new System.Windows.Interop.WindowInteropHelper(this);
            wih.EnsureHandle();
            Win32.User32.SetWindowLongPtr(new HandleRef(wih, wih.Handle), Win32.User32.GWL_HWNDPARENT, appearance.OwnerHwnd);

            Show();

            m_ViewModel.WaitWindowVisualState = "Active";
        }
 // Displays the object property window
 private void ResultGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
 {
     var selected = GetFirstSelected () ;
     if ( selected != null ) {
         HWNDWrapper mww ;
         try {
             // Try with a Maya host first
             System.Windows.Forms.NativeWindow wnd =Runtime.MayaApplication.MainWindow ;
             IntPtr mwh =MDockingStation.GetMayaMainWindow () ;
             mww =new HWNDWrapper (mwh) ;
         } catch {
             // We are in standalone mode (WPF application)
             IntPtr mwh =new System.Windows.Interop.WindowInteropHelper (Application.Current.MainWindow).Handle ;
             mww =new HWNDWrapper (mwh) ;
         }
         Form1 t =new Form1 (selected) ;
         t.ShowDialog (mww) ;
     }
 }
        public EditOutputCoordinateView(ObservableCollection<DefaultFormatModel> formats, List<string> names, OutputCoordinateModel outputCoordItem)
        {
            InitializeComponent();

            var vm = this.DataContext as EditOutputCoordinateViewModel;

            if (vm == null)
                return;

            vm.DefaultFormats = formats;
            vm.OutputCoordItem = outputCoordItem;
            vm.Names = names;

            var win = Window.GetWindow(this);

            if(win != null)
            {
                var temp = new System.Windows.Interop.WindowInteropHelper(win);

            }
        }
        /// <summary>
        /// Called when the command is in interactive (window) mode
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        static Result RunInteractive(ViewModels.InsertCommandViewModel model)
        {
            var result = Result.Cancel;

              #region Windows Specific UI
              #if ON_OS_WINDOWS
              var window = new Win.InsertCommandWindow();
              model.Window = window;
              // Attach the view model to the window
              window.DataContext = model;
              // Need to set the Rhino main frame window as the parent
              // for the new window otherwise the window will go behind
              // the main frame when the Rhino is deactivated then
              // activated again.
              // http://blogs.msdn.com/b/mhendersblog/archive/2005/10/04/476921.aspx
              var interopHelper = new System.Windows.Interop.WindowInteropHelper(window);
              interopHelper.Owner = Rhino.RhinoApp.MainWindowHandle();
              window.ShowDialog();
              result = (true == window.DialogResult ? Result.Success : Result.Cancel);
              #endif
              #endregion

              #region Mac Specific UI

              #if ON_OS_MAC
              // Create a NSWindow from a Nib file
              var window = RhinoMac.Window.FromNib("InsertWindow", model);
              // Associate the window with the View Model so that the
              // model's Okay and Cancel methods can close the window
              model.Window = window;
              // Display the window
              window.ShowModal();
              // Success will be true if the window was closed by the
              // OK button otherwise it should be false.
              result = (window.DialogResult == true ? Result.Success : Result.Cancel);
              #endif
              #endregion

              return result;
        }
        /// <summary>
        /// Take over control. When this function exits, Chronos is in charge again.
        /// </summary>
        /// <remarks>
        /// We show some dialog window to make clear what we are doing, and that we are in charge.
        /// </remarks>
        public void DoYourJob()
        {
            // Use the process' main window as owner, so that our blocking
            // window can not be hidden behind the main window.
            System.Windows.Window win = null;
            var mainHandle = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle;

            DoOnGUIThread(new Action(() =>
            {
                win = new ShowPluginIsInCharge();
                var wih = new System.Windows.Interop.WindowInteropHelper(win);
                var myHandle = wih.EnsureHandle();
                wih.Owner = mainHandle;
                win.Show();
            }));
            try
            {
                do
                {
                    System.Threading.Thread.Sleep(5000);
                    var ex = RunSampleList(this,
                        new AxelSemrau.Chronos.Plugin.RunSampleListEventArgs()
                        {
                            //SampleListFile = @"C:\Users\Patrick\Documents\Chronos\MoveTest.csl"
                            ExtendLastPlanner = true,
                            StartAndWaitForEnd = false
                        }
                    );
                    if (ex != null)
                    {
                        System.Windows.Forms.MessageBox.Show("Error: " + ex.Message, "Plugin Provided Schedule",System.Windows.Forms.MessageBoxButtons.OK,System.Windows.Forms.MessageBoxIcon.Error);
                    }
                } while (OneMoreScheduleWanted(mainHandle));
            }
            finally
            {
                DoOnGUIThread(new Action(() => win.Close()));
            }
        }
        /// <summary>
        /// Sets the window's icon visibility.
        /// </summary>
        /// <param name="window">The window to set.</param>
        /// <param name="showIcon"><c>true</c> to show the icon in the caption; otherwise, <c>false</c></param>
        public static void SetWindowIconVisibility(Window window, bool showIcon)
        {
            System.Windows.Interop.WindowInteropHelper wih = new System.Windows.Interop.WindowInteropHelper(window);

            // For Vista/7 and higher
            if (Environment.OSVersion.Version.Major >= 6)
            {
                // Change the extended window style
                if (showIcon)
                {
                    int extendedStyle = NativeMethods.GetWindowLong(wih.Handle, NativeMethods.GWL_EXSTYLE);
                    NativeMethods.SetWindowLong(wih.Handle, NativeMethods.GWL_EXSTYLE, extendedStyle | ~NativeMethods.WS_EX_DLGMODALFRAME);
                }
                else
                {
                    int extendedStyle = NativeMethods.GetWindowLong(wih.Handle, NativeMethods.GWL_EXSTYLE);
                    NativeMethods.SetWindowLong(wih.Handle, NativeMethods.GWL_EXSTYLE, extendedStyle | NativeMethods.WS_EX_DLGMODALFRAME);
                }

                // Update the window's non-client area to reflect the changes
                NativeMethods.SetWindowPos(wih.Handle, IntPtr.Zero, 0, 0, 0, 0,
                                           NativeMethods.SWP_NOMOVE | NativeMethods.SWP_NOSIZE | NativeMethods.SWP_NOZORDER | NativeMethods.SWP_FRAMECHANGED);
            }
            // For XP and older
            // TODO Setting Window Icon visibility doesn't work in XP
            else
            {
                // 0 - ICON_SMALL (caption bar)
                // 1 - ICON_BIG   (alt-tab)

                if (showIcon)
                    NativeMethods.SendMessage(wih.Handle, NativeMethods.WM_SETICON, new IntPtr(0),
                                              NativeMethods.DefWindowProc(wih.Handle, NativeMethods.WM_SETICON, new IntPtr(0), IntPtr.Zero));
                else
                    NativeMethods.SendMessage(wih.Handle, NativeMethods.WM_SETICON, new IntPtr(0), IntPtr.Zero);
            }
        }
Example #54
0
 public Wpf32Window(Window wpfWindow)
 {
     Handle = new System.Windows.Interop.WindowInteropHelper(wpfWindow).Handle;
 }
Example #55
0
		/// <summary>
		/// Extends the aero glass to the edge of the window
		/// </summary>
		/// <param name="window">
		/// The window to be affected
		/// </param>
		/// <param name="margin">
		/// The window margins
		/// </param>
		/// <returns>
		/// Returns true/false depending on success
		/// </returns>
		public static bool ExtendGlassFrame (sw.Window window, sw.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 sw.Interop.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 = swm.Brushes.Transparent;
				sw.Interop.HwndSource.FromHwnd (hwnd).CompositionTarget.BackgroundColor = swm.Colors.Transparent;

				var margins = new MARGINS (margin);
				DwmExtendFrameIntoClientArea (hwnd, ref margins);
				return true;
			}
			catch {
				return false;
			}
		}
Example #56
0
		public static bool BlurBehindWindow (sw.Window window)
		{
			if (!DwmIsCompositionEnabled ())
				return false;

			var windowInteropHelper = new sw.Interop.WindowInteropHelper (window);
			IntPtr myHwnd = windowInteropHelper.Handle;
			var mainWindowSrc = System.Windows.Interop.HwndSource.FromHwnd (myHwnd);

			window.Background = swm.Brushes.Transparent;
			mainWindowSrc.CompositionTarget.BackgroundColor = swm.Colors.Transparent;

			var blurBehindParameters = new DWM_BLURBEHIND ();
			blurBehindParameters.dwFlags = DwmBlurBehindFlags.DWM_BB_ENABLE;
			blurBehindParameters.fEnable = true;
			blurBehindParameters.hRgnBlur = IntPtr.Zero;

			DwmEnableBlurBehindWindow (myHwnd, ref blurBehindParameters);
			int val = 1;
			DwmSetWindowAttribute (myHwnd, DwmWindowAttribute.DWMWA_TRANSITIONS_FORCEDISABLED, ref val, sizeof (int));
			return true;
		}
 private void MassagePresentParameters(PresentationParameters pp)
 {
     bool flag = pp.BackBufferWidth == 0;
     bool flag2 = pp.BackBufferHeight == 0;
     if (!pp.IsFullScreen)
     {
         NativeMethods.RECT rect;
         IntPtr deviceWindowHandle = pp.DeviceWindowHandle;
         if (deviceWindowHandle == IntPtr.Zero)
         {
             if (this.game == null)
             {
                 throw new InvalidOperationException(Resources.GraphicsComponentNotAttachedToGame);
             }
             deviceWindowHandle = new System.Windows.Interop.WindowInteropHelper(this.game.Window).Handle;
         }
         NativeMethods.GetClientRect(deviceWindowHandle, out rect);
         if (flag && (rect.Right == 0))
         {
             pp.BackBufferWidth = 1;
         }
         if (flag2 && (rect.Bottom == 0))
         {
             pp.BackBufferHeight = 1;
         }
     }
 }
 private void AddDevices(bool anySuitableDevice, List<GraphicsDeviceInformation> foundDevices)
 {
     IntPtr handle =  new System.Windows.Interop.WindowInteropHelper(this.game.Window).Handle;
     foreach (GraphicsAdapter adapter in GraphicsAdapter.Adapters)
     {
         //if (anySuitableDevice)// || this.IsWindowOnAdapter(handle, adapter))
         {
             foreach (DeviceType type in ValidDeviceTypes)
             {
                 try
                 {
                     if (adapter.IsDeviceTypeAvailable(type))
                     {
                         GraphicsDeviceCapabilities capabilities = adapter.GetCapabilities(type);
                         if ((capabilities.DeviceCapabilities.IsDirect3D9Driver && IsValidShaderProfile(capabilities.MaxPixelShaderProfile, this.MinimumPixelShaderProfile)) && IsValidShaderProfile(capabilities.MaxVertexShaderProfile, this.MinimumVertexShaderProfile))
                         {
                             GraphicsDeviceInformation baseDeviceInfo = new GraphicsDeviceInformation();
                             baseDeviceInfo.Adapter = adapter;
                             baseDeviceInfo.DeviceType = type;
                             baseDeviceInfo.PresentationParameters.DeviceWindowHandle = IntPtr.Zero;
                             baseDeviceInfo.PresentationParameters.EnableAutoDepthStencil = true;
                             baseDeviceInfo.PresentationParameters.BackBufferCount = 1;
                             baseDeviceInfo.PresentationParameters.PresentOptions = PresentOptions.None;
                             baseDeviceInfo.PresentationParameters.SwapEffect = SwapEffect.Discard;
                             baseDeviceInfo.PresentationParameters.FullScreenRefreshRateInHz = 0;
                             baseDeviceInfo.PresentationParameters.MultiSampleQuality = 0;
                             baseDeviceInfo.PresentationParameters.MultiSampleType = MultiSampleType.None;
                             baseDeviceInfo.PresentationParameters.IsFullScreen = this.IsFullScreen;
                             baseDeviceInfo.PresentationParameters.PresentationInterval = this.SynchronizeWithVerticalRetrace ? PresentInterval.One : PresentInterval.Immediate;
                             for (int i = 0; i < ValidAdapterFormats.Length; i++)
                             {
                                 this.AddDevices(adapter, type, adapter.CurrentDisplayMode, baseDeviceInfo, foundDevices);
                                 if (this.isFullScreen)
                                 {
                                     foreach (DisplayMode mode in adapter.SupportedDisplayModes[ValidAdapterFormats[i]])
                                     {
                                         if ((mode.Width >= 640) && (mode.Height >= 480))
                                         {
                                             this.AddDevices(adapter, type, mode, baseDeviceInfo, foundDevices);
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
                 catch (DeviceNotSupportedException)
                 {
                 }
             }
         }
     }
 }
        public override void CustomExecute(object parameter)
        {
            try
            {
                IGlobal global = Autodesk.Max.GlobalInterface.Instance;
                IInterface14 ip = global.COREInterface14;

                int nNumSelNodes = ip.SelNodeCount;
                if (nNumSelNodes <= 0)
                {
                    ip.PushPrompt("No nodes are selected. Please select at least one node to convert, before running the command.");
                    return;
                }

                System.Windows.Window dialog = new System.Windows.Window();
                dialog.Title = "Explode It!";
                dialog.SizeToContent = System.Windows.SizeToContent.WidthAndHeight;
                ExplodeGeomUserControl1 ctlExplode = new ExplodeGeomUserControl1(dialog);
                dialog.Content = ctlExplode;
                dialog.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner;
                dialog.ShowInTaskbar = false;
                dialog.ResizeMode = System.Windows.ResizeMode.NoResize;

                System.Windows.Interop.WindowInteropHelper windowHandle =
                    new System.Windows.Interop.WindowInteropHelper(dialog);
                windowHandle.Owner = ManagedServices.AppSDK.GetMaxHWND();
                ManagedServices.AppSDK.ConfigureWindowForMax(dialog);

                dialog.ShowDialog(); //modal version; this prevents changes being made to model while our dialog is running, etc.

            }
            catch (Exception ex)
            {
                Debug.Print(ex.Message);
            }
        }
Example #60
-1
 protected override void OnActivated(EventArgs e)
 {
     base.OnActivated(e);
       hwnd = new System.Windows.Interop.WindowInteropHelper(this);
       if (hwnd.Handle!=null && hwnd.Handle!=IntPtr.Zero) {
     nativeSource = System.Windows.Interop.HwndSource.FromHwnd(hwnd.Handle);
     nativeSource.AddHook(OnWindowMessage);
       }
 }