• 制作鼠标击穿窗体


    实现效果:

      

    知识运用:

      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;    //使窗体始终在其他窗体之上
            }
    
  • 相关阅读:
    Reporting Service筛选器的作用
    asp.net很好用的编辑器
    Filter函数详析
    很好用的模态弹出窗口,可自定义弹出窗口外观
    asp.net 3.5异步调用方法小结
    C#面向对象的一个简单例子,继承、接口、重写都用上了,还用到了工厂模式
    漂亮的ajax图片切换
    asp.net大文件上传组件
    jQuery中文入门指南,翻译加实例,jQuery的起点教程(转)
    DirectoryEntry的使用
  • 原文地址:https://www.cnblogs.com/feiyucha/p/10121437.html
Copyright © 2020-2023  润新知