FrmReceive.cs 3 KB
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using GeneralLib;



namespace SunVoteARSPPT
{
    public partial class FrmReceive : Form
    {
        public FrmReceive()
        {
            InitializeComponent();
        }

        const int WM_COPYDATA = 0x004A;

        protected override void DefWndProc(ref System.Windows.Forms.Message m)
        {
            switch (m.Msg)
            {
                case WM_COPYDATA:
                    COPYDATASTRUCT mystr = new COPYDATASTRUCT();
                    Type mytype = mystr.GetType();
                    mystr = (COPYDATASTRUCT)m.GetLParam(mytype);

                    string[] ary = mystr.lpData.Split(new char[] { ',' });
                    bool isCatch = false;
                    if (ary.Length >= 3)
                    {
                        SendKeyCodePar par = new SendKeyCodePar();
                        par.KeyCode = ConvertOper.Convert(ary[0]).ToInt;
                        par.KeyChr = ary[1];
                        par.Shift = ConvertOper.Convert(ary[2]).ToInt;
                        par.Catch = isCatch;

                        if (Globals.SunVoteARSAddIn.frmVoteBar.frmVoteDetail!=null)
                        {
                            if (Globals.SunVoteARSAddIn.frmVoteBar.Visible)
                            {
                                Globals.SunVoteARSAddIn.frmVoteBar.Select();
                                Globals.SunVoteARSAddIn.frmVoteBar.Activate();
                            }
                        }

                        tmrRun.Tag = par;
                        tmrRun.Interval = 1;
                        tmrRun.Enabled = true;
                    }

                    break;
                default:
                    base.DefWndProc(ref m);
                    break;
            }
        }

        private void FrmReceive_Load(object sender, EventArgs e)
        {
            this.Hide();
            this.ShowInTaskbar = false;
            FrmVoteBar.ActivateSlideShowWindow();
            //tmrRun.Enabled = true;
        }

        private void tmrRun_Tick(object sender, EventArgs e)
        {
            tmrRun.Enabled = false;

            if (tmrRun.Tag == null)
                return;

            SendKeyCodePar par = tmrRun.Tag as SendKeyCodePar;
            
            if (Globals.SunVoteARSAddIn.frmVoteBar != null)
            {                
                Globals.SunVoteARSAddIn.frmVoteBar.HotKey_KeyDownEvent(par.KeyCode, par.KeyChr, par.Shift, out par.Catch);                
            }
        }

        private void FrmReceive_FormClosing(object sender, FormClosingEventArgs e)
        {
            tmrRun.Enabled = false;
        }
    }

    public class SendKeyCodePar
    {
        public int KeyCode = 0;
        public string KeyChr = "";
        public int Shift = 0;
        public bool Catch = false;
    }
}