// wiz2Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "wiz2.h"
#include "wiz2Dlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CWiz2Dlg dialog

CWiz2Dlg::CWiz2Dlg(CWnd* pParent /*=NULL*/)
	: CDialog(CWiz2Dlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CWiz2Dlg)
	m_nVizibil = -1;
	m_strEgalitate = _T("");
	m_strIntext2 = _T("");
	m_strOutext2 = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CWiz2Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CWiz2Dlg)
	DDX_Control(pDX, IDC_DERIVATA, m_edtNou);
	DDX_Control(pDX, IDC_INTEXT1, m_edtIntext1);
	DDX_Control(pDX, IDC_ARATA, m_btnArata);
	DDX_Control(pDX, IDC_INACTIV, m_chkInactiv);
	DDX_Control(pDX, IDC_OUTETXT1, m_edtOutext1);
	DDX_Radio(pDX, IDC_VIZIBIL, m_nVizibil);
	DDX_Text(pDX, IDC_EGALITATE, m_strEgalitate);
	DDX_Text(pDX, IDC_INTEXT2, m_strIntext2);
	DDX_Text(pDX, IDC_OUTEXT2, m_strOutext2);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CWiz2Dlg, CDialog)
	//{{AFX_MSG_MAP(CWiz2Dlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_ARATA, OnArata)
	ON_BN_CLICKED(IDC_ACTIV, OnActiv)
	ON_BN_CLICKED(IDC_INACTIV, OnInactiv)
	ON_BN_CLICKED(IDC_VIZIBIL, OnVizibil)
	ON_BN_CLICKED(IDC_INVIZIBIL, OnInvizibil)
	ON_EN_CHANGE(IDC_INTEXT1, OnChangeIntext1)
	ON_EN_CHANGE(IDC_INTEXT2, OnChangeIntext2)
	ON_BN_CLICKED(IDC_COMPARA, OnCompara)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CWiz2Dlg message handlers

BOOL CWiz2Dlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	// TODO: Add extra initialization here
	m_nVizibil=0;
	UpdateData(FALSE);
	CButton *pActiv=(CButton*) GetDlgItem(IDC_ACTIV);
	pActiv->SetCheck(1);
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CWiz2Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CWiz2Dlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CWiz2Dlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}



void CWiz2Dlg::OnArata() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	if (m_nVizibil)
	{

		m_edtIntext1.ShowWindow(FALSE);
		m_edtOutext1.ShowWindow(FALSE);
		GetDlgItem(IDC_INTEXT2)->ShowWindow(FALSE);
		GetDlgItem(IDC_OUTEXT2)->ShowWindow(FALSE);
		GetDlgItem(IDC_EGALITATE)->ShowWindow(FALSE);
		m_btnArata.SetWindowText("Arata");
		}
	else
	{
		m_edtIntext1.ShowWindow(TRUE);
		m_edtOutext1.ShowWindow(TRUE);
		GetDlgItem(IDC_INTEXT2)->ShowWindow(TRUE);
		GetDlgItem(IDC_OUTEXT2)->ShowWindow(TRUE);
		GetDlgItem(IDC_EGALITATE)->ShowWindow(TRUE);
		m_btnArata.SetWindowText("Ascunde");
	}
}

void CWiz2Dlg::OnActiv() 
{
	// TODO: Add your control notification handler code here
	if (m_chkInactiv.GetCheck()) 
		m_chkInactiv.SetCheck(0);
	m_btnArata.EnableWindow(TRUE);
	GetDlgItem(IDC_COMPARA)->EnableWindow(TRUE);
}

void CWiz2Dlg::OnInactiv() 
{
	// TODO: Add your control notification handler code here
	CButton *pActiv=(CButton*) GetDlgItem(IDC_ACTIV);
	if (pActiv->GetCheck()) 
		(pActiv->SetCheck(0));
	m_btnArata.EnableWindow(FALSE);
	GetDlgItem(IDC_COMPARA)->EnableWindow(FALSE);
}

void CWiz2Dlg::OnVizibil() 
{
	// TODO: Add your control notification handler code here
//	UpdateData();
	m_edtIntext1.ShowWindow(TRUE);
	m_edtOutext1.ShowWindow(TRUE);
	GetDlgItem(IDC_INTEXT2)->ShowWindow(TRUE);
	GetDlgItem(IDC_OUTEXT2)->ShowWindow(TRUE);
	GetDlgItem(IDC_EGALITATE)->ShowWindow(TRUE);
	m_btnArata.SetWindowText("Ascunde");	
}

void CWiz2Dlg::OnInvizibil() 
{
	// TODO: Add your control notification handler code here
//	UpdateData();
	m_edtIntext1.ShowWindow(FALSE);
	m_edtOutext1.ShowWindow(FALSE);
	GetDlgItem(IDC_INTEXT2)->ShowWindow(FALSE);
	GetDlgItem(IDC_OUTEXT2)->ShowWindow(FALSE);
	GetDlgItem(IDC_EGALITATE)->ShowWindow(FALSE);
	m_btnArata.SetWindowText("Arata");
}

void CWiz2Dlg::OnChangeIntext1() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	m_edtIntext1.GetWindowText(strIntext1);
	m_edtOutext1.SetWindowText(strIntext1);
}

void CWiz2Dlg::OnChangeIntext2() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	UpdateData();
	m_strOutext2=m_strIntext2;
	UpdateData(FALSE);
}

void CWiz2Dlg::OnCompara() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	if (strIntext1.IsEmpty()&&m_strIntext2.IsEmpty())
		SetWindowText(" Nu am ce scrie!");
	else
		if (strIntext1.GetLength()>m_strIntext2.GetLength())
			Scrie(IDC_INTEXT1);
		else
			if (strIntext1.GetLength()<m_strIntext2.GetLength()) 
				Scrie(IDC_INTEXT2);
				else
				{
					m_strEgalitate=strIntext1;
					UpdateData(FALSE);
				}
}

void CWiz2Dlg::Scrie(UINT ID)
{
	CString strTemp;
	CEdit* pEdit=(CEdit*)GetDlgItem(ID);
	pEdit->GetWindowText(strTemp);
	SetWindowText(strTemp);
}
