213 lines
5.7 KiB
C#
213 lines
5.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Configuration;
|
|
using System.Diagnostics;
|
|
using System.Drawing;
|
|
using System.Runtime.InteropServices;
|
|
using System.Windows.Forms;
|
|
using AxWMPLib;
|
|
|
|
namespace ControlApp;
|
|
|
|
public class PopUp : Form
|
|
{
|
|
public string run_url;
|
|
|
|
private Timer tmr;
|
|
|
|
private const int GWL_STYLE = -20;
|
|
|
|
private const uint WS_POPUP = 2147483648u;
|
|
|
|
private const uint WS_CHILD = 536870912u;
|
|
|
|
private List<string> urls;
|
|
|
|
private char[] poptypearr;
|
|
|
|
private Utils Utils;
|
|
|
|
private char lastchar = 'n';
|
|
|
|
private IContainer components;
|
|
|
|
private AxWindowsMediaPlayer axWindowsMediaPlayer1;
|
|
|
|
[DllImport("user32.dll", SetLastError = true)]
|
|
private static extern uint GetWindowLong(nint hWnd, int nIndex);
|
|
|
|
[DllImport("user32.dll")]
|
|
private static extern int SetWindowLong(nint hWnd, int nIndex, uint dwNewLong);
|
|
|
|
public PopUp(string url)
|
|
{
|
|
Utils = new Utils();
|
|
urls = new List<string>();
|
|
InitializeComponent();
|
|
string poptypestr = "nnnn";
|
|
if (ConfigurationManager.AppSettings["PopType"] != null)
|
|
{
|
|
poptypestr = ConfigurationManager.AppSettings["PopType"];
|
|
}
|
|
poptypearr = poptypestr.ToCharArray();
|
|
if (poptypearr[0] == 's')
|
|
{
|
|
base.Opacity = 0.5;
|
|
}
|
|
if (poptypearr[1] == 't')
|
|
{
|
|
uint initialStyle = GetWindowLong(base.Handle, -20);
|
|
SetWindowLong(base.Handle, -20, initialStyle | 0x80000 | 0x20);
|
|
}
|
|
else if (poptypearr[1] == 'c')
|
|
{
|
|
base.Click += clickable;
|
|
axWindowsMediaPlayer1.ClickEvent += AxWindowsMediaPlayer1_ClickEvent;
|
|
}
|
|
if (poptypearr[2] == 'm' && poptypearr[3] != 'n')
|
|
{
|
|
Timer timer = new Timer();
|
|
timer.Interval = (int)TimeSpan.FromSeconds(2.0).TotalMilliseconds;
|
|
timer.Tick += popup_tick2;
|
|
timer.Start();
|
|
}
|
|
if (Utils.IsWebPage(url))
|
|
{
|
|
Process.Start(new ProcessStartInfo
|
|
{
|
|
FileName = url,
|
|
UseShellExecute = true
|
|
});
|
|
Close();
|
|
}
|
|
else
|
|
{
|
|
run_url = url;
|
|
}
|
|
tmr = new Timer();
|
|
tmr.Tick += popup_tick;
|
|
Random rand = new Random();
|
|
if (ConfigurationManager.AppSettings["PopSet"] != null)
|
|
{
|
|
string lengthtime = ConfigurationManager.AppSettings["PopSet"].ToString();
|
|
if ("Long" == lengthtime)
|
|
{
|
|
int mins = rand.Next(11);
|
|
tmr.Interval = (int)TimeSpan.FromMinutes(mins).TotalMilliseconds;
|
|
}
|
|
else
|
|
{
|
|
int mins2 = rand.Next(55) + 5;
|
|
tmr.Interval = (int)TimeSpan.FromSeconds(mins2).TotalMilliseconds;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void AxWindowsMediaPlayer1_ClickEvent(object sender, _WMPOCXEvents_ClickEvent e)
|
|
{
|
|
Close();
|
|
}
|
|
|
|
public void add_url(string url)
|
|
{
|
|
urls.Add(url);
|
|
}
|
|
|
|
public void clickable(object sender, EventArgs e)
|
|
{
|
|
Close();
|
|
}
|
|
|
|
public void popup_tick2(object sender, EventArgs e)
|
|
{
|
|
Random random = new Random();
|
|
int screenWidth = Screen.PrimaryScreen.Bounds.Width;
|
|
int screenHeight = Screen.PrimaryScreen.Bounds.Height;
|
|
int randomX = random.Next(0, screenWidth - base.Width);
|
|
int randomY = random.Next(0, screenHeight - base.Height);
|
|
base.Location = new Point(randomX, randomY);
|
|
}
|
|
|
|
public void popup_tick(object sender, EventArgs e)
|
|
{
|
|
if (urls.Count > 0)
|
|
{
|
|
run_url = urls[0];
|
|
urls.RemoveAt(0);
|
|
axWindowsMediaPlayer1.Visible = true;
|
|
axWindowsMediaPlayer1.URL = run_url;
|
|
axWindowsMediaPlayer1.Ctlenabled = false;
|
|
axWindowsMediaPlayer1.uiMode = "None";
|
|
axWindowsMediaPlayer1.stretchToFit = true;
|
|
axWindowsMediaPlayer1.settings.autoStart = true;
|
|
axWindowsMediaPlayer1.settings.setMode("loop", varfMode: true);
|
|
}
|
|
else
|
|
{
|
|
Close();
|
|
}
|
|
}
|
|
|
|
private void PopUp_Load(object sender, EventArgs e)
|
|
{
|
|
if (poptypearr[3] == 'f')
|
|
{
|
|
base.WindowState = FormWindowState.Maximized;
|
|
}
|
|
else
|
|
{
|
|
Random random = new Random();
|
|
int screenWidth = Screen.PrimaryScreen.Bounds.Width;
|
|
int screenHeight = Screen.PrimaryScreen.Bounds.Height;
|
|
int randomX = random.Next(0, screenWidth - base.Width);
|
|
int randomY = random.Next(0, screenHeight - base.Height);
|
|
base.StartPosition = FormStartPosition.Manual;
|
|
base.Location = new Point(randomX, randomY);
|
|
}
|
|
axWindowsMediaPlayer1.URL = run_url;
|
|
axWindowsMediaPlayer1.Ctlenabled = false;
|
|
axWindowsMediaPlayer1.uiMode = "None";
|
|
axWindowsMediaPlayer1.stretchToFit = true;
|
|
axWindowsMediaPlayer1.settings.autoStart = true;
|
|
axWindowsMediaPlayer1.settings.setMode("loop", varfMode: true);
|
|
tmr.Start();
|
|
}
|
|
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
if (disposing && components != null)
|
|
{
|
|
components.Dispose();
|
|
}
|
|
base.Dispose(disposing);
|
|
}
|
|
|
|
private void InitializeComponent()
|
|
{
|
|
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(PopUp));
|
|
this.axWindowsMediaPlayer1 = new AxWMPLib.AxWindowsMediaPlayer();
|
|
((System.ComponentModel.ISupportInitialize)this.axWindowsMediaPlayer1).BeginInit();
|
|
base.SuspendLayout();
|
|
this.axWindowsMediaPlayer1.Dock = System.Windows.Forms.DockStyle.Fill;
|
|
this.axWindowsMediaPlayer1.Enabled = true;
|
|
this.axWindowsMediaPlayer1.Location = new System.Drawing.Point(0, 0);
|
|
this.axWindowsMediaPlayer1.Name = "axWindowsMediaPlayer1";
|
|
this.axWindowsMediaPlayer1.OcxState = (System.Windows.Forms.AxHost.State)resources.GetObject("axWindowsMediaPlayer1.OcxState");
|
|
this.axWindowsMediaPlayer1.TabIndex = 0;
|
|
base.AutoScaleDimensions = new System.Drawing.SizeF(7f, 15f);
|
|
base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
|
base.ClientSize = new System.Drawing.Size(800, 450);
|
|
base.ControlBox = false;
|
|
base.Controls.Add(this.axWindowsMediaPlayer1);
|
|
base.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
|
|
base.Name = "PopUp";
|
|
base.ShowIcon = false;
|
|
base.ShowInTaskbar = false;
|
|
this.Text = "PopUp";
|
|
base.TopMost = true;
|
|
base.Load += new System.EventHandler(PopUp_Load);
|
|
((System.ComponentModel.ISupportInitialize)this.axWindowsMediaPlayer1).EndInit();
|
|
base.ResumeLayout(false);
|
|
}
|
|
}
|