⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainform.cs

📁 飞信的收发使用csharp进行开发
💻 CS
📖 第 1 页 / 共 5 页
字号:
namespace Imps.Client.Pc
{
    using Imps.Client;
    using Imps.Client.Base;
    using Imps.Client.CommLayer;
    using Imps.Client.Core;
    using Imps.Client.Logger;
    using Imps.Client.Pc.BizControls;
    using Imps.Client.Pc.Sensor;
    using Imps.Client.Pc.Theme;
    using Imps.Client.Pc.XControls;
    using Imps.Client.Resource;
    using Imps.Client.Utils;
    using Imps.Client.Utils.sensmon;
    using Imps.Client.Utils.Win32;
    using Imps.Common;
    using Imps.Utils;
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.IO;
    using System.Runtime.CompilerServices;
    using System.Runtime.InteropServices;
    using System.Threading;
    using System.Windows.Forms;
    using System.Xml;

    public class MainForm : XIMForm, IFrameworkWindow
    {
        private IAdBar _adBar;
        private EventWaitHandle _evSingleton;
        private OptionsForm _frmOptions;
        private uint _hotKey;
        private string _mainAppPath;
        private IUserAccountManager _mgrAccount;
        private IChannelManager _mgrChannel;
        private IContactManager _mgrContact;
        private IConversationManager _mgrConversation;
        private IImportExportManager _mgrImportExportManager;
        private IIVRManager _mgrIVRManager;
        private IMessageHistoryManager _mgrMessageHistory;
        private IOptionsManager _mgrOptions;
        private IPersistentManager _mgrPersistent;
        private Imps.Client.Pc.SystemMessageManager _mgrSysMsg;
        private volatile bool _suspended;
        private object _syncObjSensor;
        private IUnifiedMessageBox _unifiedMessageBox;
        private bool ChangeOnScreenSaverFlag;
        private volatile bool ChannelEventAttached;
        public const string CN_AccountManager = "UserAccountManager";
        public const string CN_AdBar = "AdBar";
        public const string CN_ChannelManager = "ChannelManager";
        public const string CN_ConnectionManager = "ConnectionManager";
        public const string CN_ContactManager = "ContactManager";
        public const string CN_ConversationManager = "ConversationManager";
        public const string CN_HistoryManager = "HistoryManager";
        public const string CN_ImportExportManager = "ImportExportManager";
        public const string CN_IVRManager = "IVRManager";
        public const string CN_Logger = "Logger";
        public const string CN_MessageHistoryManager = "MessageHistoryManager";
        public const string CN_OptionsManager = "OptionsManager";
        public const string CN_UnifiedMessageBox = "UnifiedMessageBox";
        private IContainer components;
        private HandleRef CurHandleRef;
        private const string DefaultLoggerArgs = @"Folder=%AppData%\Fetion\Log;Type=1;HisLen=9;Threshold=10;Category=11001";
        private const int HotKeyId = 0;
        private Imps.Client.Utils.sensmon.sensmon.sens_simple_notify_proc_type m_sens_lock_proc;
        private MenuStrip menuMain;
        private ToolStripMenuItem miOperation;
        private ToolStripMenuItem miToolsOptions;
        private const int SC_CLOSE = 0xf060;
        private const int SC_MAXIMIZE = 0xf030;
        private const int SC_MINIMIZE = 0xf020;
        private int screenSaverRunning;
        private const int ShowAdHeight = 400;
        private const int ShowUserInfoHeight = 300;
        private const int SPI_GETSCREENSAVERRUNNING = 0x72;
        private AutoResetEvent SuspendAre;
        private ImageList tbILHover;
        private ImageList tbILNomal;
        private XTabControl tcMain;
        private System.Windows.Forms.Timer timerMain;
        private XTabPage tpContactList;
        private NotifyIcon trayIcon;
        private int WM_TASKBARCREATED;

        public event EventHandler BeginSuspend;

        public event EventHandler MainWindowLoaded;

        public event EventHandler SuspendRestored;

        public MainForm() : this(new string[0])
        {
        }

