| 1 |
#include "stdafx.h" |
| 2 |
#include "WinCS.h" |
| 3 |
#include "SlaveView.h" |
| 4 |
#include "WinCSDlg.h" |
| 5 |
#include <atlimage.h> |
| 6 |
|
| 7 |
IMPLEMENT_DYNAMIC(CSlaveView, CDialog) |
| 8 |
|
| 9 |
BEGIN_MESSAGE_MAP(CSlaveView, CDialog) |
| 10 |
ON_BN_CLICKED(IDOK, &CSlaveView::OnBnClickedOk) |
| 11 |
ON_BN_CLICKED(IDC_BTN_SLAVE_SEND, &CSlaveView::OnBnClickedBtnSlaveSend) |
| 12 |
ON_WM_CTLCOLOR() |
| 13 |
ON_CBN_SELCHANGE(IDC_CMB_SLAVE_USAGE, &CSlaveView::OnCbnSelchangeCmbSlaveUsage) |
| 14 |
END_MESSAGE_MAP() |
| 15 |
|
| 16 |
////////////////////////////////////////////////////////////////////////// |
| 17 |
|
| 18 |
CSlaveView::CSlaveView(CWnd* pParent /*=NULL*/) |
| 19 |
: CDialog(CSlaveView::IDD, pParent), |
| 20 |
m_hSystem(NULL), |
| 21 |
m_nUsageMode(0) |
| 22 |
{ |
| 23 |
} |
| 24 |
|
| 25 |
CSlaveView::~CSlaveView() |
| 26 |
{ |
| 27 |
if (m_hSystem != NULL) |
| 28 |
{ |
| 29 |
DeleteTimerQueueTimer(NULL, m_hSystem, NULL); |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
void CSlaveView::DoDataExchange(CDataExchange* pDX) |
| 34 |
{ |
| 35 |
CDialog::DoDataExchange(pDX); |
| 36 |
DDX_Control(pDX, IDC_EDIT_SLAVE_CONSOLE, m_xEditConsole); |
| 37 |
DDX_Control(pDX, IDC_EDIT_SLAVE_INPUT, m_xEditInput); |
| 38 |
DDX_Control(pDX, IDC_EDIT_SLAVE_PHYSICAL_MEMORY1, m_xEditAvailPhys); |
| 39 |
DDX_Control(pDX, IDC_EDIT_SLAVE_PHYSICAL_MEMORY2, m_xEditTotalPhys); |
| 40 |
DDX_Control(pDX, IDC_EDIT_SLAVE_VIRTUAL_MEMORY1, m_xEditAvailVirtual); |
| 41 |
DDX_Control(pDX, IDC_EDIT_SLAVE_VIRTUAL_MEMORY2, m_xEditTotalVirtual); |
| 42 |
DDX_Control(pDX, IDC_EDIT_SLAVE_USAGE_RATE, m_xEditUsageRate); |
| 43 |
DDX_Control(pDX, IDC_CMB_SLAVE_USAGE, m_xCmbUsageMode); |
| 44 |
DDX_Control(pDX, IDC_EDIT_SLAVE_PROCESSORS1, m_xEditProcessors1); |
| 45 |
DDX_Control(pDX, IDC_EDIT_SLAVE_PROCESSORS2, m_xEditProcessors2); |
| 46 |
DDX_Control(pDX, IDC_EDIT_MASTER_PLUGIN, m_xEditPlugin); |
| 47 |
DDX_Control(pDX, IDC_EDIT_SLAVE_PLUGIN_RUNTIME, m_xEditRuntime1); |
| 48 |
DDX_Control(pDX, IDC_EDIT_SLAVE_BENCHMARK_SCORE, m_xEditScore); |
| 49 |
DDX_Control(pDX, IDC_EDIT_SLAVE_BENCHMARK_RUNTIME, m_xEditRuntime2); |
| 50 |
DDX_Control(pDX, IDC_EDIT_SLAVE_BENCHMARK_TESTTIME, m_xEditTestTime); |
| 51 |
DDX_Control(pDX, IDC_EDIT_SLAVE_BENCHMARK_RANKING1, m_xEditRanking1); |
| 52 |
DDX_Control(pDX, IDC_EDIT_SLAVE_BENCHMARK_RANKING2, m_xEditRanking2); |
| 53 |
DDX_Control(pDX, IDC_EDIT_SLAVE_PLUGIN_STATUS, m_xEditStatus); |
| 54 |
DDX_Control(pDX, IDC_TXT_SLAVE_PLUGIN_PERCENT, m_xTxtPercent); |
| 55 |
DDX_Control(pDX, IDC_PRG_SLAVE_PLUGIN_PROGRESS, m_xProgress); |
| 56 |
} |
| 57 |
|
| 58 |
HBRUSH CSlaveView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) |
| 59 |
{ |
| 60 |
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); |
| 61 |
int nCtlID = pWnd->GetDlgCtrlID(); |
| 62 |
|
| 63 |
switch (nCtlID) |
| 64 |
{ |
| 65 |
case IDC_EDIT_SLAVE_CONSOLE: |
| 66 |
case IDC_EDIT_SLAVE_PHYSICAL_MEMORY1: |
| 67 |
case IDC_EDIT_SLAVE_PHYSICAL_MEMORY2: |
| 68 |
case IDC_EDIT_SLAVE_VIRTUAL_MEMORY1: |
| 69 |
case IDC_EDIT_SLAVE_VIRTUAL_MEMORY2: |
| 70 |
case IDC_EDIT_SLAVE_USAGE_RATE: |
| 71 |
case IDC_EDIT_SLAVE_PROCESSORS1: |
| 72 |
case IDC_EDIT_SLAVE_PROCESSORS2: |
| 73 |
case IDC_EDIT_MASTER_PLUGIN: |
| 74 |
case IDC_EDIT_SLAVE_PLUGIN_STATUS: |
| 75 |
case IDC_EDIT_SLAVE_PLUGIN_RUNTIME: |
| 76 |
case IDC_EDIT_SLAVE_BENCHMARK_SCORE: |
| 77 |
case IDC_EDIT_SLAVE_BENCHMARK_RUNTIME: |
| 78 |
case IDC_EDIT_SLAVE_BENCHMARK_TESTTIME: |
| 79 |
case IDC_EDIT_SLAVE_BENCHMARK_RANKING1: |
| 80 |
case IDC_EDIT_SLAVE_BENCHMARK_RANKING2: |
| 81 |
hbr = static_cast<HBRUSH>(GetStockObject(WHITE_BRUSH)); |
| 82 |
pDC->SetBkColor(RGB(255, 255, 255)); |
| 83 |
break; |
| 84 |
} |
| 85 |
|
| 86 |
return hbr; |
| 87 |
} |
| 88 |
|
| 89 |
BOOL CSlaveView::OnInitDialog() |
| 90 |
{ |
| 91 |
CDialog::OnInitDialog(); |
| 92 |
|
| 93 |
SYSTEM_INFO si; |
| 94 |
|
| 95 |
GetSystemInfo(&si); |
| 96 |
InitProgress(si.dwNumberOfProcessors); |
| 97 |
SetProcessors(si.dwNumberOfProcessors); |
| 98 |
m_xEditProcessors2.SetWindowText(DwToString(si.dwNumberOfProcessors)); |
| 99 |
m_xCmbUsageMode.AddString(_T("Total")); |
| 100 |
m_xCmbUsageMode.AddString(_T("WinCS")); |
| 101 |
m_xCmbUsageMode.SetCurSel(0); |
| 102 |
m_xProgress.SetRange(0, 100); |
| 103 |
m_xEditInput.SetFocus(); |
| 104 |
|
| 105 |
m_xEditAvailPhys.SetWindowText(STRING_NONE); |
| 106 |
m_xEditTotalPhys.SetWindowText(STRING_NONE); |
| 107 |
m_xEditAvailVirtual.SetWindowText(STRING_NONE); |
| 108 |
m_xEditTotalVirtual.SetWindowText(STRING_NONE); |
| 109 |
m_xEditUsageRate.SetWindowText(STRING_NONE); |
| 110 |
m_xEditPlugin.SetWindowText(STRING_NONE); |
| 111 |
m_xEditRuntime1.SetWindowText(STRING_NONE); |
| 112 |
m_xEditScore.SetWindowText(STRING_NONE); |
| 113 |
m_xEditRuntime2.SetWindowText(STRING_NONE); |
| 114 |
m_xEditTestTime.SetWindowText(STRING_NONE); |
| 115 |
m_xEditRanking1.SetWindowText(STRING_NONE); |
| 116 |
m_xEditRanking2.SetWindowText(STRING_NONE); |
| 117 |
|
| 118 |
if (!CreateTimerQueueTimer(&m_hSystem, NULL, doRefreshSystemInfo, this, 0, 5000, 0)) |
| 119 |
{ |
| 120 |
m_hSystem = FALSE; |
| 121 |
} |
| 122 |
|
| 123 |
return FALSE; |
| 124 |
} |
| 125 |
|
| 126 |
BOOL CSlaveView::PreTranslateMessage(MSG* pMsg) |
| 127 |
{ |
| 128 |
if ((pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN) && |
| 129 |
(GetFocus() != NULL && GetFocus() == GetDlgItem(IDC_EDIT_SLAVE_INPUT))) |
| 130 |
{ |
| 131 |
SendTextMessage(); |
| 132 |
return TRUE; |
| 133 |
} |
| 134 |
|
| 135 |
return CDialog::PreTranslateMessage(pMsg); |
| 136 |
} |
| 137 |
|
| 138 |
void CSlaveView::SetBenchmarkScore(double dbScore) |
| 139 |
{ |
| 140 |
CString cs; |
| 141 |
cs.Format(_T("%.4lf GFLOPS"), dbScore); |
| 142 |
m_xEditScore.SetWindowText(cs); |
| 143 |
} |
| 144 |
|
| 145 |
void CSlaveView::SetBenchmarkRanking(DWORD dwPosition, DWORD dwAll) |
| 146 |
{ |
| 147 |
m_xEditRanking1.SetWindowText(DwToString(dwPosition)); |
| 148 |
m_xEditRanking2.SetWindowText(DwToString(dwAll)); |
| 149 |
} |
| 150 |
|
| 151 |
void CSlaveView::SetProgress(DWORD dwIndex, int nPoint) |
| 152 |
{ |
| 153 |
CSingleLock sl(&m_cs, TRUE); |
| 154 |
CString cs; |
| 155 |
DWORD dwMinIndex = 0; |
| 156 |
|
| 157 |
if (dwIndex < m_dwProcessors) |
| 158 |
{ |
| 159 |
m_dwPrgList[dwIndex] = nPoint; |
| 160 |
|
| 161 |
for (UINT i = 0; i < m_dwProcessors; i++) |
| 162 |
{ |
| 163 |
dwMinIndex = (m_dwPrgList[dwMinIndex] > m_dwPrgList[i]) ? i : dwMinIndex; |
| 164 |
} |
| 165 |
|
| 166 |
if (dwMinIndex == dwIndex) |
| 167 |
{ |
| 168 |
// Update progress point |
| 169 |
m_xEditStatus.SetWindowText(_T("Running")); |
| 170 |
cs.Format(_T("%d%%"), nPoint); |
| 171 |
m_xTxtPercent.SetWindowText(cs); |
| 172 |
m_xProgress.SetPos(nPoint); |
| 173 |
} |
| 174 |
} |
| 175 |
} |
| 176 |
|
| 177 |
void CSlaveView::InitProgress(DWORD dwProcessors) |
| 178 |
{ |
| 179 |
m_dwProcessors = dwProcessors; |
| 180 |
m_dwPrgList.SetSize(dwProcessors); |
| 181 |
|
| 182 |
for (UINT i = 0; i < dwProcessors; i++) |
| 183 |
{ |
| 184 |
m_dwPrgList[i] = 100; |
| 185 |
} |
| 186 |
} |
| 187 |
|
| 188 |
void CSlaveView::EndProgress() |
| 189 |
{ |
| 190 |
m_xEditStatus.SetWindowText(_T("Finish")); |
| 191 |
m_xTxtPercent.SetWindowText(_T("100%")); |
| 192 |
m_xProgress.SetPos(100); |
| 193 |
} |
| 194 |
|
| 195 |
void CSlaveView::SetPluginRuntime(double dbRuntime) |
| 196 |
{ |
| 197 |
CString cs; |
| 198 |
|
| 199 |
if (dbRuntime == 0.0) |
| 200 |
{ |
| 201 |
cs = STRING_NONE; |
| 202 |
} |
| 203 |
else |
| 204 |
{ |
| 205 |
cs.Format(_T("%.4lf sec"), dbRuntime); |
| 206 |
} |
| 207 |
|
| 208 |
m_xEditRuntime1.SetWindowText(cs); |
| 209 |
} |
| 210 |
|
| 211 |
void CSlaveView::ResetBenchmark() |
| 212 |
{ |
| 213 |
m_xEditScore.SetWindowText(STRING_NONE); |
| 214 |
m_xEditRuntime2.SetWindowText(STRING_NONE); |
| 215 |
m_xEditTestTime.SetWindowText(STRING_NONE); |
| 216 |
m_xEditRanking1.SetWindowText(STRING_NONE); |
| 217 |
m_xEditRanking2.SetWindowText(STRING_NONE); |
| 218 |
} |
| 219 |
|
| 220 |
void CSlaveView::OnBnClickedBtnSlaveSend() |
| 221 |
{ |
| 222 |
SendTextMessage(); |
| 223 |
} |
| 224 |
|
| 225 |
void CSlaveView::SendTextMessage() |
| 226 |
{ |
| 227 |
CString cs; |
| 228 |
m_xEditInput.GetWindowText(m_MsgString); |
| 229 |
|
| 230 |
if (m_MsgString.GetLength() > 0) |
| 231 |
{ |
| 232 |
cs.Format(_T("Local message : (%s)\r\n>> %s"), GetNowTime(), m_MsgString); |
| 233 |
AddConsoleText(cs); |
| 234 |
GetParent()->SendMessage(WM_SEND_TEXT); |
| 235 |
m_xEditInput.SetWindowText(STRING_EMPTY); |
| 236 |
} |
| 237 |
|
| 238 |
m_xEditInput.SetFocus(); |
| 239 |
} |
| 240 |
|
| 241 |
void CSlaveView::AddConsoleText(const CString &csText, BOOL fReturn) |
| 242 |
{ |
| 243 |
CString cs; |
| 244 |
BOOL bFocus; |
| 245 |
int nLastPos; |
| 246 |
|
| 247 |
if (csText.GetLength() < 1) |
| 248 |
{ |
| 249 |
return; |
| 250 |
} |
| 251 |
|
| 252 |
cs.Format(_T("%s%s"), csText, fReturn ? STRING_RETURN : STRING_EMPTY); |
| 253 |
nLastPos = m_xEditConsole.GetWindowTextLength(); |
| 254 |
bFocus = FALSE; |
| 255 |
|
| 256 |
if (::GetFocus() == m_xEditConsole.m_hWnd) |
| 257 |
{ |
| 258 |
bFocus = TRUE; |
| 259 |
GetParent()->SetFocus(); |
| 260 |
} |
| 261 |
|
| 262 |
m_xEditConsole.SetSel(nLastPos, nLastPos); |
| 263 |
m_xEditConsole.ReplaceSel(cs); |
| 264 |
|
| 265 |
if (bFocus) |
| 266 |
{ |
| 267 |
m_xEditConsole.SetFocus(); |
| 268 |
} |
| 269 |
} |
| 270 |
|
| 271 |
// static |
| 272 |
void WINAPI CSlaveView::doRefreshSystemInfo(LPVOID pvContext, BOOLEAN fTimeout) |
| 273 |
{ |
| 274 |
((CSlaveView *)pvContext)->RefreshSystemInfo(); |
| 275 |
} |
| 276 |
|
| 277 |
void CSlaveView::RefreshSystemInfo() |
| 278 |
{ |
| 279 |
MEMORYSTATUSEX ms = { sizeof(ms) }; |
| 280 |
PDH_HQUERY hQuery; |
| 281 |
PDH_HCOUNTER hCounter; |
| 282 |
CString cs; |
| 283 |
PDH_FMT_COUNTERVALUE fntValue; |
| 284 |
|
| 285 |
GlobalMemoryStatusEx(&ms); |
| 286 |
|
| 287 |
cs.Format(_T("%I64d"), ms.ullTotalPhys / 1000); |
| 288 |
BigNumToString(cs); |
| 289 |
m_xEditTotalPhys.SetWindowText(cs + _T(" KB")); |
| 290 |
|
| 291 |
cs.Format(_T("%I64d"), ms.ullAvailPhys / 1000); |
| 292 |
BigNumToString(cs); |
| 293 |
m_xEditAvailPhys.SetWindowText(cs + _T(" KB")); |
| 294 |
|
| 295 |
cs.Format(_T("%I64d"), ms.ullTotalVirtual / 1000); |
| 296 |
BigNumToString(cs); |
| 297 |
m_xEditTotalVirtual.SetWindowText(cs + _T(" KB")); |
| 298 |
|
| 299 |
cs.Format(_T("%I64d"), ms.ullAvailVirtual / 1000); |
| 300 |
BigNumToString(cs); |
| 301 |
m_xEditAvailVirtual.SetWindowText(cs + _T(" KB")); |
| 302 |
|
| 303 |
|
| 304 |
// Usage rate of processor |
| 305 |
if (PdhOpenQuery(NULL, 0, &hQuery) == ERROR_SUCCESS) |
| 306 |
{ |
| 307 |
if (m_nUsageMode == 0) |
| 308 |
{ |
| 309 |
PdhAddCounter(hQuery ,_T("\\Processor(_Total)\\% Processor Time"), |
| 310 |
0, &hCounter); |
| 311 |
} |
| 312 |
else |
| 313 |
{ |
| 314 |
PdhAddCounter(hQuery, _T("\\Process(WinCS#0)\\% Processor Time"), |
| 315 |
0, &hCounter); |
| 316 |
} |
| 317 |
|
| 318 |
PdhCollectQueryData(hQuery); |
| 319 |
Sleep(1000); |
| 320 |
PdhCollectQueryData(hQuery); |
| 321 |
PdhGetFormattedCounterValue(hCounter, PDH_FMT_LONG, NULL, &fntValue); |
| 322 |
cs.Format(_T("%u %%"), fntValue.longValue); |
| 323 |
m_xEditUsageRate.SetWindowText(cs); |
| 324 |
PdhCloseQuery(hQuery); |
| 325 |
} |
| 326 |
} |
| 327 |
|
| 328 |
void CSlaveView::OnCbnSelchangeCmbSlaveUsage() |
| 329 |
{ |
| 330 |
m_nUsageMode = m_xCmbUsageMode.GetCurSel(); |
| 331 |
} |
| 332 |
|
| 333 |
void CSlaveView::CancelPlugin() |
| 334 |
{ |
| 335 |
m_xProgress.SetPos(0); |
| 336 |
m_xTxtPercent.SetWindowText(_T("0%")); |
| 337 |
m_xEditStatus.SetWindowText(_T("Cancel")); |
| 338 |
} |
| 339 |
|
| 340 |
////////////////////////////////////////////////////////////////////////// |