public DialogResult ShowDialog(IWin32Window owner)
 {
     form = new DummyForm(this);
     if (owner is Form)
     {
         form.Icon = ((Form)owner).Icon; // Inherit the app/window icon
     }
     form.Show(owner);
     Win32.SetWindowPos(form.Handle, IntPtr.Zero, 0, 0, 0, 0, UFLAGSHIDE);
     form.WatchForActivate = true;
     try
     {
         return(fileDialog.ShowDialog(form));
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
         return(DialogResult.Cancel);
     }
     finally
     {
         //form.Dispose();
         //form.Close();
     }
 }
Пример #2
0
		public void NormalOperation()
		{
			// need to create a dummy form because PaintEventArgs wants a Graphics object
			using (DummyForm dummy = new DummyForm())
			{
				dummy.Create();
				using (TestControl1 tc1 = new TestControl1())
				{
					Message m1 = Message.Create(IntPtr.Zero, 10, new IntPtr(101), new IntPtr(1001));
					tc1.CallWndProc(ref m1);
					Message m2 = Message.Create(IntPtr.Zero, 20, new IntPtr(201), new IntPtr(2001));
					tc1.CallWndProc(ref m2);
					using (var g = dummy.CreateGraphics())
					{
						using (var pe1 = new PaintEventArgs(g, new System.Drawing.Rectangle(0, 1, 2, 3)))
						{
							tc1.CallOnPaint(pe1);
							Message m3 = Message.Create(IntPtr.Zero, 30, new IntPtr(301), new IntPtr(3001));
							tc1.CallWndProc(ref m3);
							object[] expected = { m1, m1, m2, m2, pe1, pe1, m3, m3 };
							VerifyArray(expected, tc1);
						}
					}
				}
			}
		}
Пример #3
0
 public void NormalOperation()
 {
     // need to create a dummy form because PaintEventArgs wants a Graphics object
     using (DummyForm dummy = new DummyForm())
     {
         dummy.Create();
         using (TestControl1 tc1 = new TestControl1())
         {
             Message m1 = Message.Create(IntPtr.Zero, 10, new IntPtr(101), new IntPtr(1001));
             tc1.CallWndProc(ref m1);
             Message m2 = Message.Create(IntPtr.Zero, 20, new IntPtr(201), new IntPtr(2001));
             tc1.CallWndProc(ref m2);
             using (var g = dummy.CreateGraphics())
             {
                 using (var pe1 = new PaintEventArgs(g, new System.Drawing.Rectangle(0, 1, 2, 3)))
                 {
                     tc1.CallOnPaint(pe1);
                     Message m3 = Message.Create(IntPtr.Zero, 30, new IntPtr(301), new IntPtr(3001));
                     tc1.CallWndProc(ref m3);
                     object[] expected = { m1, m1, m2, m2, pe1, pe1, m3, m3 };
                     VerifyArray(expected, tc1);
                 }
             }
         }
     }
 }
        public void AddControl_DifferentThreadInContext_WorksFine()
        {
            var form   = new DummyForm();
            var client = Container.Resolve <ClassUsingFormInWindowsContext>();

            ExecuteInThread(() => { client.DoWork(form); });
            Assert.IsNull(uncaughtException, "Expected no exception");
        }
        public void DoWorkGeneric_DifferentThreadInContext_WorksFine()
        {
            var form   = new DummyForm();
            var client = Container.Resolve <IClassUsingContext <DummyForm> >();

            ExecuteInThread(() => Assert.AreEqual(form, client.DoWork(form)));
            Assert.IsNull(uncaughtException, "Expected no exception");
        }
