| 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 |
|