        public MainForm(string[] args)
        {
            this.screenSaverRunning = -1;
            this._syncObjSensor = new object();
            if (this.TryCheckSingleton())
            {
                Environment.Exit(0);
            }
            else
            {
                try
                {
                    this.HandleExceptions();
                    this.InitLogger();
                    this.ParseArgs(args);
                    this.InitializeComponent();
                    this.trayIcon.Icon = ImpsTrayIcons.OffLine;
                    this.trayIcon.Visible = true;
                    base.Icon = ImpsIcons.Logo;
                    FuncDispatcher.SetMainWindow(this);
                    this.BuildMainMenu();
                    this.InitUiComponents();
                    this.TryLoadSkin();
                    this.DoLocalization();
                    this.RearrangeUiElements();
                    this.TryLoadWindowsSetting();
                    if (!this.CurrentUser.Configuration.UserSetting.MainWindowSetting.AutoPopup)
                    {
                        base.WindowState = FormWindowState.Minimized;
                        if (UserAccounts.LatestAccountAutoLogin)
                        {
                            base.ShowInTaskbar = false;
                        }
                    }
                    ImpsHelp.HelpPage = Imps.Client.Core.FixedClientSetting.Instance.HelpPage;
                    this.CurHandleRef = new HandleRef(this, base.Handle);
                    this.RegWndMsg();
                }
                catch (Exception exception)
                {
                    MessageBox.Show(exception.Message);
                    Process.GetCurrentProcess().Kill();
                }
            }
        }

        public void ActiveMainWindow()
        {
            try
            {
                base.Visible = true;
                if (base.WindowState == FormWindowState.Minimized)
                {
                    base.WindowState = FormWindowState.Normal;
                }
                base.ShowInTaskbar = true;
                ControlHelper.RepositionFormOnScreenSizeChanged(this);
                base.Activate();
                Imps.Client.Utils.Win32.NativeMethods.BringWindowToTop(base.Handle);
                IPresenceSensor sensor = this.CurrentUser.Presence.IndexOfSensor("MouseKeyboardSensor");
                if (sensor != null)
                {
                    sensor.Reset();
                }
            }
            catch
            {
            }
        }

        private void AdStatusBar_Changed(object sender, EventArgs e)
        {
            try
            {
                if (this.AccountManager.CurrentUser.AdManager.AdStatusBar.Items.Count == 1)
                {
                    TextAdItem item = this.AccountManager.CurrentUser.AdManager.AdStatusBar.Items[0] as TextAdItem;
                    if (item != null)
                    {
                        base.StatusBar.Text = item.Text;
                    }
                }
                base.StatusBar.Link = this.AccountManager.CurrentUser.AdManager.AdStatusBar.Href;
                base.StatusBar.ToolTipText = this.AccountManager.CurrentUser.AdManager.AdStatusBar.Title;
            }
            catch
            {
            }
        }

        private void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
        {
            ClientLogger.WriteException("线程 Exception", e.Exception);
            this.UnifiedMessageBox.ShowException(this, e.Exception);
        }

        private void BuildMainMenu()
        {
            this.menuMain = new MenuStrip();
            ToolStripMenuItem item2 = new ToolStripMenuItem(StringTable.Framework.MI_Help);
            ToolStripMenuItem item5 = new ToolStripMenuItem(StringTable.Framework.MI_HelpTopic, ImpsResources.GetImage("Images.Help.png"));
            ToolStripMenuItem item6 = new ToolStripMenuItem(string.Format(StringTable.Framework.MI_HelpAbout, AppDictionary.CurrentClientName), null, new EventHandler(this.miHelpAbout_Click));
            this.miOperation = new ToolStripMenuItem(StringTable.Framework.MI_Operation);
            this.miToolsOptions = new ToolStripMenuItem(StringTable.Framework.MI_ToolsOptions);
            this.menuMain.SuspendLayout();
            ToolStripMenuItem item3 = new ToolStripMenuItem(StringTable.Framework.MI_Forum);
            item3.Click += new EventHandler(this.miForum_Click);
            ToolStripMenuItem item4 = new ToolStripMenuItem(StringTable.Framework.MI_Feedback);
            item4.Click += new EventHandler(this.miFeedback_Click);
            ToolStripMenuItem item = new ToolStripMenuItem(StringTable.Framework.MI_FetionWebsite);
            item.Click += new EventHandler(this.miWebsite_Click);
            item2.DropDown = new menu_widget(this.components);
            ToolStripSeparator separator = new ToolStripSeparator();
            separator.Enabled = false;
            item2.DropDown.Items.AddRange(new ToolStripItem[] { item5, item, item3, item4, separator, item6 });
            item2.Name = "miHelp";
            item5.ShortcutKeys = Keys.F1;
            item5.Click += new EventHandler(this.miHelpTopic_Click);
            this.miOperation.Name = "miOperation";
            this.miOperation.DropDown = new menu_widget(this.components);
            this.miOperation.DropDownOpening += new EventHandler(this.miOperation_DropDownOpening);
            this.miToolsOptions.Click += new EventHandler(this.miToolOption_Click);
            this.menuMain.BackColor = Color.Transparent;
            this.menuMain.Items.AddRange(new ToolStripItem[] { this.miOperation, item2 });
            this.menuMain.Name = "menuMain";
            this.menuMain.ResumeLayout(false);
        }

