dlgipaddresswithsubnet.cpp

来自「ftpserver very good sample」· C++ 代码 · 共 96 行

CPP
96
字号
// DlgIpAddressWithSubnet.cpp : implementation file//#include "stdafx.h"#include "warmmcsnapin.h"#include "DlgIpAddressWithSubnet.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif/////////////////////////////////////////////////////////////////////////////// CDlgIpAddressWithSubnet dialogCDlgIpAddressWithSubnet::CDlgIpAddressWithSubnet(CWnd* pParent /*=NULL*/)	: CDialog(CDlgIpAddressWithSubnet::IDD, pParent){	//{{AFX_DATA_INIT(CDlgIpAddressWithSubnet)	m_Subnet = 0;	//}}AFX_DATA_INIT    mIpAddress.s_addr = 0;    mIpMask.s_addr = 0;}void CDlgIpAddressWithSubnet::DoDataExchange(CDataExchange* pDX){	CDialog::DoDataExchange(pDX);	//{{AFX_DATA_MAP(CDlgIpAddressWithSubnet)	DDX_Control(pDX, IDC_IPADDRESS1, m_ctlIpAddress);	DDX_CBIndex(pDX, IDC_SUBNET, m_Subnet);	//}}AFX_DATA_MAP}BEGIN_MESSAGE_MAP(CDlgIpAddressWithSubnet, CDialog)	//{{AFX_MSG_MAP(CDlgIpAddressWithSubnet)	//}}AFX_MSG_MAPEND_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// CDlgIpAddressWithSubnet message handlersvoid CDlgIpAddressWithSubnet::OnOK() {    UpdateData();    DWORD ip_addr = 0;    m_ctlIpAddress.GetAddress(ip_addr);    mIpAddress.s_addr = ntohl(ip_addr);    if (0 != m_Subnet)        mIpMask.s_addr = ntohl(0xffffffff << (32 - m_Subnet));    else        mIpMask.s_addr = 0xffffffff;		CDialog::OnOK();}BOOL CDlgIpAddressWithSubnet::OnInitDialog() {    // Initialize subnet index    if (mIpMask.s_addr == 0xffffffff)        m_Subnet = 0;    else     {        struct in_addr test_addr;        test_addr.s_addr = 0;        for(m_Subnet = 1;; m_Subnet++)        {            test_addr.s_addr = ntohl(0xffffffff << (32 - m_Subnet));            if (test_addr.s_addr == mIpMask.s_addr)                break;            if (m_Subnet > 30)            {                m_Subnet = 0;                break; // Invalid value            }        }    }    CDialog::OnInitDialog();    m_ctlIpAddress.SetAddress(htonl(mIpAddress.s_addr));		return TRUE;  // return TRUE unless you set the focus to a control	              // EXCEPTION: OCX Property Pages should return FALSE}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?