mirror of
https://github.com/yaakov-h/Notepad.Extensions.Logging.git
synced 2024-11-22 11:14:50 +00:00
try notepad++
This commit is contained in:
parent
1a934be05f
commit
b23e186617
1 changed files with 13 additions and 8 deletions
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace Microsoft.Extensions.Logging
|
namespace Microsoft.Extensions.Logging
|
||||||
{
|
{
|
||||||
|
@ -13,14 +14,8 @@ namespace Microsoft.Extensions.Logging
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
FindMainWindow();
|
FindMainWindow();
|
||||||
if (handle == IntPtr.Zero)
|
|
||||||
{
|
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
IntPtr edit = NativeMethods.FindWindowEx(handle, IntPtr.Zero, "EDIT", null);
|
|
||||||
return edit;
|
|
||||||
}
|
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
handle = IntPtr.Zero;
|
handle = IntPtr.Zero;
|
||||||
|
@ -44,9 +39,10 @@ namespace Microsoft.Extensions.Logging
|
||||||
throw new Win32Exception(result);
|
throw new Win32Exception(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WindowFinder.handle = hWnd;
|
||||||
|
|
||||||
if (IsKnownNotepadWindow(sb.ToString()))
|
if (IsKnownNotepadWindow(sb.ToString()))
|
||||||
{
|
{
|
||||||
WindowFinder.handle = hWnd;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -58,12 +54,21 @@ namespace Microsoft.Extensions.Logging
|
||||||
[ThreadStatic]
|
[ThreadStatic]
|
||||||
static StringBuilder sb;
|
static StringBuilder sb;
|
||||||
|
|
||||||
|
static Regex notepadPlusPlusRegex = new Regex(@"^new \d+ - Notepad\+\+$", RegexOptions.Compiled);
|
||||||
|
|
||||||
static bool IsKnownNotepadWindow(string titleText)
|
static bool IsKnownNotepadWindow(string titleText)
|
||||||
{
|
{
|
||||||
switch (titleText)
|
switch (titleText)
|
||||||
{
|
{
|
||||||
case "Untitled - Notepad":
|
case "Untitled - Notepad":
|
||||||
case "*Untitled - Notepad":
|
case "*Untitled - Notepad":
|
||||||
|
handle = NativeMethods.FindWindowEx(handle, IntPtr.Zero, "EDIT", null);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (notepadPlusPlusRegex.IsMatch(titleText))
|
||||||
|
{
|
||||||
|
handle = NativeMethods.FindWindowEx(handle, IntPtr.Zero, "SysTabControl32", null);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue