|
// InsertCategoryDialog.cpp : implementation file
//
#include "stdafx.h"
#include "Exile.h"
#include "InsertCategoryDialog.h"
#include "ChangeIconDialog.h"
#include "Security.h"
#include "predefined.h"
#include "messagebox.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CInsertCategoryDialog dialog
CInsertCategoryDialog::CInsertCategoryDialog(CWnd* pParent /*=NULL*/)
: CDialog(CInsertCategoryDialog::IDD, pParent)
{
//{{AFX_DATA_INIT(CInsertCategoryDialog)
m_strCategoryName = _T("");
m_strDescription = _T("");
//}}AFX_DATA_INIT
}
CInsertCategoryDialog::~CInsertCategoryDialog()
{
CleanString(m_strCategoryName);
CleanString(m_strDescription);
}
void CInsertCategoryDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CInsertCategoryDialog)
DDX_Control(pDX, IDC_RATING, m_ctrlRating);
DDX_Control(pDX, IDC_CATEGORYICON, m_ctrlCategoryIcon);
DDX_CBString(pDX, IDC_CATEGORYNAME, m_strCategoryName);
DDX_Text(pDX, IDC_DESCRIPTION, m_strDescription);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CInsertCategoryDialog, CDialog)
//{{AFX_MSG_MAP(CInsertCategoryDialog)
ON_CBN_SELCHANGE(IDC_CATEGORYNAME, OnSelchangeCategoryname)
ON_BN_CLICKED(IDC_CHANGEICON, OnChangeicon)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CInsertCategoryDialog message handlers
BOOL CInsertCategoryDialog::OnInitDialog()
{
CDialog::OnInitDialog();
// Categories
CComboBox *pCombo = (CComboBox *)GetDlgItem(IDC_CATEGORYNAME);
for(int n = 0; n < sizeof(g_aCategories) / sizeof(g_aCategories[0]); ++n)
{
pCombo->AddString(g_aCategories[n].szName);
} // for
// Ratings
for(n = 0; n < sizeof(g_aRatings) / sizeof(g_aRatings[0]); ++n)
{
m_ctrlRating.InsertString(n, g_aRatings[n].szName);
m_ctrlRating.SetItemData(n, (DWORD)g_aRatings[n].cRating);
} // for
m_ctrlCategoryIcon.SetIcon(m_pimgList->ExtractIcon(3));
m_ctrlRating.SetCurSel(5);
m_lIconID = 3;
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CInsertCategoryDialog::OnSelchangeCategoryname()
{
CComboBox *pCombo = (CComboBox *)GetDlgItem(IDC_CATEGORYNAME);
if(CB_ERR != pCombo->GetCurSel())
{
TCHAR szName[nNameLength];
pCombo->GetLBText(pCombo->GetCurSel(), szName);
// Look in predefined categories
for(int n = 0; n < sizeof(g_aCategories) / sizeof(g_aCategories[0]); ++n)
{
#ifdef _UNICODE
if(0 == wcscmp(szName, g_aCategories[n].szName))
{
m_strDescription = g_aCategories[n].szDescription;
m_ctrlCategoryIcon.SetIcon(m_pimgList->ExtractIcon(g_aCategories[n].lIconID));
m_strCategoryName = g_aCategories[n].szName;
m_lIconID = g_aCategories[n].lIconID;
UpdateData(FALSE);
break;
} // if
#else
if(0 == strcmp(szName, g_aCategories[n].szName))
{
m_strDescription = g_aCategories[n].szDescription;
m_ctrlCategoryIcon.SetIcon(m_pimgList->ExtractIcon(g_aCategories[n].lIconID));
m_strCategoryName = g_aCategories[n].szName;
m_lIconID = g_aCategories[n].lIconID;
UpdateData(FALSE);
break;
} // if
#endif // _UNICODE
} // for
} // if
}
void CInsertCategoryDialog::OnChangeicon()
{
CChangeIconDialog dlgChange;
dlgChange.SetImageList(m_pimgList);
if(IDOK == dlgChange.DoModal())
{
m_lIconID = dlgChange.GetIconID();
m_ctrlCategoryIcon.SetIcon(m_pimgList->ExtractIcon(m_lIconID));
} // if
}
void CInsertCategoryDialog::OnOK()
{
UpdateData();
if(m_strCategoryName.IsEmpty())
{
MessageBoxEx(*this, IDS_ENTERCATEGORYNAME, IDS_TITLE);
return;
} // if
if(CB_ERR == m_ctrlRating.GetCurSel())
{
MessageBoxEx(*this, IDS_SELECTRATING, IDS_TITLE);
return;
} // if
m_cRating = (BYTE)m_ctrlRating.GetItemData(m_ctrlRating.GetCurSel());
CDialog::OnOK();
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here