码迷,mamicode.com
首页 > Windows程序 > 详细

制作鼠标击穿窗体

时间:2018-12-14 21:11:11      阅读:243      评论:0      收藏:0      [点我收藏+]

标签:top   ima   OWIN   private   一个   strong   图片   ntp   inter   

实现效果:

  技术分享图片

知识运用:

  API函数SetWindowLong和GetWindowLong

  在调用API函数的时候要添加 System.Runtime.InteropService命令空间

  [DllImport("user32", EntryPoint = "GetWindowLong")]    //从指定的结构中取得信息
  private static extern uint GetWindowLong(IntPtr hwnd, int nIndex);

  1.返回值:uint,由nIndex决定 零表是出错

  [DllImport("user32", EntryPoint = "SetWindowLong")]    //在窗口结构中为指定的窗口设置信息
  private static extern uint SetWindowLong(IntPtr hwnd,int nIndex,uint dwNewLong);

  1. nIndex:int,欲取回的信息 其常量如图
  2. hwnd:IntPtr,欲为其取得信息的窗口的句柄
  3. dwNewLong:uint,由nIndex指定的窗口信息的新值
  4. 返回值:uint,指定数据的前一个值

  技术分享图片

 实现代码:

        private const uint WS_EX_LAYERED = 0x80000;
        private const int WS_EX_TRANSPARENT = 0x20;
        private const int GWL_EXSTYLE = -20;
        private const int LWA_COLORKEY = 1;

        [DllImport("user32", EntryPoint = "SetWindowLong")]
        private static extern uint SetWindowLong(IntPtr hwnd,int nIndex,uint dwNewLong);
        [DllImport("user32", EntryPoint = "GetWindowLong")]
        private static extern uint GetWindowLong(IntPtr hwnd, int nIndex);
        private void CanPenetrate() {
            uint intExTemp = GetWindowLong(this.Handle, GWL_EXSTYLE);   //从当前窗口中取得信息
            //在窗口结构中为当前窗口设置信息
            uint oldGWLEx = SetWindowLong(this.Handle, GWL_EXSTYLE, WS_EX_LAYERED|WS_EX_TRANSPARENT);
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            this.ShowInTaskbar = false; //窗体不出现在Windows任务栏中
            CanPenetrate();
            this.TopMost = true;    //使窗体始终在其他窗体之上
        }

 

制作鼠标击穿窗体

标签:top   ima   OWIN   private   一个   strong   图片   ntp   inter   

原文地址:https://www.cnblogs.com/feiyucha/p/10121437.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!