// AddKey.h.h : Declaration of the CAddKey

#include "resource.h"       // main symbols

/////////////////////////////////////////////////////////////////////////////
// CAddKey
class CAddKey : 
	public CDialogImpl<CAddKey>
{
public:
	CAddKey() {}
	~CAddKey() {}

	enum { IDD = IDD_ADDKEY };

BEGIN_MSG_MAP(CAddKey)
	MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
	COMMAND_ID_HANDLER(IDOK, OnOK)
	COMMAND_ID_HANDLER(IDCANCEL, OnCancel)
END_MSG_MAP()


	LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
	{
		return 1;  // Let the system set the focus
	}

	LRESULT OnOK(WORD wNotifyCode, WORD wID, HWND hWndCtlr, BOOL& bHandled)
	{
		HWND hWnd = GetDlgItem(IDC_EDIT);
		if (hWnd)
			::SendMessage(hWnd, WM_GETTEXT, _MAX_PATH, (LPARAM)m_szPath);
		EndDialog(IDOK);
		return 0;
	}

	LRESULT OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtlr, BOOL& bHandled)
	{
		EndDialog(IDCANCEL);
		return 0;
	}
	TCHAR m_szPath[_MAX_PATH];
};

/////////////////////////////////////////////////////////////////////////////
// CAddRootKey
class CAddRootKey : 
	public CDialogImpl<CAddRootKey>
{
public:
	CAddRootKey(){}
	~CAddRootKey(){}

	enum { IDD = IDD_ADDROOTKEY };

BEGIN_MSG_MAP(CAddRootKey)
	MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
	COMMAND_ID_HANDLER(IDOK, OnOK)
	COMMAND_ID_HANDLER(IDCANCEL, OnCancel)
END_MSG_MAP()

	LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
	{
		HWND hWnd = GetDlgItem(IDC_ROOTKEYS);
		if (hWnd)
		{
			::SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("HKEY_CLASSES_ROOT"));
			::SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("HKEY_CURRENT_USER"));
			::SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("HKEY_LOCAL_MACHINE"));
			::SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("HKEY_USERS"));
			::SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("HKEY_PERFORMANCE_DATA"));
			::SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("HKEY_DYN_DATA"));
			::SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)_T("HKEY_CURRENT_CONFIG"));
		}
		
		return 1;
	}
	LRESULT OnOK(WORD wNotifyCode, WORD wID, HWND hWndCtlr, BOOL& bHandled)
	{
		HWND hWnd = GetDlgItem(IDC_ROOTKEYS);
		if (hWnd)
			::SendMessage(hWnd, WM_GETTEXT, _MAX_PATH, (LPARAM)m_szRootKey);
		EndDialog(IDOK);
		return 0;
	}

	LRESULT OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtlr, BOOL& bHandled)
	{
		EndDialog(IDCANCEL);
		return 0;
	}
	TCHAR m_szRootKey[_MAX_PATH];
};


/////////////////////////////////////////////////////////////////////////////
// CAddValue
class CAddValue : 
	public CDialogImpl<CAddValue>
{
public:
	CAddValue() {}
	~CAddValue() {}

	enum { IDD = IDD_ADDVALUE };

BEGIN_MSG_MAP(CAddValue)
	MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
	COMMAND_ID_HANDLER(IDOK, OnOK)
	COMMAND_ID_HANDLER(IDCANCEL, OnCancel)
END_MSG_MAP()


	LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
	{
		return 1;  // Let the system set the focus
	}

	LRESULT OnOK(WORD wNotifyCode, WORD wID, HWND hWndCtlr, BOOL& bHandled)
	{
		HWND hWndRBString = GetDlgItem(IDC_STRING);
		HWND hWndValueName = GetDlgItem(IDC_VALUENAME);
		HWND hWndValue = GetDlgItem(IDC_VALUE);

		_ASSERTE(hWndRBString != NULL);
		_ASSERTE(hWndValueName != NULL);
		_ASSERTE(hWndValue != NULL);
		m_bString = ::SendMessage(hWndRBString, BM_GETCHECK, 0, 0) == BST_CHECKED;
		m_bDefault = ::SendMessage(hWndValueName, WM_GETTEXT, _MAX_PATH, (LPARAM)m_szValueName) == 0;
		::SendMessage(hWndValue, WM_GETTEXT, _MAX_PATH, (LPARAM)m_szValue);
		EndDialog(IDOK);
		return 0;
	}

	LRESULT OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtlr, BOOL& bHandled)
	{
		EndDialog(IDCANCEL);
		return 0;
	}
	TCHAR m_szValueName[_MAX_PATH];
	TCHAR m_szValue[_MAX_PATH];
	unsigned m_bString:1;
	unsigned m_bDefault:1;
};

