Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
Fixed #4 其他截图工具截图时置顶问题
Browse files Browse the repository at this point in the history
  • Loading branch information
tylearymf committed Aug 28, 2019
1 parent 1b6ca39 commit cf61612
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 7 deletions.
28 changes: 23 additions & 5 deletions SETUNA/Main/Other/LayerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ public class LayerManager

List<LayerInfo> mFormList = new List<LayerInfo>();
public int clickCount { set; get; }
static List<string> mIgnoreClassNames = new List<string>()
{
//QQ
"TXGuiFoundation",
//有度
"ScreenShotWnd",
//微信
"SnapshotWnd",
"CToolBarWnd",
};

public void AddInfo(LayerInfo pInfo)
{
Expand All @@ -58,14 +68,22 @@ public void RemoveInfo(LayerInfo pInfo)

public void Update()
{
var tTopHandler = WindowsAPI.GetForegroundWindow();
var tTopTitle = WindowsAPI.GetWindowTitle(tTopHandler);
var tTopModuleName = WindowsAPI.GetModuleName(tTopHandler);
var tTopClassName = WindowsAPI.GetClassName(tTopHandler);

//过滤其他截图工具
if (!string.IsNullOrEmpty(tTopClassName) && mIgnoreClassNames.Contains(tTopClassName))
{
return;
}

mFormList.Sort((x, y) =>
{
return x.clickCount.CompareTo(y.clickCount);
});

var tTopHandler = WindowsAPI.GetForegroundWindow();
var tTopTitle = WindowsAPI.GetWindowTItle(tTopHandler);

var tTopOrder = 0;
WindowsAPI.GetWindowZOrder(tTopHandler, out tTopOrder);

Expand Down Expand Up @@ -98,8 +116,8 @@ public void Update()
}
if (tIsTop) return;

MyConsole.WriteLine("UpdateLayer" + " TopTitle:{0} " + "TopOrder:{1} " + "OrderList:{2}",
tTopTitle, tTopOrder, string.Join(",", tOrderList.ToArray()));
MyConsole.WriteLine("UpdateLayer TopTitle:{0} TopOrder:{1} OrderList:{2} ModuleName:{3} ClassName:{4}",
tTopTitle, tTopOrder, string.Join(",", tOrderList.ToArray()), tTopModuleName, tTopClassName);

//刷新层级
for (int i = 0, imax = mFormList.Count; i < imax; i++)
Expand Down
24 changes: 22 additions & 2 deletions SETUNA/Main/Other/WindowsAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ class WindowsAPI
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static public extern int GetWindowTextLength(IntPtr hWnd);

[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern int GetWindowModuleFileName(IntPtr hWnd, StringBuilder lpFilename, int nSize);

[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern int GetClassName(IntPtr hWnd, StringBuilder lpFilename, int nSize);

static public bool GetWindowZOrder(IntPtr hwnd, out int zOrder)
{
const uint GW_HWNDPREV = 3;
Expand All @@ -44,17 +50,31 @@ static public bool GetWindowZOrder(IntPtr hwnd, out int zOrder)
return false;
}

static public string GetWindowTItle(IntPtr hwnd)
static public string GetWindowTitle(IntPtr hwnd)
{

int length = GetWindowTextLength(hwnd);
if (length == 0) return string.Empty;

var builder = new StringBuilder(length);
GetWindowText(hwnd, builder, length + 1);

return builder.ToString();
}

static public string GetModuleName(IntPtr hwnd)
{
var builder = new StringBuilder(1024);
var len = GetWindowModuleFileName(hwnd, builder, builder.Capacity);

return builder.ToString();
}

static public string GetClassName(IntPtr hwnd)
{
var builder = new StringBuilder(1024);
var len = GetClassName(hwnd, builder, builder.Capacity);

return builder.ToString();
}
}
}

0 comments on commit cf61612

Please sign in to comment.