Skip to content

Commit

Permalink
文件允许拖入窗口
Browse files Browse the repository at this point in the history
  • Loading branch information
WhatDamon committed Aug 20, 2024
1 parent 5a6c919 commit a774461
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 5 deletions.
9 changes: 6 additions & 3 deletions WndMain.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 75 additions & 2 deletions WndMain.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace NCMDumpGUI
{
Expand All @@ -10,6 +12,59 @@ public WndMain()
InitializeComponent();
}

#region fields
private const int WM_SYSCOMMAND = 0X112;
private const int MF_STRING = 0X0;
private const int MF_SEPARATOR = 0X800;
private enum SystemMenuItem : int
{
About,
FeedBack,
}
#endregion

#region GetSystemMenu
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
#endregion

#region AppendMenu
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern bool AppendMenu(IntPtr hMenu, int uFlags, int uIDNewItem, string lpNewItem);
#endregion

#region InsertMenu
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern bool InsertMenu(IntPtr hMenu, int uPosition, int uFlags, int uIDNewItem, string lpNewItem);
#endregion

#region OnHandleCreated
protected override void OnHandleCreated(EventArgs e)
{
base.OnHandleCreated(e);
var hSysMenu = GetSystemMenu(this.Handle, false);
AppendMenu(hSysMenu, MF_SEPARATOR, 0, String.Empty);
AppendMenu(hSysMenu, MF_STRING, (int)SystemMenuItem.About, "关于");
}
#endregion

#region WndProc
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);

if (m.Msg == WM_SYSCOMMAND)
{
switch ((SystemMenuItem)m.WParam)
{
case SystemMenuItem.About:
MessageBox.Show("NCMDumpGUI v1.0.0.1\n基于libncmdump开发", "关于", MessageBoxButtons.OK, MessageBoxIcon.Information);
break;
}
}
}
#endregion

private void browseButton_Click(object sender, EventArgs e)
{
OpenFileDialog dialog = new OpenFileDialog();
Expand Down Expand Up @@ -47,8 +102,9 @@ private void convertButton_Click(object sender, EventArgs e)
neteaseCrypt.FixMetadata();
}
neteaseCrypt.Destroy();
if (result != 0) {
toolStripStatusLabel2.Text = "发生错误,错误代码:" + result.ToString();
if (result != 0)
{
toolStripStatusLabel2.Text = "发生错误,返回值为:" + result.ToString();
}
else
{
Expand All @@ -67,5 +123,22 @@ public void WndMain_KeyDown(object sender, KeyEventArgs e)
convertButton.PerformClick();
}
}

private void WndMain_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
e.Effect = DragDropEffects.All;
}
else
{
e.Effect = DragDropEffects.None;
}
}

private void WndMain_DragDrop(object sender, DragEventArgs e)
{
filepathTextBox.Text = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();
}
}
}

0 comments on commit a774461

Please sign in to comment.