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

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image1DblClick(TObject *Sender)
{
	if (OpenDialog1->Execute())
	{
		Image1->Picture->LoadFromFile(OpenDialog1->FileName);
		Form1->Caption=OpenDialog1->FileName;
		StatusBar1->Panels->Items[0]->Text=ExtractFileName(OpenDialog1->FileName);
		StatusBar1->Panels->Items[1]->Text=IntToStr(Image1->Picture->Width)+" x " +IntToStr(Image1->Picture->Height);
	}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormKeyDown(TObject *Sender, WORD &Key,
	  TShiftState Shift)
{
	switch (Key)
	{
		case VK_ESCAPE: Close(); break;
		case 'O': Image1DblClick(Sender); break;
		case 'S': Zapiszjako1Click(Sender); break;
	}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
	AnsiString NazwaPliku;
	if (_argc>1)
	{
		NazwaPliku=_argv[1];
		if (FileExists(NazwaPliku))
		{
			Image1->Picture->LoadFromFile(NazwaPliku);
			this->Caption=NazwaPliku;
			StatusBar1->Panels->Items[0]->Text=ExtractFileName(NazwaPliku);
			StatusBar1->Panels->Items[1]->Text=IntToStr(Image1->Picture->Width)+" x " +IntToStr(Image1->Picture->Height);
		}
		else
		ShowMessage("Plik "+NazwaPliku+" nie istnieje!");
	}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Zakocz1Click(TObject *Sender)
{
	Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Zapiszjako1Click(TObject *Sender)
{
	if (SaveDialog1->Execute())
	{
		Image1->Picture->SaveToFile(SaveDialog1->FileName);
		Form1->Caption=SaveDialog1->FileName;
	}
}
//---------------------------------------------------------------------------

