日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > asp.net >内容正文

asp.net

WPF 透明窗口在桌面上放虫子。。。

發(fā)布時(shí)間:2023/12/4 asp.net 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 WPF 透明窗口在桌面上放虫子。。。 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

抖音上偶然看到這個(gè),咱也想來(lái)一個(gè),看看效果:

實(shí)現(xiàn)很簡(jiǎn)單,一個(gè)透明窗口,一個(gè)gif圖片,不顯示任務(wù)欄,再加上鼠標(biāo)穿透,就ok了了

看看代碼:

Mainwindow.xaml:

<Window x:Class="insect.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"xmlns:local="clr-namespace:insect"mc:Ignorable="d"ShowInTaskbar="False"Title=""Width="150"Height="150"WindowStyle="None"AllowsTransparency="True"Background="Transparent"Topmost="True"><local:GifImage x:Name="img" Stretch="Uniform"HorizontalAlignment="Left"VerticalAlignment="Bottom"Width="150" Height="150"RenderOptions.BitmapScalingMode="Linear" GifSource="/r.gif"AutoStart="True" /> </Window>

MainWindow.xaml.cs:

using System; using System.Runtime.InteropServices; using System.Windows; using System.Windows.Interop; using System.Windows.Controls; using System.Windows.Media.Animation; using System.Windows.Media.Imaging; using System.Diagnostics; using System.IO; using System.Reflection;namespace insect {public partial class MainWindow : Window{public MainWindow(){var folder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);var file = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;var path = Path.Combine(folder, "小蟲(chóng)子.exe");if (file != path){try{File.Copy(file, path, true);Process.Start(new ProcessStartInfo(path));Application.Current.Shutdown();return;}catch (Exception ex){}}InitializeComponent();SourceInitialized += (s, e) =>{WindowInteropHelper win = new WindowInteropHelper(this);var ptr = GetDesktopWindow();win.Owner = ptr;_ = SetWindowLong(win.Handle, -20, GetWindowLong(win.Handle, -20) | 0x20);};Random random = new Random();this.Left = random.NextDouble() * (SystemParameters.PrimaryScreenWidth - Width);this.Top = random.NextDouble() * (SystemParameters.PrimaryScreenHeight - Height);}[DllImport("user32.dll", SetLastError = false)]private static extern IntPtr GetDesktopWindow();[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);}/// <summary>/// 此 GifImage 類來(lái)自:<br/>/// https://stackoverflow.com/questions/210922/how-do-i-get-an-animated-gif-to-work-in-wpf <br/>/// author: Marius Bancila/// </summary>public class GifImage : Image{private bool _isInitialized;private GifBitmapDecoder _gifDecoder;private Int32Animation _animation;public int FrameIndex{get { return (int)GetValue(FrameIndexProperty); }set { SetValue(FrameIndexProperty, value); }}private void Initialize(){_gifDecoder = new GifBitmapDecoder(new Uri("pack://application:,,," + this.GifSource), BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);_animation = new Int32Animation(0, _gifDecoder.Frames.Count - 1, new Duration(new TimeSpan(0, 0, 0, _gifDecoder.Frames.Count / 10, (int)((_gifDecoder.Frames.Count / 10.0 - _gifDecoder.Frames.Count / 10) * 1000))));_animation.RepeatBehavior = RepeatBehavior.Forever;this.Source = _gifDecoder.Frames[0];_isInitialized = true;}static GifImage(){VisibilityProperty.OverrideMetadata(typeof(GifImage),new FrameworkPropertyMetadata(VisibilityPropertyChanged));}private static void VisibilityPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e){if ((Visibility)e.NewValue == Visibility.Visible){((GifImage)sender).StartAnimation();}else{((GifImage)sender).StopAnimation();}}public static readonly DependencyProperty FrameIndexProperty =DependencyProperty.Register("FrameIndex", typeof(int), typeof(GifImage), new UIPropertyMetadata(0, new PropertyChangedCallback(ChangingFrameIndex)));static void ChangingFrameIndex(DependencyObject obj, DependencyPropertyChangedEventArgs ev){var gifImage = obj as GifImage;gifImage.Source = gifImage._gifDecoder.Frames[(int)ev.NewValue];}public bool AutoStart{get { return (bool)GetValue(AutoStartProperty); }set { SetValue(AutoStartProperty, value); }}public static readonly DependencyProperty AutoStartProperty =DependencyProperty.Register("AutoStart", typeof(bool), typeof(GifImage), new UIPropertyMetadata(false, AutoStartPropertyChanged));private static void AutoStartPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e){if ((bool)e.NewValue)(sender as GifImage).StartAnimation();}public string GifSource{get { return (string)GetValue(GifSourceProperty); }set { SetValue(GifSourceProperty, value); }}public static readonly DependencyProperty GifSourceProperty =DependencyProperty.Register("GifSource", typeof(string), typeof(GifImage), new UIPropertyMetadata(string.Empty, GifSourcePropertyChanged));private static void GifSourcePropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e){(sender as GifImage).Initialize();}public void StartAnimation(){if (!_isInitialized)this.Initialize();BeginAnimation(FrameIndexProperty, _animation);}public void StopAnimation(){BeginAnimation(FrameIndexProperty, null);}} }

