www.pudn.com > Property_List_src.zip > myPropertyListDlg.cpp
// myPropertyListDlg.cpp : implementation file
//
#include "stdafx.h"
#include "myPropertyList.h"
#include "myPropertyListDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
static CMyPropertyListDlg* g_pPropList = NULL;
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyPropertyListDlg dialog
CMyPropertyListDlg::CMyPropertyListDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMyPropertyListDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMyPropertyListDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMyPropertyListDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMyPropertyListDlg)
DDX_Control(pDX, IDC_TREE1, m_tree);
DDX_Control(pDX, IDC_LIST1, m_propList);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMyPropertyListDlg, CDialog)
//{{AFX_MSG_MAP(CMyPropertyListDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_ADD, OnButtonAdd)
ON_BN_CLICKED(IDC_BUTTON_DELETEALL, OnButtonDeleteall)
ON_NOTIFY(TVN_SELCHANGED, IDC_TREE1, OnSelchangedTree1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyPropertyListDlg message handlers
BOOL CMyPropertyListDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// 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
m_tree.InsertItem("1");
m_tree.InsertItem("2");
m_propList.AddPropItem("Catalog0", "A", "0", PIT_EDIT, "");
m_propList.AddPropItem("Catalog1", "B", "64", PIT_COMBO, "16|64|128");
m_propList.AddPropItem("Catalog2", "C", "250 250 0", PIT_COLOR, "");
m_propList.AddPropItem("Catalog2", "F", "test", PIT_COMBO2, "25|125");
m_propList.AddPropItem("Catalog2", "H", "shanghai|changsha", PIT_COMBO3, "beijing|shanghai|changsha|chengdu|wuhan");
m_propList.AddPropItem("Catalog1", "I", "N", PIT_CHECK, "");
m_propList.AddPropItem("Catalog0", "J", "127.0.0.1", PIT_IP, "");
m_propList.AddPropItem("Catalog0", "X", "2005/7/2", PIT_DATE, "");
m_propList.AddPropItem("Catalog1", "Y", "12:23:45", PIT_TIME, "");
m_propList.AddPropItem("Catalog2", "Z", "2005/7/2 12:23:45", PIT_DATETIME, "");
//if you use OnSelChanged, you must provid a PFN_OnSelChanged function point;
g_pPropList = this;
m_propList.SetPFNOnSelChanged(pfnOnSelChangedPropertyList);
return TRUE; // return TRUE unless you set the focus to a control
}
void CMyPropertyListDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// 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 CMyPropertyListDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (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 to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CMyPropertyListDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMyPropertyListDlg::OnOK()
{
// TODO: Add extra validation here
CString strValue;
for(POSITION pos=m_propList.GetHead(); pos!=NULL;)
{
const CPropertyItem* pItem = m_propList.GetNext(pos);
strValue += pItem->m_propName + " = " + pItem->m_curValue + "\n";
}
SetDlgItemText(IDC_STATIC, strValue);
//CDialog::OnOK();
}
void pfnOnSelChangedPropertyList(const CPropertyItem* pItem)
{
if(g_pPropList)
{
g_pPropList->SetDlgItemText(IDC_STATIC, pItem->m_propName +" = "+pItem->m_curValue);
}
}
void CMyPropertyListDlg::OnButtonAdd()
{
// TODO: Add your control notification handler code here
m_propList.AddPropItem("Catalog1", "G", "d:\\downloads", PIT_FOLDER, "");
m_propList.AddPropItem("Catalog0", "D", "", PIT_FONT, "");
m_propList.AddPropItem("Catalog2", "E", "c:\\zzlog.txt", PIT_FILE, "");
m_propList.AddPropItem("Catalog0", "E", "c:\\zzlog.txt", PIT_FILE, "");
m_propList.AddPropItem("Catalog0", "E", "c:\\zzlog.txt", PIT_FILE, ""); //ignored if catalog+propname is repeated
}
void CMyPropertyListDlg::OnButtonDeleteall()
{
// TODO: Add your control notification handler code here
m_propList.DeleteAll();
}
void CMyPropertyListDlg::OnSelchangedTree1(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
HTREEITEM node = pNMTreeView->itemNew.hItem;
CString s = m_tree.GetItemText(node);
if(s == "1")
{
m_propList.DeleteAll();
m_propList.AddPropItem("Catalog0", "A", "0", PIT_EDIT, "");
m_propList.AddPropItem("Catalog1", "B", "64", PIT_COMBO, "16|64|128");
m_propList.AddPropItem("Catalog2", "C", "250 250 0", PIT_COLOR, "");
m_propList.AddPropItem("Catalog2", "F", "test", PIT_COMBO2, "25|125");
m_propList.AddPropItem("Catalog2", "H", "shanghai|changsha", PIT_COMBO3, "beijing|shanghai|changsha|chengdu|wuhan");
}
else
{
m_propList.DeleteAll();
m_propList.AddPropItem("Catalog1", "I", "N", PIT_CHECK, "");
m_propList.AddPropItem("Catalog0", "J", "127.0.0.1", PIT_IP, "");
m_propList.AddPropItem("Catalog0", "X", "2005/7/2", PIT_DATE, "");
m_propList.AddPropItem("Catalog1", "Y", "12:23:45", PIT_TIME, "");
m_propList.AddPropItem("Catalog2", "Z", "2005/7/2 12:23:45", PIT_DATETIME, "");
}
*pResult = 0;
}