Programaci¢n en Windows (I) Entorno de programaci¢n Windows (Win32) Orientado a eventos Orientado a objetos API ampliable mediante los distintos SDK's existentes (SAPI, MAPI, SMAPI, TAPI, etc...) Tipos de aplicaciones en Windows 95/NT Consola GUI Aplicaciones en consola M‚todo de programaci¢n orientado a funciones Funciones "callback" Aplicaciones GUI Bucle de mensajes Procedimiento de ventana M‚todo de programaci¢n orientado a eventos Funciones "callback" y mensajes El procedimiento de ventana Toda clase de ventana tiene asociado uno. Tipos de eventos gestionados:  Ventana  Entrada de datos  Sistema  Controles  etc... C++ Builder Incorpora procedimientos de ventana est ndar para cada clase de ventana. Sigue el paradigma de OOP: propiedades, m‚todos y eventos. Soporta herencia m£ltiple y sobrecarga de operadores. Permite, donde se considere necesario, el uso de llamadas al API est ndar de Windows, incluso el uso de ensamblador "inline". Win Mandel (versi¢n en C usando el API Win32) #include #define APPNAME "WINMANDEL" #define TITULO "WinMandel" #define MINY -1.2 #define MAXY 1.2 #define MINX -2.4 #define MAXX 0.8 HINSTANCE hInstApp; HWND hWndApp; long WINAPI WndProc (HWND, UINT, WPARAM, LPARAM); int PASCAL WinMain (HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpszcmdline, int ncmdshow) { static char szappname[]=APPNAME; HDC hdc; HWND hwnd; MSG msg; TEXTMETRIC tm; WNDCLASS wndclass; hInstApp=hinstance; if (!hprevinstance) { wndclass.style=CS_HREDRAW | CS_VREDRAW | CS_BYTEALIGNWINDOW | CS_BYTEALIGNCLIENT; wndclass.lpfnWndProc= (WNDPROC) WndProc; wndclass.cbClsExtra=0; wndclass.cbWndExtra=0; wndclass.hInstance=hinstance; wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION); wndclass.hCursor=LoadCursor(NULL,IDC_ARROW); wndclass.hbrBackground=GetStockObject(WHITE_BRUSH); wndclass.lpszMenuName=NULL; wndclass.lpszClassName=szappname; RegisterClass(&wndclass); } hwnd=hWndApp=CreateWindow(szappname,TITULO,WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT, HWND_DESKTOP,NULL,hinstance,NULL); ShowWindow(hwnd,SW_SHOWNORMAL); UpdateWindow(hwnd); while (GetMessage(&msg,NULL,0,0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } int EsConvergente (float cr, float ci, int maximo) { float zr=0.0; float zi=0.0; float nzr; float nzi; int i=0; while (i #pragma hdrstop #include "eventos.h" #define MINX -2.4 #define MAXX 0.8 #define MINY -1.2 #define MAXY 1.2 void DibujarFractal (TImage *Imagen, int anchura, int altura); int EsConvergente (float real, float img, int maximo); //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TProg *Prog; //--------------------------------------------------------------------------- __fastcall TProg::TProg(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void DibujarFractal (TImage *Imagen, int anchura, int altura) { int x,y; float cr,ci; int color; HDC hdc; hdc=Imagen->Canvas->Handle; for (y=0;yRefresh(); } } int EsConvergente (float cr, float ci, int maximo) { float zr=0.0; float zi=0.0; float nzr; float nzi; int i=0; while (iHeight=Prog->ClientHeight; Imagen->Width=Prog->ClientWidth; } //--------------------------------------------------------------------------- void __fastcall TProg::ImagenClick(TObject *Sender) { DibujarFractal (Imagen, Imagen->Width, Imagen->Height); } //---------------------------------------------------------------------------