Develop and Download Open Source Software

Browse Subversion Repository

Contents of /WinCS/StatusView.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 11 - (show annotations) (download) (as text)
Wed Feb 10 18:21:00 2010 UTC (14 years ago) by sho1get
File MIME type: text/x-c++src
File size: 6651 byte(s)


1 #include "stdafx.h"
2 #include "WinCS.h"
3 #include "StatusView.h"
4 #include "WinCSDlg.h"
5 #include <atlimage.h>
6
7 IMPLEMENT_DYNAMIC(CStatusView, CDialog)
8
9 BEGIN_MESSAGE_MAP(CStatusView, CDialog)
10 ON_BN_CLICKED(IDOK, &CStatusView::OnBnClickedOk)
11 ON_WM_CTLCOLOR()
12 ON_BN_CLICKED(IDC_BTN_STATUS_PLUGIN_RELOAD, &CStatusView::OnBnClickedBtnStatusPluginReload)
13 ON_CBN_SELCHANGE(IDC_CMB_STATUS_PLUGIN, &CStatusView::OnCbnSelchangeCmbStatusPlugin)
14 END_MESSAGE_MAP()
15
16 //////////////////////////////////////////////////////////////////////////
17
18 CStatusView::CStatusView(CWnd* pParent /*=NULL*/)
19 : CDialog(CStatusView::IDD, pParent)
20 {
21 m_hTimer = NULL;
22 m_hBtnIcon = NULL;
23 m_wNodeType = WCS_NODE_UNDEFINED;
24 }
25
26 CStatusView::~CStatusView()
27 {
28 if (m_hTimer != NULL)
29 {
30 DeleteTimerQueueTimer(NULL, m_hTimer, NULL);
31 }
32 }
33
34 void CStatusView::DoDataExchange(CDataExchange* pDX)
35 {
36 CDialog::DoDataExchange(pDX);
37 DDX_Control(pDX, IDC_EDIT_STATUS_LOCAL_ADDRESS, m_xEditLocalAddress);
38 DDX_Control(pDX, IDC_EDIT_STATUS_NODE_ID, m_xEditNodeID);
39 DDX_Control(pDX, IDC_EDIT_STATUS_UDP_PORT, m_xEditUDPClientPort);
40 DDX_Control(pDX, IDC_EDIT_STATUS_TCP_PORT, m_xEditTCPPort);
41 DDX_Control(pDX, IDC_STATUS_IMAGE_TYPE, m_xImageType);
42 DDX_Control(pDX, IDC_EDIT_STATUS_MASTER_ADDRESS, m_xEditMasterAddress);
43 DDX_Control(pDX, IDC_EDIT_STATUS_NODE_STATE, m_xEditNodeState);
44 DDX_Control(pDX, IDC_EDIT_STATUS_PLUGIN_DETAIL, m_xEditPluginText);
45 DDX_Control(pDX, IDC_BTN_STATUS_PLUGIN_RELOAD, m_xBtnPluginReload);
46 DDX_Control(pDX, IDC_CMB_STATUS_PLUGIN, m_xCmbPlugin);
47 DDX_Control(pDX, IDC_EDIT_STATUS_PLUGIN_VERSION, m_xEditPluginVersion);
48 DDX_Control(pDX, IDC_EDIT_STATUS_PLUGIN_TYPE, m_xEditPluginType);
49 DDX_Control(pDX, IDC_EDIT_STATUS_RUNTIME, m_xEditRuntime);
50 }
51
52 BOOL CStatusView::OnInitDialog()
53 {
54 CDialog::OnInitDialog();
55
56 m_hBtnIcon = (HICON)LoadImage(AfxGetInstanceHandle(),
57 MAKEINTRESOURCE(IDI_RELOAD),
58 IMAGE_ICON, 15, 15,
59 LR_DEFAULTSIZE);
60 m_xBtnPluginReload.SetIcon(m_hBtnIcon);
61
62 m_Stopwatch.Start();
63
64 if (!CreateTimerQueueTimer(&m_hTimer, NULL, doRuntimeTimer, this, 500, 500, 0))
65 {
66 m_hTimer = NULL;
67 }
68
69 return TRUE;
70 }
71
72 void WINAPI CStatusView::doRuntimeTimer(LPVOID pvContext, BOOLEAN fTimeout)
73 {
74 ((CStatusView *)pvContext)->RuntimeTimer();
75 }
76
77 void CStatusView::RuntimeTimer()
78 {
79 CString cs;
80 m_Stopwatch.GetHMS(cs);
81 m_xEditRuntime.SetWindowText(cs);
82 }
83
84 HBRUSH CStatusView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
85 {
86 HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
87 int nCtlID = pWnd->GetDlgCtrlID();
88
89 switch (nCtlID)
90 {
91 case IDC_EDIT_STATUS_LOCAL_ADDRESS:
92 case IDC_EDIT_STATUS_MASTER_ADDRESS:
93 case IDC_EDIT_STATUS_NODE_STATE:
94 case IDC_EDIT_STATUS_NODE_ID:
95 case IDC_EDIT_STATUS_UDP_PORT:
96 case IDC_EDIT_STATUS_TCP_PORT:
97 case IDC_EDIT_STATUS_PLUGIN_VERSION:
98 case IDC_EDIT_STATUS_PLUGIN_TYPE:
99 case IDC_EDIT_STATUS_PLUGIN_DETAIL:
100 case IDC_EDIT_STATUS_RUNTIME:
101 hbr = static_cast<HBRUSH>(GetStockObject(WHITE_BRUSH));
102 pDC->SetBkColor(RGB(255, 255, 255));
103 break;
104 }
105
106 return hbr;
107 }
108
109 void CStatusView::SetNodeType(WORD wNodeType)
110 {
111 DWORD dwResourceID = 0;
112
113 m_wNodeType = wNodeType;
114 m_xImageType.UpdateWindow();
115
116 switch (wNodeType)
117 {
118 case WCS_NODE_MASTER:
119 dwResourceID = IDB_MASTER;
120 break;
121
122 case WCS_NODE_SLAVE:
123 dwResourceID = IDB_SLAVE;
124 break;
125 }
126
127 if (dwResourceID != 0)
128 {
129 try
130 {
131 CImgExResPtr pBmp = CImgExResPtr(new CImageExResource());
132
133 if (pBmp->Load(MAKEINTRESOURCE(dwResourceID), _T("PNG")))
134 {
135 CRect cr;
136 CClientDC dc(&m_xImageType);
137 m_xImageType.GetClientRect(&cr);
138 dc.FillSolidRect(&cr, GetSysColor(COLOR_BTNFACE));
139 Gdiplus::Graphics graphics(dc);
140 graphics.DrawImage(*pBmp, 0, 0);
141 }
142 }
143 catch (std::bad_alloc &)
144 {
145 TRACE0("***** ERROR: shared_ptr(bad_alloc) *****\n");
146 return;
147 }
148 }
149 }
150
151 void CStatusView::SetNodeID(WORD wNodeID)
152 {
153 CString cs = (wNodeID != WCS_DEFAULT_NODE_ID) ? DwToString(wNodeID) : STRING_NONE;
154 m_xEditNodeID.SetWindowText(cs);
155 }
156
157 void CStatusView::ResetNodeID()
158 {
159 m_xEditNodeID.SetWindowText(STRING_NONE);
160 }
161
162 void CStatusView::SetNodeState(WORD wNodeState)
163 {
164 switch (wNodeState)
165 {
166 case WCS_STATE_WAITING:
167 m_xEditNodeState.SetWindowText(_T("Waiting"));
168 break;
169
170 case WCS_STATE_EXECUTING:
171 m_xEditNodeState.SetWindowText(_T("Executing"));
172 break;
173
174 case WCS_STATE_BENCHMARKING:
175 m_xEditNodeState.SetWindowText(_T("Benchmarking"));
176 break;
177
178 case WCS_STATE_DOWNLOADING:
179 m_xEditNodeState.SetWindowText(_T("Downloading"));
180 break;
181 }
182 }
183
184 void CStatusView::SetLocalAddress(DWORD dwAddress)
185 {
186 m_xEditLocalAddress.SetWindowText(DwToIPAddress(dwAddress));
187 }
188
189 void CStatusView::SetMasterAddress(DWORD dwAddress)
190 {
191 m_xEditMasterAddress.SetWindowText(DwToIPAddress(dwAddress));
192 }
193
194 void CStatusView::ResetMasterAddress()
195 {
196 m_xEditMasterAddress.SetWindowText(STRING_NONE);
197 }
198
199 void CStatusView::SetUDPPort(WORD wPort)
200 {
201 m_xEditUDPClientPort.SetWindowText(DwToString(wPort));
202 }
203
204 void CStatusView::SetTCPPort(WORD wPort)
205 {
206 m_xEditTCPPort.SetWindowText(DwToString(wPort));
207 }
208
209 void CStatusView::SetReloadBtn(BOOL fEnable)
210 {
211 m_xBtnPluginReload.EnableWindow(fEnable);
212 }
213
214 void CStatusView::OnBnClickedBtnStatusPluginReload()
215 {
216 GetParent()->SendMessage(WM_PLUGIN_RELOAD);
217 }
218
219 void CStatusView::SetPluginInfo(const PLUGIN_INFO &info)
220 {
221 CString cs;
222 cs.Format(_T("%d.%d"), LOBYTE(info.wVersion), HIBYTE(info.wVersion));
223 m_xEditPluginVersion.SetWindowText(cs);
224 m_xEditPluginText.SetWindowText(info.szText);
225 cs = (info.wType == WCS_PLUGIN_TYPE_GRAPHICS) ? _T("Graphics") : _T("Console");
226 m_xEditPluginType.SetWindowText(cs);
227 }
228
229 void CStatusView::SetPluginState(BOOL fLock)
230 {
231 // Master function
232 m_xCmbPlugin.EnableWindow(!fLock);
233 m_xBtnPluginReload.EnableWindow(!fLock);
234 }
235
236 void CStatusView::PluginInfoClear()
237 {
238 m_xEditPluginVersion.SetWindowText(STRING_EMPTY);
239 m_xEditPluginType.SetWindowText(STRING_EMPTY);
240 m_xEditPluginText.SetWindowText(STRING_EMPTY);
241 }
242
243 void CStatusView::DeletePluginList()
244 {
245 m_xCmbPlugin.ResetContent();
246 }
247
248 void CStatusView::AddPluginList(const CString &csModule)
249 {
250 m_xCmbPlugin.AddString(csModule);
251 }
252
253 void CStatusView::SelectPluginList(UINT nIndex)
254 {
255 m_xCmbPlugin.SetCurSel(nIndex);
256 }
257
258 void CStatusView::OnCbnSelchangeCmbStatusPlugin()
259 {
260 int nIndex = m_xCmbPlugin.GetCurSel();
261 GetParent()->SendMessage(WM_PLUGIN_CHANGE, (WPARAM)nIndex, 0);
262 }
263
264 //////////////////////////////////////////////////////////////////////////
265

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26