首先,这里是头文件(不确定要不要全部)
#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;
}