Skip to content

Commit

Permalink
Update C.O.
Browse files Browse the repository at this point in the history
Update C.O.
  • Loading branch information
TGSAN committed Jun 25, 2019
1 parent 3d76a91 commit ec1bb1d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

.vs
OSUDesktop/bin
OSUDesktop/bin/Debug
OSUDesktop/obj
40 changes: 18 additions & 22 deletions OSUDesktop/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public partial class Form1 : Form
*/

[Flags]
public enum SendMessageTimeoutFlags : uint
internal enum SendMessageTimeoutFlags : uint
{
SMTO_NORMAL = 0x0,
SMTO_BLOCK = 0x1,
Expand All @@ -29,9 +29,10 @@ public enum SendMessageTimeoutFlags : uint
}

internal const uint GW_OWNER = 4;
internal const int WM_CLOSE = 0x10; // ExitWindows函数

[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr FindWindow([MarshalAs(UnmanagedType.LPTStr)] string lpClassName, [MarshalAs(UnmanagedType.LPTStr)] string lpWindowName);
internal static extern IntPtr FindWindow([MarshalAs(UnmanagedType.LPTStr)] string lpClassName, [MarshalAs(UnmanagedType.LPTStr)] string lpWindowName);

[DllImport("user32.dll", CharSet = CharSet.Auto)]
internal static extern int GetWindowThreadProcessId(IntPtr hWnd, out IntPtr lpdwProcessId);
Expand All @@ -43,21 +44,26 @@ public enum SendMessageTimeoutFlags : uint
internal static extern bool IsWindowVisible(IntPtr hWnd);

[DllImport("user32.dll", EntryPoint = "SendMessage")]
private static extern int SendMessage(IntPtr hWnd, int msg, uint wParam, uint lParam);
internal static extern int SendMessage(IntPtr hWnd, int msg, uint wParam, uint lParam);

[DllImport("user32")]
private static extern IntPtr FindWindowEx(IntPtr hWnd1, IntPtr hWnd2, string lpsz1, string lpsz2);
internal static extern IntPtr FindWindowEx(IntPtr hWnd1, IntPtr hWnd2, string lpsz1, string lpsz2);

[DllImport("user32.dll")]
public static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
internal static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern IntPtr SendMessageTimeout(IntPtr windowHandle, uint Msg, IntPtr wParam, IntPtr lParam, SendMessageTimeoutFlags flags, uint timeout, out IntPtr result);
internal static extern IntPtr SendMessageTimeout(IntPtr windowHandle, uint Msg, IntPtr wParam, IntPtr lParam, SendMessageTimeoutFlags flags, uint timeout, out IntPtr result);

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool EnumWindows(EnumWindowsProc lpEnumFunc, IntPtr lParam);
public delegate bool EnumWindowsProc(IntPtr hwnd, IntPtr lParam);
internal static extern bool EnumWindows(EnumWindowsProc lpEnumFunc, IntPtr lParam);
internal delegate bool EnumWindowsProc(IntPtr hwnd, IntPtr lParam);

int ModeA_PID = 0;
string ModeA_Name = "";
private static Boolean winseven = false;
IntPtr WorkerWIntPtr = fWorker(); // 定义句柄并设置为桌面WorkerW的句柄

public Form1()
{
Expand All @@ -69,7 +75,7 @@ private void StartOSU_Click(object sender, EventArgs e)
openFileDialog1.ShowDialog(); // 显示选取对话框
}

public static System.Diagnostics.Process p; // 定义进程p
private static System.Diagnostics.Process p; // 定义进程p

StartMode cmode;

Expand All @@ -79,9 +85,6 @@ enum StartMode
ModeB, // 传统模式
}

int ModeA_PID = 0;
string ModeA_Name = "";

private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
{
MessageBox.Show("请先将游戏设置为无边框窗口全屏,然后在系统托盘设置壁纸即可~");
Expand All @@ -91,10 +94,6 @@ private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
notifyIcon1.Visible = true; // 显示托盘图标
}

public static Boolean winseven = false;

IntPtr WorkerWIntPtr = fWorker(); // 定义句柄并设置为桌面WorkerW的句柄

private void Form1_Load(object sender, EventArgs e)
{
// 系统检测
Expand Down Expand Up @@ -122,7 +121,7 @@ private void Form1_Load(object sender, EventArgs e)
}
}

public static IntPtr fWorker()
private static IntPtr fWorker()
{

IntPtr workerw = IntPtr.Zero;
Expand All @@ -132,7 +131,7 @@ public static IntPtr fWorker()
IntPtr result = IntPtr.Zero;

SendMessageTimeout(progman,
0x052C,//用户码
0x052C, // 用户码
new IntPtr(0),
IntPtr.Zero,
SendMessageTimeoutFlags.SMTO_NORMAL,
Expand Down Expand Up @@ -185,7 +184,7 @@ private List<int> GetPIDByPName(string processName)
// Console.WriteLine(list[0]);
}

public static IntPtr GetMainWindowHandle(int processId)
private static IntPtr GetMainWindowHandle(int processId)
{
IntPtr MainWindowHandle = IntPtr.Zero;
EnumWindows(new EnumWindowsProc((hWnd, lParam) =>
Expand Down Expand Up @@ -231,9 +230,6 @@ private void AsWallpaperToolStripMenuItem_Click(object sender, EventArgs e)
SetParent(p.MainWindowHandle, WorkerWIntPtr); // 设置父窗体为桌面(注入WorkerW)
}

public const int WM_CLOSE = 0x10;
// ExitWindows函数

private void ExitToolStripMenuItem_Click(object sender, EventArgs e)
{
SendMessage(p.MainWindowHandle, WM_CLOSE, 0, 0); // 先关闭OSU!
Expand Down
Binary file added OSUDesktop/bin/Release/OSUDesktop.exe
Binary file not shown.
3 changes: 3 additions & 0 deletions OSUDesktop/bin/Release/OSUDesktop.exe.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup></configuration>
Binary file added OSUDesktop/bin/Release/OSUDesktop.pdb
Binary file not shown.

0 comments on commit ec1bb1d

Please sign in to comment.