Ventanas en C

Juan
15 de Marzo del 2005
Hola, alguien sabe como hacer una ventana sensilla en C, me gustaria mucho que me mandaran un link que explique bien como hacerla, se los pido por favor... Muchas gracias!!!

Juan

Alejandro_
15 de Marzo del 2005
Es un poco arduo, pero la mayoría de los compiladores para Windows escriben la parte gruesa del soporte por ti. Una ventana "Hola Mundo!" puede ser:

#include <windows.h>

/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

void MuestraTexto(HWND, HDC);

/* Make the class name into a global variable */
char szClassName[ ] = "WindowsApp";

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 (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
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 Windows's default color as the background of the window */
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

/* Register the window class, and if it fails 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 */
"Texto de título", /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
544, /* The programs width */
375, /* 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 */
);



ShowWindow (hwnd, nFunsterStil);


while (GetMessage (&messages, NULL, 0, 0))
{

TranslateMessage(&messages);

DispatchMessage(&messages);
}


return messages.wParam;
}



LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps ;
HDC hdc ;


switch (message)
{
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;
MuestraTexto(hwnd, ps.hdc);
EndPaint (hwnd, &ps) ;
return 0 ;
case WM_DESTROY:
PostQuitMessage (0);
break;
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}

return 0;
}


//-----------------------------------------

void MuestraTexto(HWND hwnd, HDC hdc)
{
RECT r;

GetClientRect(hwnd, &r);

TextOut(hdc, r.left+50, r.top+100, "Hola Mundo!", 11);
}
//-----------------------------------------

Este es un programa que supongo podrás compilar sin dificultad. Notarás que hay unas cuantas cosas para leer antes de decir que uno tiene muy en claro cómo hacer una ventanita en Windows... En un mensaje anterior, Mariano Ventaja había puesto la dirección del sitio que mantiene, donde había algunos tutoriales o libros muy útiles para empezar (http://c0d3rz.com.ar) Creo que allí se podía ver el Programming Windows (muy recomendable).

Alejandro

noel solw
15 de Marzo del 2005
Me parece que tu pregunta se refiere a una ventana en dos.
Adjunto un programa que puede ayudarte.

// written in borland c++, ver 3.1
// creo que correra tambien en turbo c

#include <conio.h>
#include <dos.h>

void main()
{
textbackground(RED);
clrscr();
int x1 = 10,y1 = 10,x2 = 50,y2 = 20,d = 1;
window(x1+d,y1-d,x2+d,y2-d);
textbackground(LIGHTGRAY);
clrscr();
window(x1,y1,x2,y2);
textbackground(BLUE);
clrscr();
for(int i = 0;i < 100;i++)
{
textcolor(i % 7 + 2);
delay(200);
cprintf("window ");
}
window(0,0,80,24);
textbackground(BLACK);
textcolor(WHITE);
getch();
clrscr();
}