是否可以在Notepad ++中显示当前打开文件上次修改的日期和时间? 让这些信息始终可见是很好的,例如,在状态栏中。
我在Windows XP SP3上使用Notepad ++ v5.9.3(UNICODE)。
答案 0 :(得分:1)
C#控制台应用;我在五分钟内写完了这个,因为这就是我所拥有的并且想要这样。它不漂亮但是我现在可以做的很好。这至少是一个起点。
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Notepadd___DateModified
{
class Program
{
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
[DllImport("user32.dll", EntryPoint = "SendMessage", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
public static extern bool SendMessage(IntPtr hWnd, uint Msg, int wParam, StringBuilder lParam);
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr SendMessage(int hWnd, int Msg, int wparam, int lparam);
[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int msg, int Param, string s);
const int WM_GETTEXT = 0x000D;
const int WM_SETTEXT = 0x000c;
const int WM_GETTEXTLENGTH = 0x000E;
static void Main(string[] args)
{
while (true)
{
foreach (Process p in Process.GetProcessesByName("Notepad++"))
{
if (p.Id != Process.GetCurrentProcess().Id)
{
try
{
DateTime LastModified = Directory.GetLastWriteTime(p.MainWindowTitle.Replace(" - Notepad++", ""));
IntPtr childHandle;
childHandle = FindWindowEx(p.MainWindowHandle, IntPtr.Zero, "msctls_statusbar32", null);
StringBuilder subtitle = new StringBuilder();
Int32 subsize = SendMessage((int)childHandle, WM_GETTEXTLENGTH, 0, 0).ToInt32();
if (subsize > 0)
{
subtitle = new StringBuilder(subsize + 1);
SendMessage(childHandle, (int)WM_GETTEXT, subtitle.Capacity, subtitle);
}
if (!subtitle.ToString().Contains(" - Last Modified: " + LastModified.ToString()))
{
SendMessage(childHandle, WM_SETTEXT, 0, subtitle.ToString().Split(new string[] { " - Last Modified: " },StringSplitOptions.None)[0] + " - Last Modified: " + LastModified.ToString());
Console.Out.WriteLine(subtitle + " - Last Modified: " + LastModified.ToString());
}
}
catch
{
break;
}
}
else return;
}
Thread.Sleep(1000);
}
}
}
}