用 C++ 在Windows中清空回收站内文件/隐藏和显示桌面图标 / Windows任务栏 / 任务栏时钟 / 更改桌面壁纸

本文介绍了如何使用C++在Windows系统中实现清空回收站、隐藏与显示桌面图标、任务栏以及任务栏时钟的功能,并提供了更改桌面壁纸的方法。通过调用SHEmptyRecycleBin()等函数,实现了无确认删除、隐藏/显示桌面元素和自定义壁纸等操作。
摘要由CSDN通过智能技术生成

如果感觉这篇文章帮助到你的话,欢迎捐助我!
bitcoin : bc1qvvkqmwcd7s9fas063htffm76k63rx7f3r9dp4r

清空回收站内文件

#include<windows.h>
#include<WinUser.h>
int main()
{
	SHEmptyRecycleBin(NULL,NULL,NULL);
}

原理:SHEmptyRecycleBin()函数原型

SHEmptyRecycleBin(
HWND hwnd,
LPCTSTR pszRootPath,	//要清空回收站所在驱动器根目录。NULL表示所有驱动器。
DWORD dwFlags);			//清空回收站选项

注意:dwFlags 表示选项,例如:
SHERB_NOCONFIRMATION 不显示确认删除对话框
SHERB_NOSOUND 删除完成后不播放声音

例如

#include<windows.h>
#include<WinUser.h>
int main()
{
	SHEmptyRecycleBin(NULL,NULL,SHERB_NOCONFIRMATION);
}

执行后没有确认删除对话框。

隐藏和显示桌面图标

隐藏桌面图标

#include<windows.h>
#include<WinUser.h>
int main()
{
	HWND hDeskWnd=::FindWindow("Progman",NULL);
	ShowWindow(hDeskWnd,SW_HIDE);
}

运行后如下图:
在这里插入图片描述

显示桌面图标

#include<windows.h>
#include<WinUser.h>
int main()
{
	HWND hDeskWnd=::FindWindow("Progman",NULL);
	ShowWindow(hDeskWnd,SW_SHOW);
}

注意: ::FindWindow(“Progman”,NULL); 为获取桌面窗体句柄。

隐藏和显示 Windows 任务栏

隐藏任务栏

#include<windows.h>
int main()
{
	HWND hWinBar = ::FindWindow("Shell_TrayWnd","");
	:: ShowWindow(hWinBar,SW_HIDE);
}

运行后如下图:
在这里插入图片描述

显示任务栏

#include<windows.h>
int main()
{
	HWND hWinBar = ::FindWindow("Shell_TrayWnd","");
	:: ShowWindow(hWinBar,SW_SHOW);
}

隐藏和显示任务栏时钟

隐藏任务栏时钟

#include<windows.h>
int main()
{
	HWND hWinBar= :: FindWindow("Shell_TrayWnd",NULL);
	HWND hNotifyWnd = :: FindWindowEx(hWinBar,0,"TrayNotifyWnd",NULL);
	HWND hClockWnd = :: FindWindowEx(hNotifyWnd,0,"TrayClockWClass",NULL);
	::ShowWindow(hClockWnd,SW_HIDE);
}

运行后如下图:
在这里插入图片描述

显示任务栏时钟

#include<windows.h>
int main()
{
	HWND hWinBar= :: FindWindow("Shell_TrayWnd",NULL);
	HWND hNotifyWnd = :: FindWindowEx(hWinBar,0,"TrayNotifyWnd",NULL);
	HWND hClockWnd = :: FindWindowEx(hNotifyWnd,0,"TrayClockWClass",NULL);
	::ShowWindow(hClockWnd,SW_SHOW);
}

更改桌面壁纸

#include<windows.h>
#include<bits/stdc++.h>
int main()
{
	SystemParametersInfo (SPI_SETDESKWALLPAPER, 0 , (void*)"C:\\Untitled.png" , 0);
}

注意: (void*) 后面是你要更换的壁纸的路径,用双重反斜杠 \\ !

评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值