Ver Mensaje Individual
  #1 (permalink)  
Antiguo 23/05/2008, 18:17
Tikitios
 
Fecha de Ingreso: mayo-2008
Ubicación: Chile
Mensajes: 189
Antigüedad: 15 años, 11 meses
Puntos: 3
El juego de adivinar el numero

aqui esta el codigo:
Código PHP:
#include <windows.h>
#include <ctime>
#include <cstdlib>
#include "Define.h"

/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure(HWNDUINTWPARAMLPARAM);
/* Make the class name into a global variable */
char szClassName[ ] = "MiAleatorio";
HINSTANCE hInst;
HWND hwndAceptarhwndCerrarhwndAleatoriohwndNumero;
HWND hwndTexto1hwndTexto2hwndNuevohwndAcercahwndFrame;
unsigned int ebcnt 0opcac;
char num_e[3];
char num_i[3];
int WINAPI WinMain(HINSTANCE hThisInstanceHINSTANCE hPrevInstanceLPSTR lpszArgumentint 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(hThisInstanceMAKEINTRESOURCE(MICONO));
    
wincl.hIconSm LoadIcon(hThisInstanceMAKEINTRESOURCE(MICONO));
    
wincl.hCursor LoadCursor(NULLIDC_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 = (HBRUSHGetStockObject(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(hwndnFunsterStil);
    
/* Run the message loop. It will run until GetMessage( ) returns 0 */
    
while(GetMessage(&messagesNULL00))
    {
           
/* 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 hwndUINT messageWPARAM wParamLPARAM lParam)
{
    switch (
message)                  /* handle the messages */
    
{
           case 
WM_CREATE:
                
srand(time(0));
                
rand()%100;
                
e;
                
itoa(enum_e10);
                
hwndFrame CreateWindow("button""Opciones"WS_CHILD|WS_VISIBLE|BS_GROUPBOX,
                                          
2307190100hwnd, (HMENU)FR_FRAMEhInstNULL);
                
hwndTexto1 CreateWindow("static""Aquí tengo un número"WS_CHILD|WS_VISIBLE|SS_LEFT,
                                          
203015020hwndNULLhInstNULL);
                
hwndAleatorio CreateWindow("edit"""WS_CHILD|WS_VISIBLE|ES_PASSWORD|ES_NUMBER|WS_BORDER,
                                          
180302520hwnd, (HMENU)ED_ALEATORIOhInstNULL);
                
hwndTexto2 CreateWindow("static""Qué número tengo?"WS_CHILD|WS_VISIBLE|SS_LEFT,
                                          
206013020hwndNULLhInstNULL);
                
hwndNumero CreateWindow("edit"""WS_CHILD|WS_VISIBLE|ES_NUMBER|WS_BORDER,
                                          
180602520hwnd, (HMENU)ED_NUMEROhInstNULL);
                
hwndAceptar CreateWindow("button""Entrar"WS_CHILD|WS_VISIBLE|BS_CENTER,
                                           
240308030hwnd, (HMENU)BT_ACEPTARhInstNULL);
                
hwndNuevo CreateWindow("button""Nuevo"WS_CHILD|WS_VISIBLE|BS_CENTER,
                                           
330308030hwnd, (HMENU)BT_NUEVOhInstNULL);
                
hwndCerrar CreateWindow("button""Cerrar"WS_CHILD|WS_VISIBLE|BS_CENTER,
                                           
240708030hwnd, (HMENU)BT_CERRARhInstNULL);
                
hwndAcerca CreateWindow("button""Créditos"WS_CHILD|WS_VISIBLE|BS_CENTER,
                                           
330708030hwnd, (HMENU)BT_ACERCAhInstNULL);
                
SetWindowText(hwndAleatorionum_e);
           break;
           case 
WM_COMMAND:
                switch(
LOWORD(wParam)){
                       case 
BT_ACEPTAR:
                            
cnt++;
                            
GetWindowText(hwndNumeronum_i3);
                            
atoi(num_i);
                            if(
cnt != 7){
                               if(
!= a){
                                 if(
a)
                                    
MessageBox (NULL"El numero que pienso es mayor" "Fallaste!"MB_ICONASTERISK);
                                 else
                                    
MessageBox (NULL"El numero que pienso es menor" "Fallaste!"MB_ICONASTERISK);
                               }
                               else{
                                    
MessageBox (NULL"Adivinaste el número" "Lo lograste"MB_ICONASTERISK MB_SYSTEMMODAL);
                                    
cnt 0;
                                    
srand(time(0));
                                    
rand()%100;
                                    
e;
                                    
itoa(enum_e10);
                                    
SetWindowText(hwndAleatorionum_e);
                                    
SetWindowText(hwndNumero"");
                               }
                            }
                            else{
                               
opc MessageBox (hwnd"Se acabaron las 7 oportunidades\n"
                                                       " ¿Deseas seguir jugando?" 
"Lo siento"MB_YESNO MB_ICONQUESTION MB_SYSTEMMODAL);
                                   switch(
opc){
                                       case 
IDYES:
                                          
cnt 0;
                                          
srand(time(0));
                                          
rand()%100;
                                          
e;
                                          
itoa(enum_e10);
                                          
SetWindowText(hwndAleatorionum_e);
                                          
SetWindowText(hwndNumero"");
                                       break;
                                       case 
IDNO:
                                          
SendMessage(hwndWM_DESTROYwParamlParam);
                                       break;
                                   }
                               }
                       break;
                       case 
BT_NUEVO:
                            
srand(time(0));
                            
rand()%100;
                            
e;
                            
itoa(enum_e10);
                            
SetWindowText(hwndAleatorionum_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"MB_ICONASTERISK);
                       break;
                       case 
BT_CERRAR:
                            
SendMessage(hwndWM_DESTROYwParamlParam);
                       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(hwndmessagewParamlParam);
    }
    return 
0;

Ojala que les guste, los creditos no los pongo, es una mezcla entre mio y uno que encontre en la web(no me acuerdo de donde).