在屏幕上放置一个半透明的标记(Windows XP)
本文关键字:半透明 XP Windows 一个 屏幕 | 更新日期: 2023-09-27 18:06:37
我想在windows XP电脑屏幕上显示半透明图像(类似于水印)。这是因为我从同一个终端访问不同的计算机,我想随时看到这台终端连接的是哪台计算机。
这个"半透明"的图像不应该干扰Windows的正常操作,它应该允许点击通过(因为它实际上不存在)。
我会一点c++和c#编程。因为我只需要一个能在Windows XP上运行的解决方案,我实际上只能想到一个钩子,它捕获窗口刷新事件,并以某种方式注入我想要的图像,然后再显示它,但我从来没有这样做过,也不知道是否有任何其他更优化的方法。什么好主意吗?
如果你想要一个快速而肮脏的解决方案,在Visual Studio中创建一个新的默认c# WinForms应用程序,然后将Form1.cs中的Form1部分类代码替换为:
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);
}
}
然后将以下using
语句添加到顶部:
using System.Runtime.InteropServices;
如果你建立并运行,你应该发现"水印"这个词透明地漂浮在你的屏幕上,你可以使用它下面的所有其他窗口,就像它不存在一样。
(DLLImport
代码从这里的答案借鉴)
根据您想要显示的信息类型,您可以尝试Microsoft Sysinternals BgInfo。它允许将信息集成到桌面的背景图像中。
http://technet.microsoft.com/en-us/sysinternals/bb897557.aspx