EasyX 绘图库绘图窗口设置为桌面实时动态视屏壁纸(最新日期完善中)
2023-7-19 ~ 2023-7-21
(0)
0.将 EasyX 绘图窗口设为桌面实时动态视屏壁纸截图(桌面壁纸:字符雨与星空)
1.技术流程
- EasyX 绘图窗口内容设为实时桌面动态视屏壁纸。有三个关键技术流程:
- 设置分裂桌面窗口函数:向桌面窗口发送 0x52C 消息,使其分裂为,三层三个窗口。分别为 1 层图标窗口(WorkerW1)、2 层静态壁纸窗口(WorkerW2)、3 层最底层窗口(Progman)。
SendMessageTimeout(hProgman, 0x52C, 0, 0, 0, 100, 0); // 给它发特殊消息
- 设置隐藏第二层静态,壁纸窗口函数(WorkerW2):隐藏越来第二层窗口,露出设置的 Progman 窗口,里头的子窗口上的 EasyXWnd 窗口类(我们自绘制的程序窗口)。
BOOL CALLBACK EnumWindowsProc(_In_ HWND hwnd, _In_ LPARAM Lparam) { HWND hDefView = FindWindowEx(hwnd, 0, L"SHELLDLL_DefView", 0); if (hDefView != 0) { // 找它的下一个窗口,类名为 WorkerW,隐藏它 HWND hWorkerw = FindWindowEx(0, hwnd, L"WorkerW", 0); ShowWindow(hWorkerw, SW_HIDE); return FALSE; } return TRUE; }
- 设置 EasyX 绘图窗口至桌面壁纸函数(把自绘图窗口变成第三层 Progman 窗口的子窗口):
HWND hProgman = FindWindow(L"Progman", 0); // 找到 第三层 Progman PM 窗口类 HWND hFfplay = FindWindow(L"EasyXWnd", 0); // 找到 EasyX 程序 的窗口类窗口 // HWND hFfplay = GetHWnd(); 不设置成窗口类也行,这个只针对单独程序,EasyXWnd 是针对所有的 EasyX 程序 SetParent(hFfplay, hProgman); // 设置 EasyX 程序绘图窗口至桌面
2.整合封装函数
- 将上述各函数整合封装起来,方便使用,我定义了一个函数:
/* 设置 EASYX 绘图库程序到第三层 Progman 桌面成为时实动态壁纸函数 */ void EasyX_Desktop();
-
EasyX_Desktop 函数封装内容:
void EasyX_Desktop() { HWND hProgman = FindWindow(L"Progman", 0); // 找到第三层 PM 窗口 SendMessageTimeout(hProgman, 0x52C, 0, 0, 0, 100, 0); // 给它发特殊消息,变成三个桌面窗口 // HWND hFfplay = FindWindow(L"EasyXWnd", 0); // 找到 EasyX 窗口类,所有的 EasyX 程序的类 HWND hFfplay = GetHWnd(); // 本代码程序单独的类或者句柄,不会影响其他的 EasyX 程序 SetParent(hFfplay, hProgman); // 将 EasyX 绘图窗口设置为 第三层 Progman 的子窗口,达到动态桌面壁纸目的 EnumWindows(EnumWindowsProc, 0); // 隐藏第二层的壁纸 }
-
设置桌面时实动态壁纸,简单代码模板示例:
int main() { // 合成初始化精简版 iniwindows(0, 0, 0, 0, RGB(45, 65, 152), L"EASYX 桌面壁纸"); // 设置本程序窗口,变成时实桌面动态壁纸函数 EasyX_Desktop(); // 满屏都是彩色小字母(基于官方代码改的全屏化) char_srand(); // 暂缓 getmessage(EX_CHAR); // 关闭绘图库 closegraph(); // 返回 return 0; }
3.注意事项
- 如果 SetParent 函数,设置句柄为窗口类:EasyXWnd。那么所有在运行中的 EasyX 绘图库程序,将全部会被强制设置成桌面子窗口(嵌入桌面成壁纸)。
- 正常情况下,当程序成功设置为桌面动态时实壁纸时。该程序标题栏会强制变成 XP 系统上的古老样式。很难看,所以得去掉标题栏(包括:最小化、最大化、关闭等按钮)。
- 某些电脑系统运行该程序,程序设为桌面壁纸并不会立马生效,可能需要重启,或者需要管理员权限。重启电脑后,再次运行,程序设为桌面壁纸程序,则会生效。
- 在某些系统上。WIN10 系统会放大程序 125 % 的效果,所以桌面壁纸程序会出现不占满屏窗口。需要使用特殊代码还原,本文章代码中有示例。
- 设置成桌面后,按 ESC 键退出 EasyX 时实桌面动态壁纸。
- WIn7 系统可能不支持(没测试过,理论支持),WIN11 系统的电脑也支持(测试过),WIN10 部分高版本系统,可能存在桌面图标消失等问题。原因是单桌面窗口,0x52C 消息没有让单桌面窗口分裂成三层窗口,或者第三层窗口被其他的软件占用。
- 查看桌面窗口的层,外部获取窗口进程 ID 句柄,线程进程,或者查看 0x52C 消息是否生效。打开 VC 自带的宝藏软件 Spy++ 即可(在菜单栏的工具里)。
4.EasyX 程序窗口设为时实桌面壁纸代码实例
// 程序名称:把 EasyX 程序设置为时实桌面动态视屏壁纸(示例:动态星空与字符)
// 作者:随波逐流
// 绘图库版本:EasyX20230719(公测 Beta)
// 时间:2022-12-8
// 联系:2963787923@qq.com
//
#include<math.h>
#include <windows.h>
#include <stdio.h>
#include<graphics.h>
#include <time.h>
#include <conio.h>
#include<algorithm> // 针对设置该进程不受系统 DPI 设置影响的头文件。
#include <ShellScalingApi.h> // 引用头文件。
#pragma comment(lib, "Shcore.lib") // 链接库文件。
// 桌面壁纸背景 RGB 颜色值数组。
int R[] =
{
16, 17, 16, 17, 15, 16, 16, 17, 16, 16, 16, 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 23, 23, 23, 23, 23, 23, 23, 23, 24, 25, 25, 25, 24, 24, 24, 25, 25, 25, 25, 25, 25, 26, 26, 25, 25, 26, 26, 27, 28, 30, 31, 31, 32, 33, 33, 34, 34, 36, 39, 42, 43, 44, 43, 42, 43, 45, 42, 42, 44, 42, 40, 40, 40, 40, 39, 39, 38, 37, 38, 40, 40, 39, 40, 38, 38, 37, 37, 37, 37, 37, 37, 37, 37, 36, 36, 36, 36, 36, 35, 35, 35, 35, 34, 34, 34, 34, 34, 35, 35, 35, 35, 36, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 37, 37, 36, 36, 36, 37, 36, 36, 38, 38, 40, 40, 43, 43, 44, 44, 44, 44, 44, 45, 45, 45, 45, 46, 44, 45, 44, 45, 48, 48, 47, 48, 48, 48, 48, 49, 49, 48, 47, 47, 49, 51, 52, 53, 56, 59, 59, 61, 62, 64, 68, 62, 66, 64, 68, 66, 68, 66, 64, 64, 63, 61, 60, 59, 58, 57, 58, 59, 60, 59, 57, 55, 51, 50, 49, 49, 49, 49, 48, 48, 47, 46, 45, 45, 46, 46, 47, 47, 46, 45, 42, 41, 40, 39, 37, 39, 41, 41, 42, 41, 43, 41, 40, 38, 37, 35, 35, 35, 37, 37, 40, 40, 37, 36, 36, 36, 36, 36, 36, 36, 35, 35, 35, 35, 34, 34, 34, 34, 34, 34, 33, 33, 33, 32, 32, 32, 31, 31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 30, 30, 30, 30, 31, 31, 31, 31, 31, 32, 32, 32, 33, 33, 33, 34, 34, 34, 34, 34, 35, 36, 38, 38, 38, 39, 41, 42, 45, 45, 45, 45, 44, 44, 46, 48, 46, 46, 47, 47, 48, 48, 48, 49, 49, 49, 50, 50, 50, 50, 50, 50, 50, 50, 51, 51, 52, 53, 55, 55, 54, 56, 58, 60, 62, 62, 64, 68, 68, 73, 83, 86, 105, 117, 122, 128, 129, 119, 106, 96, 87, 79, 76, 76, 71, 70, 68, 66, 66, 65, 64, 64, 64, 63, 60, 62, 63, 63, 61, 59, 54, 54, 53, 53, 50, 49, 51, 50, 46, 46, 47, 47, 44, 41, 39, 37, 37, 37, 38, 38, 37, 36, 35, 35, 34, 34, 33, 33, 30, 30, 30, 29, 29, 29, 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 29, 29, 30, 30, 31, 31, 33, 33, 34, 34, 37, 37, 38, 38, 39, 39, 41, 41, 41, 41, 40, 41, 43, 44, 46, 44, 44, 45, 46, 45, 45, 46, 47, 47, 47, 50, 52, 53, 54, 58, 60, 59, 59, 61, 63, 63, 61, 60, 63, 62, 63, 65, 67, 69, 72, 74, 76, 80, 87, 97, 114, 135, 153, 163, 159, 142, 121, 102, 88, 85, 76, 71, 68, 65, 61, 58, 59, 58, 57, 57, 55, 54, 54, 54, 53, 53, 52, 51, 51, 50, 50, 50, 50, 49, 48, 49, 47, 47, 47, 47, 47, 46, 44, 44, 43, 43, 43, 43, 42, 42, 42, 43, 46, 46, 46, 46, 44, 44, 44, 44, 43, 43, 42, 42, 41, 41, 41, 40, 39, 39, 39, 39, 40, 41, 41, 41, 41, 41, 42, 42, 42, 42, 42, 43, 43, 43, 43, 49, 50, 50, 50, 49, 51, 50, 50, 49, 50, 50, 48, 46, 47, 47, 45, 48, 48, 48, 48, 47, 47, 47, 47, 47, 47, 47, 47, 47, 48, 49, 50, 49, 48, 46, 46, 45, 45, 46, 46, 46, 46, 45, 45, 45, 44, 44, 44, 44, 44, 44, 44, 44, 44, 43, 43, 44, 46, 46, 45, 44, 43, 44, 44, 45, 46, 47, 48, 49, 52, 51, 49, 48, 49, 50, 51, 51, 50, 50, 51, 50, 50, 50, 52, 53, 53, 53, 53, 52, 52, 53, 55, 56, 61, 60, 60, 59, 59, 59, 59, 59, 59, 59, 58, 57, 56, 54, 52, 52, 51, 51, 51, 51, 51, 51, 51, 51, 52, 51, 51, 51, 51, 51, 51, 52, 52, 52, 52, 52, 52, 53, 53, 53, 50, 50, 50, 50, 51, 51, 51, 51, 50, 50, 49, 49, 49, 49, 49, 49, 47, 47, 47, 47, 47, 49, 49, 49, 49, 50, 51, 51, 51, 51, 51, 51, 52, 52, 52, 52, 53, 52, 53, 55, 53, 53, 53, 53, 54, 54, 55, 55, 53, 52, 51, 51, 51, 50, 52, 53, 52, 53, 53, 54, 54, 54, 54, 55, 56, 56, 58, 61, 63, 64, 65, 66, 66, 67, 70, 75, 79, 82, 88, 96, 112, 137, 157, 227, 221, 214, 212, 193, 156, 121, 107, 98, 86, 85, 82, 84, 83, 83, 82, 85, 89, 97, 117, 140, 167, 200, 227, 239, 240, 235, 222, 199, 173, 148, 111, 105, 100, 95, 90, 89, 83, 80, 76, 74, 72, 71, 70, 69, 73, 70, 71, 71, 72, 72, 72, 72, 73, 72, 72, 73, 70, 69, 69, 70, 71, 70, 70, 74, 78, 80, 82, 87, 100, 123, 144, 160, 164, 153, 135, 116, 92, 83, 76, 73, 69, 67, 67, 65, 63, 62, 60, 61, 61, 60, 60, 60, 58, 58, 59, 58, 58, 58, 57, 57, 56, 56, 57, 57, 57, 57, 59, 59, 60, 61, 63, 64, 64, 67, 68, 69, 73, 74, 77, 77, 75, 76, 77, 77, 77, 77, 75, 71, 69, 70, 70, 69, 71, 72, 74, 74, 77, 79, 78, 79, 81, 82, 83, 87, 88, 90, 86, 82, 81, 79, 79, 75, 77, 72, 72, 71, 70, 71, 73, 77, 78, 77, 76, 77, 80, 80, 81, 81, 80, 79, 79, 79, 78, 77, 77, 77, 76, 76, 75, 75, 75, 74, 74, 75, 70, 71, 72, 72, 76, 77, 78, 78, 79, 81, 82, 83, 83, 84, 85, 81, 79, 79, 77, 75, 72, 69, 68, 68, 68, 67, 66, 66, 70, 68, 67, 63, 65, 65, 65, 65, 67, 66, };
int G[] =
{
15, 16, 14, 15, 13, 14, 14, 15, 14, 14, 14, 14, 14, 14, 14, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 23, 23, 23, 22, 22, 22, 23, 23, 23, 23, 23, 23, 24, 24, 25, 25, 26, 26, 27, 28, 30, 31, 31, 32, 33, 33, 34, 34, 36, 39, 42, 43, 44, 43, 42, 43, 45, 42, 42, 44, 42, 40, 40, 40, 40, 39, 39, 38, 37, 38, 40, 40, 37, 38, 36, 36, 35, 35, 35, 35, 35, 35, 35, 35, 34, 34, 34, 34, 34, 33, 33, 33, 33, 32, 32, 32, 32, 32, 33, 33, 33, 33, 34, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 34, 34, 34, 35, 35, 35, 36, 36, 36, 36, 37, 37, 36, 36, 38, 38, 38, 39, 39, 39, 39, 40, 38, 39, 38, 39, 40, 40, 39, 40, 40, 40, 40, 41, 41, 40, 39, 39, 41, 43, 44, 45, 48, 51, 51, 53, 54, 56, 60, 54, 60, 58, 62, 60, 62, 60, 58, 58, 57, 55, 54, 53, 52, 51, 52, 53, 54, 53, 51, 49, 45, 44, 43, 43, 43, 43, 42, 42, 43, 42, 41, 41, 40, 40, 39, 39, 40, 39, 38, 37, 38, 38, 39, 37, 34, 34, 33, 32, 31, 32, 33, 34, 36, 37, 37, 37, 36, 34, 33, 33, 33, 32, 32, 32, 32, 32, 31, 31, 32, 32, 32, 32, 31, 31, 31, 31, 31, 31, 30, 30, 30, 29, 29, 29, 28, 28, 28, 28, 28, 28, 28, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28, 28, 28, 28, 28, 29, 29, 29, 30, 30, 30, 31, 31, 31, 31, 31, 32, 33, 35, 35, 35, 36, 38, 39, 42, 42, 42, 42, 41, 41, 42, 44, 42, 42, 40, 40, 41, 41, 41, 42, 42, 42, 43, 43, 43, 42, 42, 42, 42, 42, 43, 43, 44, 45, 47, 50, 51, 53, 55, 57, 59, 59, 61, 65, 65, 70, 80, 83, 102, 114, 119, 125, 126, 116, 103, 93, 84, 76, 72, 72, 66, 65, 63, 61, 61, 60, 59, 59, 56, 55, 55, 57, 59, 59, 57, 55, 52, 52, 51, 51, 48, 47, 47, 46, 44, 44, 44, 44, 44, 41, 38, 38, 38, 38, 37, 37, 36, 35, 34, 34, 34, 34, 33, 33, 33, 33, 33, 32, 34, 34, 33, 33, 33, 33, 33, 33, 33, 33, 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 34, 33, 34, 34, 35, 35, 36, 36, 37, 37, 37, 37, 38, 38, 39, 39, 39, 39, 39, 39, 40, 41, 43, 44, 45, 44, 45, 46, 47, 46, 46, 47, 48, 46, 46, 49, 51, 52, 53, 57, 59, 58, 58, 60, 59, 59, 57, 56, 57, 56, 57, 59, 61, 63, 65, 69, 71, 75, 82, 93, 110, 131, 149, 159, 155, 139, 118, 99, 85, 82, 75, 70, 67, 64, 59, 56, 54, 53, 52, 52, 53, 52, 52, 52, 50, 50, 49, 48, 48, 47, 47, 47, 47, 46, 45, 46, 45, 45, 45, 45, 45, 44, 45, 45, 44, 44, 44, 44, 45, 45, 45, 44, 44, 44, 44, 44, 45, 45, 45, 45, 44, 44, 44, 44, 43, 43, 43, 44, 46, 46, 46, 46, 47, 48, 48, 48, 48, 48, 49, 49, 49, 49, 49, 50, 50, 50, 50, 54, 55, 55, 55, 54, 56, 55, 55, 54, 55, 55, 53, 50, 51, 50, 48, 51, 51, 51, 51, 50, 50, 50, 50, 50, 50, 50, 50, 50, 51, 52, 53, 52, 51, 49, 49, 48, 48, 49, 49, 49, 49, 48, 48, 48, 47, 47, 49, 49, 49, 49, 49, 49, 49, 48, 48, 49, 51, 51, 50, 49, 48, 47, 47, 48, 49, 50, 51, 52, 55, 54, 52, 51, 52, 53, 54, 54, 53, 53, 54, 53, 53, 53, 53, 54, 54, 54, 54, 53, 54, 55, 57, 58, 63, 62, 62, 61, 61, 61, 61, 61, 61, 61, 60, 59, 58, 56, 54, 54, 53, 53, 53, 53, 52, 52, 52, 52, 53, 52, 52, 52, 52, 52, 52, 53, 53, 53, 53, 53, 53, 54, 54, 54, 53, 53, 53, 53, 54, 54, 54, 54, 54, 54, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 54, 55, 55, 55, 55, 55, 55, 56, 56, 56, 56, 57, 56, 57, 59, 57, 57, 57, 57, 58, 58, 59, 59, 57, 56, 55, 55, 54, 53, 53, 54, 53, 54, 56, 57, 57, 57, 57, 58, 58, 58, 59, 62, 64, 65, 66, 67, 68, 69, 73, 78, 82, 86, 92, 101, 116, 141, 161, 232, 226, 219, 217, 197, 160, 125, 110, 101, 89, 88, 86, 88, 87, 87, 88, 91, 95, 103, 124, 145, 168, 200, 227, 240, 238, 233, 218, 195, 169, 144, 107, 101, 98, 93, 90, 88, 84, 83, 79, 77, 75, 74, 73, 72, 76, 73, 74, 74, 73, 73, 73, 73, 72, 71, 71, 72, 71, 70, 70, 71, 72, 73, 73, 77, 81, 84, 86, 91, 106, 129, 150, 166, 170, 159, 141, 122, 97, 88, 84, 80, 76, 74, 74, 72, 67, 66, 67, 68, 68, 67, 67, 67, 66, 66, 66, 65, 65, 65, 64, 64, 64, 64, 64, 64, 64, 64, 63, 63, 63, 64, 64, 65, 65, 65, 66, 66, 70, 73, 76, 76, 74, 75, 76, 76, 76, 76, 74, 70, 68, 68, 68, 67, 69, 70, 72, 72, 72, 74, 73, 74, 76, 77, 81, 85, 87, 89, 88, 84, 85, 83, 85, 80, 82, 77, 76, 75, 74, 75, 77, 81, 82, 81, 80, 79, 83, 83, 84, 84, 85, 84, 84, 84, 84, 83, 83, 83, 82, 82, 81, 81, 81, 80, 80, 81, 78, 79, 80, 80, 82, 83, 84, 84, 85, 87, 88, 89, 89, 90, 91, 87, 85, 85, 83, 81, 78, 78, 77, 77, 77, 76, 75, 75, 76, 77, 78, 77, 76, 76, 76, 76, 76, 75, };
int B[] =
{
21, 24, 25, 28, 26, 27, 27, 28, 27, 25, 25, 27, 27, 28, 28, 29, 27, 28, 28, 29, 29, 30, 30, 31, 32, 32, 32, 32, 32, 32, 32, 32, 33, 34, 34, 34, 33, 33, 33, 34, 34, 34, 34, 34, 34, 35, 35, 35, 35, 36, 36, 37, 38, 40, 43, 43, 44, 45, 45, 46, 46, 48, 51, 54, 55, 56, 55, 54, 55, 57, 54, 54, 56, 54, 52, 52, 52, 52, 51, 51, 50, 49, 50, 52, 52, 51, 52, 50, 50, 49, 49, 49, 49, 49, 49, 49, 49, 48, 48, 48, 48, 48, 47, 47, 47, 47, 46, 46, 46, 46, 46, 47, 47, 47, 47, 48, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 48, 48, 48, 49, 51, 51, 50, 50, 50, 50, 49, 49, 47, 47, 48, 48, 48, 49, 49, 49, 49, 50, 48, 49, 48, 49, 53, 53, 52, 53, 53, 53, 53, 54, 54, 53, 52, 52, 54, 56, 57, 58, 61, 64, 64, 66, 67, 69, 73, 67, 72, 70, 74, 72, 76, 74, 72, 72, 71, 69, 68, 67, 66, 65, 66, 67, 68, 67, 65, 63, 59, 58, 57, 57, 57, 57, 56, 56, 57, 56, 55, 55, 54, 54, 54, 54, 54, 53, 53, 52, 52, 52, 52, 51, 52, 50, 50, 51, 51, 51, 49, 49, 50, 50, 50, 50, 52, 51, 51, 51, 50, 49, 49, 49, 49, 49, 51, 51, 51, 51, 51, 51, 52, 52, 52, 52, 52, 52, 51, 51, 51, 50, 50, 50, 49, 49, 49, 49, 49, 49, 49, 48, 48, 48, 48, 48, 48, 48, 48, 48, 49, 49, 49, 49, 49, 50, 50, 50, 51, 51, 51, 52, 52, 52, 52, 52, 51, 52, 54, 54, 54, 55, 57, 58, 59, 59, 59, 59, 58, 58, 59, 61, 59, 59, 58, 58, 59, 59, 59, 60, 60, 60, 61, 61, 61, 63, 63, 63, 63, 63, 64, 66, 67, 69, 71, 73, 72, 74, 76, 78, 78, 78, 80, 82, 82, 87, 97, 102, 121, 133, 138, 144, 145, 135, 122, 112, 105, 97, 95, 95, 89, 88, 86, 84, 84, 83, 82, 82, 79, 78, 77, 79, 82, 82, 80, 78, 74, 74, 73, 73, 72, 71, 72, 71, 68, 68, 71, 71, 72, 69, 69, 68, 69, 69, 69, 69, 68, 67, 66, 66, 68, 68, 67, 67, 66, 66, 64, 63, 64, 64, 65, 65, 65, 65, 65, 65, 63, 63, 64, 64, 64, 64, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 66, 68, 69, 69, 70, 70, 71, 71, 72, 72, 73, 73, 74, 74, 75, 75, 76, 76, 76, 76, 76, 77, 79, 80, 79, 78, 76, 77, 78, 77, 77, 78, 79, 78, 78, 81, 83, 84, 85, 89, 91, 90, 90, 92, 92, 92, 90, 89, 91, 90, 91, 93, 95, 97, 98, 101, 103, 105, 112, 120, 137, 158, 176, 186, 182, 168, 147, 128, 114, 113, 107, 102, 101, 98, 96, 93, 94, 93, 93, 93, 93, 92, 92, 92, 93, 93, 92, 91, 93, 92, 92, 92, 92, 91, 90, 91, 92, 92, 92, 92, 92, 91, 91, 91, 90, 90, 90, 90, 90, 90, 90, 90, 93, 93, 93, 93, 93, 93, 93, 93, 92, 92, 92, 92, 91, 91, 91, 91, 92, 92, 92, 92, 93, 94, 94, 94, 94, 94, 95, 93, 93, 93, 93, 94, 94, 96, 96, 96, 97, 97, 97, 96, 98, 97, 97, 96, 97, 97, 95, 95, 96, 95, 93, 96, 96, 96, 96, 95, 95, 95, 95, 95, 95, 95, 95, 95, 94, 95, 96, 95, 94, 92, 92, 91, 91, 92, 92, 92, 92, 91, 91, 91, 90, 90, 91, 91, 91, 91, 91, 91, 91, 90, 90, 91, 93, 93, 92, 91, 90, 88, 88, 89, 90, 91, 92, 93, 98, 97, 95, 94, 95, 96, 97, 97, 96, 96, 97, 96, 96, 98, 99, 100, 100, 98, 98, 97, 95, 96, 96, 97, 101, 100, 100, 99, 99, 99, 99, 99, 99, 99, 99, 98, 97, 95, 95, 95, 94, 94, 94, 94, 96, 96, 96, 96, 99, 98, 98, 98, 100, 100, 100, 99, 97, 97, 97, 97, 97, 98, 98, 98, 96, 98, 98, 98, 99, 99, 99, 99, 101, 101, 100, 100, 100, 100, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 100, 101, 102, 102, 102, 102, 102, 102, 103, 103, 103, 103, 104, 103, 104, 106, 104, 104, 104, 104, 105, 105, 106, 106, 104, 103, 102, 102, 99, 98, 99, 100, 99, 100, 101, 102, 102, 102, 102, 103, 106, 106, 107, 110, 112, 113, 114, 115, 117, 117, 118, 121, 123, 123, 127, 131, 145, 168, 188, 254, 248, 241, 239, 222, 189, 154, 141, 134, 124, 123, 123, 125, 124, 124, 122, 125, 127, 135, 153, 174, 196, 224, 251, 255, 255, 254, 241, 218, 194, 171, 140, 136, 135, 132, 128, 128, 128, 126, 122, 120, 118, 117, 116, 115, 119, 116, 117, 117, 117, 117, 117, 117, 116, 115, 115, 116, 117, 116, 116, 117, 118, 118, 116, 120, 122, 122, 124, 128, 142, 165, 186, 202, 206, 195, 177, 158, 135, 128, 123, 122, 120, 118, 120, 118, 112, 111, 111, 112, 114, 113, 113, 113, 112, 112, 112, 111, 111, 111, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 108, 109, 110, 111, 111, 112, 113, 111, 113, 113, 116, 116, 114, 115, 116, 116, 116, 116, 114, 110, 108, 108, 107, 106, 108, 109, 111, 111, 112, 114, 113, 115, 117, 118, 121, 125, 127, 129, 127, 123, 122, 120, 121, 118, 120, 115, 114, 113, 112, 113, 115, 118, 119, 118, 117, 117, 118, 118, 119, 117, 117, 116, 116, 116, 116, 115, 115, 117, 116, 116, 115, 117, 117, 116, 116, 115, 114, 115, 116, 116, 118, 119, 120, 118, 119, 121, 122, 123, 123, 122, 123, 121, 119, 117, 115, 113, 110, 109, 108, 108, 108, 107, 106, 106, 108, 108, 108, 106, 106, 108, 108, 108, 109, 108,
};
/* 隐藏桌面第二层的程序,目标显出第三层 */
BOOL CALLBACK EnumWindowsProc(_In_ HWND hwnd, _In_ LPARAM Lparam)
{
HWND hDefView = FindWindowEx(hwnd, 0, L"SHELLDLL_DefView", 0);
if (hDefView != 0)
{
// 找它的下一个窗口,类名为 WorkerW,隐藏它。
HWND hWorkerw = FindWindowEx(0, hwnd, L"WorkerW", 0);
ShowWindow(hWorkerw, SW_HIDE);
return FALSE;
}
return TRUE;
}
/* 设置 EASYX 绘图库程序到第三层 Progman 桌面成为时实动态壁纸函数 */
void EasyX_Desktop()
{
HWND hProgman = FindWindow(L"Progman", 0); // 找到第三层 PM 窗口。
SendMessageTimeout(hProgman, 0x52C, 0, 0, 0, 100, 0); // 给它发特殊消息,变成三个桌面窗口。
// HWND hFfplay = FindWindow(L"EasyXWnd", 0); // 找到 EasyX 窗口类,所有的 EasyX 程序的类。
HWND hFfplay = GetHWnd(); // 本代码程序单独的类或者句柄,不会影响其他的 EasyX 程序。
SetParent(hFfplay, hProgman); // 将 EasyX 绘图窗口设置为 第三层 Progman 的子窗口,达到动态桌面壁纸目的。
EnumWindows(EnumWindowsProc, 0); // 隐藏第二层的壁纸。
}
// 合成初始化,初始程序位置,大小背景及标题名称。
void iniwindows(int x, int y, int w, int h, COLORREF RGB, LPCTSTR str)
{
// 设置该进程不受系统 DPI 设置影响。
SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE);
// 获取桌面窗口大小的高宽。
int WIDTH = GetSystemMetrics(SM_CXSCREEN);
int HEIGHT = GetSystemMetrics(SM_CYSCREEN);
// 初始化绘图库。
initgraph(WIDTH, HEIGHT);
setbkmode(TRANSPARENT);
setbkcolor(RGB);
// 刷新背景。
cleardevice();
// 获得窗口句柄。
HWND hWnd = GetHWnd();
// 初始程序位置。
MoveWindow(hWnd, x, y, WIDTH, HEIGHT, true);
// 由于会把程序的标题栏,最小化,最大化,关闭,也会变成桌面的一部分,而且还是很老的,所以我把这些去掉了。
SetWindowLong(hWnd, GWL_STYLE,
GetWindowLong(hWnd, GWL_STYLE) & ~(WS_CAPTION | WS_DLGFRAME | WS_BORDER));
SetWindowLong(hWnd, GWL_EXSTYLE,
GetWindowLong(hWnd, GWL_EXSTYLE) &
~(WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE | WS_EX_DLGMODALFRAME));
// 设置去掉。
SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);
// 使用 Windows API 修改窗口名称。
SetWindowText(hWnd, str);
setlinecolor(BLACK);
}
#define MAXSTAR 100 // 星星总数
struct STAR
{
double x;
int y;
double step;
int color;
};
STAR star[MAXSTAR];
// 初始化星星
void InitStar(int i, int w, int h)
{
star[i].x = 0;
star[i].y = rand() % h;
star[i].step = (rand() % 5000) / 1000.0 + 1;
star[i].color = (int)(star[i].step * 255 / 6.0 + 0.5); // 速度越快,颜色越亮
star[i].color = RGB(star[i].color, star[i].color, star[i].color);
}
// 移动星星
void MoveStar(int i, int w, int h)
{
HWND hWnd = GetHWnd();
// 擦掉原来的星星
putpixel((int)star[i].x, star[i].y, RGB(R[i], G[i], B[i]));
// 计算新位置
star[i].x += star[i].step;
if (star[i].x > w) InitStar(i, w, h);
// 画新星星
putpixel((int)star[i].x, star[i].y, star[i].color);
}
// 动态星空与菜字符。
void char_srand_start()
{
// 设置背景。
for (int i = 0; i < getheight(); i++)
{
for (int k = 0; k < getwidth(); k++)
{
putpixel(k, i, RGB(R[i], G[i], B[i]));
}
}
TCHAR STR[400] = { _T("按“ESC”键退出,EasyX 实时桌面动态视屏壁纸程序") };
int WIDTH = GetSystemMetrics(SM_CXSCREEN);
int HEIGHT = GetSystemMetrics(SM_CYSCREEN);
// 设置随机种子
srand((unsigned)time(NULL));
// 初始化所有星星
for (int i = 0; i < MAXSTAR; i++)
{
InitStar(i, WIDTH, HEIGHT);
star[i].x = rand() % WIDTH;
}
int x, y;
char c;
bool bol = true;
settextstyle(16, 8, _T("Courier")); // 设置字体
HWND hWnd = GetHWnd();
for (; bol; )
{
for (int i = 0; i <= HEIGHT && bol; i++)
{
for (int i = 0; i < MAXSTAR && bol; i++)
MoveStar(i, WIDTH, HEIGHT);
// 在随机位置显示三个随机字母
for (int j = 0; j < 3 && bol; j++)
{
// 设置颜色
settextcolor(RGB(rand() % 255 + 1, rand() % 255 + 1, rand() % 255 + 1));
x = rand() % WIDTH + 1;
y = rand() % HEIGHT + 1;
c = (rand() % 26) + 65;
setbkmode(TRANSPARENT);
outtextxy(x, y, c);
// 按 ESC 键停止桌面壁纸程序,可以退出。
if (GetAsyncKeyState(VK_ESCAPE) & 0x8000)
{
if (MessageBox(hWnd, _T("EASYX 桌面动态壁纸程序已启动是否需要终止?\n"), _T("EASYX 桌面动态壁纸程序 - 询问"), MB_YESNO | MB_ICONQUESTION) == IDYES)
{
bol = false;
break;
}
else
{
continue;
}
}
}
// 画线擦掉一个像素行
setlinecolor(RGB(R[i], G[i], B[i]));
line(0, i, WIDTH, i);
setbkmode(OPAQUE);
outtextxy(WIDTH - 450, 0, STR);
// 延时
Sleep(25);
if (i >= HEIGHT) i = -1;
FlushBatchDraw();
}
}
}
int main()
{
// 合成初始化精简版。
iniwindows(0, 0, 0, 0, RGB(45, 65, 152), L"EASYX 桌面壁纸");
// 设置本程序窗口,只要在绘图程序前使用就可以变成时实桌面动态壁纸函数。核心代码函数就是这个。
EasyX_Desktop();
BeginBatchDraw();
// 满屏都是彩色小字母与星空(基于官方代码改的全屏化)。
char_srand_start();
EndBatchDraw();
closegraph();
// 返回。
return 0;
}
5.参考资料
- 字符代码来源于:EasyX 官方演示教程例子 1
星空代码来源于:EasyX 官方演示教程例子 2
程序设为时实桌面壁纸资料来源于:B 站 UP 主偶而有点小迷糊(修改特化成支持 EasyX 绘图库而来)
6.指导老师:
- 慢羊羊
添加评论
取消回复