new screenshot

This commit is contained in:
Frank Skare
2019-10-09 07:05:46 +02:00
parent 327a097bcf
commit f5e0c92824
5 changed files with 95 additions and 90 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 MiB

After

Width:  |  Height:  |  Size: 2.2 MiB

View File

@@ -66,7 +66,9 @@ namespace mpvnet
return; return;
} }
if (App.IsStartedFromTerminal) Native.AttachConsole(-1 /*ATTACH_PARENT_PROCESS*/); if (App.IsStartedFromTerminal)
Native.AttachConsole(-1 /*ATTACH_PARENT_PROCESS*/);
Application.Run(new MainForm()); Application.Run(new MainForm());
if (App.IsStartedFromTerminal) Native.FreeConsole(); if (App.IsStartedFromTerminal) Native.FreeConsole();
mutex.Dispose(); mutex.Dispose();

View File

@@ -10,7 +10,7 @@ public class MediaInfo : IDisposable
{ {
if (!Loaded) if (!Loaded)
{ {
if (LoadLibrary("MediaInfo.dll") == IntPtr.Zero) if (Native.LoadLibrary("MediaInfo.dll") == IntPtr.Zero)
throw new Exception("Failed to load MediaInfo.dll."); throw new Exception("Failed to load MediaInfo.dll.");
Loaded = true; Loaded = true;
@@ -56,21 +56,27 @@ public class MediaInfo : IDisposable
~MediaInfo() { Dispose(); } ~MediaInfo() { Dispose(); }
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)] [DllImport("kernel32.dll")]
static extern IntPtr LoadLibrary(string path); public static extern IntPtr LoadLibrary(string path);
[DllImport("MediaInfo.dll")] [DllImport("MediaInfo.dll")]
static extern IntPtr MediaInfo_New(); static extern IntPtr MediaInfo_New();
[DllImport("MediaInfo.dll")] [DllImport("MediaInfo.dll", CharSet = CharSet.Unicode)]
static extern void MediaInfo_Delete(IntPtr handle); static extern int MediaInfo_Open(IntPtr handle, string path);
[DllImport("MediaInfo.dll", CharSet = CharSet.Unicode)] [DllImport("MediaInfo.dll", CharSet = CharSet.Unicode)]
static extern int MediaInfo_Open(IntPtr handle, string fileName); static extern IntPtr MediaInfo_Option(IntPtr handle, string optionString, string value);
[DllImport("MediaInfo.dll")]
static extern IntPtr MediaInfo_Inform(IntPtr handle, int reserved);
[DllImport("MediaInfo.dll")] [DllImport("MediaInfo.dll")]
static extern int MediaInfo_Close(IntPtr handle); static extern int MediaInfo_Close(IntPtr handle);
[DllImport("MediaInfo.dll")]
static extern void MediaInfo_Delete(IntPtr handle);
[DllImport("MediaInfo.dll", CharSet = CharSet.Unicode)] [DllImport("MediaInfo.dll", CharSet = CharSet.Unicode)]
static extern IntPtr MediaInfo_Get(IntPtr handle, static extern IntPtr MediaInfo_Get(IntPtr handle,
MediaInfoStreamKind streamKind, MediaInfoStreamKind streamKind,

View File

@@ -2,97 +2,94 @@
using System.Drawing; using System.Drawing;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace mpvnet public class Native
{ {
public class Native [DllImport("kernel32.dll")]
public static extern bool AttachConsole(int dwProcessId);
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool FreeConsole();
[DllImport("kernel32.dll")]
public static extern IntPtr LoadLibrary(string path);
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string lclassName, string windowTitle);
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, ref COPYDATASTRUCT lParam);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern IntPtr PostMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern int RegisterWindowMessage(string id);
[DllImport("user32.dll")]
public static extern bool AllowSetForegroundWindow(int dwProcessId);
[DllImport("user32.dll")]
public static extern void ReleaseCapture();
[DllImport("user32.dll")]
public static extern bool AdjustWindowRect(ref RECT lpRect, uint dwStyle, bool bMenu);
[DllImport("user32.dll", SetLastError = true)]
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, int uFlags);
[DllImport("user32.dll", EntryPoint = "GetWindowLong")]
private static extern IntPtr GetWindowLong32(IntPtr hWnd, int nIndex);
[DllImport("user32.dll", EntryPoint = "GetWindowLongPtr")]
private static extern IntPtr GetWindowLong64(IntPtr hWnd, int nIndex);
public static IntPtr GetWindowLong(IntPtr hWnd, int nIndex)
{ {
[DllImport("kernel32.dll")] if (IntPtr.Size == 8)
public static extern bool AttachConsole(int dwProcessId); return GetWindowLong64(hWnd, nIndex);
else
return GetWindowLong32(hWnd, nIndex);
}
[DllImport("kernel32.dll", SetLastError = true)] [StructLayout(LayoutKind.Sequential)]
public static extern bool FreeConsole(); public struct RECT
{
public int Left;
public int Top;
public int Right;
public int Bottom;
[DllImport("kernel32.dll")] public RECT(Rectangle r)
public static extern IntPtr LoadLibrary(string dllToLoad);
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string lclassName, string windowTitle);
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, ref COPYDATASTRUCT lParam);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern IntPtr PostMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern int RegisterWindowMessage(string id);
[DllImport("user32.dll")]
public static extern bool AllowSetForegroundWindow(int dwProcessId);
[DllImport("user32.dll")]
public static extern void ReleaseCapture();
[DllImport("user32.dll")]
public static extern bool AdjustWindowRect(ref RECT lpRect, uint dwStyle, bool bMenu);
[DllImport("user32.dll", SetLastError = true)]
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, int uFlags);
[DllImport("user32.dll", EntryPoint = "GetWindowLong")]
private static extern IntPtr GetWindowLong32(IntPtr hWnd, int nIndex);
[DllImport("user32.dll", EntryPoint = "GetWindowLongPtr")]
private static extern IntPtr GetWindowLong64(IntPtr hWnd, int nIndex);
public static IntPtr GetWindowLong(IntPtr hWnd, int nIndex)
{ {
if (IntPtr.Size == 8) Left = r.Left;
return GetWindowLong64(hWnd, nIndex); Top = r.Top;
else Right = r.Right;
return GetWindowLong32(hWnd, nIndex); Bottom = r.Bottom;
} }
[StructLayout(LayoutKind.Sequential)] public RECT(int left, int top, int right, int bottom)
public struct RECT
{ {
public int Left; Left = left;
public int Top; Top = top;
public int Right; Right = right;
public int Bottom; Bottom = bottom;
public RECT(Rectangle r)
{
Left = r.Left;
Top = r.Top;
Right = r.Right;
Bottom = r.Bottom;
}
public RECT(int left, int top, int right, int bottom)
{
Left = left;
Top = top;
Right = right;
Bottom = bottom;
}
public Rectangle ToRectangle() { return Rectangle.FromLTRB(Left, Top, Right, Bottom); }
public Size Size => new Size(Right - Left, Bottom - Top);
public int Width => Right - Left;
public int Height => Bottom - Top;
} }
[StructLayout(LayoutKind.Sequential)] public Rectangle ToRectangle() { return Rectangle.FromLTRB(Left, Top, Right, Bottom); }
public struct COPYDATASTRUCT public Size Size => new Size(Right - Left, Bottom - Top);
{ public int Width => Right - Left;
public IntPtr dwData; public int Height => Bottom - Top;
public int cbData; }
[MarshalAs(UnmanagedType.LPTStr)]
public string lpData; [StructLayout(LayoutKind.Sequential)]
} public struct COPYDATASTRUCT
{
public IntPtr dwData;
public int cbData;
[MarshalAs(UnmanagedType.LPTStr)]
public string lpData;
} }
} }

View File

@@ -16,7 +16,7 @@ using System.Windows.Forms;
using WinForms = System.Windows.Forms; using WinForms = System.Windows.Forms;
using static mpvnet.libmpv; using static mpvnet.libmpv;
using static mpvnet.Native; using static Native;
namespace mpvnet namespace mpvnet
{ {