private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            System.Windows.Forms.Message m = System.Windows.Forms.Message.Create(hwnd, msg, wParam, lParam);
            if (m.Msg != ProcessInterop.WM_COPYDATA)
            {
                return(IntPtr.Zero);
            }

            // Get the CopyDataStruct struct from lParam.
            CopyDataStruct cds = (CopyDataStruct)m.GetLParam(typeof(CopyDataStruct));

            if (cds.cbData == Marshal.SizeOf(typeof(FilePathStruct)))
            {
                                                                      // If the size matches
                {
                    // Marshal the data from the unmanaged memory block to a FilePathStruct managed struct.
                    FilePathStruct filePathStruct = (FilePathStruct)Marshal.PtrToStructure(cds.lpData, typeof(FilePathStruct));

                    OpenFile(filePathStruct.FilePath);
                    if (this.Owner.WindowState == WindowState.Minimized)
                    {
                        this.Owner.WindowState = WindowState.Normal;
                    }
                    this.Owner.Activate(); // Bring the Gherkin window to the foreground and activates it.
                }
            }
            return(IntPtr.Zero);
        }
示例#2
0
 /// <summary>
 /// 接收的到数据
 /// </summary>
 /// <param name="m"></param>
 /// <returns></returns>
 public static string Receive(ref System.Windows.Forms.Message m)
 {
     COPYDATASTRUCT cds = new COPYDATASTRUCT();
     Type cdsType = cds.GetType();
     cds = (COPYDATASTRUCT)m.GetLParam(cdsType);
     return cds.lpData;
 }
示例#3
0
        public static void OnDeviceChange(System.Windows.Forms.Message m)
        {
            if (m.Msg == WM_DEVICECHANGE)
            {
                var lpdb = (DEV_BROADCAST_HDR)m.GetLParam(typeof(DEV_BROADCAST_HDR));

                if ((DeviceChangeEvent)m.WParam.ToInt32() == DeviceChangeEvent.DBT_DEVICEREMOVECOMPLETE)
                {
                    if (lpdb.dbchDeviceType == DeviceChangeType.DBT_DEVTYP_PORT)
                    {
                        string portName = Marshal.PtrToStringUni((IntPtr)(m.LParam.ToInt32() + Marshal.SizeOf(typeof(DEV_BROADCAST_HDR))));

                        var handler = ListChanged;
                        if (handler != null)
                        {
                            handler(null, new SerialPortListChangedEventArgs(portName, SerialPortListAction.Removed));
                        }
                    }
                }
                else if ((DeviceChangeEvent)m.WParam.ToInt32() == DeviceChangeEvent.DBT_DEVICEARRIVAL)
                {
                    if (lpdb.dbchDeviceType == DeviceChangeType.DBT_DEVTYP_PORT)
                    {
                        string portName = Marshal.PtrToStringUni((IntPtr)(m.LParam.ToInt32() + Marshal.SizeOf(typeof(DEV_BROADCAST_HDR))));

                        var handler = ListChanged;
                        if (handler != null)
                        {
                            handler(null, new SerialPortListChangedEventArgs(portName, SerialPortListAction.Added));
                        }
                    }
                }
            }
        }
示例#4
0
    /// <summary>
    /// 处理拷贝数据
    /// </summary>
    /// <param name="msg"></param>
    /// <returns></returns>
    public bool DoMsgCopyData(ref System.Windows.Forms.Message msg)
    {
        bool tested = false;

        if (tetsingEnable)
        {
            try
            {
                Win32Message.COPYDATASTRUCT mystr = new Win32Message.COPYDATASTRUCT();
                Type mytype = mystr.GetType();
                mystr = (Win32Message.COPYDATASTRUCT)msg.GetLParam(mytype);
                Byte[] scriptbytes = new Byte[mystr.cbData];
                Marshal.Copy(mystr.lpData, scriptbytes, 0, mystr.cbData);
                System.Text.Encoding utf8 = System.Text.Encoding.UTF8;
                testingScript = utf8.GetString(scriptbytes);

                System.Windows.Forms.MessageBox.Show(testingScript);

                tested = true;
            }
            catch
            {
                tested = false;
            }
        }

        return(tested);
    }
示例#5
0
        public static string[] ParseMessage(ref System.Windows.Forms.Message m)
        {
            CopyDataStruct data = (CopyDataStruct)m.GetLParam(typeof(CopyDataStruct));

            m.Result = (IntPtr)200;
            return(data.lpData.Split('\n'));
        }
