第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請及時(shí)綁定郵箱和手機(jī)立即綁定

把WPF Dialog轉(zhuǎn)成WinForm Dialog需要注意的問題續(xù)

標(biāo)簽:
資訊

上一篇讲到将WPF的窗口转为WinForm窗口需要注意的问题,这里给出了另一种解决方案,闲话不说,请看代码:

?

//==============================================================================//  File Name   :   WpfModalDialogFixer.cs////  Copyright (C) 2010 GrapeCity Inc. All rights reserved.////  Distributable under LGPL license.////============================================================================== // <fileinformation>//   <summary>//     This file defines the class WpfModalDialogFixer for solve the problem as below://     When showing a modal dialog which ShowTaskBar is false, first deactive the application the activate it again.//     The modal dialog would be at behind of MainWindow.//   </summary>//   <author name="WinkingZhang" mail="Winking.Zhang@GrapeCity.com"/>//   <seealso ref=""/>//   <remarks>//     //   </remarks>// </fileinformation> // <history>//   <record date="10/21/2010 6:07:04 PM" author="WinkingZhang" revision="1.00.000">//     Create the file and define the class.//   </record>// </history> using System;using System.Threading;using System.Windows;using System.Windows.Interop;using System.Runtime.InteropServices; namespace GrapeCity.Windows{    /// <summary>    ///   Represents the <see cref="WpfModalDialogFixer"/> class.    /// </summary>    public class WpfModalDialogFixer    {        [ThreadStatic]        private static WpfModalDialogFixer _fixer;        private static readonly object _rootSync = new object();         static WpfModalDialogFixer()        {            ComponentDispatcher.EnterThreadModal += new EventHandler(OnComponentDispatcherEnterThreadModal);            ComponentDispatcher.LeaveThreadModal += new EventHandler(OnComponentDispatcherLeaveThreadModal);        }         private WpfModalDialogFixer()        {        }         static void OnComponentDispatcherLeaveThreadModal(object sender, EventArgs e)        {            if (WpfModalDialogFixer.Current.Enable)            {                HwndSource src = HwndSource.FromVisual(Application.Current.MainWindow) as HwndSource;                if (src != null)                {                    src.RemoveHook(new HwndSourceHook(OnComponentDispatcherThreadPreprocessMessage));                }            }        }         static IntPtr OnComponentDispatcherThreadPreprocessMessage(IntPtr hwnd, int message, IntPtr wparam, IntPtr lparam, ref bool handled)        {            // Need take care the message: WM_SETFOCUS, and if now in Modal dialog mode.            if (message == 0x7 && ComponentDispatcher.IsThreadModal)            {                bool actived = false;                foreach (Window w in Application.Current.Windows)                {                    HwndSource src = HwndSource.FromVisual(w) as HwndSource;                    if (src != null /*&& src.Handle != hwnd*/)                    {                        if (IsWindowEnabled(src.Handle))                        {                            w.Activate();                            actived = true;                            break;                        }                    }                }                if (!actived) // in this case, caused by MessageBox.Show(...)                {                    //TODO: how to handle?                }                handled = true; // set handled to prevent default implement.            }            return IntPtr.Zero;        }         static void OnComponentDispatcherEnterThreadModal(object sender, EventArgs e)        {            if (WpfModalDialogFixer.Current.Enable)            {                HwndSource src = HwndSource.FromVisual(Application.Current.MainWindow) as HwndSource;                if (src != null)                {                    src.AddHook(new HwndSourceHook(OnComponentDispatcherThreadPreprocessMessage));                }            }        }         [DllImport("user32.dll")]        [return: MarshalAs(UnmanagedType.Bool)]        private static extern bool IsWindowEnabled(IntPtr hwnd);         public static WpfModalDialogFixer Current        {            get            {                if (_fixer == null)                {                    lock (_rootSync)                    {                        if (_fixer == null)                        {                            _fixer = new WpfModalDialogFixer();                        }                    }                }                return _fixer;            }        }         public bool Enable        {            get;            set;        }    }}
點(diǎn)擊查看更多內(nèi)容
TA 點(diǎn)贊

若覺得本文不錯(cuò),就分享一下吧!

評論

作者其他優(yōu)質(zhì)文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學(xué)習(xí),寫下你的評論
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊有機(jī)會(huì)得

100積分直接送

付費(fèi)專欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會(huì)
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)

舉報(bào)

0/150
提交
取消