1 /*---------------------------------------------------------------------------*
2 Project: HIO2 demos - multi
3 File: multiView.cpp
4
5 (C)2005 HUDSON SOFT
6
7 $Header: /home/cvsroot/SDK/build/demos/hio2demo/vc++/multi/multiView.cpp,v 1.4 2007/11/26 13:56:47 iwai_yuma Exp $
8
9 $NoKeywords: $
10 *---------------------------------------------------------------------------*/
11
12 // multiView.cpp : Implementation of the CMultiView class
13 //
14
15 #include "stdafx.h"
16 #include "multi.h"
17
18 #include "multiDoc.h"
19 #include "multiView.h"
20 #include ".\multiview.h"
21
22 #ifdef _DEBUG
23 #define new DEBUG_NEW
24 #endif
25
26
27 // CMultiView
28
IMPLEMENT_DYNCREATE(CMultiView,CFormView)29 IMPLEMENT_DYNCREATE(CMultiView, CFormView)
30
31 BEGIN_MESSAGE_MAP(CMultiView, CFormView)
32 ON_MESSAGE(WM_USER, OnMyMessage)
33 ON_BN_CLICKED(IDC_BTN_SEND, OnBnClickedBtnSend)
34 ON_BN_CLICKED(IDC_BTN_CONNECT, OnBnClickedBtnConnect)
35 ON_BN_CLICKED(IDC_BTN_DISCONNECT, OnBnClickedBtnDisconnect)
36 ON_BN_CLICKED(IDC_RADIO_SYNC, OnBnClickedRadioSync)
37 ON_BN_CLICKED(IDC_RADIO_ASYNC, OnBnClickedRadioAsync)
38 END_MESSAGE_MAP()
39
40 // CMultiView construction/destruction
41
42 CMultiView::CMultiView()
43 : CFormView(CMultiView::IDD)
44 {
45 // TODO: Add construction code here
46
47 }
48
~CMultiView()49 CMultiView::~CMultiView()
50 {
51 }
52
DoDataExchange(CDataExchange * pDX)53 void CMultiView::DoDataExchange(CDataExchange* pDX)
54 {
55 CFormView::DoDataExchange(pDX);
56 }
57
PreCreateWindow(CREATESTRUCT & cs)58 BOOL CMultiView::PreCreateWindow(CREATESTRUCT& cs)
59 {
60 // TODO: Modify the Window class or styles here by modifying
61 // the CREATESTRUCT cs
62
63 return CFormView::PreCreateWindow(cs);
64 }
65
OnInitialUpdate()66 void CMultiView::OnInitialUpdate()
67 {
68 CFormView::OnInitialUpdate();
69 ResizeParentToFit();
70
71 ///////// for multiApp /////////
72 CheckRadioButton(IDC_RADIO_SYNC, IDC_RADIO_ASYNC, IDC_RADIO_SYNC);
73 }
74
75
76 // CMultiView diagnostics
77
78 #ifdef _DEBUG
AssertValid() const79 void CMultiView::AssertValid() const
80 {
81 CFormView::AssertValid();
82 }
83
Dump(CDumpContext & dc) const84 void CMultiView::Dump(CDumpContext& dc) const
85 {
86 CFormView::Dump(dc);
87 }
88
GetDocument() const89 CMultiDoc* CMultiView::GetDocument() const // Non-debug version is inline
90 {
91 ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMultiDoc)));
92 return (CMultiDoc*)m_pDocument;
93 }
94 #endif //_DEBUG
95
96 ///////// for multiApp /////////
97
98 // CMultiView message handlers
99
OnMyMessage(WPARAM wParam,LPARAM lParam)100 LRESULT CMultiView::OnMyMessage(WPARAM wParam, LPARAM lParam)
101 {
102 TCHAR szBuffer[128];
103
104 switch ( wParam )
105 {
106 case EVENCT_RECEIVED:
107 {
108 int nIndex =
109 GetApp()->m_cInfoList.IndexOf( (LPVOID)( GetDocument()->m_nHioIfID ), MultiCompID );
110 // MultiPacketToString(
111 // szBuffer,
112 // sizeof( szBuffer ),
113 // (MULTI_PACKET *)&(GetApp()->m_cInfoList.GetItem(nIndex)->m_stPacket)
114 // );
115 MultiPacketToString(
116 szBuffer,
117 (MULTI_PACKET *)&(GetApp()->m_cInfoList.GetItem(nIndex)->m_stPacket)
118 );
119 SetDlgItemText(IDC_RECV_DATA, szBuffer);
120 }
121 break;
122 case EVENT_CONNECT:
123 GetDocument()->UpdateTitle();
124 GetDlgItem(IDC_BTN_SEND)->EnableWindow(TRUE);
125 GetDlgItem(IDC_BTN_CONNECT)->EnableWindow(FALSE);
126 GetDlgItem(IDC_BTN_DISCONNECT)->EnableWindow(TRUE);
127 break;
128 case EVENT_DISCONNECT:
129 GetDocument()->UpdateTitle();
130 GetDlgItem(IDC_BTN_SEND)->EnableWindow(FALSE);
131 GetDlgItem(IDC_BTN_CONNECT)->EnableWindow(TRUE);
132 GetDlgItem(IDC_BTN_DISCONNECT)->EnableWindow(FALSE);
133 break;
134 case EVENT_UPDATE_PC_TIME:
135 {
136 // PC time
137 MULTI_PACKET stPacket;
138 GetApp()->CreatePcTime(&stPacket);
139 // MultiPacketToString( szBuffer, sizeof( szBuffer ), &stPacket );
140 MultiPacketToString( szBuffer, &stPacket );
141 SetDlgItemText(IDC_PC_TIME, szBuffer);
142 // Communication status
143 wsprintf(szBuffer,"ST:%04X",lParam);
144 SetDlgItemText(IDC_STATUS, szBuffer);
145 break;
146 }
147 case EVENT_WRITE_DONE:
148 break;
149 }
150 return 0;
151 }
152
OnBnClickedBtnSend()153 void CMultiView::OnBnClickedBtnSend()
154 {
155 HIO2IF_RESULT result;
156
157 GetApp()->CreatePcTime(&m_stPacket);
158 int nIndex =
159 GetApp()->m_cInfoList.IndexOf((LPVOID)GetDocument()->m_nHioIfID, MultiCompID);
160 BOOL bSync = GetApp()->m_cInfoList.GetItem(nIndex)->m_bSync;
161
162 GetApp()->m_pHioIf->EnterCriticalSection();
163
164 #ifdef PROTOCOL_USED
165 result = GetApp()->m_pHioIf->Write(
166 GetDocument()->m_nHioIfID,
167 MULTI_PC2NNGC_ADDR,
168 (LPVOID)&m_stPacket,
169 MULTI_BUFFER_SIZE,
170 bSync);
171
172 #else // PROTOCOL_USED
173 result = GetApp()->m_pHioIf->WriteFree(
174 GetDocument()->m_nHioIfID,
175 MULTI_PC2NNGC_ADDR,
176 (LPVOID)&m_stPacket,
177 MULTI_BUFFER_SIZE,
178 bSync);
179 #endif // PROTOCOL_USED
180
181 GetApp()->m_pHioIf->LeaveCriticalSection();
182
183 if ( HIO2IF_FAILED(result) )
184 MessageBox("Send Error", "ERROR", MB_OK);
185 }
186
OnBnClickedBtnConnect()187 void CMultiView::OnBnClickedBtnConnect()
188 {
189 GetApp()->Connect(GetDocument()->m_nHioIfID);
190 }
191
OnBnClickedBtnDisconnect()192 void CMultiView::OnBnClickedBtnDisconnect()
193 {
194 GetApp()->Disconnect(GetDocument()->m_nHioIfID);
195 }
196
OnBnClickedRadioSync()197 void CMultiView::OnBnClickedRadioSync()
198 {
199 int nIndex =
200 GetApp()->m_cInfoList.IndexOf((LPVOID)GetDocument()->m_nHioIfID, MultiCompID);
201 GetApp()->m_cInfoList.GetItem(nIndex)->m_bSync = FALSE;
202 }
203
OnBnClickedRadioAsync()204 void CMultiView::OnBnClickedRadioAsync()
205 {
206 int nIndex =
207 GetApp()->m_cInfoList.IndexOf((LPVOID)GetDocument()->m_nHioIfID, MultiCompID);
208 GetApp()->m_cInfoList.GetItem(nIndex)->m_bSync = TRUE;
209 }
210
211
OnDraw(CDC *)212 void CMultiView::OnDraw(CDC* /*pDC*/)
213 {
214 CMultiApp* pApp = GetApp();
215 CMultiDoc* pDoc = GetDocument();
216
217 // Case when launched earlier from NNGC
218 if ( (pDoc->m_nHioIfID != HIO2IF_INVALID_ID)
219 && (pApp->m_pHioIf->IsConnected(pDoc->m_nHioIfID)) )
220 {
221 pDoc->UpdateTitle();
222 GetDlgItem(IDC_BTN_SEND)->EnableWindow(TRUE);
223 GetDlgItem(IDC_BTN_CONNECT)->EnableWindow(FALSE);
224 GetDlgItem(IDC_BTN_DISCONNECT)->EnableWindow(TRUE);
225 }
226 }
227