#include "pch.h"
#include "GenericBkMFC.h"
#include "DlgLayeredWindowHelperST.h"

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

CDlgLayeredWindowHelperST::CDlgLayeredWindowHelperST(CWnd* pParent, CResourceServerST*	m_pIcons, HWND hParentWnd)
	: CDialog(CDlgLayeredWindowHelperST::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlgLayeredWindowHelperST)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT

	m_pIconsDLL = m_pIcons;
	m_hParentWnd = hParentWnd;
}

void CDlgLayeredWindowHelperST::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgLayeredWindowHelperST)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP

	DDX_Control(pDX, IDC_SLIDER, m_OpacitySlider);
}

BEGIN_MESSAGE_MAP(CDlgLayeredWindowHelperST, CDialog)
	//{{AFX_MSG_MAP(CDlgLayeredWindowHelperST)
	ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDER, OnReleasedcaptureSlider)
	ON_NOTIFY(NM_CUSTOMDRAW, IDC_SLIDER, OnCustomdrawSlider)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

BOOL CDlgLayeredWindowHelperST::OnInitDialog() 
{
	COLORREF	crBtnColor = 0;

	CDialog::OnInitDialog();

	m_Layered.AddLayeredStyle(m_hParentWnd);
	m_Layered.SetTransparentPercentage(m_hParentWnd, 100);

	m_OpacitySlider.SetRangeMin(20);
	m_OpacitySlider.SetRangeMax(100);
	m_OpacitySlider.SetPos(100);

	return TRUE;
} // End of OnInitDialog

void CDlgLayeredWindowHelperST::OnOK()
{
} // End of OnOK

void CDlgLayeredWindowHelperST::OnCancel()
{
} // End of OnCancel

void CDlgLayeredWindowHelperST::OnReleasedcaptureSlider(NMHDR* pNMHDR, LRESULT* pResult)
{
	SetTransparency();
	*pResult = 0;
} // End of OnReleasedcaptureSlider

void CDlgLayeredWindowHelperST::OnCustomdrawSlider(NMHDR* pNMHDR, LRESULT* pResult)
{
	SetTransparency();
	*pResult = 0;
} // End of OnCustomdrawSlider

void CDlgLayeredWindowHelperST::SetTransparency()
{
	// Slider range is 20 to 100
	int nValue = m_OpacitySlider.GetPos();

	CString sText;
	sText.Format(_T("Under Windows 10 this dialog\nwill have a %d%% opacity.\n\nTry moving the slider...."), nValue);

	SetDlgItemText(IDC_STCTEXT, sText);

	m_Layered.SetTransparentPercentage(m_hParentWnd, nValue);
} // End of SetTransparency
