#include <windows.h>
// Prototipo de la función de ventana
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int nShowCmd) {
// Definir la clase de la ventana
const char CLASS_NAME[] = "MiVentanaPopup";
WNDCLASS wc = {};
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.lpszClassName = CLASS_NAME;
RegisterClass(&wc);
// Crear la ventana
HWND hwnd = CreateWindowEx(
0, // Estilo extendido
CLASS_NAME, // Nombre de la clase
"Ventana Popup", // TÃtulo de la ventana
WS_POPUP | WS_VISIBLE, // Estilo de la ventana
100, 100, // Posición x, y
400, 300, // Ancho, alto
NULL, // Ventana padre
NULL, // Menú
hInstance, // Instancia de la aplicación
NULL // Parámetros adicionales
);
if (hwnd == NULL) {
return 0;
}
// Mostrar la ventana
ShowWindow(hwnd, nShowCmd);
UpdateWindow(hwnd);
// Bucle de mensajes
MSG msg;
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
// Función de procesamiento de mensajes
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
switch (uMsg) {
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_PAINT: {
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
// Aquà puedes dibujar en la ventana
FillRect(hdc, &ps.rcPaint, (HBRUSH)(COLOR_GRAYTEXT + 1)); // Rellenar con gris
EndPaint(hwnd, &ps);
}
return 0;
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}