Click here to Skip to main content
15,887,585 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I write a small desktop application (wpf main form) in the C# language (.net4.0).IDE:vs2013;

And i want to have my application in top of the start menu (Windows 10).

See screenshot what i want for my small application.

What I have tried:

1.The application must demand uiAccess (app.manifest)
2.The application must assert “topmost” window positioning (either in Win32/SetWindowPos or WinForms/WPF’s “Topmost” property, programmatically or otherwise)
3.Without making changes to the group policy setting, it must be installed to some trusted location [C:\Windows, C:\Program Files, C:\Program Files (x86)].
Posted
Updated 12-Nov-17 20:54pm
Comments
Dave Kreskowiak 12-Nov-17 22:52pm    
What screen shot?
xxyxxb2080 12-Nov-17 23:00pm    
my demo source:
<Window x:Class="WpfTopmost.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowStyle="None"
AllowsTransparency="True"
Loaded="Window_Loaded"
Background="Transparent"
Title="MainWindow" Height="130" Width="130">
<Grid Background="Transparent">
<Ellipse Fill="Transparent" Stroke="Green" StrokeThickness="3">



-------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfTopmost
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
///
public partial class MainWindow : Window
{
private Object _thisLock = new Object();
public MainWindow()
{
InitializeComponent();
}

private void Window_Loaded(object sender, RoutedEventArgs e)
{
Thread globalThread = new Thread((ThreadStart)delegate
{
MouseStopTimeSpan();
});
globalThread.IsBackground = true;
globalThread.Start();
}

private void MouseStopTimeSpan()
{
try
{

while (true)
{
try
{
Thread.Sleep(200);
lock (_thisLock)
{
this.Dispatcher.Invoke(new Action(() =>
{
// SetWindowPos(, -1, 0, 0, 0, 0, 0x4000 | 0x0001 | 0x0002); 我以前试过这个效果不太好,所以注掉了
//HwndSource source = (HwndSource)PresentationSource.FromVisual(this);
//IntPtr handle = source.Handle;
//bool b1 = BringWindowToTop(handle);
this.Topmost = false;
//Thread.Sleep(2);
this.Topmost = true;
//HwndSource source = (HwndSource)PresentationSource.FromVisual(this);
//IntPtr handle = source.Handle;
//bool b1 = BringWindowToTop(handle);



//系统所在鼠标位置
MousePosTool.POINT p = new MousePosTool.POINT();
if (MousePosTool.GetCursorPos(out p))//API方法
{
this.Top = p.Y - 65;
this.Left = p.X - 65;
}
}), null);
}
}
catch (Exception ex)
{

MessageBox.Show(ex.Message);
}

}
}
catch (Exception ex)
{

MessageBox.Show(ex.Message);
}
}
}

public static class MousePosTool
{
/// <summary>
/// 设置鼠标的坐标
///
/// <param name="x">横坐标
/// <param name="y">纵坐标
[DllImport("User32")]
public extern static void SetCursorPos(int x, int y);
public struct POINT
{
public int X;
public int Y;
publ
Dave Kreskowiak 12-Nov-17 23:02pm    
Your screen shot makes no sense. Where do you want the icon for this app to show up? Or are you talking about having your application window show up on top of every other window?
xxyxxb2080 12-Nov-17 23:44pm    
I want to do my own application on top in the window10
xxyxxb2080 13-Nov-17 2:43am    
my application window show up on top of every other window.On the windows10 operating system.
windows7 and windows8 operating system have succeeded.

As far as I know, you can't have a window TopMost over the top of the start menu in Windows 10.

Apps that I have don't show up over the top of start menu either.
 
Share this answer
 
Comments
xxyxxb2080 13-Nov-17 19:53pm    
Is there no solution?
the code of xaml:
XML
<pre><Window x:Class="WpfTopmost.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        WindowStyle="None"
        AllowsTransparency="True"
        Loaded="Window_Loaded"
        Background="Transparent"
        Title="MainWindow" Height="130" Width="130">
    <Grid  Background="Transparent">
        <Ellipse Fill="Transparent" Stroke="Green" StrokeThickness="3"></Ellipse>
    </Grid>
</Window>



the code of xaml.cs:
C#
private void Window_Loaded(object sender, RoutedEventArgs e)
{
    try
     {
       Thread globalThread = new Thread((ThreadStart)delegate
                {
                    MouseStopTimeSpan();
                });
                globalThread.IsBackground = true;
                globalThread.Start();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
}


C#
private void MouseStopTimeSpan()
        {
            try
            {

                while (true)
                {
                    try
                    {
                        Thread.Sleep(2);
                        lock (_thisLock)
                        {
                            this.Dispatcher.Invoke(new Action(() =>
                            {
                               
                                this.Topmost = false;
                                //Thread.Sleep(2);
                                this.Topmost = true;
                               
                            }), null);
                        }
                    }
                    catch (Exception ex)
                    {

                        MessageBox.Show(ex.Message);
                    }

                }
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }
 
Share this answer
 
Comments
Dave Kreskowiak 13-Nov-17 8:52am    
Stop posting stuff as a SOLUTION to your own question!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900