Hello people !!!. May be you can help me with this one problem:
I want to open a window with HwndSource, that not appear in task bar and don't have the focus and is top most, like a popup.
I try this:
private HwndSource testHwnd;
private const int WS_EX_TOPMOST = 0x00000008;
private const int WS_EX_TOOLWINDOW = 0x80;
private const int FLAGS = WS_EX_TOOLWINDOW | WS_EX_TOPMOST ;
protected override void OnStartup(StartupEventArgs e)
{
HwndSourceParameters parameters = new HwndSourceParameters("ObservaWinfx");
parameters.PositionX = (int)(SystemParameters.VirtualScreenWidth) - 250;
parameters.PositionY = 0;
parameters.Width = (int)(SystemParameters.VirtualScreenWidth);
parameters.Height = (int)(SystemParameters.VirtualScreenHeight);
parameters.UsesPerPixelOpacity = true;
parameters.ExtendedWindowStyle = FLAGS;
testHwnd = new HwndSource(parameters);
But the problem is when the window is showed, It appear like a flirk in the task bar like it appear and desappaer. Do you recomend me other parameters to the HwndSource
I have this code that run me well for a framework 2.0 winform
[DllImport("user32.dll")]
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, int uFlags);
public const int HWND_TOPMOST = -1; // 0xffff
public const int SWP_NOSIZE = 1; // 0x0001
public const int SWP_NOMOVE = 2; // 0x0002
public const int SWP_NOZORDER = 4; // 0x0004
public const int SWP_NOACTIVATE = 16; // 0x0010
public const int SWP_SHOWWINDOW = 64; // 0x0040
public const int SWP_HIDEWINDOW = 128; // 0x0080
public const int SWP_DRAWFRAME = 32; // 0x0020
public static void ShowWindowTopMost(IntPtr handle)
{
SetWindowPos(handle,
(IntPtr)HWND_TOPMOST, 0, 0, 0, 0,
SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_SHOWWINDOW);
}
public static void SetVisibleNoActivate(Control control, bool visible)
{
if (visible)
{
ShowWindowTopMost(control.Handle);
control.Visible = true;
}
else
control.Visible = false;
}
Can you tell me what I'm doing wrong in FX 3.0 or how can I pass the correct parameters
Thanks a lot !!!!

HwndSource + task bar + show top + no focus.
fddsfsdf
hello,
I also have the same question.I only can make window that show topmost
Matt Stum
Dwayne wrote the following response to this question (but was getting an error when trying to post this to the forum):
The initial design for per-pixel opacity support in HwndSource required us to strip certain styles that were applied to the window, due to their impact on the non-client area. This had the side effect of disallowing certain window behavior, not just visual appearance, so we have redesigned this aspect of the code, and we now support the full compliment of window styles. This may or may not explain the difficulties you are having, but I was able to get your desired behavior with the following code:
NOTE: you are creating a VERY LARGE transparent window. (VirtualScreenWidth x VirtualScreenHeight). This is not advisable at all, as we will not be able to render this window within any reasonable expectation of performance. Especially if you have multiple monitors, the size of this window is exceedingly large. I have left the code as you initially had it to assist you as much as possible, but please do not use a window this large in your final version.
The only changes I made to your code were:
1) Use WS_EX_NOACTIVATE to prevent the window from gaining keyboard activation
2) Putting some content in the window so I could see it (an animating ellipse in this case)
3) A hook for WM_CLOSE that shuts down the program, but that is just for completeness.
using System;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Shapes;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Threading;
namespace LayeredWindowSample
{
public class LayeredWindowApp : Application
{
[STAThread]
public static void Main()
{
LayeredWindowApp app = new LayeredWindowApp();
app.Run();
}
protected override void OnStartup(StartupEventArgs args)
{
HwndSourceParameters parameters = new HwndSourceParameters("ObservaWinfx");
parameters.PositionX = (int)(SystemParameters.VirtualScreenWidth)-250;
parameters.PositionY = 0;
parameters.Width = (int)(SystemParameters.VirtualScreenWidth);
parameters.Height = (int)(SystemParameters.VirtualScreenHeight);
parameters.UsesPerPixelOpacity = true;
parameters.ExtendedWindowStyle = WS_EX_TOPMOST | WS_EX_TOOLWINDOW | WS_EX_NOACTIVATE;
testHwnd = new HwndSource(parameters);
HwndSourceHook h = new HwndSourceHook(hook);
testHwnd.AddHook(h);
Ellipse e = new Ellipse();
e.Width = 400;
e.Height= 400;
e.Opacity = 0.5;
SolidColorBrush referenceBrush = new SolidColorBrush();
referenceBrush.Color = Colors.White;
//Even Add some animation
System.Windows.Media.Animation.ColorAnimation myColorAnimation = new System.Windows.Media.Animation.ColorAnimation();
myColorAnimation.From = System.Windows.Media.Colors.White;
myColorAnimation.To = System.Windows.Media.Colors.Red;
myColorAnimation.Duration = new System.Windows.Duration(TimeSpan.FromSeconds(0.5));
myColorAnimation.AutoReverse = true;
myColorAnimation.RepeatBehavior = RepeatBehavior.Forever;
referenceBrush.BeginAnimation(System.Windows.Media.SolidColorBrush.ColorProperty, myColorAnimation);
e.Fill = referenceBrush;
Canvas.SetTop(e, 0);
Canvas.SetLeft(e, 0);
Canvas body = new Canvas();
body.Children.Add(e);
testHwnd.RootVisual = body;
}
// Shutdown the app when the layered window is closed.
public IntPtr hook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
if (msg == WM_CLOSE)
{
DoExit(null, null);
handled = true;
}
return IntPtr.Zero;
}
private void DoExit(object s, EventArgs e)
{
Dispatcher d = Dispatcher.CurrentDispatcher;
d.InvokeShutdown();
}
private const int WM_CLOSE = 0x10;
private const int WS_EX_TOPMOST = 0x00000008;
private const int WS_EX_TOOLWINDOW = 0x00000080;
private const int WS_EX_NOACTIVATE = 0x08000000;
private HwndSource testHwnd = null;
}
}