Пример #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="notify"></param>
        public static void StartWatch(RemovalEvent notify = null)
        {
            if (notify != null)
            {
                OnNotify += notify;
            }

            dummy = new DummyForm();
        }
 protected override void SetVisibleCore(bool value)
 {
     // Prevent window getting visible
     if (mInstance == null)
     {
         CreateHandle();
     }
     mInstance = this;
     base.SetVisibleCore(false);
 }
        public void Component_depending_on_unregistered_context_via_type_throws_even_if_another_is_available()
        {
            Container.Register(Component.For <ClassInContextWithMissingDependency>(),
                               Component.For <SynchronizationContext>().Named("foo").UsingFactoryMethod(k => k.Resolve <WindowsFormsSynchronizationContext>()));

            var instance = Container.Resolve <ClassInContextWithMissingDependency>();

            var form = new DummyForm();

            ExecuteInThread(() => instance.DoWork(form));
        }
        public void AddControl_DifferentThread_ThrowsException()
        {
            var form = new DummyForm();

            ExecuteInThread(() => form.AddControl(new Button()));
            Assert.IsNotNull(uncaughtException, "Expected an exception");

            uncaughtException = null;

            var classInCtx = new ClassUsingFormInWindowsContext();

            ExecuteInThread(() => classInCtx.DoWork(form));
            Assert.IsNotNull(uncaughtException, "Expected an exception");
        }
        public void SendScrReference()
        {
            DummyForm.Start();

            // MAT 28:18
            VerseRef vr = new VerseRef(040028018);

            vr.SendScrReference();

            Thread.Sleep(1000);

            Assert.AreEqual(vr, DummyForm.MessageReceived);

            DummyForm.Stop();
        }
        public void AddControl_DifferentThreadInContextUsingConfiguration_UsesAmbientContext()
        {
            var form   = new DummyForm();
            var client = Container.Resolve <ClassUsingFormInAmbientContext>();

            ExecuteInThread(() =>
            {
                using (var winCtx = new WindowsFormsSynchronizationContext())
                {
                    SynchronizationContext.SetSynchronizationContext(winCtx);
                    client.DoWork(form);
                }
            });
            Assert.IsNull(uncaughtException, "Expected no exception");
        }
Пример #12
0
 public void ShowDialog(IWin32Window owner)
 {
     this.form = new DummyForm(this, this.Lable_OpenFloder, this.Lable_SelectTexg, this.Lable_CancelText);
     this.form.Show(owner);
     NativeMethods.SetWindowPos(this.form.Handle, IntPtr.Zero, 0, 0, 0, 0, this.UFLAGSHIDE);
     this.form.WatchForActivate = true;
     try
     {
         int num = (int)this.dlgOpen.ShowDialog((IWin32Window)this.form);
     }
     catch (Exception)
     {
     }
     this.form.Dispose();
     this.form.Close();
     this.Dispose();
 }
Пример #13
0
        public DialogResult ShowDialog(IWin32Window owner)
        {
            DialogResult returnDialogResult = DialogResult.Cancel;
            DummyForm    form = new DummyForm(this);

            form.Show(owner);
            Win32.SetWindowPos(form.Handle, IntPtr.Zero, 0, 0, 0, 0, UFLAGSHIDE);
            form.WatchForActivate = true;
            try
            {
                returnDialogResult = dlgOpen.ShowDialog(form);
            }
            // Sometimes if you open a animated .gif on the preview and the Form is closed, .Net class throw an exception
            // Lets ignore this exception and keep closing the form.
            catch (Exception) {}
            form.Close();
            return(returnDialogResult);
        }
