实现ppt幻灯片播放倒计时

需求:为控制会议时间,采取ppt幻灯片播放倒计时的办法,倒计时5分钟。

分析:用EnumWindows枚举窗口,发现PPT窗口类名有三种:PP12FrameClass、MS-SDIb、screenClass。其中screenClass代表全屏播放窗口。

设计思路:在timer控件中用FindWindow检查有无screenClass的窗口,用TimeSpan倒计时。

代码如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;

namespace pptClock
{
    public partial class Form1 : Form
    {
        [DllImport("user32.dll", EntryPoint = "FindWindow")]
        private extern static IntPtr FindWindow(string lpClassName, string lpWindowName);
               
        TimeSpan ts ;//设定播放限时器

        public Form1()
        {
            InitializeComponent();
            this.timer1.Enabled = true;
            this.timer1.Interval = 1000;
        }
      
        private void timer1_Tick(object sender, EventArgs e)
        {
           
            IntPtr hwnd = FindWindow("screenClass", null);
            if (hwnd != IntPtr.Zero)//有全屏播放的PPT
            {
                ts = new TimeSpan(0, 5, 0);//计时5分钟
                ts = ts.Subtract(new TimeSpan(0, 0, 1));//每隔一秒减去一秒 
                this.Text = ts.Minutes.ToString() + ":" + ts.Seconds.ToString();
                this.Show();//显示计时窗口
                this.BringToFront();
                this.TopMost = true;
            }
            else {//没有ppt在播放
                this.Hide();
            }

        }


    }
}

猜你喜欢

转载自www.cnblogs.com/pu369/p/9930842.html