-
Notifications
You must be signed in to change notification settings - Fork 2
/
DlgGetIP.cpp
executable file
·69 lines (55 loc) · 1.48 KB
/
DlgGetIP.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// DlgGetIP.cpp : implementation file
//
#include "stdafx.h"
#include "HuiReversi.h"
#include "DlgGetIP.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDlgGetIP dialog
CDlgGetIP::CDlgGetIP(CWnd* pParent /*=NULL*/)
: CDialog(CDlgGetIP::IDD, pParent)
{
//{{AFX_DATA_INIT(CDlgGetIP)
m_strIP = _T("");
//}}AFX_DATA_INIT
}
void CDlgGetIP::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgGetIP)
DDX_Text(pDX, IDC_IP, m_strIP);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDlgGetIP, CDialog)
//{{AFX_MSG_MAP(CDlgGetIP)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDlgGetIP message handlers
void CDlgGetIP::OnOK()
{
CDialog::OnOK();
}
BOOL CDlgGetIP::OnInitDialog()
{
CDialog::OnInitDialog();
// 设置IP地址
char szHostName[128];
struct hostent * pHost;
if( gethostname(szHostName, 128) == 0 )
{
pHost = gethostbyname(szHostName);
m_strIP = inet_ntoa (*(struct in_addr *)pHost->h_addr_list[0]);
UpdateData(FALSE);
}
// 设定焦点,选中IP地址字符串
CEdit * pEdit = (CEdit *)GetDlgItem(IDC_IP);
pEdit->SetFocus();
pEdit->SetSel(0, -1);
return FALSE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}