正常打开程序是矩形的窗口。
但是多次重复打开程序有机率变成老古懂的方形窗口求解。
#define WINVER 0x0A00
#define _WIN32_WINNT 0x0A00
#include <graphics.h> // 绘图库头文件
#include <conio.h> // 基本头文件
#include<algorithm> // 针对设置该进程不受系统 DPI 设置影响 的头文件
#include <ShellScalingApi.h> // 引用头文件
#pragma comment(lib, "Shcore.lib") // 链接库文件
void lnitial_drawing()
{
A:
// 设置该进程不受系统 DPI 设置影响
SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE);
system("mode con cols=27 lines=18 && color 8f");
initgraph(230, 290, NOMINIMIZE | EX_SHOWCONSOLE);
HWND hWnd = GetHWnd();
// 获取窗口边框宽高
RECT rcClient, rcWind;
GetClientRect(hWnd, &rcClient);
GetWindowRect(hWnd, &rcWind);
int cx1 = ((rcWind.right - rcWind.left) - rcClient.right) / 2;
int cy1 = ((rcWind.bottom - rcWind.top + GetSystemMetrics(SM_CYCAPTION)) - rcClient.bottom) / 2;
HRGN rgn = CreateRoundRectRgn(1 + cx1, 0 + cy1, 215 + cx1, 290 + cy1, 20, 20);
if (SetWindowRgn(hWnd, rgn, true)==0){ goto A; }
SetWindowPos(hWnd, HWND_TOPMOST, // 置顶
(GetSystemMetrics(SM_CXFULLSCREEN) - 230) / 2,
(GetSystemMetrics(SM_CYFULLSCREEN) - 340) / 2, // 坐标
232, 340, // 宽高
SWP_SHOWWINDOW); // 方式
setbkcolor(RGB(62, 69, 89));
setbkmode(TRANSPARENT);
cleardevice();
settextcolor(RGB(0, 132, 132));
outtextxy(10, 10+35, L"1.重复打开这个程序");
outtextxy(10, 30+35, L"2.窗口初始样式为矩形");
outtextxy(10, 50+35, L"3.但会有机率把矩形边框");
outtextxy(10, 70+35, L"4.变成复古XP的样式");
outtextxy(10, 90+35, L"5.原因不明所以");
outtextxy(10, 110 + 35, L"6.隶属于颜色诱捕子程序");
outtextxy(10, 130 + 35, L"7.有趣的是当软件打开");
outtextxy(10, 150 + 35, L"8.为矩形窗口时");
outtextxy(10, 170 + 35, L"8.用截图软件会自动把这");
outtextxy(10, 190 + 35, L"8.复古窗口范围为标出来");
}
void inigra()
{
int x1 = 0, y1 = 0, x2 = 216, y2 = 30;
setfillcolor(RGB(51, 51, 51));
setlinecolor(RGB(166, 166, 166));
solidrectangle(x1, y1 - 5, x2, y2);
line(x1+2, y2 , x2-4, y2 );
settextcolor(RGB(206, 238, 255));
outtextxy(10, 10, L"矩形窗口标题栏");
setlinecolor(RGB(206, 238, 255));
circle(200,15,10);
circle(200, 15, 9);
line(200, 15,200+7 , 15-7);
line(200, 15 , 200+7, 15+7);
line(200, 15, 200-7,15+7 );
line(200, 15, 200-7,15-7 );
rectangle(165+2,5+2,185-2,25-2);
rectangle(165 + 2-1, 5 + 2-1, 185 - 2+1, 25 - 2+1);
rectangle(140-1, 12-1, 160+1, 18+1);
rectangle(140, 12, 160, 18);
}
int main()
{
lnitial_drawing();
inigra();
BOOL ZEOR = true;
HWND h1;
h1 = GetHWnd();
while (ZEOR)
{
POINT pt11;
GetCursorPos(&pt11);
ScreenToClient(h1, &pt11);
while ((GetAsyncKeyState(VK_LBUTTON)) && ZEOR)
{
if ((pt11.x > 140 && pt11.y > 5 && pt11.x < 207 && pt11.y < 25))
{
ZEOR = false; // rectangle(140,5,210,25);
}
if ((pt11.x > 0 && pt11.y > 0 && pt11.x < 140 && pt11.y < 30))
{
while ((GetAsyncKeyState(VK_LBUTTON)))
{
RECT rcClient, rcWind;
GetClientRect(h1, &rcClient);
GetWindowRect(h1, &rcWind);
int cx = ((rcWind.right - rcWind.left) - rcClient.right) / 2;
int cy = ((rcWind.bottom - rcWind.top + GetSystemMetrics(SM_CYCAPTION)) - rcClient.bottom) / 2;
POINT pt2;
GetCursorPos(&pt2);
HDC hDC0 = GetDC(NULL);
MoveWindow(h1, pt2.x - pt11.x - cx, pt2.y - pt11.y - cy, 245, 340, true);
}
}
}
}
closegraph();
return 0;
}
经过时间探索改良版或者叫修复版,大量的减少重复打开程序有机率变成老古懂的方形窗口的机率
#define WINVER 0x0A00
#define _WIN32_WINNT 0x0A00
// 修复改良版
#include <graphics.h> // 绘图库头文件
#include <conio.h> // 基本头文件
#include<algorithm> // 针对设置该进程不受系统 DPI 设置影响 的头文件
#include <ShellScalingApi.h> // 引用头文件
#pragma comment(lib, "Shcore.lib") // 链接库文件
void lnitial_drawing()
{
// 设置该进程不受系统 DPI 设置影响
SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE);
system("mode con cols=27 lines=18 && color 8f");
initgraph(230, 290, NOMINIMIZE | EX_SHOWCONSOLE);
HWND hWnd = GetHWnd();
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);
HRGN rgn = CreateRoundRectRgn(0, 0, 230, 290, 20, 20);
SetWindowRgn(hWnd, rgn, true);
setbkcolor(RGB(246, 209, 195));
setbkmode(TRANSPARENT);
cleardevice();
settextcolor(RGB(0, 132, 132));
outtextxy(10, 10 + 35, L"1.重复打开这个程序");
outtextxy(10, 30 + 35, L"2.窗口初始样式为矩形");
outtextxy(10, 50 + 35, L"3.但会有机率把矩形边框");
outtextxy(10, 70 + 35, L"4.变成复古XP的样式");
outtextxy(10, 90 + 35, L"5.原因不明所以");
outtextxy(10, 110 + 35, L"6.隶属于颜色诱捕子程序");
outtextxy(10, 130 + 35, L"7.有趣的是当软件打开");
outtextxy(10, 150 + 35, L"8.为矩形窗口时");
outtextxy(10, 170 + 35, L"8.用截图软件会自动把这");
outtextxy(10, 190 + 35, L"8.复古窗口范围为标出来");
outtextxy(10, 210 + 35, L"9.以上问题均以修复");
}
void inigra()
{
int x1 = 0, y1 = 0, x2 = 228, y2 = 30;
setfillcolor(RGB(212, 95, 102));
setlinecolor(RGB(131, 43, 50));
solidrectangle(x1, y1 - 5, x2, y2);
line(x1, y2, x2, y2);
settextcolor(RGB(0, 0, 0));
outtextxy(10, 10, L"修复版矩形窗口");
setlinecolor(RGB(211, 211, 211));
setfillcolor(RGB(197, 85, 89));
fillcircle(200 + 10, 15, 10);
fillcircle(200 + 10, 15, 10);
setfillcolor(RGB(183, 183, 183));
fillcircle(175 + 10, 15, 10);
fillcircle(175 + 10, 15,10);
setfillcolor(RGB(155, 203, 155));
fillcircle(150 + 10, 15, 10);
fillcircle(150 + 10, 15, 10);
}
int main()
{
lnitial_drawing();
inigra();
BOOL ZEOR = true;
HWND h1;
h1 = GetHWnd();
while (ZEOR)
{
POINT pt11;
GetCursorPos(&pt11);
ScreenToClient(h1, &pt11);
while ((GetAsyncKeyState(VK_LBUTTON)) && ZEOR)
{
if ((pt11.x > 150 && pt11.y > 5 && pt11.x < 220 && pt11.y < 25))
{
ZEOR = false; // rectangle(140,5,210,25);
}
if ((pt11.x > 0 && pt11.y > 0 && pt11.x < 140 && pt11.y < 30))
{
BeginBatchDraw();
while ((GetAsyncKeyState(VK_LBUTTON)))
{
inigra();
POINT pt2;
GetCursorPos(&pt2);
HDC hDC0 = GetDC(NULL);
MoveWindow(h1, pt2.x - pt11.x, pt2.y - pt11.y, 245, 340, true);
FlushBatchDraw();
}
}
}
}
EndBatchDraw();
closegraph();
return 0;
}