/// <summary> /// 提示信息 /// </summary> /// <param name="msg">信息</param> /// <param name="keepTime">彈窗顯示持續時間(毫秒)</param> public static void Info(string msg, int keepTime, Action callBack = null) { try { if (keepTime <= 0) { return; } if (Application.Current == null || Application.Current.MainWindow == null) { return; } if (Application.Current.Dispatcher.CheckAccess()) { if (Application.Current.MainWindow.WindowState == WindowState.Minimized) { return; } InkMessageBox box = new InkMessageBox() { Message = msg, KeepTime = keepTime, ToastBack = callBack }; RoutedEventHandler loadHandler = null; loadHandler = (sender, e) => { Window win = sender as Window; win.Loaded -= loadHandler; IntPtr hwnd = new WindowInteropHelper(win).Handle; if (hwnd != IntPtr.Zero) { NativeMethods.SetWindowLong(hwnd, NativeMethods.GwlExstyle, NativeMethods.WsExToolwindow); } }; box.Loaded += loadHandler; var winformWindow = (HwndSource.FromDependencyObject(Application.Current.MainWindow) as HwndSource); if (winformWindow != null) { new WindowInteropHelper(box) { Owner = winformWindow.Handle } } ; box.Show(); } else { Action <string, int, Action> func = Info; Application.Current.Dispatcher.Invoke(func, msg, keepTime, callBack); } } catch (Exception ex) { //LogFactory.Log.Error("MessageBox Info Error", ex); } }
void OnLoaded(object sender, RoutedEventArgs e) { this.Loaded -= new RoutedEventHandler(OnLoaded); this.SetParentToMainWindowOf(Model.Root.Manager); _hwndSrc = HwndSource.FromDependencyObject(this) as HwndSource; _hwndSrcHook = new HwndSourceHook(FilterMessage); _hwndSrc.AddHook(_hwndSrcHook); }
private void UILOADED__MainWindow_LayoutUpdated(object sender, EventArgs e) { HwndSource hwndSource = HwndSource.FromDependencyObject(Application.Current.MainWindow) as HwndSource; if (hwndSource == null) { return; } // sender comes as null so can't use it here Application.Current.MainWindow.LayoutUpdated -= UILOADED__MainWindow_LayoutUpdated; RunUILoadedActions(); }
private void _button修改用户资料_Click(object sender, RoutedEventArgs e) { ModifyUserInfo mui = new ModifyUserInfo(_Session.LoginedUserId); HwndSource winformWindow = (HwndSource.FromDependencyObject(this) as HwndSource); if (winformWindow != null) { new WindowInteropHelper(mui) { Owner = winformWindow.Handle }; } mui.ShowDialog(); }
private void _btn交易品种_Click(object sender, RoutedEventArgs e) { CommodityDialog cd = new CommodityDialog(); HwndSource winformWindow = (HwndSource.FromDependencyObject(this) as HwndSource); if (winformWindow != null) { new WindowInteropHelper(cd) { Owner = winformWindow.Handle }; } cd.ShowDialog(); }
private void OnLoaded(object sender, RoutedEventArgs e) { this.Loaded -= new RoutedEventHandler(OnLoaded); this.SetParentToMainWindowOf(Model.Root.Manager); _hwndSrc = HwndSource.FromDependencyObject(this) as HwndSource; _hwndSrcHook = new HwndSourceHook(FilterMessage); _hwndSrc.AddHook(_hwndSrcHook); // Restore maximize state var maximized = Model.Descendents().OfType <ILayoutElementForFloatingWindow>().Any(l => l.IsMaximized); UpdateMaximizedState(maximized); }
void InitializeWin32Hooks() { user32.ChangeWindowMessageFilter((int)dwmapi.WM_Messages.WM_DWMSENDICONICTHUMBNAIL, user32.ChangeWindowMessageFilterFlags.MSGFLT_ADD); user32.ChangeWindowMessageFilter((int)dwmapi.WM_Messages.WM_DWMSENDICONICLIVEPREVIEWBITMAP, user32.ChangeWindowMessageFilterFlags.MSGFLT_ADD); HwndSource hwndSource = HwndSource.FromDependencyObject(Application.Current.MainWindow) as HwndSource; hwndSource.AddHook(HwndSourceHook); //if (Config.IsEnabled) //{ dwmapi.EnableCustomWindowPreview(MainWindowHandle); //} RequestRefresh(); }
/// <summary> /// 设置窗体的父窗体 /// </summary> private void SetWindowOwner(Window win) { HwndSource winformWindow = HwndSource.FromDependencyObject(this) as HwndSource; if (winformWindow != null) { new WindowInteropHelper(win) { Owner = winformWindow.Handle } } ; if (win.Owner != null) { AppConst.winMain = win.Owner;//赋值给保存起来 } }
private bool SelectTypes(out List <Type> selectedTypes) { SelectTableNameList st = new SelectTableNameList(); this.Dispatcher.Invoke(new FormControlInvoker(() => { HwndSource winformWindow = (HwndSource.FromDependencyObject(this) as HwndSource); if (winformWindow != null) { new WindowInteropHelper(st) { Owner = winformWindow.Handle }; } st.ShowDialog(); })); selectedTypes = st.SelectedTypes; return(st.DialogResult.Value); }
private void _button添加配资账户_Click(object sender, RoutedEventArgs e) { AddCooperateAccountDialog aaf = new AddCooperateAccountDialog(); HwndSource winformWindow = (HwndSource.FromDependencyObject(this) as HwndSource); if (winformWindow != null) { new WindowInteropHelper(aaf) { Owner = winformWindow.Handle }; } aaf.ShowDialog(); // if (aaf.DialogResult.Value) { InitializeAccountList(); } }
public void RegisterVisualStudioUILoadedAction(Action action) { //! this methid must run on UI thread // because it accesses Main Window if (!UIService.IsUIThread) { UIService.Run(() => RegisterVisualStudioUILoadedAction(action)); return; } if (Application.Current.MainWindow == null) { UILoadedActions.Enqueue(action); // Main Window not yet created, listen to Activated event and perform actions when it is raised // make sure the handler is added only once (it is safe to try to remove handler even if it's not there) Application.Current.Activated -= UILOADED__CurrentApplication_Activated; Application.Current.Activated += UILOADED__CurrentApplication_Activated; } else { HwndSource hwndSource = HwndSource.FromDependencyObject(Application.Current.MainWindow) as HwndSource; if (hwndSource == null) { // Main Window created but not yet ready UILoadedActions.Enqueue(action); // make sure the handler is added only once (it is safe to try to remove handler even if it's not there) Application.Current.MainWindow.LayoutUpdated -= UILOADED__MainWindow_LayoutUpdated; Application.Current.MainWindow.LayoutUpdated += UILOADED__MainWindow_LayoutUpdated; } else { action(); } } }
private void _menuItemP查看数据_Click(object sender, RoutedEventArgs e) { if (selectedAccountItem == null) { return; } if (selectedAccountItem.Type != 2 && selectedAccountItem.Type != 20) { return; } ImportCooperateDataDialog acdd = new ImportCooperateDataDialog(selectedAccountItem.Id); HwndSource winformWindow = (HwndSource.FromDependencyObject(this) as HwndSource); if (winformWindow != null) { new WindowInteropHelper(acdd) { Owner = winformWindow.Handle }; } acdd.ShowDialog(); }
private void _button添加账户_Click(object sender, RoutedEventArgs e) { AddAccountWindow aaf = new AddAccountWindow(); HwndSource winformWindow = (HwndSource.FromDependencyObject(this) as HwndSource); if (winformWindow != null) { new WindowInteropHelper(aaf) { Owner = winformWindow.Handle }; } aaf.ShowDialog(); // if (aaf.DialogResult.Value) { using (StatementContext statement = new StatementContext(typeof(Account))) { InitializeAccountList(); } } }
protected static HwndSource GetSafeHwndSource(Object owner) { HwndSource source = null; if (owner is DependencyObject) { source = HwndSource.FromDependencyObject(owner as DependencyObject) as HwndSource; } else if (owner is Visual) { source = HwndSource.FromVisual(owner as Visual) as HwndSource; } else if (owner is IntPtr) { source = HwndSource.FromHwnd((IntPtr)owner) as HwndSource; } if (source != null) { return(source); } return(HwndSource.FromHwnd(HwndHelper.GetForegroundWindow()) as HwndSource); }
void AttachWindow() { _hwndSrc = HwndSource.FromDependencyObject(WrappedWindow) as HwndSource; _hwndSrcHook = new HwndSourceHook(this.HookHandler); _hwndSrc.AddHook(_hwndSrcHook); }
void OnLoaded(object sender, RoutedEventArgs e) { _hwndSrc = HwndSource.FromDependencyObject(this) as HwndSource; _hwndSrcHook = FilterMessage; _hwndSrc.AddHook(_hwndSrcHook); }