#include <windows.h>
#include <cmath>
#define PI 3.14159265
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
switch (uMsg) {
case WM_PAINT: {
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
// Datos de porcentajes
double percentages[] = { 25.0, 35.0, 20.0, 20.0 }; // Porcentajes
int numSegments = sizeof(percentages) / sizeof(percentages[0]);
int radius = 100; // Radio del círculo
int centerX = 200; // Centro del círculo
int centerY = 200;
// Variables para el ángulo
double startAngle = 0.0;
// Dibujar cada segmento
for (int i = 0; i < numSegments; i++) {
double angle = percentages[i] * 360.0 / 100.0; // Convertir porcentaje a ángulo
double endAngle = startAngle + angle;
// Calcular las coordenadas del arco
POINT startPoint = {
static_cast<LONG>(centerX + radius * cos(startAngle * PI / 180)),
static_cast<LONG>(centerY - radius * sin(startAngle * PI / 180))
};
POINT endPoint = {
static_cast<LONG>(centerX + radius * cos(endAngle * PI / 180)),
static_cast<LONG>(centerY - radius * sin(endAngle * PI / 180))
};
// Dibujar el arco
Arc(hdc, centerX - radius, centerY - radius, centerX + radius, centerY + radius,
endPoint.x, endPoint.y, startPoint.x,startPoint.y);
// Actualizar el ángulo de inicio
startAngle += angle;
}
EndPaint(hwnd, &ps);
} break;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int nShowCmd) {
const char CLASS_NAME[] = "MiClaseVentana";
WNDCLASS wc = {};
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.lpszClassName = CLASS_NAME;
RegisterClass(&wc);
HWND hwnd = CreateWindowEx(0, CLASS_NAME, "Círculo de porcentajes", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 400, 400,
NULL, NULL, hInstance, NULL);
ShowWindow(hwnd, nShowCmd);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}