Пример #1
0
		/// <summary>
		/// Implementation of the INotifiable Notify method.
		/// </summary>
		/// <remarks>Receives notification messages from the native HTMLViewer control.</remarks>
		/// <param name="notifydata">Pointer to a Notification struct.</param>
		void INotifiable.Notify(IntPtr notifydata)
		{
			//marshal data to custom nmhtml struct
			//Marshal.PtrToStructure doesn't work so marshalling items individually
			NM_HTMLVIEW nmhtml = new NM_HTMLVIEW();
			nmhtml.hwndFrom = (IntPtr)Marshal.ReadInt32(notifydata, 0);
			nmhtml.idFrom = Marshal.ReadInt32(notifydata, 4);
			nmhtml.code = Marshal.ReadInt32(notifydata, 8);
			nmhtml.szTarget = (IntPtr)Marshal.ReadInt32(notifydata, 12);
			nmhtml.szData = (IntPtr)Marshal.ReadInt32(notifydata, 16);
			nmhtml.dwCookie = (IntPtr)Marshal.ReadInt32(notifydata, 20);
			nmhtml.szExInfo = (IntPtr)Marshal.ReadInt32(notifydata, 24);

			//check the incoming message code and process as required
			switch(nmhtml.code)
			{
					//hotspotclick
				case (int)HtmlNotification.Hotspot:
					//use the new PtrToStringAuto to get string whether Unicode or ASCII
					string url = OpenNETCF.Runtime.InteropServices.MarshalEx.PtrToStringAuto(nmhtml.szTarget);

					HotSpotClickEventArgs e = new HotSpotClickEventArgs(url);
					OnHotSpotClick(e);
					break;
					//navigate complete
				case (int)HtmlNotification.NavigateComplete:
					OnNavigateComplete(new EventArgs());
					break;
					//document complete
				case (int)HtmlNotification.DocumentComplete:
					OnDocumentComplete(new EventArgs());
					break;
					//title notification
				case (int)HtmlNotification.Title:
					//copy target to title field
					//byte[] titlechars = new byte[256];
					//Marshal.Copy(nmhtml.szTarget, titlechars, 0, 256);
					//m_title = System.Text.Encoding.ASCII.GetString(titlechars, 0, 256);
					//marshal the title
					m_title = MarshalEx.PtrToStringAuto(nmhtml.szTarget);
					break;
			}
		}
Пример #2
0
        /// <summary>
        /// Handles notification messages from the native control
        /// </summary>
        /// <param name="m">Message</param>
        protected override void OnNotifyMessage(ref Microsoft.WindowsCE.Forms.Message m)
        {
            //check message is a notification
            if (m.Msg == (int)WM.NOTIFY)
            {
                //marshal notification data into NMHDR struct
                NMHDR hdr = (NMHDR)Marshal.PtrToStructure(m.LParam, typeof(NMHDR));


                //context menu event is a special case
                if (hdr.code == (int)NM.CONTEXTMENU)
                {
                    //if the ContextMenu property is set show the user's context menu
                    //if no ContextMenu is set we ignore this notification and use the built in Context Menu.
                    if (this.ContextMenu != null)
                    {
                        NM_HTMLCONTEXT nmhc = (NM_HTMLCONTEXT)Marshal.PtrToStructure(m.LParam, typeof(NM_HTMLCONTEXT));

                        //cancel default context menu
                        m.Result = new IntPtr(-1);
                        //set position
                        System.Drawing.Point pos = new System.Drawing.Point(nmhc.x, nmhc.y);
                        //show popup
                        this.ContextMenu.Show(this, pos);
                    }
                }
                else
                {
                    //get html viwer specific data from the notification message
                    NM_HTMLVIEW nmhtml = (NM_HTMLVIEW)Marshal.PtrToStructure(m.LParam, typeof(NM_HTMLVIEW));

                    //marshal the Target string
                    string target = MarshalEx.PtrToStringAuto(nmhtml.szTarget);

                    //check the incoming message code and process as required
                    switch (nmhtml.code)
                    {
                    //hotspot click
                    case (int)NM.HOTSPOT:
                    case (int)NM.BEFORENAVIGATE:
                        OnNavigating(new WebBrowserNavigatingEventArgs(target));
                        break;

                    //navigate complete
                    case (int)NM.NAVIGATECOMPLETE:
                        OnNavigated(new WebBrowserNavigatedEventArgs(target));
                        break;

                    //document complete
                    case (int)NM.DOCUMENTCOMPLETE:
                        OnDocumentCompleted(new WebBrowserDocumentCompletedEventArgs(target));
                        break;

                    //title notification
                    case (int)NM.TITLECHANGE:
                    case (int)NM.TITLE:
                        m_title = target;
                        OnDocumentTitleChanged(new EventArgs());
                        break;
                    }
                }
            }

            base.OnNotifyMessage(ref m);
        }