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

Annotation of /trunk/Client/ClientDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 12 - (hide annotations) (download)
Mon Jan 29 20:10:02 2007 UTC (17 years, 4 months ago) by kevin
File size: 6145 byte(s)
min spand fucker, men regner med tcp/ip connection køre nu
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 kevin 12
14     CString Ip;
15     unsigned long Port;
16 kevin 4
17     // CAboutDlg dialog used for App About
18    
19     class CAboutDlg : public CDialog
20     {
21     public:
22     CAboutDlg();
23    
24     // Dialog Data
25     enum { IDD = IDD_ABOUTBOX };
26    
27     protected:
28     virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
29    
30     // Implementation
31     protected:
32     DECLARE_MESSAGE_MAP()
33     };
34    
35     CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
36     {
37     }
38    
39     void CAboutDlg::DoDataExchange(CDataExchange* pDX)
40     {
41     CDialog::DoDataExchange(pDX);
42     }
43    
44     BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
45     END_MESSAGE_MAP()
46    
47    
48     // CClientDlg dialog
49    
50    
51     CClientDlg::CClientDlg(CWnd* pParent /*=NULL*/)
52     : CDialog(CClientDlg::IDD, pParent)
53     {
54     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
55     }
56    
57     void CClientDlg::DoDataExchange(CDataExchange* pDX)
58     {
59     CDialog::DoDataExchange(pDX);
60     DDX_Control(pDX, IDC_LED1, m_led1);
61     DDX_Control(pDX, IDC_LED2, m_led2);
62     DDX_Control(pDX, IDC_LED3, m_led3);
63     DDX_Control(pDX, IDC_KNAP1, m_knap1);
64     DDX_Control(pDX, IDC_KNAP2, m_knap2);
65     DDX_Control(pDX, IDC_TEMP, m_temp);
66     DDX_Control(pDX, IDC_POT, m_pot);
67     DDX_Control(pDX, IDC_IPADDRESS1, m_ip);
68     DDX_Control(pDX, IDC_PORT, m_port);
69     }
70    
71     BEGIN_MESSAGE_MAP(CClientDlg, CDialog)
72     ON_WM_SYSCOMMAND()
73     ON_WM_PAINT()
74     ON_WM_QUERYDRAGICON()
75     //}}AFX_MSG_MAP
76     ON_BN_CLICKED(IDC_IPPORT, OnBnClickedIpport)
77 kevin 9 ON_BN_CLICKED(IDC_Connect, OnBnClickedConnect)
78 kevin 4 END_MESSAGE_MAP()
79    
80    
81     // CClientDlg message handlers
82 kevin 9 /*Client socket class*/
83     class ClientSocket : public CSocket{
84     public:
85     ClientSocket() { };
86     virtual void OnReceive(int nErrorCode);
87     virtual void OnSend(int nErrorCode);
88     virtual void OnConnect(int nErrorCode);
89     };
90 kevin 4 BOOL CClientDlg::OnInitDialog()
91     {
92     CDialog::OnInitDialog();
93    
94     // Add "About..." menu item to system menu.
95    
96     // IDM_ABOUTBOX must be in the system command range.
97     ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
98     ASSERT(IDM_ABOUTBOX < 0xF000);
99    
100     CMenu* pSysMenu = GetSystemMenu(FALSE);
101     if (pSysMenu != NULL)
102     {
103     CString strAboutMenu;
104     strAboutMenu.LoadString(IDS_ABOUTBOX);
105     if (!strAboutMenu.IsEmpty())
106     {
107     pSysMenu->AppendMenu(MF_SEPARATOR);
108     pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
109     }
110     }
111    
112     // Set the icon for this dialog. The framework does this automatically
113     // when the application's main window is not a dialog
114     SetIcon(m_hIcon, TRUE); // Set big icon
115     SetIcon(m_hIcon, FALSE); // Set small icon
116    
117     // TODO: Add extra initialization here
118 kevin 9
119     // Get data from regedit
120 kevin 4 CString strip, strport;
121 kevin 12 char chaip[16];
122 kevin 4 CRegKey reg;
123     unsigned long size = 16;
124 kevin 9 LONG res=reg.Open(HKEY_LOCAL_MACHINE, "SOFTWARE\\Projekt\\Client",KEY_READ);
125 kevin 4
126     if (res == ERROR_SUCCESS)
127     {
128 kevin 12 res=reg.QueryStringValue("IP", chaip, &size);
129 kevin 4 }
130 kevin 12 Ip = chaip;
131 kevin 4 m_ip.SetWindowText(Ip);
132 kevin 9 LONG res2=reg.Open(HKEY_LOCAL_MACHINE, "SOFTWARE\\Projekt\\Client",KEY_READ);
133 kevin 4
134     if (res2 == ERROR_SUCCESS)
135     {
136 kevin 12 res2=reg.QueryDWORDValue("Port", Port);
137 kevin 4 }
138 kevin 12 strport.Format("%d",Port);
139     m_port.SetWindowText(strport);
140 kevin 4 reg.Close();
141    
142 kevin 9 //connect til server
143 kevin 12
144 kevin 4
145     return TRUE; // return TRUE unless you set the focus to a control
146     }
147    
148     void CClientDlg::OnSysCommand(UINT nID, LPARAM lParam)
149     {
150     if ((nID & 0xFFF0) == IDM_ABOUTBOX)
151     {
152     CAboutDlg dlgAbout;
153     dlgAbout.DoModal();
154     }
155     else
156     {
157     CDialog::OnSysCommand(nID, lParam);
158     }
159     }
160    
161     // If you add a minimize button to your dialog, you will need the code below
162     // to draw the icon. For MFC applications using the document/view model,
163     // this is automatically done for you by the framework.
164    
165     void CClientDlg::OnPaint()
166     {
167     if (IsIconic())
168     {
169     CPaintDC dc(this); // device context for painting
170    
171     SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
172    
173     // Center icon in client rectangle
174     int cxIcon = GetSystemMetrics(SM_CXICON);
175     int cyIcon = GetSystemMetrics(SM_CYICON);
176     CRect rect;
177     GetClientRect(&rect);
178     int x = (rect.Width() - cxIcon + 1) / 2;
179     int y = (rect.Height() - cyIcon + 1) / 2;
180    
181     // Draw the icon
182     dc.DrawIcon(x, y, m_hIcon);
183     }
184     else
185     {
186     CDialog::OnPaint();
187     }
188     }
189    
190     // The system calls this function to obtain the cursor to display while the user drags
191     // the minimized window.
192     HCURSOR CClientDlg::OnQueryDragIcon()
193     {
194     return static_cast<HCURSOR>(m_hIcon);
195     }
196    
197    
198 kevin 9 ClientSocket sockClient;
199     CString strIp, strPort;
200    
201     /*Clientsocket class used for client socket connections*/
202     void ClientSocket::OnReceive( int nErrorCode )
203     {
204     CString ip;
205     UINT port;
206     char buffer[4096];
207     CString str;
208     int size;
209    
210     str.Format("%s %d",ip,port,"");
211     size = Receive(buffer,4095);
212     buffer[size] = 0;
213     // Recivetekst = buffer; recivetekst er der ikke endnu
214     //Send(str,str.GetLength()); vi skal ikke sende endnu
215     Close();
216     }
217     void ClientSocket::OnSend( int nErrorCode )
218     {
219     // CString sendnu; skal ikke sende nu
220    
221     // sendnu = Sendtekst; skal ikke sende nu
222    
223     // Send(sendnu,sendnu.GetLength()); skal ikke sende nu
224     }
225 kevin 4 void CClientDlg::OnBnClickedIpport()
226     {
227 kevin 9 //Set new port and ip for the server in regedit
228     m_ip.GetWindowText(strIp);
229     m_port.GetWindowText(strPort);
230 kevin 4 CRegKey reg;
231 kevin 9 reg.Create(HKEY_LOCAL_MACHINE, "SOFTWARE\\Projekt\\Client");
232 kevin 4 reg.SetStringValue("","Project-data");
233 kevin 9 reg.Create(HKEY_LOCAL_MACHINE, "SOFTWARE\\Projekt\\Client");
234     reg.SetStringValue("IP",strIp);
235     reg.Create(HKEY_LOCAL_MACHINE, "SOFTWARE\\Projekt\\Client");
236 kevin 12 reg.SetDWORDValue("Port",atoi(strPort));
237 kevin 4 reg.Close();
238     }
239 kevin 9
240     void ClientSocket::OnConnect(int nErrorCode)
241     {
242     // TODO: Add your specialized code here and/or call the base class
243 kevin 12 strPort.Format("%d",strPort);
244     sockClient.Connect(strIp,Port);
245     sockClient.Send(strPort,strPort.GetLength(),0);
246     sockClient.Close();
247 kevin 9 CSocket::OnConnect(nErrorCode);
248     }
249     void Start()
250     {
251 kevin 12 strPort.Format("%d",Port);
252     sockClient.Connect(Ip,Port);
253     sockClient.Send(strPort,strPort.GetLength(),NULL);
254     sockClient.Close();
255 kevin 9 }
256     void CClientDlg::OnBnClickedConnect()
257     {
258     Start();
259     }

  ViewVC Help
Powered by ViewVC 1.1.20