- Código: Seleccionar todo
// ProyectoF.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "stdlib.h"
#include "string.h"
#include "stdio.h"
#include "ProyectoF.h"
#define MAX_LOADSTRING 100
#define BAJA -1
///////////////////// Variables Globales :
struct registro{
char nombre [40];
char apellidos [30];
char calle [30];
char colonia[20];
char ciudad[40];
char estado [15];
char cp [6];
}reg;
char cadena [15];
void escribe_reg(registro reg, FILE *fp);
registro *lee_reg(FILE *globfp);
void muestra_reg(registro reg);
FILE *arch;
registro *agenda;
registro ax;
registro direccion;
int i;
void Accion_Buscar(char *cadena, FILE *arch);
int BuscaEn(char *buscada, char *cadena);
HDC manejador;
char *dato;
int opcion = 0;
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
// Forward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK Agregar(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK Buscar(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK ResultadoB(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
// TODO: Place code here.
MSG msg;
HACCEL hAccelTable;
// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_PROYECTOF, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_PROYECTOF));
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int) msg.wParam;
}
//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
// COMMENTS:
//
// This function and its usage are only necessary if you want this code
// to be compatible with Win32 systems prior to the 'RegisterClassEx'
// function that was added to Windows 95. It is important to call this function
// so that the application will get 'well formed' small icons associated
// with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_PROYECTOF));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = MAKEINTRESOURCE(IDC_PROYECTOF);
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
return RegisterClassEx(&wcex);
}
//
// FUNCTION: InitInstance(HINSTANCE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
hInst = hInstance; // Store instance handle in our global variable
hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if (!hWnd)
{
return FALSE;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
//
// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
arch=fopen("datos.dat","r+b");
if(arch==NULL)
{
arch=fopen("datos.dat","w+b");
}
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDD_AGREGAR:
DialogBox(hInst, (LPCTSTR) IDD_AGREGAR, hWnd, (DLGPROC) Agregar);
InvalidateRect(hWnd, NULL, TRUE);
UpdateWindow(hWnd);
break;
case ID_FILE_BUSCARTRABAJADOR:
DialogBox(hInst, (LPCTSTR) IDD_BUSQUEDA, hWnd, (DLGPROC) Buscar);
InvalidateRect(hWnd, NULL, TRUE);
UpdateWindow(hWnd);
opcion=10;
break;
case IDM_ABOUT:
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
break;
case IDM_EXIT:
MessageBox(hWnd,"Gracias por utilizar el sistema", NULL, MB_ICONEXCLAMATION|MB_OK);
DestroyWindow(hWnd);
break;
default:
dato = 0;
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
manejador = hdc;
switch(opcion){
case 10:
TextOutA(hdc, 60, 60, dato, strlen(dato));
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
// ---------------------------MANEJADOR DE MENSAJE PARA LA CAJA ACERCA DE ...
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
return (INT_PTR)TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
break;
}
return (INT_PTR)FALSE;
}
// ********************* FUNCION PARA AGREGAR TRABAJADORES *****************
LRESULT CALLBACK Agregar(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message){
case WM_INITDIALOG:
return false;
case WM_COMMAND:
switch(wParam)
{
case IDOK:
GetDlgItemTextA(hDlg, IDC_EDIT1, reg.nombre, 40);
GetDlgItemTextA(hDlg, IDC_EDIT2, reg.apellidos, 30);
GetDlgItemTextA(hDlg, IDC_EDIT3, reg.calle, 30);
GetDlgItemTextA(hDlg, IDC_EDIT4, reg.colonia, 20);
GetDlgItemTextA(hDlg, IDC_EDIT5, reg.ciudad, 40);
GetDlgItemTextA(hDlg, IDC_EDIT6, reg.estado, 15);
GetDlgItemTextA(hDlg, IDC_EDIT7, reg.cp, 6);
EndDialog(hDlg, TRUE);
escribe_registro(reg, arch);
break;
case IDCANCEL:
EndDialog(hDlg, TRUE);
break;
default:
return FALSE;
}
break;
default:
return FALSE;
}
return TRUE;
}
//****************** FIN DE LA FUNCION PARA AGREGAR TRABAJADORES******
// ****************************** FUNCION PARA BUSCAR TRABAJADORES ********
LRESULT CALLBACK Buscar(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message){
case WM_INITDIALOG:
return false;
case WM_COMMAND:
switch(wParam)
{
case IDOKNOMBRE:
GetDlgItemTextA(hDlg, IDC_EDIT1, cadena, 15);
dato=Accion_Buscar(cadena,arch);
break;
case IDOKAPELLIDO:
GetDlgItemTextA(hDlg, IDC_EDIT2, cadena, 15);
Accion_Buscar(cadena,arch);
break;
case IDCANCEL:
EndDialog(hDlg, TRUE);
break;
default:
return FALSE;
}
break;
default:
return FALSE;
}
return TRUE;
}
// ****************** FIN DE LA FUNCION PARA BUSCAR TRABAJADORES *********
void escribe_reg(registro reg, FILE *fp)
{
fwrite(®, sizeof(reg),1,fp);
}
registro *lee_reg(FILE *fp)
{
registro tmp;
fread(&tmp, sizeof(tmp),1,fp);
return &tmp;
}
void muestra_reg(registro reg)
{
printf("\n%s",reg.nombre);
printf("\n%s",reg.calle);
printf("\n%s",reg.ciudad);
printf("\n%s",reg.estado);
printf("\n%s",reg.cp);
}
// *********/////////////***********----------- DECLARACION DE FUNCIONES PARA LA BUSQUEDA
void Accion_Buscar(char *cadena, FILE *arch)
{
registro reg;
int regreso;
do{
fread(®, sizeof(reg), 1, arch);
regreso = BuscaEn(cadena, reg.nombre);
if(regreso==1) break;
if(feof(arch)) break;
}while (regreso != 1);
if (regreso == 1)
return reg.nombre;
else
return 0;
}
int BuscaEn(char *buscada, char *cadena)
{
int i;
int j=0;
int bandera = 100;
for (i=0; i<=strlen(cadena); i++)
{
if(cadena[i]==buscada[0])
for(j=0; j<strlen(buscada); j++)
{
if(buscada[j] == cadena[i+j])
bandera = true;
else bandera = false;
}
if((j == strlen(buscada)) && (bandera == 1))
return bandera;
}
return bandera;
}
// *************-------------------- FUNCION PARA IMPRIMIR LOS RESULTADOS DE BUSQUEDA EN UNA DIALOG BOX
LRESULT CALLBACK ResultadoB(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message){
case WM_INITDIALOG:
return false;
case WM_COMMAND:
switch(wParam)
{
case IDOKNOMBRE:
GetDlgItemTextA(hDlg, IDC_EDIT1, cadena, 15);
Accion_Buscar(cadena,arch);
break;
case IDOKAPELLIDO:
GetDlgItemTextA(hDlg, IDC_EDIT2, cadena, 15);
EndDialog(hDlg, TRUE);
break;
case IDCANCEL:
EndDialog(hDlg, TRUE);
break;
default:
return FALSE;
}
break;
default:
return FALSE;
}
return TRUE;
}





