2

I want to show a semi-transparent image (similar to a watermark) on a windows XP computer screen. It's because I access different computers from the same terminal, and I would like to see in any moment what computer is that terminal connected to.

This 'semi-transparent' image should not interfere with the normal operation of Windows, it should allow click-through (as it efectively didn't exist).

I program a bit C++ and C#. As I just need a dirty solution that would work in Windows XP, I actually conly can think on a hook that captures windows refreshing events and somehow injecting the image I want before showing it, but I've never done this before nor know if there could be any other and more optimized approach. Any ideas?

Manuel Allenspach
  • 12,467
  • 14
  • 54
  • 76
Ptolomeo XII
  • 107
  • 1
  • 9
  • 1
    [BGInfo](http://technet.microsoft.com/en-US/sysinternals/bb897557.aspx) allows you to create "watermarks" on the desktop-background. – Manuel Allenspach Jun 03 '14 at 07:41
  • This question here will probably be useful: http://stackoverflow.com/questions/2842667/how-to-create-a-semi-transparent-window-in-wpf-that-allows-mouse-events-to-pass – Baldrick Jun 03 '14 at 07:44

2 Answers2

4

If you want a quick and dirty solution, create an new default C# WinForms application in Visual Studio, then replace the Form1 partial class code in Form1.cs with this:

public partial class Form1 : Form
{
    private Label waterMarkLabel;

    public Form1()
    {
        waterMarkLabel = new Label
        {
            Anchor = (AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right),
            Font = new Font("Microsoft Sans Serif", 80F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0))),
            ForeColor = SystemColors.ControlDarkDark,
            Location = new Point(126, 178),
            Name = "WATERMARK",
            Size = new Size(338, 120),
            TabIndex = 0,
            Text = "W A T E R M A R K",
            TextAlign = ContentAlignment.MiddleCenter
        };

        InitializeComponent();
        SuspendLayout();
        AutoScaleDimensions = new SizeF(6F, 13F);
        AutoScaleMode = AutoScaleMode.Font;
        ClientSize = new Size(579, 489);
        ControlBox = false;
        FormBorderStyle = FormBorderStyle.None;
        MaximizeBox = false;
        MinimizeBox = false;
        Opacity = 0.1D;
        ShowIcon = false;
        ShowInTaskbar = false;
        TopMost = true;
        var hwnd = Handle;
        WindowsServices.SetWindowExTransparent(hwnd);
        TopMost = true;
        AllowTransparency = true;
        ResumeLayout(false);

        Controls.Add(waterMarkLabel);
        WindowState = FormWindowState.Maximized;
    }
}

public static class WindowsServices
{
    const int WS_EX_TRANSPARENT = 0x00000020;
    const int GWL_EXSTYLE = (-20);

    [DllImport("user32.dll")]
    static extern int GetWindowLong(IntPtr hwnd, int index);

    [DllImport("user32.dll")]
    static extern int SetWindowLong(IntPtr hwnd, int index, int newStyle);

    public static void SetWindowExTransparent(IntPtr hwnd)
    {
        var extendedStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
        SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle | WS_EX_TRANSPARENT);
    }
}

Then add the following using statement to the top:

using System.Runtime.InteropServices;

If you build and run, you should find the word 'WATERMARK' transparently floating on your screen, and you'll be able to use all the other windows underneath it like it's not there.

(DLLImport code borrowed from this answer here)

Community
  • 1
  • 1
Baldrick
  • 11,712
  • 2
  • 31
  • 35
  • Hello, I am going to try this approach as the BGinfo shows the infor in the background (it can be overlapped by other windows) and not right in front as I need. – Ptolomeo XII Jun 03 '14 at 11:42
  • I've discovered this sourceforge project that fully satisfied my (computer) needs. http://sourceforge.net/projects/screenwatermark/ However, I am still doing some trials on the Baldrick approach as I would prefer to have full control on how to manage the watermark on my screen. – Ptolomeo XII Jun 04 '14 at 11:44
  • 1
    Baldrick source code worked like a charm, in case anyone needs it. – Ptolomeo XII Jun 04 '14 at 14:07
  • 1
    Great for me. add 0x80 to EXSTYLE to hide the form from alt+tab list "extendedStyle | WS_EX_TRANSPARENT | 0x80" – culy Mar 15 '19 at 14:49
  • Works like a charm. I too suggest to use 0x80 along WS_EX_TRANSPARANT to hide it from Alt+Tab, but also something else: With this code, theres noticable coverup of everything else on desktop. This can be seen more if you increase opacity. I suggest to add "BackColor = Color.Lime; TransparencyKey = Color.Lime;" (or any color that will not be used as a text color for that matter, point is both, BackColor and TransparencyKey are the same) so that the form is trully transparent, and you can control opacity of controls on it separately... :) – That Marc Aug 19 '20 at 15:00
0

Depending on what type of information you want to display, you might try Microsoft Sysinternals BgInfo. It allows to integrate information into the background image of your desktop.

http://technet.microsoft.com/en-us/sysinternals/bb897557.aspx

sibi
  • 39
  • 6
  • I believe the OP wants it overlaid over everything, not just the desktop background. Does this solution overlay? – Baldrick Jun 03 '14 at 08:08
  • @Baldrick - I just checked again, no it does not overlay, you are right. – sibi Jun 05 '14 at 12:01