using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using System.Threading;
using System.Xml;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
namespace auplayer
{
class Program
{
static void Main(string[] args)
{
Thread th = new Thread(new ThreadStart(formshow));
th.Start();
Play pla = new Play();
pla.Init();
pla.loadconfig("./config.xml");
pla.backfunc();
}
static void formshow()
{
Application.Run(new Alert());
}
}
public class Play
{
[DllImport("user32.dll")]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", EntryPoint = "SendMessage")]
private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
[DllImport("user32.dll", SetLastError = true)]
static extern bool PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", SetLastError = true)]
static extern bool PostMessage(IntPtr hwnd, int wmsg, int wparam, int lparam);
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool CloseHandle(IntPtr handle);
[DllImport("user32.dll", EntryPoint = "GetWindowThreadProcessId")]
public static extern uint GetWindowThreadProcessId(IntPtr hWnd, ref uint lpdwProcessId);
[DllImport("User32.dll", EntryPoint = "SendMessage")]
private static extern int SendMessage(
IntPtr hWnd, // 信息发往的窗口的句柄
int Msg, // 消息ID
int wParam, // 参数1
ref AUO_lParam lParam
);
private const int WM_ACTIVATEAPP = 0x001C;
const int WM_CLOSE = 0x10;
const int SC_CLOSE = 0xF060; //close the window
const uint WM_DESTROY = 0x02;
const int WM_SYSCOMMAND = 0x0112;
const int SC_MINIMIZE = 0xF020;
const int SC_MAXIMIZE = 0xF030;
const uint WM_QUIT = 0x12;
public const int USER = 0x500;
public const int MYMESSAGE = USER + 100;
XmlDocument doc;
String DirFile;
Int32 ScanTime;
IntPtr ptr;
string cmddir;
string runfilename;
string runpptid;
string[] filenames;
string newfilename;
filelist[] fileattr;
int filenum;
public struct AUO_lParam
{
public int i;
public string s;
}
public struct filelist
{
public string name;
public string time;
public DateTime tdate;
}
AUO_lParam message;
void formf()
{
//Application.Run(new Alert());
}
public void Init()
{
message = new AUO_lParam();
ptr = FindWindow(null, "Alert");
if (ptr.ToInt32() == 0)
{
Console.WriteLine("none found form ");
}
}
public void loadconfig(string data)
{
try
{
cmddir = "ff";
Console.WriteLine("Start Loading Config File...");
XmlNode dirfilenode, scantimenode;
doc = new XmlDocument();
doc.Load(data);
dirfilenode = doc.SelectSingleNode("/root/DirFile");
scantimenode = doc.SelectSingleNode("/root/ScanTime");
DirFile = dirfilenode.InnerText.Trim() + "\\" + cmddir;
ScanTime = Convert.ToInt32(scantimenode.InnerText.Trim());
Console.WriteLine("ScanTime is: " + ScanTime);
Console.WriteLine("Dest File is: " + DirFile);
Console.WriteLine("Config File Loading Success...");
}
catch (Exception ex)
{
message.s = "加载配置文件时出现错误,请重试!";
message.i = message.s.Length;
PostMessage(ptr, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
SendMessage(ptr, MYMESSAGE, 1, ref message);
Console.WriteLine(ex.ToString());
}
}
public void StartPPT(String path)
{
PPT pproc = new PPT();
pproc.StartFile(path);
runpptid = pproc.pptname;
}
public void backfunc()
{
while (true)
{
// getfilenames(DirFile);
getattrfile(getfilelist(DirFile));
// getfileattr();
getlastfile();
if (checkchange() == true)
{
if (runpptid == null || runpptid == "")
{
runfilename = newfilename;
StartPPT(runfilename);
}
else
{
killrunppt(runpptid);
Thread.Sleep(1000);
runfilename = newfilename;
StartPPT(runfilename);
}
}
else
{
Thread.Sleep(2000);
}
Thread.Sleep(ScanTime + 6000);
}
}
public void killrunppt(string filename)
{
Thread.Sleep(1000);
Process[] temp = Process.GetProcessesByName(filename);
Int32 i = 0;
Console.WriteLine(temp.Length);
for (i = 0; i < temp.Length; i++)
{
temp[i].Kill();
}
}
public string[] getfilelist(string path)
{
string[] temp;
try
{
if (System.IO.Directory.Exists(path))
{
temp = Directory.GetFiles(path, "*.ppt");
filenum = temp.Length;
}
else
{
temp = Directory.GetFiles(path, "*.ppt");
SendInfo("目录指定错误请重新指定目录...");
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
temp = Directory.GetFiles(path, "*.ppt");
}
return temp;
}
public void getfilenames(string path)
{
try
{
if (System.IO.Directory.Exists(path))
{
filenames = Directory.GetFiles(path, "*.ppt");
}
else
{
SendInfo("目录指定错误请重新指定目录...");
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
public void getlastfile()
{
Console.WriteLine("get file number " + filenum);
if (filenum == 0)
{
SendInfo("目标文件夹中没有要播放的文件,请放置文件..");
return;
}
DateTime temp;
string tempname = fileattr[0].name;
temp = fileattr[0].tdate;
int i = 0;
int j = 0;
for (i = 0; i < filenum; i++)
{
if (temp < fileattr[i].tdate)
{
temp = fileattr[i].tdate;
j = i;
tempname = fileattr[i].name;
}
}
newfilename = tempname;
}
public void getattrfile(string[] filelist)
{
if (filelist.Length == 0)
{
SendInfo("目标文件夹内没有要播放的文件,请放置播放文件..");
return;
}
fileattr = new filelist[filelist.Length];
int i;
for (i = 0; i < filelist.Length; i++)
{
fileattr[i].name = filelist[i];
fileattr[i].tdate = getfiledate(filelist[i]);
}
}
public void getfileattr()
{
if (filenames.Length == 0)
{
SendInfo("目标文件夹内没有要播放的文件,请放置播放文件..");
return;
}
fileattr = new filelist[filenames.Length];
int i;
for (i = 0; i < filenames.Length; i++)
{
fileattr[i].name = filenames[i];
fileattr[i].tdate = getfiledate(filenames[i]);
}
}
public bool checkchange()
{
if (runfilename != newfilename)
{
Console.WriteLine(runfilename);
Console.WriteLine(newfilename);
runfilename = newfilename;
Console.WriteLine("checkchange true");
return true;
}
else
{
Console.WriteLine("checkchange false");
return false;
}
}
public DateTime getfiledate(string filename)
{
if (System.IO.File.Exists(filename))
{
FileInfo info = new FileInfo(filename);
return info.CreationTime;
}
else
{
String time = "1900-02-21 12:23:33";
return DateTime.Parse(time);
}
}
public void SendInfo(string data)
{
message.s = data;
message.i = message.s.Length;
PostMessage(ptr, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
SendMessage(ptr, MYMESSAGE, 1, ref message);
}
}
public class PPT
{
public IntPtr ppt;
public int errcode;
public string pptname;
public PPT()
{
errcode = 0;
}
public void StartFile(string data)
{
try
{
if (data == "")
{
}
Process myProcess = new Process();
myProcess.StartInfo.UseShellExecute = true;
myProcess.StartInfo.FileName = data;
myProcess.StartInfo.CreateNoWindow = true;
myProcess.Start();
ppt = myProcess.Handle;
pptname = myProcess.ProcessName;
}
catch (Exception ex)
{
}
}
public void KillPPT()
{
if (ppt.ToInt32() != 0)
{
try
{
// Process.GetProcessById(Convert.ToInt32(ppt)).Close();
Process[] temp = Process.GetProcessesByName(pptname);
Int32 i = 0;
Console.WriteLine(temp.Length);
Thread.Sleep(3000);
for (i = 0; i < temp.Length; i++)
{
temp[i].Kill();
}
errcode = 100;
}
catch (Exception Ex)
{
Console.WriteLine(Ex.ToString());
errcode = 200;
}
}
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using System.Threading;
using System.Xml;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
namespace auplayer
{
class Program
{
static void Main(string[] args)
{
Thread th = new Thread(new ThreadStart(formshow));
th.Start();
Play pla = new Play();
pla.Init();
pla.loadconfig("./config.xml");
pla.backfunc();
}
static void formshow()
{
Application.Run(new Alert());
}
}
public class Play
{
[DllImport("user32.dll")]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", EntryPoint = "SendMessage")]
private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
[DllImport("user32.dll", SetLastError = true)]
static extern bool PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", SetLastError = true)]
static extern bool PostMessage(IntPtr hwnd, int wmsg, int wparam, int lparam);
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool CloseHandle(IntPtr handle);
[DllImport("user32.dll", EntryPoint = "GetWindowThreadProcessId")]
public static extern uint GetWindowThreadProcessId(IntPtr hWnd, ref uint lpdwProcessId);
[DllImport("User32.dll", EntryPoint = "SendMessage")]
private static extern int SendMessage(
IntPtr hWnd, // 信息发往的窗口的句柄
int Msg, // 消息ID
int wParam, // 参数1
ref AUO_lParam lParam
);
private const int WM_ACTIVATEAPP = 0x001C;
const int WM_CLOSE = 0x10;
const int SC_CLOSE = 0xF060; //close the window
const uint WM_DESTROY = 0x02;
const int WM_SYSCOMMAND = 0x0112;
const int SC_MINIMIZE = 0xF020;
const int SC_MAXIMIZE = 0xF030;
const uint WM_QUIT = 0x12;
public const int USER = 0x500;
public const int MYMESSAGE = USER + 100;
XmlDocument doc;
String DirFile;
Int32 ScanTime;
IntPtr ptr;
string cmddir;
string runfilename;
string runpptid;
string[] filenames;
string newfilename;
filelist[] fileattr;
int filenum;
public struct AUO_lParam
{
public int i;
public string s;
}
public struct filelist
{
public string name;
public string time;
public DateTime tdate;
}
AUO_lParam message;
void formf()
{
//Application.Run(new Alert());
}
public void Init()
{
message = new AUO_lParam();
ptr = FindWindow(null, "Alert");
if (ptr.ToInt32() == 0)
{
Console.WriteLine("none found form ");
}
}
public void loadconfig(string data)
{
try
{
cmddir = "ff";
Console.WriteLine("Start Loading Config File...");
XmlNode dirfilenode, scantimenode;
doc = new XmlDocument();
doc.Load(data);
dirfilenode = doc.SelectSingleNode("/root/DirFile");
scantimenode = doc.SelectSingleNode("/root/ScanTime");
DirFile = dirfilenode.InnerText.Trim() + "\\" + cmddir;
ScanTime = Convert.ToInt32(scantimenode.InnerText.Trim());
Console.WriteLine("ScanTime is: " + ScanTime);
Console.WriteLine("Dest File is: " + DirFile);
Console.WriteLine("Config File Loading Success...");
}
catch (Exception ex)
{
message.s = "加载配置文件时出现错误,请重试!";
message.i = message.s.Length;
PostMessage(ptr, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
SendMessage(ptr, MYMESSAGE, 1, ref message);
Console.WriteLine(ex.ToString());
}
}
public void StartPPT(String path)
{
PPT pproc = new PPT();
pproc.StartFile(path);
runpptid = pproc.pptname;
}
public void backfunc()
{
while (true)
{
// getfilenames(DirFile);
getattrfile(getfilelist(DirFile));
// getfileattr();
getlastfile();
if (checkchange() == true)
{
if (runpptid == null || runpptid == "")
{
runfilename = newfilename;
StartPPT(runfilename);
}
else
{
killrunppt(runpptid);
Thread.Sleep(1000);
runfilename = newfilename;
StartPPT(runfilename);
}
}
else
{
Thread.Sleep(2000);
}
Thread.Sleep(ScanTime + 6000);
}
}
public void killrunppt(string filename)
{
Thread.Sleep(1000);
Process[] temp = Process.GetProcessesByName(filename);
Int32 i = 0;
Console.WriteLine(temp.Length);
for (i = 0; i < temp.Length; i++)
{
temp[i].Kill();
}
}
public string[] getfilelist(string path)
{
string[] temp;
try
{
if (System.IO.Directory.Exists(path))
{
temp = Directory.GetFiles(path, "*.ppt");
filenum = temp.Length;
}
else
{
temp = Directory.GetFiles(path, "*.ppt");
SendInfo("目录指定错误请重新指定目录...");
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
temp = Directory.GetFiles(path, "*.ppt");
}
return temp;
}
public void getfilenames(string path)
{
try
{
if (System.IO.Directory.Exists(path))
{
filenames = Directory.GetFiles(path, "*.ppt");
}
else
{
SendInfo("目录指定错误请重新指定目录...");
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
public void getlastfile()
{
Console.WriteLine("get file number " + filenum);
if (filenum == 0)
{
SendInfo("目标文件夹中没有要播放的文件,请放置文件..");
return;
}
DateTime temp;
string tempname = fileattr[0].name;
temp = fileattr[0].tdate;
int i = 0;
int j = 0;
for (i = 0; i < filenum; i++)
{
if (temp < fileattr[i].tdate)
{
temp = fileattr[i].tdate;
j = i;
tempname = fileattr[i].name;
}
}
newfilename = tempname;
}
public void getattrfile(string[] filelist)
{
if (filelist.Length == 0)
{
SendInfo("目标文件夹内没有要播放的文件,请放置播放文件..");
return;
}
fileattr = new filelist[filelist.Length];
int i;
for (i = 0; i < filelist.Length; i++)
{
fileattr[i].name = filelist[i];
fileattr[i].tdate = getfiledate(filelist[i]);
}
}
public void getfileattr()
{
if (filenames.Length == 0)
{
SendInfo("目标文件夹内没有要播放的文件,请放置播放文件..");
return;
}
fileattr = new filelist[filenames.Length];
int i;
for (i = 0; i < filenames.Length; i++)
{
fileattr[i].name = filenames[i];
fileattr[i].tdate = getfiledate(filenames[i]);
}
}
public bool checkchange()
{
if (runfilename != newfilename)
{
Console.WriteLine(runfilename);
Console.WriteLine(newfilename);
runfilename = newfilename;
Console.WriteLine("checkchange true");
return true;
}
else
{
Console.WriteLine("checkchange false");
return false;
}
}
public DateTime getfiledate(string filename)
{
if (System.IO.File.Exists(filename))
{
FileInfo info = new FileInfo(filename);
return info.CreationTime;
}
else
{
String time = "1900-02-21 12:23:33";
return DateTime.Parse(time);
}
}
public void SendInfo(string data)
{
message.s = data;
message.i = message.s.Length;
PostMessage(ptr, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
SendMessage(ptr, MYMESSAGE, 1, ref message);
}
}
public class PPT
{
public IntPtr ppt;
public int errcode;
public string pptname;
public PPT()
{
errcode = 0;
}
public void StartFile(string data)
{
try
{
if (data == "")
{
}
Process myProcess = new Process();
myProcess.StartInfo.UseShellExecute = true;
myProcess.StartInfo.FileName = data;
myProcess.StartInfo.CreateNoWindow = true;
myProcess.Start();
ppt = myProcess.Handle;
pptname = myProcess.ProcessName;
}
catch (Exception ex)
{
}
}
public void KillPPT()
{
if (ppt.ToInt32() != 0)
{
try
{
// Process.GetProcessById(Convert.ToInt32(ppt)).Close();
Process[] temp = Process.GetProcessesByName(pptname);
Int32 i = 0;
Console.WriteLine(temp.Length);
Thread.Sleep(3000);
for (i = 0; i < temp.Length; i++)
{
temp[i].Kill();
}
errcode = 100;
}
catch (Exception Ex)
{
Console.WriteLine(Ex.ToString());
errcode = 200;
}
}
}
}
}