-rw-r--r-- | GeneralPage.cpp | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/GeneralPage.cpp b/GeneralPage.cpp new file mode 100644 index 0000000..78863fc --- a/dev/null +++ b/GeneralPage.cpp | |||
@@ -0,0 +1,100 @@ | |||
1 | // GeneralPage.cpp : implementation file | ||
2 | // | ||
3 | |||
4 | #include "stdafx.h" | ||
5 | #include "T42.h" | ||
6 | #include "GeneralPage.h" | ||
7 | |||
8 | #ifdef _DEBUG | ||
9 | #define new DEBUG_NEW | ||
10 | #undef THIS_FILE | ||
11 | static char THIS_FILE[] = __FILE__; | ||
12 | #endif | ||
13 | |||
14 | ///////////////////////////////////////////////////////////////////////////// | ||
15 | // CGeneralPage property page | ||
16 | |||
17 | IMPLEMENT_DYNCREATE(CGeneralPage, CPropertyPage) | ||
18 | |||
19 | CGeneralPage::CGeneralPage() : CPropertyPage(CGeneralPage::IDD) | ||
20 | { | ||
21 | //{{AFX_DATA_INIT(CGeneralPage) | ||
22 | //}}AFX_DATA_INIT | ||
23 | m_ntalkPort = 518; | ||
24 | } | ||
25 | |||
26 | CGeneralPage::~CGeneralPage() | ||
27 | { | ||
28 | } | ||
29 | |||
30 | void CGeneralPage::DoDataExchange(CDataExchange* pDX) | ||
31 | { | ||
32 | CPropertyPage::DoDataExchange(pDX); | ||
33 | //{{AFX_DATA_MAP(CGeneralPage) | ||
34 | DDX_Control(pDX, IDC_NTALKPORTSPIN, m_ntalkSpinCtl); | ||
35 | DDX_Control(pDX, IDC_NTALKPORT, m_ntalkPortCtl); | ||
36 | //}}AFX_DATA_MAP | ||
37 | if(pDX->m_bSaveAndValidate){ | ||
38 | pDX->PrepareEditCtrl(IDC_NTALKPORT); | ||
39 | CString ntp; | ||
40 | m_ntalkPortCtl.GetWindowText(ntp); | ||
41 | UINT p = atoi(ntp); | ||
42 | if(!p){ | ||
43 | servent* se = getservbyname((LPCTSTR)ntp,"udp"); | ||
44 | if(se) | ||
45 | p = ntohs(se->s_port); | ||
46 | else{ | ||
47 | AfxMessageBox(IDS_FAILVALIDATE_NTALKPORT,MB_OK|MB_ICONSTOP); | ||
48 | pDX->Fail(); | ||
49 | return; | ||
50 | } | ||
51 | } | ||
52 | m_ntalkPort = p; | ||
53 | } | ||
54 | } | ||
55 | |||
56 | |||
57 | BEGIN_MESSAGE_MAP(CGeneralPage, CPropertyPage) | ||
58 | //{{AFX_MSG_MAP(CGeneralPage) | ||
59 | ON_NOTIFY(UDN_DELTAPOS, IDC_NTALKPORTSPIN, OnDeltaposNtalkportspin) | ||
60 | //}}AFX_MSG_MAP | ||
61 | END_MESSAGE_MAP() | ||
62 | |||
63 | ///////////////////////////////////////////////////////////////////////////// | ||
64 | // CGeneralPage message handlers | ||
65 | |||
66 | BOOL CGeneralPage::OnInitDialog() | ||
67 | { | ||
68 | CPropertyPage::OnInitDialog(); | ||
69 | |||
70 | m_ntalkSpinCtl.SetRange(1,min(UD_MAXVAL,65535)); | ||
71 | m_ntalkSpinCtl.SetPos(m_ntalkPort); | ||
72 | SetPortCtl(); | ||
73 | |||
74 | return TRUE; // return TRUE unless you set the focus to a control | ||
75 | // EXCEPTION: OCX Property Pages should return FALSE | ||
76 | } | ||
77 | |||
78 | void CGeneralPage::SetPortCtl() | ||
79 | { | ||
80 | servent* se = getservbyport(htons(m_ntalkPort),"udp"); | ||
81 | if(se) | ||
82 | m_ntalkPortCtl.SetWindowText(se->s_name); | ||
83 | else{ | ||
84 | CString tmp; | ||
85 | tmp.Format("%u",m_ntalkPort); | ||
86 | m_ntalkPortCtl.SetWindowText(tmp); | ||
87 | } | ||
88 | } | ||
89 | |||
90 | void CGeneralPage::OnDeltaposNtalkportspin(NMHDR* pNMHDR, LRESULT* pResult) | ||
91 | { | ||
92 | NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR; | ||
93 | |||
94 | TRACE3("UD iP %d, iD %d, p %d\n",pNMUpDown->iPos, | ||
95 | pNMUpDown->iDelta, m_ntalkSpinCtl.GetPos()); | ||
96 | m_ntalkPort = pNMUpDown->iPos+pNMUpDown->iDelta; | ||
97 | SetPortCtl(); | ||
98 | |||
99 | *pResult = 0; | ||
100 | } | ||