Example #1
0
        public static void TestUseCase(Assert assert)
        {
            assert.Expect(7);

            var t1 = new Type();
            assert.Ok(t1 != null, "#565 t1");

            var t2 = new ValueType();
            assert.Ok(t2 != null, "#565 t2");

            var t3 = new IntPtr();
            assert.Ok(t3.GetType() == typeof(IntPtr) , "#565 t3");

            var t4 = new UIntPtr();
            assert.Ok(t4.GetType() == typeof(UIntPtr), "#565 t4");

            var t5 = new ParamArrayAttribute();
            assert.Ok(t5 != null, "#565 t5");

            var t6 = new RuntimeTypeHandle();
            assert.Ok(t6.GetType() == typeof(RuntimeTypeHandle), "#565 t6");

            var t7 = new RuntimeFieldHandle();
            assert.Ok(t7.GetType() == typeof(RuntimeFieldHandle), "#565 t7");
        }
        public TaskbarHelper()
        {
            ProgramForm = Program.Form;
            WindowHandle = ProgramForm.Handle;
            try
            {
                MicrosoftWindowsAPICodePackShell = Assembly.LoadFrom("Microsoft.WindowsAPICodePack.Shell.dll");

                Type TaskbarManager = MicrosoftWindowsAPICodePackShell.GetType("Microsoft.WindowsAPICodePack.Taskbar.TaskbarManager");
                windowsTaskbar = TaskbarManager.GetProperty("Instance").GetValue(TaskbarManager, null);

                //windowsTaskbar.ApplicationId = "Transmission Remote Dotnet";
                TaskbarManager.GetProperty("ApplicationId").SetValue(windowsTaskbar, "Transmission Remote Dotnet", null);

                //windowsTaskbar.SetApplicationIdForSpecificWindow(WindowHandle, windowsTaskbar.ApplicationId);
                MethodInfo SetApplicationIdForSpecificWindow = TaskbarManager.GetMethod("SetApplicationIdForSpecificWindow", new Type[] { WindowHandle.GetType(), typeof(string) });
                SetApplicationIdForSpecificWindow.Invoke(windowsTaskbar, new object[] {
                    WindowHandle,
                    TaskbarManager.GetProperty("ApplicationId").GetValue(windowsTaskbar, null)
                });

                iconPause = Icon.FromHandle(Properties.Resources.pause16.GetHicon());
                iconPauseAll = Icon.FromHandle(Properties.Resources.player_pause_all.GetHicon());
                iconStartAll = Icon.FromHandle(Properties.Resources.player_play_all.GetHicon());
                iconAddTorrent = Icon.FromHandle(Properties.Resources.add16.GetHicon());

                //buttonStartAll = new ThumbnailToolbarButton(iconStartAll, OtherStrings.StartAll);
                //buttonPauseAll = new ThumbnailToolbarButton(iconPauseAll, OtherStrings.PauseAll);
                //buttonAddTorrent = new ThumbnailToolbarButton(iconAddTorrent, OtherStrings.NewTorrentIs);

                Type ThumbnailToolbarButton = MicrosoftWindowsAPICodePackShell.GetType("Microsoft.WindowsAPICodePack.Taskbar.ThumbnailToolBarButton");
                buttonStartAll = Activator.CreateInstance(ThumbnailToolbarButton, new object[] { iconStartAll, OtherStrings.StartAll });
                buttonPauseAll = Activator.CreateInstance(ThumbnailToolbarButton, new object[] { iconPauseAll, OtherStrings.PauseAll });
                buttonAddTorrent = Activator.CreateInstance(ThumbnailToolbarButton, new object[] { iconAddTorrent, ProgramForm.AddTorrentString });

                SetConnected(false);

                //buttonStartAll.Click+=new EventHandler<ThumbnailButtonClickedEventArgs>(buttonStartAll_Click);
                //buttonPauseAll.Click += new EventHandler<ThumbnailButtonClickedEventArgs>(buttonPauseAll_Click);
                //buttonAddTorrent.Click += new EventHandler<ThumbnailButtonClickedEventArgs>(buttonAddTorrent_Click);

                Type ThumbnailButtonClickedEventArgs = MicrosoftWindowsAPICodePackShell.GetType("Microsoft.WindowsAPICodePack.Taskbar.ThumbnailButtonClickedEventArgs");
                EventInfo ei = ThumbnailToolbarButton.GetEvent("Click");
                ei.AddEventHandler(buttonStartAll, Delegate.CreateDelegate(ei.EventHandlerType, null, GetType().GetMethod("buttonStartAll_Click")));
                ei.AddEventHandler(buttonPauseAll, Delegate.CreateDelegate(ei.EventHandlerType, null, GetType().GetMethod("buttonPauseAll_Click")));
                ei.AddEventHandler(buttonAddTorrent, Delegate.CreateDelegate(ei.EventHandlerType, null, GetType().GetMethod("buttonAddTorrent_Click")));

                //windowsTaskbar.ThumbnailToolbars.AddButtons(WindowHandle, buttonStartAll, buttonPauseAll, buttonAddTorrent);
                object ThumbnailToolbars = TaskbarManager.GetProperty("ThumbnailToolBars").GetValue(windowsTaskbar, null);
                Type ThumbnailToolBarManager = MicrosoftWindowsAPICodePackShell.GetType("Microsoft.WindowsAPICodePack.Taskbar.ThumbnailToolBarManager");
                Type ThumbnailToolbarButtonArray = MicrosoftWindowsAPICodePackShell.GetType("Microsoft.WindowsAPICodePack.Taskbar.ThumbnailToolBarButton[]");
                MethodInfo AddButtons = ThumbnailToolBarManager.GetMethod("AddButtons", new Type[] { WindowHandle.GetType(), ThumbnailToolbarButtonArray });
                Array ThumbnailToolbarButtons = Array.CreateInstance(ThumbnailToolbarButton, 3);
                ThumbnailToolbarButtons.SetValue(buttonStartAll, 0);
                ThumbnailToolbarButtons.SetValue(buttonPauseAll, 1);
                ThumbnailToolbarButtons.SetValue(buttonAddTorrent, 2);
                AddButtons.Invoke(ThumbnailToolbars, new object[] { WindowHandle, ThumbnailToolbarButtons });
            }
            catch (TargetInvocationException)
            { // this is normal: this is only supported on Windows 7 or newer.
            }
            catch (Exception ee)
            {
                Console.WriteLine(ee.ToString());
            }
        }
        //pguidCmdGroup must be declared as IntPtr not a GUID, as pguidCmdGroup may be null, hence generating execption
        int IOleCommandTarget.Exec(IntPtr pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            int hr = Hresults.S_OK;
            
            if ((pguidCmdGroup != m_NullPointer) &&
                (Type.GetTypeCode(pguidCmdGroup.GetType()) != TypeCode.Empty))
            {
                try
                {
                    ////Allocate mem for a GUID
                    //byte[] bguid = Guid.Empty.ToByteArray();
                    ////Copy incoming into byte array
                    //Marshal.Copy(pguidCmdGroup, bguid, 0, bguid.Length);
                    ////back to GUID
                    //Guid guid = new Guid(bguid);

                    Guid guid = (Guid)Marshal.PtrToStructure(pguidCmdGroup, typeof(Guid));

                    //Only group we are interested
                    if (guid == Iid_Clsids.CLSID_CGID_DocHostCommandHandler)
                    {
                        //http://support.microsoft.com/kb/261003
                        if (nCmdID == (int)OLECMDID.OLECMDID_SHOWSCRIPTERROR)
                        {
                            //Default Continue running scripts
                            if (pvaOut != IntPtr.Zero)
                                Marshal.GetNativeVariantForObject(true, pvaOut);
                            //false -> stop running scripts
                            if (ScriptError != null)
                            {
                                ScriptErrorEvent.SetParameters();
                                try
                                {
                                    IHTMLDocument2 doc2 = (IHTMLDocument2)Marshal.GetObjectForNativeVariant(pvaIn);
                                    IHTMLWindow2 win2 = (IHTMLWindow2)doc2.parentWindow;
                                    IHTMLEventObj2 eveobj = (IHTMLEventObj2)win2.eventobj;

                                    if (eveobj != null)
                                    {
                                        ScriptErrorEvent.lineNumber = (int)eveobj.getAttribute("errorLine", 0);
                                        ScriptErrorEvent.characterNumber = (int)eveobj.getAttribute("errorCharacter", 0);
                                        ScriptErrorEvent.errorCode = (int)eveobj.getAttribute("errorCode", 0);
                                        ScriptErrorEvent.errorMessage = eveobj.getAttribute("errorMessage", 0) as string;
                                        ScriptErrorEvent.url = eveobj.getAttribute("errorUrl", 0) as string;
                                    }
                                }
                                catch (Exception)
                                {
                                }
                                ScriptError(this, ScriptErrorEvent);
                                if (pvaOut != IntPtr.Zero)
                                    Marshal.GetNativeVariantForObject(ScriptErrorEvent.continueScripts, pvaOut);
                                ScriptErrorEvent.SetParameters();
                           }
                        }
                        else
                            hr = Hresults.OLECMDERR_E_NOTSUPPORTED;
                    }
                    else
                        hr = Hresults.OLECMDERR_E_UNKNOWNGROUP;
                }
                catch (Exception)
                {
                    hr = Hresults.OLECMDERR_E_UNKNOWNGROUP;
                }
            }
            else
                hr = Hresults.OLECMDERR_E_UNKNOWNGROUP;
            return hr;
        }
