mirror of
https://github.com/Gericom/EveryFileExplorer.git
synced 2025-06-19 09:25:42 -04:00
Moved all DllImports to the Win32Util class
This commit is contained in:
parent
5daa139d6f
commit
4adb414a72
@ -12,6 +12,7 @@ using LibEveryFileExplorer.Files;
|
|||||||
using System.Drawing.Imaging;
|
using System.Drawing.Imaging;
|
||||||
using NintendoWare.LYT;
|
using NintendoWare.LYT;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using LibEveryFileExplorer;
|
||||||
|
|
||||||
namespace _3DS.UI
|
namespace _3DS.UI
|
||||||
{
|
{
|
||||||
@ -23,15 +24,12 @@ namespace _3DS.UI
|
|||||||
BasicShader BShader = new BasicShader();
|
BasicShader BShader = new BasicShader();
|
||||||
ImageList ImageL;
|
ImageList ImageL;
|
||||||
|
|
||||||
[DllImport("uxtheme.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
|
|
||||||
private static extern int SetWindowTheme(IntPtr hWnd, string appName, string partList);
|
|
||||||
|
|
||||||
public CLYTViewer(CLYT Layout)
|
public CLYTViewer(CLYT Layout)
|
||||||
{
|
{
|
||||||
this.NWLayout = Layout;
|
this.NWLayout = Layout;
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
SetWindowTheme(treeView1.Handle, "explorer", null);
|
Win32Util.SetWindowTheme(treeView1.Handle, "explorer", null);
|
||||||
SetWindowTheme(treeView2.Handle, "explorer", null);
|
Win32Util.SetWindowTheme(treeView2.Handle, "explorer", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CLYTViewer_Load(object sender, EventArgs e)
|
private void CLYTViewer_Load(object sender, EventArgs e)
|
||||||
|
@ -60,7 +60,6 @@
|
|||||||
<Compile Include="Plugins\PluginManager.cs" />
|
<Compile Include="Plugins\PluginManager.cs" />
|
||||||
<Compile Include="Program.cs" />
|
<Compile Include="Program.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Win32MessageHelper.cs" />
|
|
||||||
<EmbeddedResource Include="Form1.resx">
|
<EmbeddedResource Include="Form1.resx">
|
||||||
<DependentUpon>Form1.cs</DependentUpon>
|
<DependentUpon>Form1.cs</DependentUpon>
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
|
@ -18,33 +18,6 @@ namespace EveryFileExplorer
|
|||||||
{
|
{
|
||||||
public partial class Form1 : Form
|
public partial class Form1 : Form
|
||||||
{
|
{
|
||||||
private const int GWL_STYLE = -16;
|
|
||||||
private const int GWL_EXSTYLE = -20;
|
|
||||||
|
|
||||||
private const int WS_BORDER = 0x00800000;
|
|
||||||
private const int WS_EX_CLIENTEDGE = 0x00000200;
|
|
||||||
|
|
||||||
private const uint SWP_NOSIZE = 0x0001;
|
|
||||||
private const uint SWP_NOMOVE = 0x0002;
|
|
||||||
private const uint SWP_NOZORDER = 0x0004;
|
|
||||||
private const uint SWP_NOREDRAW = 0x0008;
|
|
||||||
private const uint SWP_NOACTIVATE = 0x0010;
|
|
||||||
private const uint SWP_FRAMECHANGED = 0x0020;
|
|
||||||
private const uint SWP_SHOWWINDOW = 0x0040;
|
|
||||||
private const uint SWP_HIDEWINDOW = 0x0080;
|
|
||||||
private const uint SWP_NOCOPYBITS = 0x0100;
|
|
||||||
private const uint SWP_NOOWNERZORDER = 0x0200;
|
|
||||||
private const uint SWP_NOSENDCHANGING = 0x0400;
|
|
||||||
|
|
||||||
[DllImport("user32.dll", CharSet = CharSet.Auto)]
|
|
||||||
private static extern int SetWindowLong(IntPtr hWnd, int Index, int Value);
|
|
||||||
|
|
||||||
[DllImport("user32.dll", CharSet = CharSet.Auto)]
|
|
||||||
private static extern int GetWindowLong(IntPtr hWnd, int Index);
|
|
||||||
|
|
||||||
[DllImport("user32.dll", ExactSpelling = true)]
|
|
||||||
private static extern int SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
|
|
||||||
|
|
||||||
public Form1()
|
public Form1()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@ -66,7 +39,7 @@ namespace EveryFileExplorer
|
|||||||
MdiClient mdiClient = this.Controls[i] as MdiClient;
|
MdiClient mdiClient = this.Controls[i] as MdiClient;
|
||||||
if (mdiClient != null)
|
if (mdiClient != null)
|
||||||
{
|
{
|
||||||
SetMDIBorderStyle(mdiClient, BorderStyle.None);
|
Win32Util.SetMDIBorderStyle(mdiClient, BorderStyle.None);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
menuNew.MenuItems.Clear();
|
menuNew.MenuItems.Clear();
|
||||||
@ -127,40 +100,7 @@ namespace EveryFileExplorer
|
|||||||
PendingPath = null;
|
PendingPath = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetMDIBorderStyle(MdiClient mdiClient, BorderStyle value)
|
|
||||||
{
|
|
||||||
// Get styles using Win32 calls
|
|
||||||
int style = GetWindowLong(mdiClient.Handle, GWL_STYLE);
|
|
||||||
int exStyle = GetWindowLong(mdiClient.Handle, GWL_EXSTYLE);
|
|
||||||
|
|
||||||
// Add or remove style flags as necessary.
|
|
||||||
switch (value)
|
|
||||||
{
|
|
||||||
case BorderStyle.Fixed3D:
|
|
||||||
exStyle |= WS_EX_CLIENTEDGE;
|
|
||||||
style &= ~WS_BORDER;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case BorderStyle.FixedSingle:
|
|
||||||
exStyle &= ~WS_EX_CLIENTEDGE;
|
|
||||||
style |= WS_BORDER;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case BorderStyle.None:
|
|
||||||
style &= ~WS_BORDER;
|
|
||||||
exStyle &= ~WS_EX_CLIENTEDGE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set the styles using Win32 calls
|
|
||||||
SetWindowLong(mdiClient.Handle, GWL_STYLE, style);
|
|
||||||
SetWindowLong(mdiClient.Handle, GWL_EXSTYLE, exStyle);
|
|
||||||
|
|
||||||
// Update the non-client area.
|
|
||||||
SetWindowPos(mdiClient.Handle, IntPtr.Zero, 0, 0, 0, 0,
|
|
||||||
SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER |
|
|
||||||
SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void BringMDIWindowToFront(Form Dialog)
|
public void BringMDIWindowToFront(Form Dialog)
|
||||||
{
|
{
|
||||||
@ -380,19 +320,14 @@ namespace EveryFileExplorer
|
|||||||
panel2.Controls.Clear();
|
panel2.Controls.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
[DllImport("user32.dll")]
|
|
||||||
private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
|
|
||||||
|
|
||||||
private const int SW_RESTORE = 0x09;
|
|
||||||
|
|
||||||
protected override void WndProc(ref Message m)
|
protected override void WndProc(ref Message m)
|
||||||
{
|
{
|
||||||
if (m.Msg == Win32MessageHelper.WM_COPYDATA)
|
if (m.Msg == Win32Util.WM_COPYDATA)
|
||||||
{
|
{
|
||||||
if (WindowState == FormWindowState.Minimized) ShowWindowAsync(Handle, SW_RESTORE);
|
if (WindowState == FormWindowState.Minimized) Win32Util.ShowWindowAsync(Handle, Win32Util.SW_RESTORE);
|
||||||
TopMost = true;
|
TopMost = true;
|
||||||
TopMost = false;
|
TopMost = false;
|
||||||
String path = Win32MessageHelper.GetStringFromMessage(m);
|
String path = Win32Util.GetStringFromMessage(m);
|
||||||
if (path.Length < 1 || !System.IO.File.Exists(path)) return;
|
if (path.Length < 1 || !System.IO.File.Exists(path)) return;
|
||||||
Program.FileManager.OpenFile(new EFEDiskFile(path));
|
Program.FileManager.OpenFile(new EFEDiskFile(path));
|
||||||
return;
|
return;
|
||||||
|
@ -8,6 +8,7 @@ using System.Reflection;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using LibEveryFileExplorer;
|
||||||
|
|
||||||
namespace EveryFileExplorer
|
namespace EveryFileExplorer
|
||||||
{
|
{
|
||||||
@ -37,7 +38,7 @@ namespace EveryFileExplorer
|
|||||||
{
|
{
|
||||||
String arg0 = "";
|
String arg0 = "";
|
||||||
if (Arguments.Length > 0) arg0 = Arguments[0];
|
if (Arguments.Length > 0) arg0 = Arguments[0];
|
||||||
Win32MessageHelper.SendString((IntPtr)Win32MessageHelper.HWND_BROADCAST, arg0);
|
Win32Util.SendString((IntPtr)Win32Util.HWND_BROADCAST, arg0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,39 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
|
|
||||||
namespace EveryFileExplorer
|
|
||||||
{
|
|
||||||
class Win32MessageHelper
|
|
||||||
{
|
|
||||||
public const int HWND_BROADCAST = 0xffff;
|
|
||||||
public const int WM_COPYDATA = 0x004A;
|
|
||||||
|
|
||||||
[DllImport("user32")]
|
|
||||||
static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, ref COPYDATASTRUCT lParam);
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
private struct COPYDATASTRUCT
|
|
||||||
{
|
|
||||||
public IntPtr dwData;
|
|
||||||
public int cbData;
|
|
||||||
[MarshalAs(UnmanagedType.LPWStr)]
|
|
||||||
public String lpData;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool SendString(IntPtr Handle, String Data)
|
|
||||||
{
|
|
||||||
COPYDATASTRUCT c = new COPYDATASTRUCT() { lpData = Data, cbData = Data.Length * 2 + 2 };
|
|
||||||
return SendMessage(Handle, WM_COPYDATA, IntPtr.Zero, ref c) == IntPtr.Zero;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String GetStringFromMessage(Message m)
|
|
||||||
{
|
|
||||||
COPYDATASTRUCT c = (COPYDATASTRUCT)m.GetLParam(typeof(COPYDATASTRUCT));
|
|
||||||
return c.lpData;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -50,15 +50,12 @@ namespace LibEveryFileExplorer
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
[DllImport("Shlwapi.dll", CharSet = CharSet.Auto)]
|
|
||||||
private static extern long StrFormatByteSize(long fileSize, [MarshalAs(UnmanagedType.LPTStr)] StringBuilder buffer, int bufferSize);
|
|
||||||
|
|
||||||
public static ListViewItem GetFileItem(EFEFile File)
|
public static ListViewItem GetFileItem(EFEFile File)
|
||||||
{
|
{
|
||||||
Type[] formats = Program.FileManager.GetPossibleFormats(File);
|
Type[] formats = Program.FileManager.GetPossibleFormats(File);
|
||||||
ListViewItem i = new ListViewItem(File.Name);
|
ListViewItem i = new ListViewItem(File.Name);
|
||||||
StringBuilder b = new StringBuilder(50);
|
StringBuilder b = new StringBuilder(50);
|
||||||
StrFormatByteSize(File.Data.Length, b, 50);
|
Win32Util.StrFormatByteSize(File.Data.Length, b, 50);
|
||||||
i.SubItems.Add(b.ToString());
|
i.SubItems.Add(b.ToString());
|
||||||
if (formats.Length == 1)
|
if (formats.Length == 1)
|
||||||
{
|
{
|
||||||
|
@ -108,6 +108,7 @@
|
|||||||
<Compile Include="UI\GameDataSectionViewerBase.Designer.cs">
|
<Compile Include="UI\GameDataSectionViewerBase.Designer.cs">
|
||||||
<DependentUpon>GameDataSectionViewerBase.cs</DependentUpon>
|
<DependentUpon>GameDataSectionViewerBase.cs</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="Win32Util.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Tools\" />
|
<Folder Include="Tools\" />
|
||||||
|
@ -16,14 +16,11 @@ namespace LibEveryFileExplorer.UI
|
|||||||
ImageList images;
|
ImageList images;
|
||||||
ImageList images2;
|
ImageList images2;
|
||||||
|
|
||||||
[DllImport("uxtheme.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
|
|
||||||
private static extern int SetWindowTheme(IntPtr hWnd, string appName, string partList);
|
|
||||||
|
|
||||||
public FileBrowser()
|
public FileBrowser()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
SetWindowTheme(treeView1.Handle, "explorer", null);
|
Win32Util.SetWindowTheme(treeView1.Handle, "explorer", null);
|
||||||
SetWindowTheme(listView1.Handle, "explorer", null);
|
Win32Util.SetWindowTheme(listView1.Handle, "explorer", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FileBrowser_Load(object sender, EventArgs e)
|
private void FileBrowser_Load(object sender, EventArgs e)
|
||||||
|
112
LibEveryFileExplorer/Win32Util.cs
Normal file
112
LibEveryFileExplorer/Win32Util.cs
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace LibEveryFileExplorer
|
||||||
|
{
|
||||||
|
public class Win32Util
|
||||||
|
{
|
||||||
|
public const int HWND_BROADCAST = 0xffff;
|
||||||
|
public const int WM_COPYDATA = 0x004A;
|
||||||
|
|
||||||
|
private const int GWL_STYLE = -16;
|
||||||
|
private const int GWL_EXSTYLE = -20;
|
||||||
|
|
||||||
|
private const int WS_BORDER = 0x00800000;
|
||||||
|
private const int WS_EX_CLIENTEDGE = 0x00000200;
|
||||||
|
|
||||||
|
public const int SW_RESTORE = 0x09;
|
||||||
|
|
||||||
|
private const uint SWP_NOSIZE = 0x0001;
|
||||||
|
private const uint SWP_NOMOVE = 0x0002;
|
||||||
|
private const uint SWP_NOZORDER = 0x0004;
|
||||||
|
private const uint SWP_NOREDRAW = 0x0008;
|
||||||
|
private const uint SWP_NOACTIVATE = 0x0010;
|
||||||
|
private const uint SWP_FRAMECHANGED = 0x0020;
|
||||||
|
private const uint SWP_SHOWWINDOW = 0x0040;
|
||||||
|
private const uint SWP_HIDEWINDOW = 0x0080;
|
||||||
|
private const uint SWP_NOCOPYBITS = 0x0100;
|
||||||
|
private const uint SWP_NOOWNERZORDER = 0x0200;
|
||||||
|
private const uint SWP_NOSENDCHANGING = 0x0400;
|
||||||
|
|
||||||
|
[DllImport("Shlwapi.dll", CharSet = CharSet.Auto)]
|
||||||
|
public static extern long StrFormatByteSize(long fileSize, [MarshalAs(UnmanagedType.LPTStr)] StringBuilder buffer, int bufferSize);
|
||||||
|
|
||||||
|
[DllImport("user32", CharSet = CharSet.Auto)]
|
||||||
|
private static extern int GetWindowLong(IntPtr hWnd, int Index);
|
||||||
|
|
||||||
|
[DllImport("user32")]
|
||||||
|
private static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, ref COPYDATASTRUCT lParam);
|
||||||
|
|
||||||
|
[DllImport("user32", CharSet = CharSet.Auto)]
|
||||||
|
private static extern int SetWindowLong(IntPtr hWnd, int Index, int Value);
|
||||||
|
|
||||||
|
[DllImport("user32", ExactSpelling = true)]
|
||||||
|
private static extern int SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
|
||||||
|
|
||||||
|
[DllImport("user32.dll")]
|
||||||
|
public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
|
||||||
|
|
||||||
|
[DllImport("uxtheme.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
|
||||||
|
public static extern int SetWindowTheme(IntPtr hWnd, string appName, string partList);
|
||||||
|
|
||||||
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
private struct COPYDATASTRUCT
|
||||||
|
{
|
||||||
|
public IntPtr dwData;
|
||||||
|
public int cbData;
|
||||||
|
[MarshalAs(UnmanagedType.LPWStr)]
|
||||||
|
public String lpData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool SendString(IntPtr Handle, String Data)
|
||||||
|
{
|
||||||
|
COPYDATASTRUCT c = new COPYDATASTRUCT() { lpData = Data, cbData = Data.Length * 2 + 2 };
|
||||||
|
return SendMessage(Handle, WM_COPYDATA, IntPtr.Zero, ref c) == IntPtr.Zero;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetStringFromMessage(Message m)
|
||||||
|
{
|
||||||
|
COPYDATASTRUCT c = (COPYDATASTRUCT)m.GetLParam(typeof(COPYDATASTRUCT));
|
||||||
|
return c.lpData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void SetMDIBorderStyle(MdiClient mdiClient, BorderStyle value)
|
||||||
|
{
|
||||||
|
// Get styles using Win32 calls
|
||||||
|
int style = GetWindowLong(mdiClient.Handle, GWL_STYLE);
|
||||||
|
int exStyle = GetWindowLong(mdiClient.Handle, GWL_EXSTYLE);
|
||||||
|
|
||||||
|
// Add or remove style flags as necessary.
|
||||||
|
switch (value)
|
||||||
|
{
|
||||||
|
case BorderStyle.Fixed3D:
|
||||||
|
exStyle |= WS_EX_CLIENTEDGE;
|
||||||
|
style &= ~WS_BORDER;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BorderStyle.FixedSingle:
|
||||||
|
exStyle &= ~WS_EX_CLIENTEDGE;
|
||||||
|
style |= WS_BORDER;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BorderStyle.None:
|
||||||
|
style &= ~WS_BORDER;
|
||||||
|
exStyle &= ~WS_EX_CLIENTEDGE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the styles using Win32 calls
|
||||||
|
SetWindowLong(mdiClient.Handle, GWL_STYLE, style);
|
||||||
|
SetWindowLong(mdiClient.Handle, GWL_EXSTYLE, exStyle);
|
||||||
|
|
||||||
|
// Update the non-client area.
|
||||||
|
SetWindowPos(mdiClient.Handle, IntPtr.Zero, 0, 0, 0, 0,
|
||||||
|
SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER |
|
||||||
|
SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -25,14 +25,11 @@ namespace NDS.UI
|
|||||||
NSBMD mod;
|
NSBMD mod;
|
||||||
NSBTX tex = null;
|
NSBTX tex = null;
|
||||||
|
|
||||||
[DllImport("uxtheme.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
|
|
||||||
private static extern int SetWindowTheme(IntPtr hWnd, string appName, string partList);
|
|
||||||
|
|
||||||
public NSBMDViewer(NSBMD mod)
|
public NSBMDViewer(NSBMD mod)
|
||||||
{
|
{
|
||||||
this.mod = mod;
|
this.mod = mod;
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
SetWindowTheme(treeView1.Handle, "explorer", null);
|
Win32Util.SetWindowTheme(treeView1.Handle, "explorer", null);
|
||||||
ImageL = new ImageList();
|
ImageL = new ImageList();
|
||||||
ImageL.ColorDepth = ColorDepth.Depth32Bit;
|
ImageL.ColorDepth = ColorDepth.Depth32Bit;
|
||||||
ImageL.ImageSize = new Size(16, 16);
|
ImageL.ImageSize = new Size(16, 16);
|
||||||
|
Loading…
Reference in New Issue
Block a user