Click here to Skip to main content
15,889,462 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to remain WPF Window always on top of all windows? Pin
Eddy Vluggen22-Sep-15 1:15
professionalEddy Vluggen22-Sep-15 1:15 
GeneralRe: How to remain WPF Window always on top of all windows? Pin
Benjamin.Buhr22-Sep-15 1:36
Benjamin.Buhr22-Sep-15 1:36 
GeneralRe: How to remain WPF Window always on top of all windows? Pin
Eddy Vluggen22-Sep-15 2:12
professionalEddy Vluggen22-Sep-15 2:12 
GeneralRe: How to remain WPF Window always on top of all windows? Pin
Benjamin.Buhr24-Sep-15 1:09
Benjamin.Buhr24-Sep-15 1:09 
GeneralRe: How to remain WPF Window always on top of all windows? Pin
Eddy Vluggen24-Sep-15 1:20
professionalEddy Vluggen24-Sep-15 1:20 
GeneralRe: How to remain WPF Window always on top of all windows? Pin
Benjamin.Buhr24-Sep-15 2:23
Benjamin.Buhr24-Sep-15 2:23 
GeneralRe: How to remain WPF Window always on top of all windows? Pin
Eddy Vluggen24-Sep-15 3:46
professionalEddy Vluggen24-Sep-15 3:46 
GeneralRe: How to remain WPF Window always on top of all windows? Pin
Benjamin.Buhr25-Sep-15 0:08
Benjamin.Buhr25-Sep-15 0:08 
It's a little bit confusing now ... I found one mistake :-|
The App.xaml is defined this way:
C#
<Application x:Class="Technewlogic.Samples.WpfModalDialog.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	Startup="Application_Startup">
	
    <Application.Resources>
    </Application.Resources>
	
</Application>

So I had to correct the fiering of the timer in the App.xaml.cs this way:
C#
using System;
using System.Runtime.InteropServices;
using System.Security;
using System.Threading;
using System.Windows;

namespace Technewlogic.Samples.WpfModalDialog
{	
	/// <summary>
	/// Interaction logic for App.xaml
	/// </summary>
	public partial class App : Application
	{
        // 24.09.2015: Timer in WPF
        System.Windows.Threading.DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
        private void dispatcherTimer_Tick(object sender, EventArgs e)
        {
            TopMost = true;
            this.TopMost = true;
            //MessageBox.Show("Popup: dispatcherTimer_Tick");
            InitializeComponent();
        }

        // 24.09.2015: Keep my application on top
        public bool TopMost { get; set; }
        // couldn't find a .NET-way to bring the window
        // to top, reverting to old Win32 functions...
        [SuppressUnmanagedCodeSecurity]
        public class SafeNativeMethods
        {
            [System.Runtime.InteropServices.DllImport("User32.dll", CharSet = CharSet.Unicode)]
            public static extern Int32 FindWindow(String lpClassName, String lpWindowName);
            [System.Runtime.InteropServices.DllImport("User32.dll", CharSet = CharSet.Unicode)]
            public static extern Int32 SetForegroundWindow(int hWnd);
        }

        private void triMain_Click(object sender, System.EventArgs e)
        {
            int hWnd = SafeNativeMethods.FindWindow(null, "Test"); // Win32 API, don't want to use this
            SafeNativeMethods.SetForegroundWindow(hWnd); // Win32 API, don't want to use this
            TopMost = true;
        }

        // Only One Instance of App allowed
        private void Application_Startup(object sender, StartupEventArgs e)
		{
            // 24.09.2015: Keep my application on top + Timer in WPF
            dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
            dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
            dispatcherTimer.Start();

            bool createdNew;
      		Mutex mutex = new Mutex(true, this.GetType().GUID.ToString(), out createdNew);
      		if (createdNew)
      			{
                	Window window = new MainWindow();
        			window.Closed += (sender2, args) => mutex.Close(); ;
        			window.Show();
                }
      		    else
      			{
        			// MessageBox.Show("App already running...");
        			mutex.Close();
        			Application.Current.Shutdown();
      			}
		}
    }
}

