From 2d7840e08e7205e50699ac840b74fd22800e7bef Mon Sep 17 00:00:00 2001 From: Jaex Date: Sat, 3 May 2014 23:06:02 +0300 Subject: [PATCH] Workaround for have avi options button --- HelpersLib/AVIOptions.cs | 1 + HelpersLib/AviWriter.cs | 10 +++++++++- HelpersLib/Native/NativeMethods_Helpers.cs | 4 ++-- ScreenCaptureLib/ScreenRecorder.cs | 1 - ShareX/Forms/TaskSettingsForm.cs | 17 ++++++++++++++++- 5 files changed, 28 insertions(+), 5 deletions(-) diff --git a/HelpersLib/AVIOptions.cs b/HelpersLib/AVIOptions.cs index 51261f935..40e7e144e 100644 --- a/HelpersLib/AVIOptions.cs +++ b/HelpersLib/AVIOptions.cs @@ -39,5 +39,6 @@ public class AVIOptions public int FPS; public Size Size; public bool ShowOptionsDialog; + public IntPtr ParentWindow; } } \ No newline at end of file diff --git a/HelpersLib/AviWriter.cs b/HelpersLib/AviWriter.cs index e85c08f2f..551965728 100644 --- a/HelpersLib/AviWriter.cs +++ b/HelpersLib/AviWriter.cs @@ -206,7 +206,15 @@ public void Open() if (Options.ShowOptionsDialog) { - NativeMethods.AVISaveOptions(stream, ref Options.CompressOptions); + AVICOMPRESSOPTIONS options = new AVICOMPRESSOPTIONS(); + options.handler = Options.CompressOptions.handler; + options.quality = Options.CompressOptions.quality; + options.flags = 8; // AVICOMPRESSF_VALID + int result = NativeMethods.AVISaveOptions(stream, ref options, Options.ParentWindow); + if (result == 1) + { + Options.CompressOptions = options; + } } // create compressed stream diff --git a/HelpersLib/Native/NativeMethods_Helpers.cs b/HelpersLib/Native/NativeMethods_Helpers.cs index 0ef283d0e..81112533b 100644 --- a/HelpersLib/Native/NativeMethods_Helpers.cs +++ b/HelpersLib/Native/NativeMethods_Helpers.cs @@ -379,7 +379,7 @@ public static void RestoreWindow(IntPtr handle) /// Stream options. /// /// Returns TRUE if the user pressed OK, FALSE for CANCEL, or an error otherwise. - public static int AVISaveOptions(IntPtr stream, ref AVICOMPRESSOPTIONS options) + public static int AVISaveOptions(IntPtr stream, ref AVICOMPRESSOPTIONS options, IntPtr parentWindow) { IntPtr[] streams = new IntPtr[1]; IntPtr[] infPtrs = new IntPtr[1]; @@ -394,7 +394,7 @@ public static int AVISaveOptions(IntPtr stream, ref AVICOMPRESSOPTIONS options) infPtrs[0] = mem; // show dialog with a list of available compresors and configuration - int ret = AVISaveOptions(IntPtr.Zero, 0, 1, streams, infPtrs); + int ret = AVISaveOptions(parentWindow, 0, 1, streams, infPtrs); // copy from unmanaged memory to managed structure options = (AVICOMPRESSOPTIONS)Marshal.PtrToStructure(mem, typeof(AVICOMPRESSOPTIONS)); diff --git a/ScreenCaptureLib/ScreenRecorder.cs b/ScreenCaptureLib/ScreenRecorder.cs index 8eb21dad8..63273d211 100644 --- a/ScreenCaptureLib/ScreenRecorder.cs +++ b/ScreenCaptureLib/ScreenRecorder.cs @@ -121,7 +121,6 @@ public ScreenRecorder(int fps, float durationSeconds, Rectangle captureRectangle CompressOptions = compressOptions, FPS = FPS, OutputPath = CachePath, - ShowOptionsDialog = OutputType == ScreenRecordOutput.AVI, Size = CaptureRectangle.Size }; diff --git a/ShareX/Forms/TaskSettingsForm.cs b/ShareX/Forms/TaskSettingsForm.cs index 62bfb3c07..09a37fec2 100644 --- a/ShareX/Forms/TaskSettingsForm.cs +++ b/ShareX/Forms/TaskSettingsForm.cs @@ -28,6 +28,7 @@ using ScreenCaptureLib; using System; using System.Collections.Generic; +using System.Drawing; using System.Linq; using System.Windows.Forms; using UploadersLib; @@ -650,7 +651,21 @@ private void cbScreenRecorderOutput_SelectedIndexChanged(object sender, EventArg private void btnScreenRecorderAVIOptions_Click(object sender, EventArgs e) { - //NativeMethods.AVISaveOptions(IntPtr.Zero, ref TaskSettings.CaptureSettings.ScreenRecordAVIOptions); + AVIOptions options = new AVIOptions + { + CompressOptions = TaskSettings.CaptureSettings.ScreenRecordCompressOptions, + FPS = 10, + OutputPath = Program.ScreenRecorderCacheFilePath, + ParentWindow = this.Handle, + ShowOptionsDialog = true, + Size = new Size(100, 100) + }; + + // Ugly workaround for show AVI compression dialog + using (AVICache aviCache = new AVICache(options)) + { + TaskSettings.CaptureSettings.ScreenRecordCompressOptions = options.CompressOptions; + } } private void cboEncoder_SelectedIndexChanged(object sender, EventArgs e)