// IkonaWZasobnikuDlg.cpp : implementation file
//

#include "stdafx.h"
#include "IkonaWZasobniku.h"
#include "IkonaWZasobnikuDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

// CIkonaWZasobnikuDlg dialog




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

void CIkonaWZasobnikuDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CIkonaWZasobnikuDlg, CDialog)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	//}}AFX_MSG_MAP
	ON_BN_CLICKED(IDC_BUTTON1, &CIkonaWZasobnikuDlg::OnBnClickedButton1)
	ON_BN_CLICKED(IDC_BUTTON2, &CIkonaWZasobnikuDlg::OnBnClickedButton2)
	ON_MESSAGE(WM_USER + 1, &CIkonaWZasobnikuDlg::OnTrayClick)
	ON_BN_CLICKED(IDC_BUTTON3, &CIkonaWZasobnikuDlg::OnBnClickedButton3)
END_MESSAGE_MAP()


// CIkonaWZasobnikuDlg message handlers

BOOL CIkonaWZasobnikuDlg::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 CIkonaWZasobnikuDlg::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 CIkonaWZasobnikuDlg::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}


void CIkonaWZasobnikuDlg::OnBnClickedButton1()
{
	informacjeOIkonie.cbSize = sizeof(informacjeOIkonie);
	informacjeOIkonie.hWnd = m_hWnd;
	wcscpy_s(informacjeOIkonie.szTip, L"PodpowiedŸ");
	informacjeOIkonie.hIcon = LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_MAINFRAME));
	informacjeOIkonie.uID = 0;
	informacjeOIkonie.uFlags = NIF_TIP | NIF_ICON | NIF_MESSAGE;
	informacjeOIkonie.uVersion = NOTIFYICON_VERSION_4;
	informacjeOIkonie.uCallbackMessage = WM_USER + 1;
	
	Shell_NotifyIcon(NIM_ADD, &informacjeOIkonie);
}

void CIkonaWZasobnikuDlg::OnBnClickedButton2()
{
	Shell_NotifyIcon(NIM_DELETE, &informacjeOIkonie);
}

LRESULT CIkonaWZasobnikuDlg::OnTrayClick(WPARAM wParam, LPARAM lParam)
{
	UINT uMsg = (UINT) lParam; 
	switch (uMsg) 
	{ 
		case WM_LBUTTONDBLCLK:
			AfxMessageBox(L"Dwukrotne klikniêcie");
			break;
		case WM_LBUTTONDOWN:
			AfxMessageBox(L"Klikniêcie");
			break;
		case WM_RBUTTONUP:
			CPoint pt;    
			CMenu trayMenu;
			GetCursorPos(&pt);
			trayMenu.LoadMenuW(MAKEINTRESOURCE(IDR_MENU1));
			trayMenu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, pt.x, pt.y, this);
			break;
	} 
	return TRUE;
}

void CIkonaWZasobnikuDlg::OnBnClickedButton3()
{
	informacjeOIkonie.cbSize = sizeof(informacjeOIkonie);
	informacjeOIkonie.hWnd = m_hWnd;
	wcscpy_s(informacjeOIkonie.szInfoTitle, L"Dymek");
	wcscpy_s(informacjeOIkonie.szInfo, L"Informacja umieszczona w dymku");
	informacjeOIkonie.hIcon = LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_MAINFRAME));
	informacjeOIkonie.dwInfoFlags = NIIF_INFO;
	informacjeOIkonie.uID = 0;
	informacjeOIkonie.uFlags = NIF_INFO | NIF_ICON;
	
	Shell_NotifyIcon(NIM_MODIFY, &informacjeOIkonie);
}
