C++修改其他窗口样式(通用型)

9 篇文章 0 订阅

首先,这里是头文件(不确定要不要全部)

#include<Windows.h>
//#include <Windows.h>
#include <shellapi.h>
#include <iostream>
#include<string>
#include<istream>
#include <conio.h>
#include <shlobj.h>
#include <dwmapi.h>
#include <iomanip>
#include<atltypes.h>

以下是其他代码

using namespace std;
BOOL CALLBACK EnumChildProc(HWND hwndChild, LPARAM lParam)
{
	CRect rect1;
	GetClientRect(hwndChild, &rect1);
	HRGN rgn = CreateRoundRectRgn(1, 1, rect1.Width() , rect1.Height() , 10, 10);
	SetWindowRgn(hwndChild, rgn, TRUE);

	

	return TRUE;
}
int main()
{
	HWND console;
	printf("请输入窗口名:");
	
	string mingcheng;
	getline(cin, mingcheng);
	char ming[1000] = { 0 };
	strcpy(ming, mingcheng.c_str());
	console = ::FindWindowA(NULL, ming);
	int scrWidth, scrHeight;
	bool zidingyi;
	int x1, y1, x2, y2, width, height;
	cout << "是否进行自定义?(输入1表示自定义)";
	cin >> zidingyi;
	if (zidingyi == FALSE) {
		RECT rect;
		//获得屏幕尺寸
		scrWidth = GetSystemMetrics(SM_CXSCREEN);
		scrHeight = GetSystemMetrics(SM_CYSCREEN);
		//取得窗口尺寸
		GetWindowRect(console, &rect);
		//重新设置rect里的值
		rect.left = (scrWidth - rect.right) / 2;
		rect.top = (scrHeight - rect.bottom) / 2;
		SetWindowLong(console, GWL_STYLE, GetWindowLong(console, GWL_STYLE) & ~WS_CAPTION & ~WS_BORDER & ~WS_THICKFRAME & ~WS_EX_APPWINDOW & ~WS_OVERLAPPEDWINDOW & ~WS_OVERLAPPED | WS_CHILD);
		SetWindowLong(console, GWL_EXSTYLE,
			GetWindowLong(console, GWL_EXSTYLE) ^ 0x80000 | WS_EX_LAYERED | WS_CHILD);


		
		SetLayeredWindowAttributes(console, 0, 200, 2);
		

		CRect rect1;
		GetClientRect(console, &rect1);
		HRGN rgn = CreateRoundRectRgn(1, 1, rect1.Width() - 30, rect1.Height() - 30, 25, 25);
		SetWindowRgn(console, rgn, TRUE);
	}
	else{
		cout << endl << "输入6个数字,用空格间隔,分别表示矩形左上角的x和y坐标、右下角的x和y坐标、圆角的宽和高";
		CRect rect1;
		GetClientRect(console, &rect1);
		cout << "(窗口客户区宽为" << rect1.Width() << "高为" << rect1.Height()<<endl;
		cin >> x1 >> y1 >> x2 >> y2 >> width >> height;
		cout << endl << "输入透明度(值越小越透明):";
		int touming;
		cin >> touming;
		cout << endl << "是否对窗口进行样式更改?(包括去除边框、标题栏,且圆角计算也会包含非客户区 输入1则修改):";
		bool xiugao;
		cin >> xiugao;
		cout << endl << "是否同时对子窗口进行圆角处理?(1代表是)";
		bool child;
		cin >> child;
		RECT rect;
		//获得屏幕尺寸
		scrWidth = GetSystemMetrics(SM_CXSCREEN);
		scrHeight = GetSystemMetrics(SM_CYSCREEN);
		//取得窗口尺寸
		GetWindowRect(console, &rect);
		//重新设置rect里的值
		rect.left = (scrWidth - rect.right) / 2;
		rect.top = (scrHeight - rect.bottom) / 2;
		if (xiugao == TRUE) {
			SetWindowLong(console, GWL_STYLE, GetWindowLong(console, GWL_STYLE) & ~WS_CAPTION & ~WS_BORDER & ~WS_THICKFRAME & ~WS_EX_APPWINDOW & ~WS_OVERLAPPEDWINDOW & ~WS_OVERLAPPED);
		}
		SetWindowLong(console, GWL_EXSTYLE,
			GetWindowLong(console, GWL_EXSTYLE)  | WS_EX_LAYERED);


		
		SetLayeredWindowAttributes(console, 0, touming, 2);
		
		
		HRGN rgn = CreateRoundRectRgn(x1, y1, x2, y2, width, height);
		SetWindowRgn(console, rgn, TRUE);
		if (child == TRUE) {
			while (1) {
				EnumChildWindows(console, EnumChildProc, 0);
			}
		}
		
	}
	getch();
    return 0;
}

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

爱编程的叶一笑

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值