示例#6
0
        public void Receive(
            DLDefWndProc proc,
            ref System.Windows.Forms.Message m)
        {
            #region
            proc(ref m);
            foreach (Message msg in this.Messages)
            {
                if (msg.MessageCode == m.Msg)
                {
                    TrafficMsg.COPYDATASTRUCT mystr = new TrafficMsg.COPYDATASTRUCT();
                    Type mytype = mystr.GetType();
                    try
                    {
                        mystr = (TrafficMsg.COPYDATASTRUCT)m.GetLParam(mytype);
                    }
                    catch (Exception e)
                    {
                        System.Console.WriteLine(e);
                        //Logger.ErrorWriteLog(e.ToString());
                    }

                    msg.Receive(mystr.lpData);
                    return;
                }
            }
            #endregion
        }
示例#7
0
        /// <summary>
        /// Call this inside your Window proc in the control that
        /// wants to do custom drawing.
        /// </summary>
        /// <param name="msg">The MSG.</param>
        /// <returns></returns>
        /// <remarks>
        /// Example:
        /// protected override void WndProc(ref Message m)
        /// {
        /// myCustDrawHandler.HandleReflectedCustDrawMessage( ref m );
        /// if ( !myCustDrawHandler.MessageHandled )
        /// {
        /// base.WndProc (ref m);
        /// }
        /// }
        /// </remarks>
        public IntPtr HandleReflectedCustDrawMessage(
            ref System.Windows.Forms.Message msg)
        {
            IntPtr ret = IntPtr.Zero;

            MessageHandled = false;

            if (msg.Msg == (int)Win32.OCM.OCM_NOTIFY)
            {
                var hrd = (Win32.NMHDR)msg.GetLParam(typeof(Win32.NMHDR));

                if ((hrd.code == (int)Win32.NM.NM_CUSTOMDRAW) && (hrd.hwndFrom == _interfaceCustDraw.WindowHandle))
                {
                    var nmcd = (Win32.NMCUSTOMDRAW)msg.GetLParam(typeof(Win32.NMCUSTOMDRAW));
                    msg.Result     = (IntPtr)OnCustomDraw(msg.WParam.ToInt32(), ref nmcd);
                    MessageHandled = true;
                }
            }
            return(ret);
        }
示例#8
0
 public static string ReceiveMessage(ref System.Windows.Forms.Message m)
 {
     if (m.Msg == User32.WM_COPYDATA)
     {
         User32.CopyDataStruct cds = (User32.CopyDataStruct)m.GetLParam(typeof(User32.CopyDataStruct));
         return(cds.lpData);
     }
     else
     {
         return(String.Empty);
     }
 }
示例#9
0
        public static string _GetMessage(System.Windows.Forms.Message m)
        {
            string msg = null;

            if (m.Msg == Win32.WM_COPYDATA)
            {
                if (InSendMessage())
                {
                    ReplyMessage(IntPtr.Zero);
                }
                COPYDATASTRUCT data = (COPYDATASTRUCT)m.GetLParam(typeof(COPYDATASTRUCT));
                byte[]         b    = new byte[data.cbData];
                Marshal.Copy(data.lpData, b, 0, data.cbData);
                msg = Encoding.UTF8.GetString(b);
            }
            return(msg);
        }
示例#10
0
        protected override void WndProc(ref System.Windows.Forms.Message m)
        {
            base.WndProc(ref m);
            if (m.Msg == WM_GETMINMAXINFO)
            {
                MINMAXINFO mmi = (MINMAXINFO)m.GetLParam(typeof(MINMAXINFO));
                mmi.ptMinTrackSize.x = this.MinimumSize.Width;
                mmi.ptMinTrackSize.y = this.MinimumSize.Height;
                if (this.MaximumSize.Width != 0 || this.MaximumSize.Height != 0)
                {
                    mmi.ptMaxTrackSize.x = this.MaximumSize.Width;
                    mmi.ptMaxTrackSize.y = this.MaximumSize.Height;
                }
                mmi.ptMaxPosition.x = 0;
                mmi.ptMaxPosition.y = 0;

                System.Runtime.InteropServices.Marshal.StructureToPtr(mmi, m.LParam, true);
            }
        }
 private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
 {
     System.Windows.Forms.Message m = System.Windows.Forms.Message.Create(hwnd, msg, wParam, lParam);
     if (m.Msg == WM_COPYDATA)
     {
         // Get the COPYDATASTRUCT struct from lParam.
         COPYDATASTRUCT cds = (COPYDATASTRUCT)m.GetLParam(typeof(COPYDATASTRUCT));
         // If the size matches
         if (cds.cbData == Marshal.SizeOf(typeof(MyStruct)))
         {
             // Marshal the data from the unmanaged memory block to a
             // MyStruct managed struct.
             MyStruct myStruct = (MyStruct)Marshal.PtrToStructure(cds.lpData,
                                                                  typeof(MyStruct));
             // Display the MyStruct data members.
             if (myStruct.Message == "Show Up")
             {
                 this.Show();
             }
         }
     }
     return(IntPtr.Zero);
 }