1 |
kevin |
4 |
// ClientDlg.cpp : implementation file
|
2 |
|
|
//
|
3 |
|
|
|
4 |
|
|
#include "stdafx.h"
|
5 |
|
|
#include "Client.h"
|
6 |
|
|
#include "ClientDlg.h"
|
7 |
|
|
#include ".\clientdlg.h"
|
8 |
|
|
|
9 |
|
|
#ifdef _DEBUG
|
10 |
|
|
#define new DEBUG_NEW
|
11 |
|
|
#endif
|
12 |
|
|
|
13 |
|
|
|
14 |
|
|
// CAboutDlg dialog used for App About
|
15 |
|
|
|
16 |
|
|
class CAboutDlg : public CDialog
|
17 |
|
|
{
|
18 |
|
|
public:
|
19 |
|
|
CAboutDlg();
|
20 |
|
|
|
21 |
|
|
// Dialog Data
|
22 |
|
|
enum { IDD = IDD_ABOUTBOX };
|
23 |
|
|
|
24 |
|
|
protected:
|
25 |
|
|
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
|
26 |
|
|
|
27 |
|
|
// Implementation
|
28 |
|
|
protected:
|
29 |
|
|
DECLARE_MESSAGE_MAP()
|
30 |
|
|
};
|
31 |
|
|
|
32 |
|
|
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
|
33 |
|
|
{
|
34 |
|
|
}
|
35 |
|
|
|
36 |
|
|
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
|
37 |
|
|
{
|
38 |
|
|
CDialog::DoDataExchange(pDX);
|
39 |
|
|
}
|
40 |
|
|
|
41 |
|
|
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
|
42 |
|
|
END_MESSAGE_MAP()
|
43 |
|
|
|
44 |
|
|
|
45 |
|
|
// CClientDlg dialog
|
46 |
|
|
|
47 |
|
|
|
48 |
|
|
|
49 |
|
|
CClientDlg::CClientDlg(CWnd* pParent /*=NULL*/)
|
50 |
|
|
: CDialog(CClientDlg::IDD, pParent)
|
51 |
|
|
{
|
52 |
|
|
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
|
53 |
|
|
}
|
54 |
|
|
|
55 |
|
|
void CClientDlg::DoDataExchange(CDataExchange* pDX)
|
56 |
|
|
{
|
57 |
|
|
CDialog::DoDataExchange(pDX);
|
58 |
|
|
DDX_Control(pDX, IDC_LED1, m_led1);
|
59 |
|
|
DDX_Control(pDX, IDC_LED2, m_led2);
|
60 |
|
|
DDX_Control(pDX, IDC_LED3, m_led3);
|
61 |
|
|
DDX_Control(pDX, IDC_KNAP1, m_knap1);
|
62 |
|
|
DDX_Control(pDX, IDC_KNAP2, m_knap2);
|
63 |
|
|
DDX_Control(pDX, IDC_TEMP, m_temp);
|
64 |
|
|
DDX_Control(pDX, IDC_POT, m_pot);
|
65 |
|
|
DDX_Control(pDX, IDC_IPADDRESS1, m_ip);
|
66 |
|
|
DDX_Control(pDX, IDC_PORT, m_port);
|
67 |
|
|
}
|
68 |
|
|
|
69 |
|
|
BEGIN_MESSAGE_MAP(CClientDlg, CDialog)
|
70 |
|
|
ON_WM_SYSCOMMAND()
|
71 |
|
|
ON_WM_PAINT()
|
72 |
|
|
ON_WM_QUERYDRAGICON()
|
73 |
|
|
//}}AFX_MSG_MAP
|
74 |
|
|
ON_BN_CLICKED(IDC_IPPORT, OnBnClickedIpport)
|
75 |
|
|
END_MESSAGE_MAP()
|
76 |
|
|
|
77 |
|
|
|
78 |
|
|
// CClientDlg message handlers
|
79 |
|
|
|
80 |
|
|
BOOL CClientDlg::OnInitDialog()
|
81 |
|
|
{
|
82 |
|
|
CDialog::OnInitDialog();
|
83 |
|
|
|
84 |
|
|
// Add "About..." menu item to system menu.
|
85 |
|
|
|
86 |
|
|
// IDM_ABOUTBOX must be in the system command range.
|
87 |
|
|
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
|
88 |
|
|
ASSERT(IDM_ABOUTBOX < 0xF000);
|
89 |
|
|
|
90 |
|
|
CMenu* pSysMenu = GetSystemMenu(FALSE);
|
91 |
|
|
if (pSysMenu != NULL)
|
92 |
|
|
{
|
93 |
|
|
CString strAboutMenu;
|
94 |
|
|
strAboutMenu.LoadString(IDS_ABOUTBOX);
|
95 |
|
|
if (!strAboutMenu.IsEmpty())
|
96 |
|
|
{
|
97 |
|
|
pSysMenu->AppendMenu(MF_SEPARATOR);
|
98 |
|
|
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
|
99 |
|
|
}
|
100 |
|
|
}
|
101 |
|
|
|
102 |
|
|
// Set the icon for this dialog. The framework does this automatically
|
103 |
|
|
// when the application's main window is not a dialog
|
104 |
|
|
SetIcon(m_hIcon, TRUE); // Set big icon
|
105 |
|
|
SetIcon(m_hIcon, FALSE); // Set small icon
|
106 |
|
|
|
107 |
|
|
// TODO: Add extra initialization here
|
108 |
|
|
CString strip, strport;
|
109 |
|
|
char Ip[16];
|
110 |
|
|
char Port[6];
|
111 |
|
|
CRegKey reg;
|
112 |
|
|
unsigned long size = 16;
|
113 |
|
|
LONG res=reg.Open(HKEY_CLASSES_ROOT,"Project",KEY_READ);
|
114 |
|
|
|
115 |
|
|
if (res == ERROR_SUCCESS)
|
116 |
|
|
{
|
117 |
|
|
res=reg.QueryStringValue("IP", Ip,&size);
|
118 |
|
|
}
|
119 |
|
|
m_ip.SetWindowText(Ip);
|
120 |
|
|
LONG res2=reg.Open(HKEY_CLASSES_ROOT,"Project",KEY_READ);
|
121 |
|
|
|
122 |
|
|
if (res2 == ERROR_SUCCESS)
|
123 |
|
|
{
|
124 |
|
|
res2=reg.QueryStringValue("Port", Port,&size);
|
125 |
|
|
}
|
126 |
|
|
m_port.SetWindowText(Port);
|
127 |
|
|
reg.Close();
|
128 |
|
|
|
129 |
|
|
|
130 |
|
|
|
131 |
|
|
|
132 |
|
|
return TRUE; // return TRUE unless you set the focus to a control
|
133 |
|
|
}
|
134 |
|
|
|
135 |
|
|
void CClientDlg::OnSysCommand(UINT nID, LPARAM lParam)
|
136 |
|
|
{
|
137 |
|
|
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
|
138 |
|
|
{
|
139 |
|
|
CAboutDlg dlgAbout;
|
140 |
|
|
dlgAbout.DoModal();
|
141 |
|
|
}
|
142 |
|
|
else
|
143 |
|
|
{
|
144 |
|
|
CDialog::OnSysCommand(nID, lParam);
|
145 |
|
|
}
|
146 |
|
|
}
|
147 |
|
|
|
148 |
|
|
// If you add a minimize button to your dialog, you will need the code below
|
149 |
|
|
// to draw the icon. For MFC applications using the document/view model,
|
150 |
|
|
// this is automatically done for you by the framework.
|
151 |
|
|
|
152 |
|
|
void CClientDlg::OnPaint()
|
153 |
|
|
{
|
154 |
|
|
if (IsIconic())
|
155 |
|
|
{
|
156 |
|
|
CPaintDC dc(this); // device context for painting
|
157 |
|
|
|
158 |
|
|
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
|
159 |
|
|
|
160 |
|
|
// Center icon in client rectangle
|
161 |
|
|
int cxIcon = GetSystemMetrics(SM_CXICON);
|
162 |
|
|
int cyIcon = GetSystemMetrics(SM_CYICON);
|
163 |
|
|
CRect rect;
|
164 |
|
|
GetClientRect(&rect);
|
165 |
|
|
int x = (rect.Width() - cxIcon + 1) / 2;
|
166 |
|
|
int y = (rect.Height() - cyIcon + 1) / 2;
|
167 |
|
|
|
168 |
|
|
// Draw the icon
|
169 |
|
|
dc.DrawIcon(x, y, m_hIcon);
|
170 |
|
|
}
|
171 |
|
|
else
|
172 |
|
|
{
|
173 |
|
|
CDialog::OnPaint();
|
174 |
|
|
}
|
175 |
|
|
}
|
176 |
|
|
|
177 |
|
|
// The system calls this function to obtain the cursor to display while the user drags
|
178 |
|
|
// the minimized window.
|
179 |
|
|
HCURSOR CClientDlg::OnQueryDragIcon()
|
180 |
|
|
{
|
181 |
|
|
return static_cast<HCURSOR>(m_hIcon);
|
182 |
|
|
}
|
183 |
|
|
|
184 |
|
|
|
185 |
|
|
void CClientDlg::OnBnClickedIpport()
|
186 |
|
|
{
|
187 |
|
|
CString Ip, Port;
|
188 |
|
|
m_ip.GetWindowText(Ip);
|
189 |
|
|
m_port.GetWindowText(Port);
|
190 |
|
|
CRegKey reg;
|
191 |
|
|
reg.Create(HKEY_CLASSES_ROOT, "Project");
|
192 |
|
|
reg.SetStringValue("","Project-data");
|
193 |
|
|
reg.Create(HKEY_CLASSES_ROOT, "Project");
|
194 |
|
|
reg.SetStringValue("IP",Ip);
|
195 |
|
|
reg.Create(HKEY_CLASSES_ROOT, "Project");
|
196 |
|
|
reg.SetStringValue("Port",Port);
|
197 |
|
|
reg.Close();
|
198 |
|
|
}
|