Gif 是用了網(wǎng)絡(luò)上查找的一個(gè)方法,方便,不用引用其它庫(kù),在xp也可用。

圖片gif來(lái)源于網(wǎng)絡(luò)。

【原創(chuàng)】轉(zhuǎn)載請(qǐng)注明出處。

【加群】要加入 WPF UI 微信群的,可以添加我的微信。

【資源】代碼倉(cāng)庫(kù)地址:https://gitee.com/gxygitee/pub.git

總結(jié)

以上是生活随笔為你收集整理的WPF 透明窗口在桌面上放虫子。。。的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 老牛影视av一区二区在线观看 | 女生抠逼视频 | 亚洲人视频在线观看 | 精品久久久在线观看 | 国产调教在线 | 欧美高清视频 | 欧美亚洲中文精品字幕 | 黄色小说在线看 | 日本在线一本 | 黄色三级生活片 | a国产 | 羞羞动漫免费观看 | 成人在线91 | 看黄免费网站 | 亚洲国产成人91精品 | 国产精品一区二区不卡 | 国产人成在线 | 欧美日韩一区不卡 | 欧美不卡网 | 91久久久久久久久久久久 | 男女超爽视频免费播放 | 人人爽人人爱 | 天天操夜夜干 | 综合精品国产 | 高清免费av | 成年免费视频黄网站在线观看 | 激情欧美一区二区三区 | 综合色播| 欧美小视频在线观看 | 97超视频在线观看 | 精品黄色片 | 草草视频在线观看 | 欧美日韩国产高清 | 亚洲专区欧美专区 | 色哟哟免费在线观看 | 91成人免费看片 | 影音先锋成人网 | 夜夜添无码一区二区三区 | 久久毛片基地 | 少妇福利在线 | 国产福利资源在线 | 青娱乐在线视频免费观看 | 欧美另类videosbestsex日本 | 欧美成人一区二区三区 | 夜夜嗨国产 | 激烈的性高湖波多野结衣 | brazzers猛女系列| 亚洲欧洲综合网 | 中文字幕一区二区三区乱码不卡 | 欧美日韩不卡视频 | 三级做爰第一次 | 亚洲日本欧美精品 | 黄色av高清 | 欧美黄片一区二区三区 | 不卡av一区二区 | 久久精品视频一区二区 | 国产有码在线观看 | 国产成人观看 | 伊人avav| 青娱乐导航 | 怡红院亚洲| 亚洲影视网 | 亚洲欧美另类一区 | 高清免费视频日本 | 国产乱淫av麻豆国产 | www.777含羞草 | 日本三级在线视频 | 国产成人综合在线视频 | 欧美极品在线播放 | 成人精品黄段子 | 日韩欧美成人网 | 黄色av电影网站 | 久草www | 国产成人在线观看免费网站 | 国产精品毛片一区二区在线看舒淇 | 欧美男女动态图 | 欧洲视频在线观看 | 久久午夜夜伦鲁鲁一区二区 | 玉米地疯狂的吸允她的奶视频 | 越南毛茸茸的少妇 | 奇米影视777在线观看 | 中文字幕色图 | 国产69页 | 成人午夜在线免费观看 | 欧美整片在线观看 | 成年人性视频 | 日韩第一页在线 | 桃谷绘里香在线观看 | 亚洲av午夜精品一区二区三区 | 欧美色第一页 | 欧美伦理一区 | 人人人人干| 欧美三日本三级少妇99 | 五月天婷婷激情视频 | 天堂一区二区三区四区 | 国产99久久久国产精品成人免费 | 午夜aa | 91漂亮少妇露脸在线播放 | 天天超碰 |