Example #4
0
        public void Respawn(IntPtr body)
        {
            //IPhysicsObject prueba = (IPhysicsObject)body;
            string dato = body.GetType().ToString();

            Notifier.AddMessage("Respawned");
            Matrix mat = Matrix.CreateTranslation(StartPos) *
                Matrix.CreateRotationX(MathHelper.ToRadians(90));
            Newton.NewtonBodySetMatrixRecursive(body, MatrixHelper.ToFloats(mat));
        }
Example #5
0
        //pguidCmdGroup must be declared as IntPtr not a GUID, as pguidCmdGroup may be null, hence generating execption
        int IOleCommandTarget.Exec(IntPtr pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            int hr = Hresults.S_OK;

            //Catch stop
            if( (nCmdID == (int)OLECMDID.OLECMDID_STOP) && (WBStop != null) )
            {
                WBStop(this);
            }

            if ((pguidCmdGroup != m_NullPointer) &&
                (Type.GetTypeCode(pguidCmdGroup.GetType()) != TypeCode.Empty))
            {
                try
                {
                    ////Allocate mem for a GUID
                    //byte[] bguid = Guid.Empty.ToByteArray();
                    ////Copy incoming into byte array
                    //Marshal.Copy(pguidCmdGroup, bguid, 0, bguid.Length);
                    ////back to GUID
                    //Guid guid = new Guid(bguid);

                    Guid guid = (Guid)Marshal.PtrToStructure(pguidCmdGroup, typeof(Guid));
                    //if( (this.m_DocDone) && (guid == Iid_Clsids.CGID_Explorer) && (nCmdID == 67) )
                    //{
                    //    //for 67 script exec, 69 timer/something is going
                    //    //66 open
                    //    //CGID_Explorer = 000214d0-0000-0000-c000-000000000046
                    //    //for 11 guid = 000214d4-0000-0000-c000-000000000046 , undocumented???
                    //    Debug.Print("IOleCommandTarget.Exec=> " + this.m_WBWebBrowser2.LocationURL);
                    //}

                    //Only group we are interested
                    //F38BC242-B950-11D1-8918-00C04FC2C836
                    if ( guid == Iid_Clsids.CLSID_CGID_DocHostCommandHandler)
                    {
                        //http://support.microsoft.com/kb/261003
                        if( nCmdID == (int)OLECMDID.OLECMDID_SHOWSCRIPTERROR)
                        {
                            //false -> stop running scripts
                            if ((pvaIn != IntPtr.Zero) && (ScriptError != null))
                            {
                                //default: continueScripts = true
                                ScriptErrorEvent.SetParameters();
                                try
                                {
                                    IHTMLDocument2 doc2 = (IHTMLDocument2)Marshal.GetObjectForNativeVariant(pvaIn);
                                    IHTMLWindow2 win2 = (IHTMLWindow2)doc2.parentWindow;
                                    IHTMLEventObj2 eveobj = (IHTMLEventObj2)win2.eventobj;

                                    if (eveobj != null)
                                    {
                                        ScriptErrorEvent.lineNumber = (int)eveobj.getAttribute("errorLine", 0);
                                        ScriptErrorEvent.characterNumber = (int)eveobj.getAttribute("errorCharacter", 0);
                                        ScriptErrorEvent.errorCode = (int)eveobj.getAttribute("errorCode", 0);
                                        ScriptErrorEvent.errorMessage = eveobj.getAttribute("errorMessage", 0) as string;
                                        ScriptErrorEvent.url = eveobj.getAttribute("errorUrl", 0) as string;
                                    }
                                }
                                catch (Exception)
                                {
                                }
                                ScriptError(this, ScriptErrorEvent);
                                if (pvaOut != IntPtr.Zero)
                                    Marshal.GetNativeVariantForObject(ScriptErrorEvent.continueScripts, pvaOut);
                                ScriptErrorEvent.SetParameters();
                            }
                            else
                            {
                                //Default Continue running scripts
                                if (pvaOut != IntPtr.Zero) //VARIANT (VT_NULL) - object (null)
                                    Marshal.GetNativeVariantForObject(true, pvaOut);
                            }
                        }
                        else
                            hr = Hresults.OLECMDERR_E_NOTSUPPORTED;
                    }
                    else
                        hr = Hresults.OLECMDERR_E_UNKNOWNGROUP;
                }
                catch (Exception)
                {
                    hr = Hresults.OLECMDERR_E_UNKNOWNGROUP;
                }
            }
            else
                hr = Hresults.OLECMDERR_E_UNKNOWNGROUP;
            return hr;
        }
	public static void SetTypedReference(TypedReference target, Object value)
			{
				if(value == null)
				{
					throw new ArgumentNullException("value");
				}
			#if !ECMA_COMPAT
				value = Convert.ChangeType(value, GetTargetType(target));
			#endif
				if(!ClrSetTypedReference(target, value))
				{
					throw new InvalidCastException
						(String.Format
							(_("InvalidCast_FromTo"),
 						     value.GetType().FullName,
							 GetTargetType(target).FullName));
				}
			}