我的位置: 首頁 > 學習專區 > .NET技術 > C# 鼠標穿透窗體功能

C# 鼠標穿透窗體功能

2014-05-13 10:52:59
來源:
[導讀]   通過以下代碼,在窗體啟動后調用方法SetPenetrate() 即可實現窗體的穿透功能。  同樣該功能需要加載命名空間  using System Runt
  
通過以下代碼,在窗體啟動后調用方法SetPenetrate() 即可實現窗體的穿透功能。

 

  同樣該功能需要加載命名空間

  using System.Runtime.InteropServices;

  private const uint WS_EX_LAYERED = 0x80000;

  private const int WS_EX_TRANSPARENT = 0x20;

  private const int GWL_STYLE = (-16);

  private const int GWL_EXSTYLE = (-20);

  private const int LWA_ALPHA = 0;

  [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

  );

  [DllImport("user32", EntryPoint = "SetLayeredWindowAttributes")]

  private static extern int SetLayeredWindowAttributes(

  IntPtr hwnd,

  int crKey,

  int bAlpha,

  int dwFlags

  );

  ///

 

  /// 設置窗體具有鼠標穿透效果

  ///

 

  public void SetPenetrate()

  {

  GetWindowLong(this.Handle, GWL_EXSTYLE);

  SetWindowLong(this.Handle, GWL_EXSTYLE, WS_EX_TRANSPARENT | WS_EX_LAYERED);

  SetLayeredWindowAttributes(this.Handle, 0, 100, LWA_ALPHA);

  }

評論
熱點專題
>>
相關文章推薦
>>
好吊妞免费视频在线观看,久久亚洲国产人成综合网,久久精品国产2020,欧美精品综合在线
亚洲愉拍一区二区三区 | 亚洲日韩欧美视频 | 亚洲伊人久久综合影院五月 | 中文字幕无线码一区二区 | 亚洲综合一区精品一区 | 又色又爽视频香蕉网络 |