        private void ConversationManager_ReceiveSystemMessage(object sender, ImpsNotifyEventArgs e)
        {
            UiErrorHelper.HandEventSafely(this, delegate {
                string xml = e.Text;
                XmlDocument document = new XmlDocument();
                try
                {
                    document.LoadXml(text);
                }
                catch
                {
                    return;
                }
                XmlElement node = document.DocumentElement;
                if ((documentElement != null) && (documentElement.Name == "msg"))
                {
                    string str2 = XmlHelper.ReadXmlAttributeString(documentElement, "id");
                    if (!string.IsNullOrEmpty(str2))
                    {
                        XmlElement firstChild = (XmlElement) documentElement.FirstChild;
                        if ((nextSibling != null) && (nextSibling.Name == "validity"))
                        {
                            string str3 = XmlHelper.ReadXmlAttributeString(nextSibling, "end");
                            if (!string.IsNullOrEmpty(str3))
                            {
                                nextSibling = (XmlElement) nextSibling.NextSibling;
                                if ((nextSibling != null) && (nextSibling.Name == "content"))
                                {
                                    string content = nextSibling.InnerText;
                                    nextSibling = (XmlElement) nextSibling.NextSibling;
                                    string link = "";
                                    if (nextSibling != null)
                                    {
                                        innerText = nextSibling.InnerText;
                                    }
                                    SystemMessage msg = new SystemMessage(str2, innerText, innerText, str3);
                                    this._mgrSysMsg.AddSystemMessage(msg);
                                }
                            }
                        }
                    }
                }
            });
        }

        private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            Exception exceptionObject = e.ExceptionObject as Exception;
            ClientLogger.WriteException("未捕获的 Exception", exceptionObject);
            this.UnifiedMessageBox.ShowException(this, exceptionObject);
        }

        private void CurrentUser_ExServicesStatusChanged(object sender, ExServiceEventArgs e)
        {
            if (TagedToolStripMenuItem.Items.ContainsKey(e.ServiceID))
            {
                if (e.Service.Subscribed)
                {
                    TagedToolStripMenuItem.Items[e.ServiceID].Text = string.Format("注销{0}", e.Service.Name);
                }
                else
                {
                    TagedToolStripMenuItem.Items[e.ServiceID].Text = string.Format("开通{0}", e.Service.Name);
                }
            }
        }

        private void CurrentUser_ImpsError(object sender, ImpsErrorEventArgs e)
        {
            if (ExceptionHandler.IsNetworkDiagnosticNeeded(e.ErrorCode))
            {
                this.InnerOptionsManager.HandleConnectionFailed(this, e.ErrorType);
            }
            else
            {
                UiErrorHelper.ShowImpsError(this, this, e);
            }
        }

        private void CurrentUser_StatusChanged(object sender, UserSatusChangedEventArgs e)
        {
            try
            {
                switch (e.NewStatus)
                {
                    case UserAccountStatus.None:
                    case UserAccountStatus.Disconnected:
                        break;

                    case UserAccountStatus.Initialized:
                        return;

                    case UserAccountStatus.Loginning:
                    case UserAccountStatus.Logouting:
                    case UserAccountStatus.Logoff:
                        this.InnerCloseChildWindows();
                        this.AccountManager.UserInfoControl.Enabled = false;
                        this.RemoveTabs();
                        if (e.NewStatus != UserAccountStatus.Logoff)
                        {
                            return;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -