/[H7]/trunk/Client/ClientDlg.cpp
ViewVC logotype

Contents of /trunk/Client/ClientDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 9 - (show annotations) (download)
Mon Jan 29 15:07:29 2007 UTC (17 years, 3 months ago) by kevin
File size: 5904 byte(s)
Updated client piece, need some stuff to get the ip connection running
1 // 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 ON_BN_CLICKED(IDC_Connect, OnBnClickedConnect)
76 END_MESSAGE_MAP()
77
78
79 // CClientDlg message handlers
80 /*Client socket class*/
81 class ClientSocket : public CSocket{
82 public:
83 ClientSocket() { };
84 virtual void OnReceive(int nErrorCode);
85 virtual void OnSend(int nErrorCode);
86 virtual void OnConnect(int nErrorCode);
87 };
88 BOOL CClientDlg::OnInitDialog()
89 {
90 CDialog::OnInitDialog();
91
92 // Add "About..." menu item to system menu.
93
94 // IDM_ABOUTBOX must be in the system command range.
95 ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
96 ASSERT(IDM_ABOUTBOX < 0xF000);
97
98 CMenu* pSysMenu = GetSystemMenu(FALSE);
99 if (pSysMenu != NULL)
100 {
101 CString strAboutMenu;
102 strAboutMenu.LoadString(IDS_ABOUTBOX);
103 if (!strAboutMenu.IsEmpty())
104 {
105 pSysMenu->AppendMenu(MF_SEPARATOR);
106 pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
107 }
108 }
109
110 // Set the icon for this dialog. The framework does this automatically
111 // when the application's main window is not a dialog
112 SetIcon(m_hIcon, TRUE); // Set big icon
113 SetIcon(m_hIcon, FALSE); // Set small icon
114
115 // TODO: Add extra initialization here
116
117 // Get data from regedit
118 CString strip, strport;
119 char Ip[16];
120 char Port[6];
121 CRegKey reg;
122 unsigned long size = 16;
123 LONG res=reg.Open(HKEY_LOCAL_MACHINE, "SOFTWARE\\Projekt\\Client",KEY_READ);
124
125 if (res == ERROR_SUCCESS)
126 {
127 res=reg.QueryStringValue("IP", Ip,&size);
128 }
129 m_ip.SetWindowText(Ip);
130 LONG res2=reg.Open(HKEY_LOCAL_MACHINE, "SOFTWARE\\Projekt\\Client",KEY_READ);
131
132 if (res2 == ERROR_SUCCESS)
133 {
134 res2=reg.QueryStringValue("Port", Port,&size);
135 }
136 m_port.SetWindowText(Port);
137 reg.Close();
138
139 //connect til server
140 // Start();
141
142 return TRUE; // return TRUE unless you set the focus to a control
143 }
144
145 void CClientDlg::OnSysCommand(UINT nID, LPARAM lParam)
146 {
147 if ((nID & 0xFFF0) == IDM_ABOUTBOX)
148 {
149 CAboutDlg dlgAbout;
150 dlgAbout.DoModal();
151 }
152 else
153 {
154 CDialog::OnSysCommand(nID, lParam);
155 }
156 }
157
158 // If you add a minimize button to your dialog, you will need the code below
159 // to draw the icon. For MFC applications using the document/view model,
160 // this is automatically done for you by the framework.
161
162 void CClientDlg::OnPaint()
163 {
164 if (IsIconic())
165 {
166 CPaintDC dc(this); // device context for painting
167
168 SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
169
170 // Center icon in client rectangle
171 int cxIcon = GetSystemMetrics(SM_CXICON);
172 int cyIcon = GetSystemMetrics(SM_CYICON);
173 CRect rect;
174 GetClientRect(&rect);
175 int x = (rect.Width() - cxIcon + 1) / 2;
176 int y = (rect.Height() - cyIcon + 1) / 2;
177
178 // Draw the icon
179 dc.DrawIcon(x, y, m_hIcon);
180 }
181 else
182 {
183 CDialog::OnPaint();
184 }
185 }
186
187 // The system calls this function to obtain the cursor to display while the user drags
188 // the minimized window.
189 HCURSOR CClientDlg::OnQueryDragIcon()
190 {
191 return static_cast<HCURSOR>(m_hIcon);
192 }
193
194
195 ClientSocket sockClient;
196 CString strIp, strPort;
197 UINT Portuint;
198
199 /*Clientsocket class used for client socket connections*/
200 void ClientSocket::OnReceive( int nErrorCode )
201 {
202 CString ip;
203 UINT port;
204 char buffer[4096];
205 CString str;
206 int size;
207
208 str.Format("%s %d",ip,port,"");
209 size = Receive(buffer,4095);
210 buffer[size] = 0;
211 // Recivetekst = buffer; recivetekst er der ikke endnu
212 //Send(str,str.GetLength()); vi skal ikke sende endnu
213 Close();
214 }
215 void ClientSocket::OnSend( int nErrorCode )
216 {
217 // CString sendnu; skal ikke sende nu
218
219 // sendnu = Sendtekst; skal ikke sende nu
220
221 // Send(sendnu,sendnu.GetLength()); skal ikke sende nu
222 }
223 void CClientDlg::OnBnClickedIpport()
224 {
225 //Set new port and ip for the server in regedit
226 m_ip.GetWindowText(strIp);
227 m_port.GetWindowText(strPort);
228 CRegKey reg;
229 reg.Create(HKEY_LOCAL_MACHINE, "SOFTWARE\\Projekt\\Client");
230 reg.SetStringValue("","Project-data");
231 reg.Create(HKEY_LOCAL_MACHINE, "SOFTWARE\\Projekt\\Client");
232 reg.SetStringValue("IP",strIp);
233 reg.Create(HKEY_LOCAL_MACHINE, "SOFTWARE\\Projekt\\Client");
234 reg.SetStringValue("Port",strPort);
235 reg.Close();
236 }
237
238 void ClientSocket::OnConnect(int nErrorCode)
239 {
240 // TODO: Add your specialized code here and/or call the base class
241 strPort.Format("%d",Portuint);
242 sockClient.Connect(strIp,Portuint);
243
244 CSocket::OnConnect(nErrorCode);
245 }
246 void Start()
247 {
248
249 }
250 void CClientDlg::OnBnClickedConnect()
251 {
252 Start();
253 }

  ViewVC Help
Powered by ViewVC 1.1.20