#include <windows.h>
#include <time.h>
#include <math.h>
#include <string.h>
#include <stdio.h>
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
char szClassName[ ] = "WindowsApp";
HWND hwnd;
HWND hbutton1;
HWND hEditA1;
HWND hbutton2;
HWND hEditA2;
HWND hbutton3;
char filename_1[1000];
char filename_2[1000];
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)
{
MSG messages;
WNDCLASSEX wincl;
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure;
wincl.style = CS_DBLCLKS;
wincl.cbSize = sizeof (WNDCLASSEX);
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
if (!RegisterClassEx (&wincl))
return 0;
hwnd = CreateWindowEx (
0,
szClassName,
"files",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
700,
700,
HWND_DESKTOP,
NULL,
hThisInstance,
NULL
);
HWND hbutton1 = CreateWindow(TEXT("button"),
TEXT("Открыть файл"),
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON ,
0, 0, 150, 25,
hwnd, (HMENU)10000, hThisInstance, NULL);
hEditA1=CreateWindow(TEXT("Edit"),
TEXT(""),
WS_CHILD | WS_VISIBLE | WS_BORDER,
150, 0, 500, 25,
hwnd, NULL, NULL, NULL);
HWND hbutton2 = CreateWindow(TEXT("button"),
TEXT("Открыть файл"),
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON ,
0, 100, 150, 25,
hwnd, (HMENU)10001, hThisInstance, NULL);
hEditA2=CreateWindow(TEXT("Edit"),
TEXT(""),
WS_CHILD | WS_VISIBLE | WS_BORDER,
150, 100, 500, 25,
hwnd, NULL, NULL, NULL);
HWND hbutton3 = CreateWindow(TEXT("button"),
TEXT("Сравнить файлы"),
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON ,
0, 200, 150, 25,
hwnd, (HMENU)10002, hThisInstance, NULL);
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)
{
switch (message)
{
case WM_COMMAND:
{
if (LOWORD(wParam)==10000)
{
char filename[ MAX_PATH ];
OPENFILENAME ofn;
ZeroMemory( &filename, sizeof( filename ) );
ZeroMemory( &ofn, sizeof( ofn ) );
ofn.lStructSize = sizeof( ofn );
ofn.hwndOwner = NULL;
ofn.lpstrFilter = "Any File\0*.*\0";
ofn.lpstrFile = filename;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrTitle = "Выбери файл";
ofn.Flags = OFN_DONTADDTORECENT | OFN_FILEMUSTEXIST;
GetOpenFileNameA( &ofn );
SetWindowText(hEditA1,filename);
strcpy(filename_1,filename);
}
if (LOWORD(wParam)==10001)
{
char filename[ MAX_PATH ];
OPENFILENAME ofn;
ZeroMemory( &filename, sizeof( filename ) );
ZeroMemory( &ofn, sizeof( ofn ) );
ofn.lStructSize = sizeof( ofn );
ofn.hwndOwner = NULL;
ofn.lpstrFilter = "Any File\0*.*\0";
ofn.lpstrFile = filename;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrTitle = "Выбери файл";
ofn.Flags = OFN_DONTADDTORECENT | OFN_FILEMUSTEXIST;
GetOpenFileNameA( &ofn );
SetWindowText(hEditA2,filename);
strcpy(filename_2,filename);
}
if (LOWORD(wParam)==10002)
{
FILE *pFile1 = fopen(filename_1,"r");
FILE *pFile2 = fopen(filename_2,"r");
fseek( pFile1, 0, SEEK_END );
int Size1 = ftell( pFile1 );
fseek( pFile2, 0, SEEK_END );
int Size2 = ftell( pFile2 );
if (Size1 != Size2)
{
MessageBox(hwnd,(LPSTR)"Файлы не равны", "Сообщение", MB_OK);
break;
}
rewind( pFile1 );
rewind( pFile2 );
int found = 0;
while (1)
{
int ch1 = fgetc(pFile1);
int ch2 = fgetc(pFile2);
if (ch1 == EOF) break;
if (ch1 == ch2) {
found = 1;
}
else
{
found = 2;
}
}
if (found == 1)
{
MessageBox(hwnd,(LPSTR)"Файлы равны", "Сообщение", MB_OK);
}
if (found == 2)
{
MessageBox(hwnd,(LPSTR)"Файлы не равны", "Info", MB_OK);
}
}
}
break;
case WM_DESTROY:
PostQuitMessage (0);
break;
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
|