📄 kitemadddlg.cpp
字号:
// KItemAddDlg.cpp : implementation file
//
#include "stdafx.h"
#include "test2.h"
#include "KItemAddDlg.h"
#include "item.h"
#include "group.h"
#include "server.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// Registry sections;
static LPCTSTR lpszRegSection = _T("Add Items");
static LPCTSTR lpszAutoValidate = _T("Auto Validate");
static LPCTSTR lpszBrowseFlat = _T("Browse Flat");
// Default add item list size:
#define DEF_ITEM_LIST_SIZE 16
// Branch dummy item data:
#define NULL_ITEM_NAME _T("_QCNULL_DUMMY")
#define NULL_ITEM_DATA 0xFFFFFFFF
// Image list indices:
#define ILI_BRANCH 8
#define ILI_SELBRANCH 9
#define ILI_LEAF 3
// Access rights filter combo box indices:
#define CB_ACCESS_ANY 0
#define CB_ACCESS_READONLY 1
#define CB_ACCESS_WRITEONLY 2
#define CB_ACCESS_READWRITE 4
/////////////////////////////////////////////////////////////////////////////
// CKItemAddDlg dialog
CKItemAddDlg::CKItemAddDlg(CKGroup *pGroup, IOPCBrowseServerAddressSpace *pIBrowse, CWnd *pParent /*=NULL*/)
: CDialog(CKItemAddDlg::IDD, pParent)
{
ASSERT (pGroup != NULL);
m_pGroup = pGroup;
m_pIBrowse = pIBrowse;
m_nListIndex = 0;
m_nSelIndex = 0;
m_bModified = false;
m_pIItemMgt = NULL;
// Load registry settings. These are settings we may want to use each time
// we add some items:
m_bAutoValidate = AfxGetApp ()->GetProfileInt (lpszRegSection, lpszAutoValidate, FALSE);
m_bBrowseFlat = AfxGetApp ()->GetProfileInt (lpszRegSection, lpszBrowseFlat, FALSE);
// Allocate memory for add item list:
try
{
m_cItemList.SetSize (DEF_ITEM_LIST_SIZE, DEF_ITEM_LIST_SIZE);//CObArray m_cItemList
}
catch (...)
{
ASSERT (FALSE);
}
//{{AFX_DATA_INIT(CKItemAddDlg)
m_strAccessPath = ITEM_DEFAULT_ACCESSPATH;
m_bActive = ITEM_DEFAULT_ACTIVESTATE;
m_strItemID = ITEM_DEFAULT_ITEMID;
m_vtDataType = ITEM_DEFAULT_DATATYPE;
m_strFilterLeaf = _T("");
m_strFilterBranch = _T("");
//}}AFX_DATA_INIT
// Initialize bitmap buttons:
/* m_cNext.Initialize (IDB_NEXT, IDB_NEXTGRAY);//CImageButton m_cNext;
m_cPrev.Initialize (IDB_PREVIOUS, IDB_PREVIOUSGRAY);
m_cNew.Initialize (IDB_NEWITEM, IDB_NEWITEMGRAY);
m_cDuplicate.Initialize (IDB_DUPITEM, IDB_DUPITEMGRAY);
m_cDelete.Initialize (IDB_DELETEITEM, IDB_DELETEITEMGRAY);
m_cValidate.Initialize (IDB_VALIDATEITEM, IDB_VALIDATEITEMGRAY);*/
}
CKItemAddDlg::~CKItemAddDlg ()
{
// Save registry settings:
AfxGetApp ()->WriteProfileInt (lpszRegSection, lpszAutoValidate, m_bAutoValidate);
AfxGetApp ()->WriteProfileInt (lpszRegSection, lpszBrowseFlat, m_bBrowseFlat);
}
void CKItemAddDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CKItemAddDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
DDX_Text (pDX, IDC_ACCESSPATH, m_strAccessPath);
DDX_Check (pDX, IDC_ACTIVE, m_bActive);
DDX_Text (pDX, IDC_ITEMID, m_strItemID);
DDX_Text (pDX, IDC_FILTERLEAF, m_strFilterLeaf);
DDX_Text (pDX, IDC_FILTERBRANCH, m_strFilterBranch);
//}}AFX_DATA_MAP
DDX_Check (pDX, IDC_BROWSEFLAT, m_bBrowseFlat);
DDX_Check (pDX, IDC_AUTOVALIDATE, m_bAutoValidate);
CComboBox *pCombo = (CComboBox *)GetDlgItem (IDC_DATATYPE);
// If save and validate, transfer data type combo box index to
// vartype member variable:
if (pDX->m_bSaveAndValidate)//nonzero则代表从控件到变量
{
CString strType;
pCombo->GetLBText (pCombo->GetCurSel (), strType);//Gets a string from the list box of a combo box.
m_vtDataType = VartypeFromString (strType);
}
// else use current member variable value to make combo box selection:
else
{
CString strType;
// Convert data type to combo box entry string:
switch (m_vtDataType & ~VT_ARRAY)
{
case VT_BOOL: strType = _T("Boolean"); break;
case VT_UI1: strType = _T("Byte"); break;
case VT_I1: strType = _T("Char"); break;
case VT_UI2: strType = _T("Word"); break;
case VT_I2: strType = _T("Short"); break;
case VT_UI4: strType = _T("DWord"); break;
case VT_I4: strType = _T("Long"); break;
case VT_R4: strType = _T("Float"); break;
case VT_R8: strType = _T("Double"); break;
case VT_BSTR: strType = _T("String"); break;
default: strType = _T("Native"); break;
}
// Update array flag data:
if ((m_vtDataType & VT_ARRAY) != 0)
strType += _T(" Array");
// Select combo box entry:
pCombo->SelectString (-1, strType);
}
}
BEGIN_MESSAGE_MAP(CKItemAddDlg, CDialog)
//{{AFX_MSG_MAP(CKItemAddDlg)
ON_BN_CLICKED (IDC_NEW, OnNew)
ON_NOTIFY (TVN_ITEMEXPANDING, IDC_BRANCHLIST, OnBranchExpanding)
ON_NOTIFY (TVN_SELCHANGED, IDC_BRANCHLIST, OnBranchSelected)
ON_CBN_SELCHANGE (IDC_FILTERACCESS, OnAccessFilterChange)
ON_EN_CHANGE (IDC_FILTERLEAF, OnLeafFilterChange)
ON_CBN_SELCHANGE (IDC_FILTERTYPE, OnVartypeFilterChange)
ON_BN_CLICKED (IDC_NEXT, OnNext)
ON_BN_CLICKED (IDC_PREVIOUS, OnPrevious)
ON_BN_CLICKED (IDC_VALIDATEITEM, OnValidateItem)
ON_EN_CHANGE (IDC_FILTERBRANCH, OnBranchFilterChange)
ON_NOTIFY (NM_DBLCLK, IDC_LEAFLIST, OnClickLeafList)
ON_EN_CHANGE (IDC_ITEMID, OnChange)
ON_BN_CLICKED (IDC_DELETE, OnDelete)
ON_BN_CLICKED (IDC_ADD_LEAVES, OnAddLeaves)
ON_EN_CHANGE (IDC_ACCESSPATH, OnChange)
ON_BN_CLICKED (IDC_ACTIVE, OnChange)
ON_CBN_SELCHANGE (IDC_DATATYPE, OnChange)
ON_BN_CLICKED (IDC_AUTOVALIDATE, OnAutoValidate)
ON_WM_SHOWWINDOW ()
ON_BN_CLICKED (IDC_BROWSEFLAT, OnBrowseFlat)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CKItemAddDlg message handlers
/////////////////////////////////////////////////////////////////////////////
// **************************************************************************
// OnInitDialog ()
//
// Description:
// Called immediately before the dialog box is displayed. Use opportunity
// to initialize controls.
//
// Parameters:
// none
//
// Returns:
// BOOL - TRUE.
// **************************************************************************
BOOL CKItemAddDlg::OnInitDialog ()
{
CDialog::OnInitDialog ();
// Limit the access path to 255 chars:
((CEdit *)GetDlgItem (IDC_ACCESSPATH))->LimitText (255);
// Allow 10 levels of 32 character names plus a tag name of 31 characters:
((CEdit *)GetDlgItem (IDC_ITEMID))->LimitText (10*32 + 31);
// Subclass image buttons:
/* m_cNext.SubclassDlgItem (IDC_NEXT, this);
m_cPrev.SubclassDlgItem (IDC_PREVIOUS, this);
m_cNew.SubclassDlgItem (IDC_NEW, this);
m_cDuplicate.SubclassDlgItem (IDC_DUPLICATE, this);
m_cDelete.SubclassDlgItem (IDC_DELETE, this);
m_cValidate.SubclassDlgItem (IDC_VALIDATEITEM, this);
// Create tool tips for the image buttons:
m_cToolTip.Create (this);
m_cToolTip.AddWindowTool (&m_cNext);
m_cToolTip.AddWindowTool (&m_cPrev);
m_cToolTip.AddWindowTool (&m_cNew);
m_cToolTip.AddWindowTool (&m_cDuplicate);
m_cToolTip.AddWindowTool (&m_cDelete);
m_cToolTip.AddWindowTool (&m_cValidate);*/
// Get our group's item management interface pointer for the group:
m_pIItemMgt = m_pGroup->GetIItemMgt ();
// Intialize our item browser:
InitializeBrowser ();
// Intialize control status:
UpdateStatus ();
// return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
return (TRUE);
}
// **************************************************************************
// OnShowWindow ()
//
// Description:
// This method is called by the framework when this dialog is about to be
// hidden or shown. Use opportunity to set focus.
// 这个函数就是在启动这个对话框时,自动将输入焦点定位在ID上
// Parameters:
// BOOL bShow TRUE if the window is being shown; FALSE if
// the window is being hidden.
// UINT nStatus Specifies the status of the window being shown.
//
// Returns:
// void
// **************************************************************************
void CKItemAddDlg::OnShowWindow (BOOL bShow, UINT nStatus)
{
// Perform default processing:
CDialog::OnShowWindow (bShow, nStatus);
// If showing dialog, set focus to item ID edit box:
if (bShow)
GetDlgItem (IDC_ITEMID)->SetFocus ();
}
// **************************************************************************
// OnOK ()
//
// Description:
// Override to perform the OK button action in a modal dialog box. Use
// opportunity to apply changes.
//
// Parameters:
// none
//
// Returns:
// void
// **************************************************************************
void CKItemAddDlg::OnOK ()
{
// Apply any outstanding changes:
if (OnApplyChange ())
{
// Terminate the list. Will allow us to process list using
// "while (element)" loop if we want:
if (m_nListIndex > 0)
m_cItemList.SetAtGrow (m_nListIndex, NULL);
// Perform default processing:
CDialog::OnOK ();
}
}
// **************************************************************************
// OnCancel ()
//
// Description:
// Override to perform the Cancel button or ESC key action. Use opportunity
// to free any items created.
//
// Parameters:
// none
//
// Returns:
// void
// **************************************************************************
void CKItemAddDlg::OnCancel ()
{
// Free any items we created:
for (int nIndex = 0; nIndex < m_nListIndex; nIndex++)
{
// Get next element in list:
CKItem *pItem = (CKItem *) m_cItemList.GetAt (nIndex);
ASSERT (pItem != NULL);
// Delete it:
delete pItem;
}
// Perform default processing:
CDialog::OnCancel ();
}
// **************************************************************************
// OnNew ()
//
// Description:
// New button event handler. Select a new item for edits.
//
// Parameters:
// none
//
// Returns:
// void
// **************************************************************************
void CKItemAddDlg::OnNew ()
{
// No item currently in list should be selected on new:
SelectItem (-1);
}
// **************************************************************************
// OnDuplicate ()
//
// Description:
// Duplicate button event handler. Duplicate the current item.
//
// Parameters:
// none
//
// Returns:
// void
// **************************************************************************
//DEL void CKItemAddDlg::OnDuplicate ()
//DEL {
//DEL // Validate selected item first, and see if it has an address with
//DEL // a dot bit format:
//DEL bool bDotBitAddress = false;
//DEL HRESULT hr = Validate (&bDotBitAddress);
//DEL
//DEL // If current item is not valid, don't duplicate it. Instead,
//DEL // tell user something is wrong with selected item:
//DEL if (FAILED (hr))
//DEL {
//DEL // Define a string format for the validation return code:
//DEL CString strHR;
//DEL strHR.Format (_T("0x%08X"), hr);
//DEL
//DEL // Create an error string using above format for return code::
//DEL CString strFailure;
//DEL strFailure.FormatMessage (IDS_VALIDATE_ITEM_FAILED, m_strItemID, strHR);
//DEL
//DEL // Display a message box with error string:
//DEL AfxMessageBox (strFailure);
//DEL
//DEL // Return now so we don't duplicate invalid item:
//DEL return;
//DEL }
//DEL
//DEL // Create a duplicate item dialog. This will allow the user to specify
//DEL // how many duplicates to make::
//DEL CKDuplicateItemCountDlg dlg;
//DEL
//DEL // Show as modal dialog. Duplicate item only if user hits "OK":
//DEL if (dlg.DoModal () == IDOK)
//DEL {
//DEL // Create a wait cursor object. This will cause the wait cursor,
//DEL // usually an hourglass, to be displayed. When this object goes
//DEL // out of scope, its destructor will restore the previous cursor
//DEL // type.
//DEL CWaitCursor wc;
//DEL
//DEL // Postpone repaint until we are done. This will make things go
//DEL // faster and look smoother:
//DEL SetRedraw (false);
//DEL
//DEL // Duplicate item, and select duplicate. Repeat as many times
//DEL // as user says:
//DEL for (int i = 0; i < dlg.m_cnDuplicateItems; i++)
//DEL SelectItem (-1, true, bDotBitAddress);
//DEL
//DEL // Now that we are done, allow a repaint:
//DEL SetRedraw (true);
//DEL
//DEL // Force a repaint:
//DEL Invalidate ();
//DEL }
//DEL }
// **************************************************************************
// OnDelete ()
//
// Description:
// Delete button event handler. Deletes the current item.
//
// Parameters:
// none
//
// Returns:
// void
// **************************************************************************
void CKItemAddDlg::OnDelete ()
{
// Delete the selected item (selected item index had better be
// less than the number of items in list):
if (m_nSelIndex < m_nListIndex)
{
// Get pointer to the selected item's object:
CKItem *pItem = (CKItem *) m_cItemList.GetAt (m_nSelIndex);
ASSERT (pItem != NULL);
// Delete the item object:
delete pItem;
// Remove the item from the list:
m_cItemList.RemoveAt (m_nSelIndex);
m_nListIndex--;
// Select the next item if there is one (i.e, the item that just
// took this positions place from the RemoveAt())
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -