Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
idadwind1 committed Apr 24, 2023
1 parent 74b370f commit 5986b7c
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 149 deletions.
29 changes: 26 additions & 3 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
Expand All @@ -9,6 +8,9 @@ namespace ProgressBarSrc
{
internal static class Program
{

[DllImport("user32.dll")]
private static extern bool IsWindowVisible(IntPtr handle);
/// <summary>
/// 应用程序的主入口点。
/// </summary>
Expand All @@ -17,7 +19,28 @@ static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if (args.Length != 0 && args[0].ToUpper() == "/S") { Application.Run(new ScreenSaverForm()); return; }
/*foreach (var item in args)
{
MessageBox.Show(item);
}*/
if (args.Length != 0)
{
switch (args[0].ToUpper())
{
case "-S":
case "/S":
Application.Run(new ScreenSaverForm());
return;
case "-P":
case "/P":
if (args.Length < 2) return;
if (!int.TryParse(args[1], out int result)) return;
IntPtr handle = new IntPtr(result);
Application.Run(new ScreenSaverForm(handle));
return;
}
if (!args[0].ToUpper().StartsWith("/C")) return;
}
Application.Run(new Settings());
}

Expand Down
55 changes: 52 additions & 3 deletions ScreenSaverForm.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
using System;
using System.Drawing;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace ProgressBarSrc
{
public partial class ScreenSaverForm : Form
{
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

[DllImport("user32.dll", SetLastError = true)]
static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);

[DllImport("user32.dll")]
static extern bool GetClientRect(IntPtr hWnd, out RECT lpRect);
struct RECT
{
public int Left;
public int Top;
public int Right;
public int Bottom;

public Rectangle ToRectangle()
{
return new Rectangle(Left, Top, Right - Left, Bottom - Top);
}
}

private int maxProgressBarWidth = 300;
private int minProgressBarWidth = 50;
private int maxProgressBarHeight = 40;
Expand All @@ -26,10 +48,37 @@ public ScreenSaverForm()
Bounds = Screen.PrimaryScreen.Bounds;
BackColor = Color.Black;
label1.ForeColor = Color.White;
IsPreviewMode = false;
}

private IntPtr previewHandle;

public bool IsPreviewMode;

public ScreenSaverForm(IntPtr handle)
{
InitializeComponent();
FormBorderStyle = FormBorderStyle.None;
Bounds = Screen.PrimaryScreen.Bounds;
BackColor = Color.Black;
label1.ForeColor = Color.White;
previewHandle = handle;
IsPreviewMode = true;
}

double x;
double y;

private void ScreenSaverForm_Load(object sender, EventArgs e)
{
if (IsPreviewMode)
{
SetParent(Handle, previewHandle);
GetWindowRect(previewHandle, out RECT rect);
Size = rect.ToRectangle().Size;
//GetClientRect(previewHandle, out RECT rect);
//Bounds = rect.ToRectangle();
}
Program.FilesINI iniFile = new Program.FilesINI(Path.Combine(Application.StartupPath, "ProBarScrSettings.ini"));

string background = iniFile.Read("Background", "Settings");
Expand Down Expand Up @@ -67,7 +116,7 @@ private void ScreenSaverForm_Load(object sender, EventArgs e)
Timer timer3 = new Timer();
timer.Interval = 10;
timer2.Interval = 1000;
timer3.Interval = random.Next(0, ProgressBarCount * 100 + 1);
timer3.Interval = random.Next(1, ProgressBarCount * 100 + 1);
timer.Tick += Update;
timer2.Tick += UpdateValue;
timer3.Tick += MakeDelay;
Expand Down Expand Up @@ -130,12 +179,12 @@ private void MouseLeaveProgressBar(object sender, EventArgs e)

private void ScreenSaverForm_UserActed(object sender, MouseEventArgs e)
{
Close();
if (!IsPreviewMode) Close();
}

private void ScreenSaverForm_UserActed(object sender, KeyPressEventArgs e)
{
Close();
if (!IsPreviewMode) Close();
}
}
}
Loading

0 comments on commit 5986b7c

Please sign in to comment.