コード例 #1
0
ファイル: Program.cs プロジェクト: meharryp/dermadesignerb
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            string[] args = Environment.GetCommandLineArgs();
            bool     openFileOnStartup = false;

            if (args.Length > 1 && File.Exists(args[1]) && Path.GetExtension(args[1]) == ".ddproj")
            {
                openFileOnStartup = true;
            }

            // Set this before making any derma controls
            Derma.Init(new Main(), new PropertiesWindow(), new Toolbox());
            Derma.GetWorkspace().Show();

            Derma.toolbox.Location = new System.Drawing.Point(Derma.GetWorkspace().Location.X - Derma.toolbox.ClientSize.Width - 20, Derma.GetWorkspace().Location.Y);
            Derma.toolbox.Show();

            Derma.prop.Location = new System.Drawing.Point(Derma.GetWorkspace().Location.X + Derma.GetWorkspace().ClientSize.Width + 24, Derma.GetWorkspace().Location.Y);
            Derma.prop.Show();

            Derma.GetWorkspace().Focus();

            /* here we will register all the classes derived from Panel */
            Assembly DD = Assembly.GetExecutingAssembly();

            foreach (Type type in DD.GetTypes())
            {
                if (type.IsSubclassOf(typeof(Panel)))
                {
                    MethodInfo r = type.GetMethod("Register");
                    if (r == null)
                    {
                        MessageBox.Show("Derma control \"" + type.ToString() + "\" failed to register: Register class method not found.", "Control registration error");
                    }
                    else
                    {
                        r.Invoke(type, new object[] { });
                    }
                }
            }
            /* end panel registration */

            /* here we will load all the extension modules and register the panels in them */
            string[] files = Directory.GetFiles(Application.StartupPath + "\\" + "plugins", "*.dll");

            foreach (string dll in files)
            {
                Assembly fe = LoadPlugin(Path.GetFullPath(dll), dll);
                if (fe != null)
                {
                    foreach (Type type in fe.GetTypes())
                    {
                        if (type.IsSubclassOf(typeof(Panel)))
                        {
                            MethodInfo r = type.GetMethod("Register");
                            if (r == null)
                            {
                                MessageBox.Show("Derma control \"" + type.ToString() + "\" from plugin " + dll + " failed register: Register class method not found.", "Control registration error");
                            }
                            else
                            {
                                r.Invoke(type, new object[] { });
                            }
                        }
                    }
                }
            }
            /* end module registration */

            Derma.GetWorkspace().GotFocus    += new EventHandler(Program_GotFocus);
            Derma.GetWorkspace().SizeChanged += new EventHandler(Program_GotFocus);
            Derma.GetWorkspace().LostFocus   += new EventHandler(Program_LostFocus);
            ShowWindowInterop.ShowInactiveTopmost((Form)Derma.prop);
            ShowWindowInterop.ShowInactiveTopmost((Form)Derma.toolbox);

            if (openFileOnStartup)
            {
                DSave.Load(args[1]);
            }

            Application.Run(Derma.GetWorkspace());
        }