I've tested the timer with a MessageBox => worked Smile | :)
But how is it possible to renew the TopMost for the MainWindow (Mainwindow.xaml.cs) or for the App?
Should I use the TopMost-Function better in the MainWindow-Element?

And I have a nother question:
This makes a CA1401:
C#
public class SafeNativeMethods
{
    [System.Runtime.InteropServices.DllImport("User32.dll", CharSet = CharSet.Unicode)]
    public static extern Int32 FindWindow(String lpClassName, String lpWindowName);
    [System.Runtime.InteropServices.DllImport("User32.dll", CharSet = CharSet.Unicode)]
    public static extern Int32 SetForegroundWindow(int hWnd);
}

How can I correct this?
GeneralRe: How to remain WPF Window always on top of all windows? Pin
Benjamin.Buhr28-Sep-15 1:39
Benjamin.Buhr28-Sep-15 1:39 
GeneralRe: How to remain WPF Window always on top of all windows? Pin
Eddy Vluggen28-Sep-15 5:38
professionalEddy Vluggen28-Sep-15 5:38 
GeneralRe: How to remain WPF Window always on top of all windows? Pin
Benjamin.Buhr28-Sep-15 22:49
Benjamin.Buhr28-Sep-15 22:49 
QuestionRe: How to remain WPF Window always on top of all windows? Pin
Eddy Vluggen29-Sep-15 1:25
professionalEddy Vluggen29-Sep-15 1:25 
AnswerRe: How to remain WPF Window always on top of all windows? Pin
Benjamin.Buhr14-Oct-15 0:37
Benjamin.Buhr14-Oct-15 0:37 
GeneralRe: How to remain WPF Window always on top of all windows? Pin
Eddy Vluggen15-Oct-15 4:38
professionalEddy Vluggen15-Oct-15 4:38 
QuestionMemory leak deterioration in performance in working with weight in rs232 Win-CE Pin
goldsoft21-Sep-15 21:20
goldsoft21-Sep-15 21:20 
AnswerRe: Memory leak deterioration in performance in working with weight in rs232 Win-CE Pin
OriginalGriff21-Sep-15 21:40
mveOriginalGriff21-Sep-15 21:40 
GeneralRe: Memory leak deterioration in performance in working with weight in rs232 Win-CE Pin
goldsoft21-Sep-15 23:04
goldsoft21-Sep-15 23:04 
GeneralRe: Memory leak deterioration in performance in working with weight in rs232 Win-CE Pin
Pete O'Hanlon21-Sep-15 23:08
mvePete O'Hanlon21-Sep-15 23:08 
GeneralRe: Memory leak deterioration in performance in working with weight in rs232 Win-CE Pin
OriginalGriff21-Sep-15 23:30
mveOriginalGriff21-Sep-15 23:30 
GeneralRe: Memory leak deterioration in performance in working with weight in rs232 Win-CE Pin
goldsoft23-Sep-15 22:28
goldsoft23-Sep-15 22:28 
GeneralRe: Memory leak deterioration in performance in working with weight in rs232 Win-CE Pin
OriginalGriff23-Sep-15 22:37
mveOriginalGriff23-Sep-15 22:37 
GeneralRe: Memory leak deterioration in performance in working with weight in rs232 Win-CE Pin
goldsoft24-Sep-15 0:49
goldsoft24-Sep-15 0:49 
QuestionI want to perform a similiar operation on 100 VMs open in my Remote Desktop Connection Manager; Can I Automate it? Pin
AshiSh RaNa21-Sep-15 19:35
AshiSh RaNa21-Sep-15 19:35 
AnswerRe: I want to perform a similiar operation on 100 VMs open in my Remote Desktop Connection Manager; Can I Automate it? Pin
Pete O'Hanlon21-Sep-15 21:06
mvePete O'Hanlon21-Sep-15 21:06 
GeneralRe: I want to perform a similiar operation on 100 VMs open in my Remote Desktop Connection Manager; Can I Automate it? Pin
AshiSh RaNa21-Sep-15 23:51
AshiSh RaNa21-Sep-15 23:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.