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 上测试了,不知道其它系统如何的更多相关文章

  1. UWP 设置桌面壁纸、锁屏图片

    private static Uri imgUri = new Uri("ms-appx:///pic1.jpg"); private async void btnSetWallp ...

  2. VC++ 设置桌面壁纸

    Windows Shell API提供了接口IActiveDesktop来完成墙纸的设置. //IActiveDesktop 接口方法表 (详情参见MSDN) AddDesktopItem AddDe ...

  3. sakura设置桌面壁纸

    下下载steam上的Wallpaper Engine 先将sakura.html下载为html文件. 再从文件打开 就保存了 再加载保存,就一直是了

  4. c++ 设置桌面壁纸(win)

    #include <iostream> #include <Windows.h> int main() { const char* path = "C:\\Users ...

  5. 【Win10应用开发】自定义桌面壁纸

    调用通用的API来设置桌面壁纸,是一件既简单又有趣的事情,结合XAML可以生成图像的特性,你甚至可以做一个应用,让用户用他所拍的照片做成一张自定义壁纸,然后作为桌面壁纸. 这个API是通用的,应用运行 ...

  6. python爬虫-抓取acg12动漫壁纸排行设置为桌面壁纸

    ACG-wallpaper 初学python,之前想抓取P站的一些图片来着,然后发现acg12这里有专门的壁纸榜单,就写了个抓取壁纸作为mac桌面壁纸玩玩. 功能:抓取acg12壁纸榜单的动漫壁纸,并 ...

  7. Windows 聚焦的锁屏壁纸设置为桌面壁纸

    需求: Windows的锁屏壁纸偶尔遇到非常喜欢的壁纸,想设置为桌面壁纸. 步骤如下: 1. “Windows 聚焦”的锁屏壁纸都保存在隐藏文件夹 --- Assets里. a. 打开“资源管理器 b ...

  8. Delphi通过调用COM对象实现更改桌面壁纸

    从前我也是用SystemParametersInfo这API来改桌面壁纸的,问题多多,也不知道哪错了,就没深究下去.看了CSDN的帖子后,大彻大悟~~         在XP下,SystemParam ...

  9. Win10家庭版设置桌面右键更换桌面壁纸

    Win10家庭版设置桌面右键更换桌面壁纸.. ------------------------- 这是设置之前的右键快捷菜单.. ------------------------- 开始设置:右键桌面 ...

  10. 【win10】win10下两个显示器不同桌面壁纸

    win10系统下,双屏显示为不同的桌面壁纸 操作: 1.鼠标右键点击个性化 2.点击背景选项 3.在图片上右键选择要添加为背景的图片 同理,将另一个屏幕壁纸设为监视器1 最后效果为两个分屏为不同桌面壁 ...

随机推荐

  1. 【VMware VCF】使用 Offline Bundle Transfer Utility(OBTU)配置 VCF 脱机库。

    VMware Cloud Foundation 环境中,软件包仓库的来源支持两种方式,分别是 Online Depot 和 Offline Depot.第一种方式,是在 VCF 环境能够连接互联网的情 ...

  2. 在react中使用阿里图标库

    参考教程:https://blog.csdn.net/qq_41977441/article/details/110352463 阿里图标库:https://www.iconfont.cn/ 成果展示 ...

  3. chcapter 11 熵和信息

    Entropy and information 熵:度量一个物理系统中的态的不确定度. 注意: 文中出现的' 凸性' convexity  和 ' 凹性' concavity 的在不同的教材中可能含义 ...

  4. 题解:CF1301B Motarack's Birthday

    CF1301D Time to Run 题解 思维题. 分析 把一个格子视作一个点,每个点的度数都是偶数,所以这是一张欧拉图.而需要走遍整个方格图,可以证明只要 \(k\) 不超过 \(4nm-2n- ...

  5. CSP2023 游寄

    CSP2023 游寄 没错,又寄. day -n 停课集训,天天打联测模拟赛,人麻了. day -n 请假回家了,人更麻了. 和姐姐拥抱了. 差点睡过头,天天下大雨,悲. 我妈和亲戚出去了,和哥在家通 ...

  6. The 2024 ICPC Asia East Continent Online Contest (I) C

    Link: Permutation Counting 4 我的评价是神题,给出两种做法. 方法一 利用线代技巧. 设法构造矩阵 \(A\), 其中 \(A_{ij} = [j \in [l_i, r_ ...

  7. 从零开始:NetBox 4.1 Docker 部署和升级

    前言 由于Netbox 官方的中文语言日渐完善,所以新出一个使用官方Docker源部署和升级的教程. Netbox 系列文章:https://songxwn.com/categories/NetBox ...

  8. elementUI 选择开始结束日期加限制

    需求是开始结束日期不得大于当前时间,当开始日期发生变化时,结束日期不得小于开始日期且不得大于当前日期 <el-form-item label="开始日期:"> < ...

  9. 逆向WeChat(八)

    上一篇逆向WeChat(七)是逆向微信客户端本地数据库相关事宜. 本篇逆向微信客户端本地日志xlog相关的事宜. 本篇在博客园地址https://www.cnblogs.com/bbqzsl/p/18 ...

  10. 小白PDF阅读器重排版时的自动提取背景色功能介绍及实现

    小白PDF阅读器在1.35之前的版本对于有深色背景的页面重拍版时并不太完美.对于深色背景区域主要表现在不能分割排版和重排后页面元素割裂感明显.小白PDF阅读器在1.35版本主要针对这两个问题进行了优化 ...