Esempio n. 1
0
        public const int DBT_DEVICEREMOVECOMPLETE = 0x8004;      //系统检测到设备已经卸载或者拔出
        #endregion

        //钩子(winform中直接重写WndProc即可进行消息拦截)
        protected override void WndProc(ref Message m)
        {
            try
            {
                if (m.Msg == WM_COPYDATA)
                {
                    CurGlobals.SENDMESSAGETRANSFERSTRUCT temp = (CurGlobals.SENDMESSAGETRANSFERSTRUCT)Marshal.PtrToStructure(m.LParam, typeof(CurGlobals.SENDMESSAGETRANSFERSTRUCT));
                    //新建/打开任务失败
                    if (temp.cbData == 0)
                    {
                        _clickIndex = _index;
                        deleteBtn_Click(null, null);
                    }
                    //新建/打开任务成功
                    if (temp.cbData > 0)
                    {
                    }
                    ;
                }

                if (m.Msg == WM_DEVICECHANGE)
                {
                    switch (m.WParam.ToInt32())
                    {
                    case DBT_DEVICEARRIVAL:
                        if (!_isCopy)
                        {
                            _isCopy = true;
                            //检测硬件设备是否连接成功
                            IsDeviceExist("in");
                        }
                        break;

                    case DBT_DEVICEREMOVECOMPLETE:
                        _isCopy = false;
                        //检测硬件设备是否连接成功
                        IsDeviceExist("out");
                        break;

                    default:
                        break;
                    }
                }
            }
            catch (Exception)
            {
                //MessageBox.Show("异常");
            }
            finally
            {
                base.WndProc(ref m);
            }
        }
Esempio n. 2
0
        private void FlashRecovery_Resize(object sender, EventArgs e)
        {
            Refresh();

            //通知业务进程改变窗体大小
            CurGlobals.SENDMESSAGETRANSFERSTRUCT temp = new CurGlobals.SENDMESSAGETRANSFERSTRUCT();
            temp.dwData = this.Handle;
            //设置业务进程的窗体大小
            string tempSize = $"{this.exeTabControl.Width - 5},{this.exeTabControl.Height - 5}".PadLeft(20, '0');

            byte[] arr = System.Text.Encoding.Default.GetBytes(tempSize);
            //参数的长度
            temp.cbData = arr.Length + 1;
            //业务进程窗体大小参数
            temp.lpData = tempSize;
            //向每个进程发消息
            foreach (Process p in m_AppProcess)
            {
                CurGlobals.SendMessage(p.MainWindowHandle, WM_COPYDATA, IntPtr.Zero, ref temp);
            }
        }
Esempio n. 3
0
        //将指定的程序嵌入指定的控件
        private void EmbedProcess(Process app, Control con, int flag)
        {
            if (app == null || app.MainWindowHandle == IntPtr.Zero || con == null)
            {
                return;
            }
            //设置窗体展示方式
            CurGlobals.ShowWindow(app.MainWindowHandle, (short)5);
            //设置父窗体
            CurGlobals.SetParent(app.MainWindowHandle, con.Handle);
            SetWindowLong(new HandleRef(this, app.MainWindowHandle), GWL_STYLE, WS_VISIBLE);
            CurGlobals.SendMessage(app.MainWindowHandle, WM_SETTEXT, IntPtr.Zero, strGUID);
            CurGlobals.MoveWindow(app.MainWindowHandle, 0, 0, con.Width, con.Height, true);

            if (flag != -1)
            {
                CurGlobals.SENDMESSAGETRANSFERSTRUCT temp = new CurGlobals.SENDMESSAGETRANSFERSTRUCT();
                temp.cbData = _argument;
                temp.dwData = Handle;
                CurGlobals.SendMessage(app.MainWindowHandle, WM_COPYDATA, IntPtr.Zero, ref temp);
            }
        }