C#使用Windows API实现桌面上的遮罩层(鼠标穿透)

C#实现实现桌面上的遮罩层(鼠标穿透)主要通过一下几个API函数来实现:GetWindowLong,SetWindowLong,SetLayeredWindowAttributes。其中有一个Windows 消息 WS_EX_TRANSPARENT 比较重要,它实现了鼠标穿透的功能。 下面来看看完整的实现代码:


using System;  
using System.Drawing;  
using System.Windows.Forms;  
using System.Runtime.InteropServices;  
namespace WindowsApplication40  
{  
  public partia lclass Form1:Form  
  {  
    public Form1()  
    {  
      InitializeComponent();  
    }  
    [DllImport("user32.dll",EntryPoint="GetWindowLong")]  
    public static extern long GetWindowLong(IntPtr hwnd,int nIndex);  
    [DllImport("user32.dll",EntryPoint="SetWindowLong")]  
    public static extern long SetWindowLong(IntPtr hwnd,int nIndex,long dwNewLong);  
    [DllImport("user32",EntryPoint="SetLayeredWindowAttributes")]  
    public static extern int SetLayeredWindowAttributes(IntPtr Handle,int crKey,byte bAlpha,int dwFlags);  
    const int GWL_EXSTYLE=-20;  
    const int WS_EX_TRANSPARENT=0x20;  
    const int WS_EX_LAYERED=0x80000;  
    const int LWA_ALPHA=2;  
 
    private void Form1_Load(objec tsender,EventArgs e)  
    {  
      this.BackColor=Color.Silver;  
      this.TopMost=true;  
      this.FormBorderStyle=FormBorderStyle.None;  
      this.WindowState=FormWindowState.Maximized;  
      SetWindowLong(Handle,GWL_EXSTYLE,GetWindowLong(Handle,GWL_EXSTYLE)|WS_EX_TRANSPARENT|WS_EX_LAYERED);  
      SetLayeredWindowAttributes(Handle,0,128,LWA_ALPHA);  
    }  
  }  
} 

以上就是介绍C#使用Windows API实现桌面上的遮罩层(鼠标穿透),希望对你有所帮助。

C#使用Windows API实现桌面上的遮罩层(鼠标穿透)的更多相关文章

  1. WinForm特效:桌面上的遮罩层

    一个窗体特效,帮你了解几个windows api函数.效果:windows桌面上增加一个简单的遮罩层,其中WS_EX_TRANSPARENT 比较重要,它实现了鼠标穿透的功能. using Syste ...

  2. VC Windows API获得桌面所有窗口句柄的方法

    VC Windows API应用之GetDesktopWindow ——获得桌面所有窗口句柄的方法 Windows API Windows 这个多作业系统除了协调应用程序的执行.分配内存.管理资源…之 ...

  3. [WinAPI] API 1 [桌面上画一个简单彩色图形]

    #include<Windows.h> void GdiOut(HDC hdc); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hP ...

  4. Windows api实现桌面任务栏隐藏\显示

    //隐藏任务栏 HWND hWnd = ::FindWindow(TEXT("Shell_traywnd"),TEXT("")); ::SetWindowPos ...

  5. 有时在UIWindow上添加遮罩层不成功的原因

    程序启动后,初始化window,初始化controller,加载试图,这三个方法的顺序是嵌套的 类似于: - (id) initWindow {[self initController];} 而我在i ...

  6. c# Windows Service 桌面上显示UI

    介绍 本文的目的是说明如何从Windows Vista中的服务正确启动交互式进程,以及演示如何以完全管理员权限启动该进程.交互式过程是能够在桌面上显示UI的过程. 本文介绍如何创建一个名为Loader ...

  7. 在Windows Server 2012中如何快速开关桌面上经典的“计算机、我的文档”等通用图标

    我们都知道,在Windows Server 2012系列的服务器版本中都已经引入了Modern的现代界面作为默认的用户交互界面,同时满足视觉一致化,新版的服务器管理程序也做成了扁平化.因此传统的计算机 ...

  8. Windows Server 2012 R2在桌面上顯示我的電腦等圖示

    Windows Server 2012 R2在桌面上顯示我的電腦等圖示   從Windows2012開始,微軟取消了服務器桌面個性化選項,如何重新調出配置界面,可以使用微軟命令調出.方法如下: 同時按 ...

  9. 如何在windows server 2008的桌面上显示 我的电脑

    装完windows server2008 r2 x64后发现桌面只有一个回收站图标,这一点和xp 20003都差不多,但是xp 2003很容易就把桌面上的 我的电脑 我的文档 网上邻居找到,但是win ...

随机推荐

  1. Decision Boundaries for Deep Learning and other Machine Learning classifiers

    Decision Boundaries for Deep Learning and other Machine Learning classifiers H2O, one of the leading ...

  2. 推荐一本书《深入理解PHP内核》

    <深入理解PHP内核> 在线网址:http://www.php-internals.com/

  3. WINDOWS 2008 SERVER域用户自动登陆

    The user I wanted to auto-logon as didn’t have a password, this reg hack worked instead: HKEY_LOCAL_ ...

  4. asp.net网站后台退出后,点后退按钮仍能进,如何安全退出

    用户登录成功后,将用户名保存Session Session["usrename"]=username; 退出后Sessssion["username"]=str ...

  5. 166. Fraction to Recurring Decimal

    题目: Given two integers representing the numerator and denominator of a fraction, return the fraction ...

  6. Two-Phase Locking

    两阶段封锁(Two-Phase Locking) 两段锁协议的内容 1. 在对任何数据进行读.写操作之前,事务首先要获得对该数据的封锁 2. 在释放一个封锁之后,事务不再获得任何其他封锁. “两段”锁 ...

  7. Import Items – Validation Multiple Languages Description

            ð  提交标准请求创建和更新物料,因语言环境与处理次序方式等因素,造成物料中英(更多语言)描述和长描述混乱刷新. 症状: >>> Submit Standard Op ...

  8. Android开发UI之自定义控件的皮肤

    定义一个button的皮肤,设置属性android:background="@drawable/button_skin",button_skin.xml文件为要下文中的资源文件. ...

  9. Java实现人民币大写精讲

    想要实现人民币大写,在发票等场景中使用?? 1234.56显示为:壹仟贰佰叁拾肆元伍角陆分,那就往下看看吧! 本程序可以实现 0 到 9999 9999 9999.994 以内的人民币大写转换,精确到 ...

  10. eclipse 代码中突然出现特殊字符

    在写代码的时候,不知道点到了 eclipse 的哪个属性,代码中就出现了一些特殊字符,也不能删除. 请问,在 eclipse 中该怎么设置,才能将这些字符去掉. 如下图所示: 解决方法: 选择Wind ...