示例#1
0
        //初始化和退出
        private void FormMain_Load(object sender, EventArgs e)
        {
            //加载字体
            PrivateFontCollection prc = new PrivateFontCollection();

            prc.AddFontFile(AppUtils.GetStartDir() + "\\font\\bahnschrift.ttf");
            lb_time.Font   = new Font(prc.Families[0], 16);
            lb_time.Top    = 1;
            lb_time.Height = 60;

            //创建
            //recoder_update_callback_ptr = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate((Recorder.UpdateCallback)recoder_update);
            //GC.KeepAlive(recoder_update_callback_ptr);

            //创建录制底层库实例
            Recorder.Create();
            Recorder.SetUpdateCallback(recoder_update_callback_ptr);

            API.IniWriteValue("AppSetting", "LastWindow", Handle.ToString());

            //创建矩形选择框
            formRect = new FormRect();
            formRect.Show();
            formRectRecing = new FormRectRecing();
            formRectRecing.Show();

            formRecMini = new FormRecMini();
            formRecMini.lb_time.Font = new Font(prc.Families[0], 12);
            formRecMini.Show();

            //隐藏正在录制框
            WindowUtils.Hide(formRectRecing.Handle);
            //隐藏迷你窗口
            WindowUtils.Hide(formRecMini.Handle);

            //获取屏幕大小
            UpdateScreenSize();

            //加载设置
            Settings.LoadSettings();
            //检查设置是否合法
            if (Settings.frame_rate <= 0 || Settings.frame_rate > 30)
            {
                Settings.frame_rate = 15;
            }
            if (Settings.last_appx <= 0 || Settings.last_appx > screenSize.Width)
            {
                Settings.last_appx = screenSize.Width - Width - 10;
            }
            if (Settings.last_appy <= 0 || Settings.last_appy > screenSize.Height)
            {
                Settings.last_appy = screenSize.Height - Height - 55;
            }
            if (Settings.last_x <= 0 || Settings.last_x > screenSize.Width)
            {
                Settings.last_x = 20;
            }
            if (Settings.last_y <= 0 || Settings.last_y > screenSize.Height)
            {
                Settings.last_y = 20;
            }
            if (Settings.last_w <= 160 || Settings.last_w > screenSize.Width)
            {
                Settings.last_w = 0;
            }
            if (Settings.last_h <= 92 || Settings.last_h > screenSize.Height)
            {
                Settings.last_h = 0;
            }
            if (Settings.quality > 2)
            {
                Settings.quality = 1;
            }

            //设置默认保存路径
            if (Settings.SaveDir != "DEFAULT" && !System.IO.Directory.Exists(Settings.SaveDir))
            {
                Settings.SaveDir = AppUtils.GetDefExportDir();
                //如果默认目录不存在则创建
                if (!System.IO.Directory.Exists(Settings.SaveDir))
                {
                    System.IO.Directory.CreateDirectory(Settings.SaveDir);
                }
            }
            if (Settings.fullscreen)
            {
                WindowUtils.Hide(formRect.Handle);
            }
            if (Settings.VideoType != "DEFAULT")
            {
                try
                {
                    Recorder.RecordFormat = (Recorder.VIDEO_FORMAT)Enum.Parse(typeof(Recorder.VIDEO_FORMAT), Settings.VideoType);
                }
                catch { }
            }

            //注册热键
            bool regsuccess = true;

            regsuccess = AppUtils.RegisterHotKeyEx(Handle, 0, Settings.hotkey_start);
            regsuccess = AppUtils.RegisterHotKeyEx(Handle, 1, Settings.hotkey_pause);
            regsuccess = AppUtils.RegisterHotKeyEx(Handle, 2, Settings.hotkey_stop);
            regsuccess = AppUtils.RegisterHotKeyEx(Handle, 3, Settings.hotkey_showehide);
            regsuccess = AppUtils.RegisterHotKeyEx(Handle, 4, Settings.hotkey_screenshutcut);

            //注册热键失败提示
            if (!regsuccess)
            {
                new FormMsgSmall("有可能是热键被其他软件占用。您可以尝试重新设置热键", "ScreenRecoder - 热键注册失败", "确定", "", 4000).Show(this);
            }

            //读取上次录制区域
            if (Settings.last_y != 0)
            {
                formRect.Top       = Settings.last_y;
                formRectRecing.Top = Settings.last_y;
            }
            if (Settings.last_x != 0)
            {
                formRect.Left       = Settings.last_x;
                formRectRecing.Left = Settings.last_x;
            }
            if (Settings.last_w % 4 != 0)
            {
                Settings.last_w -= Settings.last_w % 4;
            }
            if (Settings.last_h % 4 != 0)
            {
                Settings.last_h -= Settings.last_h % 4;
            }
            if (Settings.last_w != 0)
            {
                formRect.Width       = Settings.last_w;
                formRectRecing.Width = Settings.last_w;
            }
            if (Settings.last_h != 0)
            {
                formRect.Height       = Settings.last_h;
                formRectRecing.Height = Settings.last_h;
            }

            formMain.SwitchTop();

            toggle_fullscreen.Checked = Settings.fullscreen;
            btn_rec_mic.Image         = Settings.recmic ? Properties.Resources.ico_mic_on : Properties.Resources.ico_mic_off;
            btn_rec_sound.Image       = Settings.recsound ? Properties.Resources.ico_sound_on : Properties.Resources.ico_sound_off;
        }
示例#2
0
 private void check_top_CheckedChanged(object sender, EventArgs e)
 {
     Settings.window_top = check_top.Checked;
     formMain.SwitchTop();
 }