/[H8]/trunk/test-server/test-serverDlg.cpp
ViewVC logotype

Contents of /trunk/test-server/test-serverDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 112 - (show annotations) (download)
Mon May 28 16:28:03 2007 UTC (16 years, 11 months ago) by torben
File size: 4565 byte(s)
Now we have a working test-server...
1 // test-serverDlg.cpp : implementation file
2 //
3
4 #include "stdafx.h"
5 #include "test-server.h"
6 #include "test-serverDlg.h"
7 #include ".\test-serverdlg.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 // CtestserverDlg dialog
46
47
48
49 CtestserverDlg::CtestserverDlg(CWnd* pParent /*=NULL*/)
50 : CDialog(CtestserverDlg::IDD, pParent)
51 {
52 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
53 }
54
55 void CtestserverDlg::DoDataExchange(CDataExchange* pDX)
56 {
57 CDialog::DoDataExchange(pDX);
58 DDX_Control(pDX, IDC_EDIT, m_edit);
59 }
60
61 BEGIN_MESSAGE_MAP(CtestserverDlg, CDialog)
62 ON_WM_SYSCOMMAND()
63 ON_WM_PAINT()
64 ON_WM_QUERYDRAGICON()
65 //}}AFX_MSG_MAP
66 END_MESSAGE_MAP()
67
68
69 // CtestserverDlg message handlers
70
71 BOOL CtestserverDlg::OnInitDialog()
72 {
73 CDialog::OnInitDialog();
74
75 // Add "About..." menu item to system menu.
76
77 // IDM_ABOUTBOX must be in the system command range.
78 ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
79 ASSERT(IDM_ABOUTBOX < 0xF000);
80
81 CMenu* pSysMenu = GetSystemMenu(FALSE);
82 if (pSysMenu != NULL)
83 {
84 CString strAboutMenu;
85 strAboutMenu.LoadString(IDS_ABOUTBOX);
86 if (!strAboutMenu.IsEmpty())
87 {
88 pSysMenu->AppendMenu(MF_SEPARATOR);
89 pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
90 }
91 }
92
93 // Set the icon for this dialog. The framework does this automatically
94 // when the application's main window is not a dialog
95 SetIcon(m_hIcon, TRUE); // Set big icon
96 SetIcon(m_hIcon, FALSE); // Set small icon
97
98 // TODO: Add extra initialization here
99 m_server.connectionReady.connect(this, CtestserverDlg::AcceptConnection);
100 m_worker.dataRecieved.connect(this, CtestserverDlg::UpdateDisplay);
101
102
103 if (m_server.Create(3000))
104 {
105 WriteLine("Created");
106
107 if (m_server.Listen())
108 {
109 WriteLine("Listening on port 3000");
110 }
111 else
112 {
113 WriteLine("not listening");
114 }
115 }
116 else
117 {
118 int errcode = m_server.GetLastError();
119
120 CString message;
121 message.Format("Could note create socket : %d", errcode);
122 MessageBox(message);
123 }
124
125
126 return TRUE; // return TRUE unless you set the focus to a control
127 }
128
129 void CtestserverDlg::OnSysCommand(UINT nID, LPARAM lParam)
130 {
131 if ((nID & 0xFFF0) == IDM_ABOUTBOX)
132 {
133 CAboutDlg dlgAbout;
134 dlgAbout.DoModal();
135 }
136 else
137 {
138 CDialog::OnSysCommand(nID, lParam);
139 }
140 }
141
142 // If you add a minimize button to your dialog, you will need the code below
143 // to draw the icon. For MFC applications using the document/view model,
144 // this is automatically done for you by the framework.
145
146 void CtestserverDlg::OnPaint()
147 {
148 if (IsIconic())
149 {
150 CPaintDC dc(this); // device context for painting
151
152 SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
153
154 // Center icon in client rectangle
155 int cxIcon = GetSystemMetrics(SM_CXICON);
156 int cyIcon = GetSystemMetrics(SM_CYICON);
157 CRect rect;
158 GetClientRect(&rect);
159 int x = (rect.Width() - cxIcon + 1) / 2;
160 int y = (rect.Height() - cyIcon + 1) / 2;
161
162 // Draw the icon
163 dc.DrawIcon(x, y, m_hIcon);
164 }
165 else
166 {
167 CDialog::OnPaint();
168 }
169 }
170
171 // The system calls this function to obtain the cursor to display while the user drags
172 // the minimized window.
173 HCURSOR CtestserverDlg::OnQueryDragIcon()
174 {
175 return static_cast<HCURSOR>(m_hIcon);
176 }
177
178 void CtestserverDlg::AcceptConnection(void)
179 {
180 CString tmp,addr;
181 unsigned int port;
182 m_server.Accept(m_worker);
183
184 m_worker.GetPeerName(addr,port);
185
186 tmp.Format("Accepted connection from %s:%d",addr,port);
187 WriteLine(tmp);
188
189 m_worker.m_isOpen = true;
190 }
191
192 void CtestserverDlg::UpdateDisplay(void)
193 {
194 WriteLine(m_worker.GetMessage());
195 }
196
197 void CtestserverDlg::WriteLine(CString msg)
198 {
199 CString message;
200 m_edit.GetWindowText(message);
201 message += msg;
202 message += "\r\n";
203
204 m_edit.SetWindowText(message);
205
206 int lineCount = m_edit.GetLineCount();
207 m_edit.LineScroll(lineCount);
208
209 }
210
211
212 void CtestserverDlg::OnCancel()
213 {
214
215 m_server.Close();
216
217 if (m_worker.m_isOpen)
218 m_worker.Close();
219
220 CDialog::OnCancel();
221 }

  ViewVC Help
Powered by ViewVC 1.1.20