// PulpitPisanieDlg.cpp : implementation file
//

#include "stdafx.h"
#include "PulpitPisanie.h"
#include "PulpitPisanieDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CPulpitPisanieDlg dialog




CPulpitPisanieDlg::CPulpitPisanieDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CPulpitPisanieDlg::IDD, pParent)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CPulpitPisanieDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_EDIT1, Edit1);
	DDX_Control(pDX, IDC_STATIC1, Label1);
	DDX_Control(pDX, IDC_IMAGE1, Image1);
	DDX_Control(pDX, IDC_IMAGE2, Image2);
	DDX_Control(pDX, IDC_STATIC10, Label2);
}

BEGIN_MESSAGE_MAP(CPulpitPisanieDlg, CDialog)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	//}}AFX_MSG_MAP
	ON_BN_CLICKED(IDC_BUTTON1, &CPulpitPisanieDlg::OnBnClickedButton1)
	ON_BN_CLICKED(IDC_BUTTON2, &CPulpitPisanieDlg::OnBnClickedButton2)
	ON_EN_CHANGE(IDC_EDIT1, &CPulpitPisanieDlg::OnEnChangeEdit1)
END_MESSAGE_MAP()


// CPulpitPisanieDlg message handlers

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

	// 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

	return TRUE;  // return TRUE  unless you set the focus to a control
}

// 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 CPulpitPisanieDlg::OnPaint()
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<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 function to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CPulpitPisanieDlg::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}


void CPulpitPisanieDlg::OnBnClickedButton1()
{
	CFontDialog fontDialog;
	
	if(fontDialog.DoModal() != IDCANCEL)
	{
		fontDialog.GetCurrentFont(&lf);
		newFont.CreateFontIndirectW(&lf);		
		Label1.SetWindowTextW(lf.lfFaceName);
		CString temp;
		temp.Format(L"%d", fontDialog.GetSize()/10);
		Label2.SetWindowTextW(temp);
		textColor.rgbResult = fontDialog.GetColor();
		Image2.put_BackColor(textColor.rgbResult);
	}
}

void CPulpitPisanieDlg::OnBnClickedButton2()
{
	CColorDialog colorDialog;
	if(colorDialog.DoModal() != IDCANCEL)
	{
		cc = colorDialog.m_cc;
		Image1.put_BackColor(cc.rgbResult);
	}
}

void CPulpitPisanieDlg::OnEnChangeEdit1()
{
	// 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
	CClientDC dc(GetDesktopWindow());
	CString temp;

	oldFont = dc.SelectObject(&newFont);
	dc.SetBkColor(cc.rgbResult);
	dc.SetBkMode(OPAQUE);
	dc.SetTextColor(textColor.rgbResult);
	Edit1.GetWindowTextW(temp);
	dc.TextOut(200, 200, temp);
	dc.SelectObject(oldFont);
}