Пример #14
0
        public void ShowDialog(IWin32Window owner)
        {
            DummyForm form = new DummyForm(this);

            form.Show(owner);
            Win32.SetWindowPos(form.Handle, IntPtr.Zero, 0, 0, 0, 0, UFLAGSHIDE);
            form.WatchForActivate = true;
            try
            {
                dlgOpen.ShowDialog(form);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            form.Dispose();
            form.Close();
        }
Пример #15
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FullscreenRenderTarget" /> class.
        /// </summary>
        /// <param name="outputInfo">The target output monitor.</param>
        /// <param name="initialMode">The initial view mode.</param>
        public FullscreenRenderTarget(EngineOutputInfo outputInfo, EngineOutputModeInfo initialMode = default(EngineOutputModeInfo))
        {
            outputInfo.EnsureNotNull(nameof(outputInfo));

            // Check whether we are inside a win.forms application
            System.Windows.Forms.WindowsFormsSynchronizationContext syncContext = SynchronizationContext.Current
                                                                                  as System.Windows.Forms.WindowsFormsSynchronizationContext;
            if (syncContext == null)
            {
                throw new SeeingSharpException($"{nameof(FullscreenRenderTarget)} muss be created inside a Windows.Forms application context!");
            }
            m_syncContext = syncContext;

            //Set confiugration
            m_targetOutput     = outputInfo;
            m_targetOutputMode = initialMode;
            if (m_targetOutputMode.HostOutput != outputInfo)
            {
                m_targetOutputMode = m_targetOutput.DefaultMode;
            }
            m_renderAwaitors = new ThreadSaveQueue <TaskCompletionSource <object> >();

            // Ensure that graphics is initialized
            GraphicsCore.Touch();

            // Create the dummy form
            m_dummyForm = new DummyForm();
            m_dummyForm.SetStyleCustom(ControlStyles.AllPaintingInWmPaint, true);
            m_dummyForm.SetStyleCustom(ControlStyles.ResizeRedraw, true);
            m_dummyForm.SetStyleCustom(ControlStyles.OptimizedDoubleBuffer, false);
            m_dummyForm.SetStyleCustom(ControlStyles.Opaque, true);
            m_dummyForm.SetStyleCustom(ControlStyles.Selectable, true);
            m_dummyForm.SetDoubleBuffered(false);
            m_dummyForm.MouseEnter      += (sender, eArgs) => Cursor.Hide();
            m_dummyForm.MouseLeave      += (sender, eArgs) => Cursor.Show();
            m_dummyForm.HandleDestroyed += OnDummyForm_HandleDestroyed;
            m_dummyForm.GotFocus        += OnDummyForm_GotFocus;
            m_dummyForm.CreateControl();

            // Create and start the renderloop
            m_renderLoop = new RenderLoop(syncContext, this);
            m_renderLoop.Camera.SetScreenSize(m_targetOutputMode.PixelWidth, m_targetOutputMode.PixelHeight);
            m_renderLoop.RegisterRenderLoop();
        }
Пример #16
0
        public void KillFocusAndGetFocusInPaint()
        {
            // need to create a dummy form because PaintEventArgs wants a Graphics object
            using (DummyForm dummy = new DummyForm())
            {
                dummy.Create();
                // Similate OnPaint, inside which we get a kill focus and a SetFocus.
                using (System.Drawing.Graphics g = dummy.CreateGraphics())
                {
                    PaintEventArgs pe1          = new PaintEventArgs(g, new System.Drawing.Rectangle(0, 1, 2, 3));
                    Message        msgKillFocus = Message.Create(IntPtr.Zero, (int)Win32.WinMsgs.WM_KILLFOCUS, new IntPtr(201), new IntPtr(2001));
                    Message        msgSetFocus  = Message.Create(IntPtr.Zero, (int)Win32.WinMsgs.WM_SETFOCUS, new IntPtr(301), new IntPtr(3001));
                    TestControl3   tc3          = new TestControl3(pe1, msgKillFocus, msgSetFocus);

                    tc3.CallOnPaint(pe1);

                    object[] expected = { pe1, pe1, msgKillFocus, msgKillFocus, msgSetFocus, msgSetFocus };
                    VerifyArray(expected, tc3);
                }
            }
        }
Пример #17
0
        public DialogResult ShowDialog(IWin32Window owner, string filename)
        {
            DummyForm form = new DummyForm(this);

            form.Show(owner);
            Win32.SetWindowPos(form.Handle, IntPtr.Zero, 0, 0, 0, 0, UFLAGSHIDE);
            form.WatchForActivate = true;
            DialogResult r = DialogResult.None;

            dlgOpen.FileName = filename;
            try
            {
                r = dlgOpen.ShowDialog(form);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            form.Dispose();
            form.Close();
            return(r);
        }
Пример #18
0
        public DialogResult ShowDialog(IWin32Window owner)
        {
            DialogResult res = DialogResult.None;

            DummyForm form = new DummyForm(this);

            form.Show(owner);
            Win32.SetWindowPos(form.Handle, IntPtr.Zero, 0, 0, 0, 0, UFLAGSHIDE);
            form.WatchForActivate = true;
            try
            {
                res = dlgSave.ShowDialog(form);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            form.Dispose();
            form.Close();

            return(res);
        }
Пример #19
0
        public DialogResult ShowDialog(IWin32Window owner)
        {
            DummyForm form = new DummyForm(this);

            form.Show(owner);
            Win32.SetWindowPos(form.Handle, IntPtr.Zero, 0, 0, 0, 0, UFLAGSHIDE);
            form.WatchForActivate = true;
            try
            {
                return(dlgOpen.ShowDialog(form));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return(DialogResult.Cancel);
            }
            finally
            {
                //form.Dispose();
                //form.Close();
            }
        }
Пример #20
0
		public void KillFocusAndGetFocusInPaint()
		{
			// need to create a dummy form because PaintEventArgs wants a Graphics object
			using (DummyForm dummy = new DummyForm())
			{
				dummy.Create();
				// Similate OnPaint, inside which we get a kill focus and a SetFocus.
				using (var g = dummy.CreateGraphics())
				{
					using (var pe1 = new PaintEventArgs(g, new System.Drawing.Rectangle(0, 1, 2, 3)))
					{
						Message msgKillFocus = Message.Create(IntPtr.Zero, (int)Win32.WinMsgs.WM_KILLFOCUS, new IntPtr(201), new IntPtr(2001));
						Message msgSetFocus = Message.Create(IntPtr.Zero, (int)Win32.WinMsgs.WM_SETFOCUS, new IntPtr(301), new IntPtr(3001));
						using (var tc3 = new TestControl3(pe1, msgKillFocus, msgSetFocus))
						{
							tc3.CallOnPaint(pe1);

							object[] expected = { pe1, pe1, msgKillFocus, msgKillFocus, msgSetFocus, msgSetFocus };
							VerifyArray(expected, tc3);
						}
					}
				}
			}
		}
		public void AddControl_DifferentThreadInContextUsingConfiguration_UsesAmbientContext()
		{
			var form = new DummyForm();
			var client = Container.Resolve<ClassUsingFormInAmbientContext>();
			ExecuteInThread(() =>
			{
				using (var winCtx = new WindowsFormsSynchronizationContext())
				{
					SynchronizationContext.SetSynchronizationContext(winCtx);
					client.DoWork(form);
				}
			});
			Assert.IsNull(uncaughtException, "Expected no exception");
		}
		public void AddControl_DifferentThreadInContext_WorksFine()
		{
			var form = new DummyForm();
			var client = Container.Resolve<ClassUsingFormInWindowsContext>();
			ExecuteInThread(() => { client.DoWork(form); });
			Assert.IsNull(uncaughtException, "Expected no exception");
		}
		public void AddControl_DifferentThread_ThrowsException()
		{
			var form = new DummyForm();
			ExecuteInThread(() => form.AddControl(new Button()));
			Assert.IsNotNull(uncaughtException, "Expected an exception");

			uncaughtException = null;

			var classInCtx = new ClassUsingFormInWindowsContext();
			ExecuteInThread(() => classInCtx.DoWork(form));
			Assert.IsNotNull(uncaughtException, "Expected an exception");
		}
		public void AddControl_DifferentThread_ThrowsException()
		{
			DummyForm form = new DummyForm();
			ExecuteInThread(delegate { form.AddControl(new Button()); });
			Assert.IsNotNull(uncaughtException, "Expected an exception");

			uncaughtException = null;

			ClassUsingFormInContext classInCtx = new ClassUsingFormInContext();
			ExecuteInThread(delegate { classInCtx.DoWork(form); });
			Assert.IsNotNull(uncaughtException, "Expected an exception");
		}
		public void DoWorkGeneric_DifferentThreadInContext_WorksFine()
		{
			DummyForm form = new DummyForm();
			IClassUsingContext<DummyForm> client = container.Resolve<IClassUsingContext<DummyForm>>();
			ExecuteInThread(delegate { client.DoWork(form); });
			Assert.IsNull(uncaughtException, "Expected no exception");
		}
 public DialogResult ShowDialog(IWin32Window owner)
 {
     DialogResult returnDialogResult = DialogResult.Cancel;
     DummyForm form = new DummyForm(this);
     form.Show(owner);
     Win32.SetWindowPos(form.Handle, IntPtr.Zero, 0, 0, 0, 0, UFLAGSHIDE);
     form.WatchForActivate = true;
     try
     {
         returnDialogResult = dlgOpen.ShowDialog(form);
     }
     // Sometimes if you open a animated .gif on the preview and the Form is closed, .Net class throw an exception
     // Lets ignore this exception and keep closing the form.
     catch(Exception){}
     form.Close();
     return returnDialogResult;
 }
		public void DoWorkGeneric_DifferentThreadInContext_WorksFine()
		{
			var form = new DummyForm();
			var client = Container.Resolve<IClassUsingContext<DummyForm>>();
			ExecuteInThread(() => Assert.AreEqual(form, client.DoWork(form)));
			Assert.IsNull(uncaughtException, "Expected no exception");
		}
Пример #28
0
        public DialogResult ShowDialog(IWin32Window owner)
        {
            DialogResult res = DialogResult.None;

            DummyForm form = new DummyForm(this);
            form.Show(owner);
            Win32.SetWindowPos(form.Handle, IntPtr.Zero, 0, 0, 0, 0, UFLAGSHIDE);
            form.WatchForActivate = true;
            try
            {
                res = dlgSave.ShowDialog(form);
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            form.Dispose();
            form.Close();

            return res;
        }
Пример #29
0
 public void ShowDialog(IWin32Window owner)
 {
     DummyForm form = new DummyForm(this);
     form.Show(owner);
     Win32.SetWindowPos(form.Handle, IntPtr.Zero, 0, 0, 0, 0, UFLAGSHIDE);
     form.WatchForActivate = true;
     try
     {
         dlgOpen.ShowDialog(form);
     }
     catch(Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
     form.Dispose();
     form.Close();
 }
 public DialogResult ShowDialog(IWin32Window owner)
 {
     DummyForm form = new DummyForm(this);
     form.Show(owner);
     Win32.SetWindowPos(form.Handle, IntPtr.Zero, 0, 0, 0, 0, UFLAGSHIDE);
     form.WatchForActivate = true;
     try
     {
         return dlgOpen.ShowDialog(form);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
         return DialogResult.Cancel;
     }
     finally
     {
         //form.Dispose();
         //form.Close();
     }
 }
		public void AddControl_DifferentThreadInContextUsingConfiguration_WorksFine()
		{
			DummyForm form = new DummyForm();
			ClassUsingForm client = container.Resolve<ClassUsingForm>();
			ExecuteInThread(delegate { client.DoWork(form); });
			Assert.IsNull(uncaughtException, "Expected no exception");
		}
Пример #32
0
 public void openView()
 {
     view = view.createAndOrShowForm();
     view.setPresenter(this);
 }
Пример #33
0
 public DialogResult ShowDialog(IWin32Window owner, string filename)
 {
     DummyForm form = new DummyForm(this);
     form.Show(owner);
     Win32.SetWindowPos(form.Handle, IntPtr.Zero, 0, 0, 0, 0, UFLAGSHIDE);
     form.WatchForActivate = true;
     DialogResult r = DialogResult.None;
     dlgOpen.FileName = filename;
     try
     {
         r = dlgOpen.ShowDialog(form);
     }
     catch(Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
     form.Dispose();
     form.Close();
     return r;
 }
Пример #34
0
        public DialogResult ShowDialog(IWin32Window owner)
        {
            form = new DummyForm(this);
            if (owner is Form)
                form.Icon = ((Form)owner).Icon; // Inherit the app/window icon

            form.Show(owner);
            Win32.SetWindowPos(form.Handle, IntPtr.Zero, 0, 0, 0, 0, UFLAGSHIDE);
            form.WatchForActivate = true;
            try
            {
                return fileDialog.ShowDialog(form);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return DialogResult.Cancel;
            }
            finally
            {
                //form.Dispose();
                //form.Close();
            }
        }