c# 设置桌面壁纸: 只在win10 上测试了,不知道其它系统如何
c# 设置桌面壁纸:
只在win10 上测试了,不知道其它系统如何。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.IO;
using Microsoft.Win32; namespace Wallpaper
{
static class Window
{
[DllImport("user32.dll", EntryPoint = "SetParent")]
private static extern int SetParent(int hWndChild,int hWndNewParent);
[DllImport("user32.dll", EntryPoint = "FindWindowA")]
private static extern IntPtr FindWindowA(string lpClassName, string lpWindowName);
[DllImport("user32.dll", EntryPoint = "FindWindowExA")]
private static extern IntPtr FindWindowExA(IntPtr hWndParent, IntPtr hWndChildAfter, string lpszClass, string lpszWindow);
[DllImport("user32.dll", EntryPoint = "GetClassNameA")]
private static extern IntPtr GetClassNameA(IntPtr hWnd, IntPtr lpClassName, int nMaxCount);
[DllImport("user32.dll", EntryPoint = "GetParent")]
private static extern IntPtr GetParent(IntPtr hWnd); public static void SetFather(Form form)
{
SetParent((int)form.Handle, GetBackground());
} private static int GetBackground()
{
unsafe
{
IntPtr background = IntPtr.Zero;
IntPtr father = FindWindowA("progman", "Program Manager");
IntPtr workerW = IntPtr.Zero;
do
{
workerW = FindWindowExA(IntPtr.Zero, workerW, "workerW", null);
if (workerW != IntPtr.Zero)
{
char[] buff = new char[200];
IntPtr b = Marshal.UnsafeAddrOfPinnedArrayElement(buff, 0);
int ret = (int)GetClassNameA(workerW, b, 400);
if (ret == 0) throw new Exception("出错");
}
if (GetParent(workerW) == father)
{
background = workerW;
}
} while (workerW != IntPtr.Zero);
return (int)background;
}
} [DllImport("user32.dll", EntryPoint = "SystemParametersInfo")]
public static extern int SystemParametersInfo(int uAction, int uParam, StringBuilder lpvParam, int fuWinIni); public static bool Refresh()
{
StringBuilder wallpaper = new StringBuilder(200);
SystemParametersInfo(0x73, 200, wallpaper, 0);
int ret = SystemParametersInfo(20, 1, wallpaper, 3);
if(ret != 0)
{
RegistryKey hk = Registry.CurrentUser;
RegistryKey run = hk.CreateSubKey(@"Control Panel\Desktop\");
run.SetValue("Wallpaper", wallpaper.ToString());
return true;
}
return false;
} }
}
c# 设置桌面壁纸: 只在win10 上测试了,不知道其它系统如何的更多相关文章
- UWP 设置桌面壁纸、锁屏图片
private static Uri imgUri = new Uri("ms-appx:///pic1.jpg"); private async void btnSetWallp ...
- VC++ 设置桌面壁纸
Windows Shell API提供了接口IActiveDesktop来完成墙纸的设置. //IActiveDesktop 接口方法表 (详情参见MSDN) AddDesktopItem AddDe ...
- sakura设置桌面壁纸
下下载steam上的Wallpaper Engine 先将sakura.html下载为html文件. 再从文件打开 就保存了 再加载保存,就一直是了
- c++ 设置桌面壁纸(win)
#include <iostream> #include <Windows.h> int main() { const char* path = "C:\\Users ...
- 【Win10应用开发】自定义桌面壁纸
调用通用的API来设置桌面壁纸,是一件既简单又有趣的事情,结合XAML可以生成图像的特性,你甚至可以做一个应用,让用户用他所拍的照片做成一张自定义壁纸,然后作为桌面壁纸. 这个API是通用的,应用运行 ...
- python爬虫-抓取acg12动漫壁纸排行设置为桌面壁纸
ACG-wallpaper 初学python,之前想抓取P站的一些图片来着,然后发现acg12这里有专门的壁纸榜单,就写了个抓取壁纸作为mac桌面壁纸玩玩. 功能:抓取acg12壁纸榜单的动漫壁纸,并 ...
- Windows 聚焦的锁屏壁纸设置为桌面壁纸
需求: Windows的锁屏壁纸偶尔遇到非常喜欢的壁纸,想设置为桌面壁纸. 步骤如下: 1. “Windows 聚焦”的锁屏壁纸都保存在隐藏文件夹 --- Assets里. a. 打开“资源管理器 b ...
- Delphi通过调用COM对象实现更改桌面壁纸
从前我也是用SystemParametersInfo这API来改桌面壁纸的,问题多多,也不知道哪错了,就没深究下去.看了CSDN的帖子后,大彻大悟~~ 在XP下,SystemParam ...
- Win10家庭版设置桌面右键更换桌面壁纸
Win10家庭版设置桌面右键更换桌面壁纸.. ------------------------- 这是设置之前的右键快捷菜单.. ------------------------- 开始设置:右键桌面 ...
- 【win10】win10下两个显示器不同桌面壁纸
win10系统下,双屏显示为不同的桌面壁纸 操作: 1.鼠标右键点击个性化 2.点击背景选项 3.在图片上右键选择要添加为背景的图片 同理,将另一个屏幕壁纸设为监视器1 最后效果为两个分屏为不同桌面壁 ...
随机推荐
- WebDriver常用属性和方法
除了上一篇的元素定位方法,Selenium中的WebDriver类中还有一些常用的属性和方法 一.常用的属性 1.下表列出了WebDriver的常用属性 # 属性 属性描述 用途 1 driver.n ...
- Redis常见面试题:ZSet底层数据结构,SDS、压缩列表ZipList、跳表SkipList
文章目录 一.Redis数据结构概述 1.1 Redis有哪些数据类型 1.2 Redis本质是哈希表 1.3 Redis的哈希冲突与渐进式rehash 1.4 数据结构底层 1.4.1 简单动态字符 ...
- Flink window
窗口计算 我们经常需要在一个时间窗口维度上对数据进行聚合,窗口是流处理应用中经常需要解决的问题.Flink的窗口算子为我们提供了方便易用的API,我们可以将数据流切分成一个个窗口,对窗口内的数据进行处 ...
- CCF网站提供的资源
1. 电子刊物,如<CCF通讯> 实时更新:http://www.ccf.org.cn/dl/publications/ 过往期刊:http://history.ccf.org.cn/si ...
- Docker制作私有镜像仓库
构建私有仓库 启动Docker Registry,使用Docker官方提供的Registry镜像就可以搭建本地私有镜像仓库,具体指令如下. docker run -d -p 5000:5000 --r ...
- 在 Github Action 管道内集成 Code Coverage Report
Github Actions 我们的开源项目 Host 在 Github,并且使用它强大的 Actions 功能在做 CICD.单看 Github Actions 可能不知道是啥.其实它就是我们常说的 ...
- 《刚刚问世》系列初窥篇-Java+Playwright自动化测试-4-启动浏览器-基于Maven(详细教程)
1.简介 上一篇文章,宏哥已经在搭建的java项目环境中添加jar包实践了如何启动浏览器,今天就在基于maven项目的环境中给小伙伴们或者童鞋们演示一下如何启动浏览器. 2.eclipse中新建mav ...
- 人工智能模型训练技术:随机失活,丢弃法,Dropout
前一篇:<探索训练人工智能模型的词汇大小与模型的维度> 序言:Dropout 是神经网络设计领域的一种技术,通常我们把它翻译成 随机失活 或者 丢弃法.如果训练神经网络的时候不用 Drop ...
- pytest框架之fixture
1.在进行接口关联时,一般很多个接口共用一个上行接口(例如)登录,可以使用fixture定义一个测试夹具,将登录的接口写在框架的conftest.py文件中: @pytest.fixture(scop ...
- meta-analysis初学--笔记摘抄
meta-analysis的定义 Meta-analysis是指对研究的研究,可以翻译为元分析.后设分析.整合分析.荟萃分析等.最常用的翻译是荟萃分析.Meta-analysis是用统计的概念与方法, ...