2

是否可以在 Notepad++ 中显示当前打开文件的最后修改日期和时间?最好让这些信息始终可见,例如在状态栏中。

我在 Windows XP SP3 上使用 Notepad++ v5.9.3 (UNICODE)。

4

1 回答 1

1

C# 控制台应用程序;我在五分钟内写了这篇文章,因为这就是我所拥有的并且想要这个。它不漂亮,但我现在可以做的一样好。这至少是一个起点。

Notepad++ 上次修改日期

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);
            }
        }
    }
}
于 2012-12-11T18:31:12.707 回答