Código PHP:
#include <windows.h>
#include <ctime>
#include <cstdlib>
#include "Define.h"
/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM);
/* Make the class name into a global variable */
char szClassName[ ] = "MiAleatorio";
HINSTANCE hInst;
HWND hwndAceptar, hwndCerrar, hwndAleatorio, hwndNumero;
HWND hwndTexto1, hwndTexto2, hwndNuevo, hwndAcerca, hwndFrame;
unsigned int e, b, cnt = 0, opc, a, c;
char num_e[3];
char num_i[3];
int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)
{
HWND hwnd; /* This is the handle for our window */
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */
/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof(WNDCLASSEX);
/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon(hThisInstance, MAKEINTRESOURCE(MICONO));
wincl.hIconSm = LoadIcon(hThisInstance, MAKEINTRESOURCE(MICONO));
wincl.hCursor = LoadCursor(NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
/* Use light-gray as the background of the window */
wincl.hbrBackground = (HBRUSH) GetStockObject(LTGRAY_BRUSH);
hInst = hThisInstance;
/* Register the window class, if fail quit the program */
if(!RegisterClassEx(&wincl)) return 0;
/* The class is registered, let's create the program*/
hwnd = CreateWindowEx(
0, /* Extended possibilites for variation */
szClassName, /* Classname */
"Juego del número aleatorio, solo del 0 al 99", /* Title Text */
WS_SYSMENU|WS_MINIMIZEBOX, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
450, /* The programs width */
150, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);
/* Make the window visible on the screen */
ShowWindow(hwnd, nFunsterStil);
/* Run the message loop. It will run until GetMessage( ) returns 0 */
while(GetMessage(&messages, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}
/* The program return-value is 0 - The value that PostQuitMessage( ) gave */
return messages.wParam;
}
/* This function is called by the Windows function DispatchMessage( ) */
LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) /* handle the messages */
{
case WM_CREATE:
srand(time(0));
e = 0 + rand()%100;
b = e;
itoa(e, num_e, 10);
hwndFrame = CreateWindow("button", "Opciones", WS_CHILD|WS_VISIBLE|BS_GROUPBOX,
230, 7, 190, 100, hwnd, (HMENU)FR_FRAME, hInst, NULL);
hwndTexto1 = CreateWindow("static", "Aquí tengo un número", WS_CHILD|WS_VISIBLE|SS_LEFT,
20, 30, 150, 20, hwnd, NULL, hInst, NULL);
hwndAleatorio = CreateWindow("edit", "", WS_CHILD|WS_VISIBLE|ES_PASSWORD|ES_NUMBER|WS_BORDER,
180, 30, 25, 20, hwnd, (HMENU)ED_ALEATORIO, hInst, NULL);
hwndTexto2 = CreateWindow("static", "Qué número tengo?", WS_CHILD|WS_VISIBLE|SS_LEFT,
20, 60, 130, 20, hwnd, NULL, hInst, NULL);
hwndNumero = CreateWindow("edit", "", WS_CHILD|WS_VISIBLE|ES_NUMBER|WS_BORDER,
180, 60, 25, 20, hwnd, (HMENU)ED_NUMERO, hInst, NULL);
hwndAceptar = CreateWindow("button", "Entrar", WS_CHILD|WS_VISIBLE|BS_CENTER,
240, 30, 80, 30, hwnd, (HMENU)BT_ACEPTAR, hInst, NULL);
hwndNuevo = CreateWindow("button", "Nuevo", WS_CHILD|WS_VISIBLE|BS_CENTER,
330, 30, 80, 30, hwnd, (HMENU)BT_NUEVO, hInst, NULL);
hwndCerrar = CreateWindow("button", "Cerrar", WS_CHILD|WS_VISIBLE|BS_CENTER,
240, 70, 80, 30, hwnd, (HMENU)BT_CERRAR, hInst, NULL);
hwndAcerca = CreateWindow("button", "Créditos", WS_CHILD|WS_VISIBLE|BS_CENTER,
330, 70, 80, 30, hwnd, (HMENU)BT_ACERCA, hInst, NULL);
SetWindowText(hwndAleatorio, num_e);
break;
case WM_COMMAND:
switch(LOWORD(wParam)){
case BT_ACEPTAR:
cnt++;
GetWindowText(hwndNumero, num_i, 3);
a = atoi(num_i);
if(cnt != 7){
if(b != a){
if(b > a)
MessageBox (NULL, "El numero que pienso es mayor" , "Fallaste!", 0 + MB_ICONASTERISK);
else
MessageBox (NULL, "El numero que pienso es menor" , "Fallaste!", 0 + MB_ICONASTERISK);
}
else{
MessageBox (NULL, "Adivinaste el número" , "Lo lograste", 0 + MB_ICONASTERISK + MB_SYSTEMMODAL);
b = a = cnt = 0;
srand(time(0));
e = 0 + rand()%100;
b = e;
itoa(e, num_e, 10);
SetWindowText(hwndAleatorio, num_e);
SetWindowText(hwndNumero, "");
}
}
else{
opc = MessageBox (hwnd, "Se acabaron las 7 oportunidades\n"
" ¿Deseas seguir jugando?" , "Lo siento", 0 + MB_YESNO + MB_ICONQUESTION + MB_SYSTEMMODAL);
switch(opc){
case IDYES:
cnt = 0;
srand(time(0));
e = 0 + rand()%100;
b = e;
itoa(e, num_e, 10);
SetWindowText(hwndAleatorio, num_e);
SetWindowText(hwndNumero, "");
break;
case IDNO:
SendMessage(hwnd, WM_DESTROY, wParam, lParam);
break;
}
}
break;
case BT_NUEVO:
srand(time(0));
e = 0 + rand()%100;
b = e;
itoa(e, num_e, 10);
SetWindowText(hwndAleatorio, num_e);
SetWindowText(hwndNumero, "");
break;
case BT_ACERCA:
MessageBox (NULL, "Juego de adivinar un número aleatorio\nHecho por:\nCarlos Rojas\n0.o\nxD\nNo se que mas poner " , "Créditos", 0 + MB_ICONASTERISK);
break;
case BT_CERRAR:
SendMessage(hwnd, WM_DESTROY, wParam, lParam);
break;
}
break;
case WM_DESTROY:
PostQuitMessage(0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}