VbOpts.cpp
资源名称:hp_snmp3.zip [点击查看]
上传用户:czjinwang
上传日期:2007-01-12
资源大小:2484k
文件大小:5k
源码类别:
SNMP编程
开发平台:
Visual C++
- /*============================================================================
- Copyright (c) 1996
- Hewlett-Packard Company
- ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
- Permission to use, copy, modify, distribute and/or sell this software
- and/or its documentation is hereby granted without fee. User agrees
- to display the above copyright notice and this license notice in all
- copies of the software and any documentation of the software. User
- agrees to assume all liability for the use of the software; Hewlett-Packard
- makes no representations about the suitability of this software for any
- purpose. It is provided "AS-IS without warranty of any kind,either express
- or implied. User hereby grants a royalty-free license to any and all
- derivatives based upon this software code base.
- =============================================================================*/
- #include "stdafx.h"
- #include "browser.h"
- #include "vbopts.h"
- #include "snmp_pp.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- #define STRTOL( str) ((strcmp(str,"0")==0)?-1:atol(str))
- // returns status and if success, returns value
- inline int string_to_long( CString str, unsigned long &val) {
- if ( str.Find(".") != -1)
- return FALSE;
- if ( strcmp(str,"0")==0)
- {
- val = 0;
- return TRUE;
- }
- val = atol( str);
- if ( val == 0)
- return FALSE;
- else
- return TRUE;
- };
- /////////////////////////////////////////////////////////////////////////////
- // VbOpts dialog
- VbOpts::VbOpts(CWnd* pParent /*=NULL*/)
- : CDialog(VbOpts::IDD, pParent)
- {
- //{{AFX_DATA_INIT(VbOpts)
- m_vboid = _T("");
- m_vbvalue = _T("");
- //}}AFX_DATA_INIT
- }
- void VbOpts::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(VbOpts)
- DDX_Text(pDX, IDC_VBOID, m_vboid);
- DDV_MaxChars(pDX, m_vboid, 200);
- DDX_Text(pDX, IDC_VBVALUE, m_vbvalue);
- DDV_MaxChars(pDX, m_vbvalue, 200);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(VbOpts, CDialog)
- //{{AFX_MSG_MAP(VbOpts)
- ON_BN_CLICKED(IDCONTINUE, OnContinue)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // VbOpts message handlers
- BOOL VbOpts::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // TODO: Add extra initialization here
- CheckRadioButton( IDC_RADIO_OCTETSTR, IDC_RADIO_UINT32, IDC_RADIO_OCTETSTR);
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- void VbOpts::OnContinue()
- {
- // TODO: Add your control notification handler code here
- UpdateData( TRUE);
- // verify that the oid is correct
- Oid oid( m_vboid);
- if ( !oid.valid())
- {
- AfxMessageBox("Invalid VB Oid Portion!");
- return;
- }
- // set the oid portion
- my_vb.set_oid( oid);
- // verify that the value is correct based on the type selected
- int option = GetCheckedRadioButton( IDC_RADIO_OCTETSTR, IDC_RADIO_UINT32);
- switch ( option) {
- // octet string
- case IDC_RADIO_OCTETSTR:
- {
- OctetStr octetstr( m_vbvalue);
- if ( !octetstr.valid())
- {
- AfxMessageBox("Invalid Octet String Value!");
- return;
- }
- else
- my_vb.set_value( octetstr);
- }
- break;
- // oid
- case IDC_RADIO_OID:
- {
- Oid oid( m_vbvalue);
- if ( !oid.valid())
- {
- AfxMessageBox("Invalid Oid Value!");
- return;
- }
- else
- my_vb.set_value( oid);
- }
- break;
- // counter32
- case IDC_RADIO_COUNTER32:
- {
- unsigned long v;
- if ( !string_to_long( m_vbvalue, v))
- {
- AfxMessageBox("Invalid Counter32 Value!");
- return;
- }
- Counter32 counter32( v);
- if ( !counter32.valid())
- {
- AfxMessageBox("Invalid Counter32 Value!");
- return;
- }
- else
- my_vb.set_value( counter32);
- }
- break;
- // gauge32
- case IDC_RADIO_GAUGE32:
- {
- unsigned long v;
- if ( !string_to_long( m_vbvalue, v))
- {
- AfxMessageBox("Invalid Gauge32 Value!");
- return;
- }
- Gauge32 gauge32( v);
- if ( !gauge32.valid())
- {
- AfxMessageBox("Invalid Gauge32 Value!");
- return;
- }
- else
- my_vb.set_value( gauge32);
- }
- break;
- // timeticks
- case IDC_RADIO_TIMETICKS:
- {
- unsigned long t;
- if ( !string_to_long( m_vbvalue, t))
- {
- AfxMessageBox("Invalid TimeTicks Value!");
- return;
- }
- TimeTicks timeticks( t);
- if ( !timeticks.valid())
- {
- AfxMessageBox("Invalid TimeTicks Value!");
- return;
- }
- else
- my_vb.set_value( timeticks);
- }
- break;
- // ip address
- case IDC_RADIO_IPADDRESS:
- {
- IpAddress ip( m_vbvalue);
- if ( ! ip.valid())
- {
- AfxMessageBox("Invalid IP Address Value!");
- return;
- }
- else
- my_vb.set_value( ip);
- }
- break;
- // unsigned int32
- case IDC_RADIO_INT32:
- {
- unsigned long i;
- if ( ! string_to_long( m_vbvalue, (unsigned long) i))
- {
- AfxMessageBox("Invalid Integer Value!");
- return;
- }
- else
- my_vb.set_value( (long int) i);
- }
- break;
- // int32
- case IDC_RADIO_UINT32:
- {
- unsigned long int i;
- if ( ! string_to_long( m_vbvalue,i)) {
- AfxMessageBox("Invalid Unsigned Integer Value!");
- return;
- }
- else
- my_vb.set_value( (unsigned long int) i);
- }
- break;
- };
- UpdateData( TRUE);
- OnCancel();
- }
- int VbOpts::DoModal()
- {
- // TODO: Add your specialized code here and/or call the base class
- return CDialog::DoModal();
- }