示例#1
0
        /// <summary>
        /// 打开PPT文档并播放显示。
        /// </summary>
        /// <param name="filePath">PPT文件路径</param>
        public void PPTOpen(string filePath)
        {
            new Helper().InsertErrorMsg(filePath, "打开38ppt文件");
            if (filePath.ToLower().Contains("ppt"))
            {
                //Thread th1 = new Thread(new ParameterizedThreadStart(dakaippt));
                //th1.IsBackground = true;
                //th1.Start(filePath);
                //return;
                IntPtr hwndRecvWindow = IntPtr.Zero;
                try
                {
                    RegistryKey key;
                    key = Registry.CurrentUser;
                    RegistryKey s = key.OpenSubKey("SOFTWARE\\ClovSoft\\EasyControl3\\SET");

                    string sd = s.GetValue("MAINWND").ToString();
                    hwndRecvWindow = (IntPtr)UInt32.Parse(sd);
                    //hwndRecvWindow = Marshal.StringToHGlobalAnsi(sd);
                    //hwndRecvWindow = (IntPtr)s.GetValue("MAINWND");
                    s.Close();
                }
                catch (Exception e)
                {
                    new Helper().InsertErrorMsg(filePath, "打开56ppt文件");
                    Thread th = new Thread(new ParameterizedThreadStart(dakaippt));
                    th.IsBackground = true;
                    th.Start(filePath);
                    return;
                }

                //接收端的窗口句柄
                //IntPtr hwndRecvWindow = ImportFromDLL.FindWindow(null, strDlgTitle);
                if (hwndRecvWindow == IntPtr.Zero)
                {
                    new Helper().InsertErrorMsg(filePath, "打开67ppt文件");
                    if (this.objApp != null)
                    {
                        return;
                    }
                    string path = @"" + filePath;
                    Thread th   = new Thread(new ParameterizedThreadStart(dakaippt));
                    th.IsBackground = true;
                    th.Start(filePath);
                    //Console.WriteLine("请先启动接收消息程序");
                    return;
                }

                //自己的窗口句柄
                IntPtr hwndSendWindow = IndexForm.Intptrw;
                if (hwndSendWindow == IntPtr.Zero)
                {
                    Console.WriteLine("获取自己的窗口句柄失败,请重试");
                    return;
                }
                //填充COPYDATA结构
                ImportFromDLL.COPYDATASTRUCT copydata = new ImportFromDLL.COPYDATASTRUCT();
                copydata.cbData = Encoding.Unicode.GetBytes(filePath).Length; //长度 注意不要用strText.Length;
                copydata.lpData = filePath;                                   //内容
                copydata.dwData = 1;
                new Helper().InsertErrorMsg(filePath, "打开89ppt文件");
                ImportFromDLL.SendMessage(hwndRecvWindow, ImportFromDLL.WM_COPYDATA, hwndSendWindow, ref copydata);
            }
            else
            {
                new Helper().InsertErrorMsg(filePath, "打开92ppt文件");
                Thread th = new Thread(new ParameterizedThreadStart(dakaippt));
                th.IsBackground = true;
                th.Start(filePath);
                return;
            }
            //Thread.Sleep(1000);
            //防止连续打开多个PPT程序.
            //try
            //{
            //    objApp = new POWERPOINT.Application();
            //    //以非只读方式打开,方便操作结束后保存.
            //    objPresSet = objApp.Presentations.Open(filePath, OFFICECORE.MsoTriState.msoFalse, OFFICECORE.MsoTriState.msoFalse, OFFICECORE.MsoTriState.msoFalse);

            //    //Prevent Office Assistant from displaying alert messages:
            //    bAssistantOn = objApp.Assistant.On;
            //    objApp.Assistant.On = false;

            //    objSSS = this.objPresSet.SlideShowSettings;
            //    objSSS.Run();
            //}
            //catch (Exception ex)
            //{
            //    this.objApp.Quit();
            //}
        }
示例#2
0
        private void SendBtn_Click(object sender, RoutedEventArgs e)
        {
            string strDlgTitle = "RecvMessage";

            strDlgTitle = "WindowsProject2";

            //接收端的窗口句柄
            IntPtr hwndRecvWindow = ImportFromDLL.FindWindow(null, strDlgTitle);

            if (hwndRecvWindow == IntPtr.Zero)
            {
                Console.WriteLine("请先启动接收消息程序");
                return;
            }

            //自己的窗口句柄
            IntPtr hwndSendWindow = ImportFromDLL.GetConsoleWindow();

            hwndSendWindow = WHwnd.GetWindowHwndSource(this);
            if (hwndSendWindow == IntPtr.Zero)
            {
                Console.WriteLine("获取自己的窗口句柄失败,请重试");
                return;
            }

            for (int i = 0; i < 1; i++)
            {
                string strText = DateTime.Now.ToString();

                byte[] imagedata = new byte[65536];
                byte[] data      = new byte[65536];
                Random random    = new Random();
                for (int index = 0; index < imagedata.Length; index++)
                {
                    int ccc = random.Next(0, byte.MaxValue);
                    imagedata[index] = (byte)44;
                    data[index]      = (byte)ccc;
                }
                //填充COPYDATA结构
                ImportFromDLL.COPYDATASTRUCT copydata = new ImportFromDLL.COPYDATASTRUCT();
                //copydata.cbData = Encoding.Default.GetBytes(strText).Length; //长度 注意不要用strText.Length;
                //copydata.lpData = strText;                                   //内容

                // {
                ImportFromDLL.COPYDATASTRUCT cds = new ImportFromDLL.COPYDATASTRUCT();

                //cds.dwData = (IntPtr)flag;

                cds.cbData = data.Length;

                cds.lpData = Marshal.AllocHGlobal(data.Length);

                Marshal.Copy(data, 0, cds.lpData, data.Length);

                //SendMessage(WINDOW_HANDLER, WM_COPYDATA, 0, ref cds);
                // }

                //copydata.cbData = imagedata.Length; //长度 注意不要用strText.Length;
                //copydata.lpData = imagedata;                                   //内容

                ImportFromDLL.SendMessage(hwndRecvWindow, ImportFromDLL.WM_COPYDATA, hwndSendWindow, ref cds);

                Console.WriteLine(strText);
                Thread.Sleep(1000);
            }
        }