TNB Library
TnbMfcPortComboBox.h
[詳解]
1#pragma once
11#include "TnbRs232c.h"
12#include "TnbSimpleMap.h"
13
14
15
16//TNB Library
17namespace TNB {
18namespace MFC {
19
20
21
84class CPortComboBox : public CComboBox
85{
86 DEFSUPER(CComboBox);
87public:
88
93 CPortComboBox(bool isFullText = false) : m_isFullText(isFullText)
94 {
95 }
96
102 void AddExtendPort(LPCTSTR lpszName)
103 {
104 m_extPort = lpszName;
105 }
106
112 operator CRs232c::CPort(void) const
113 {
114 return GetCurPort();
115 }
116
122 int GetCurPort(void) const
123 {
124 int f = _super::GetCurSel();
125 if ( f >= 0 )
126 {
127 f = _super::GetItemData(f);
128 }
129 return f;
130 }
131
139 bool SetCurPort(int port)
140 {
141 loop ( i, _super::GetCount() )
142 {
143 if ( ToInt(_super::GetItemData(i)) == port )
144 {
145 bool r = (_super::SetCurSel(i) != CB_ERR);
146 if ( r )
147 {
148 m_toolTip.UpdateTipText(m_descList[_super::GetItemData(_super::GetCurSel())], this);
149 }
150 return r;
151 }
152 }
153 return false;
154 }
155
162 int SetCurSel(int nSelect)
163 {
164 int r = _super::SetCurSel(nSelect);
165 int f = _super::GetCurSel();
166 if ( f >= 0 )
167 {
168 f = _super::GetItemData(f);
169 m_toolTip.UpdateTipText(m_descList[f], this);
170 }
171 return r;
172 }
173
179 void ResetDevice(bool isFullText = false)
180 {
182 ResetDevice(vd, isFullText);
183 }
184
191 void ResetDevice(const CRs232c::TDeviceVector& vd, bool isFullText = false)
192 {
193 m_isFullText = isFullText;
194 _super::SetRedraw(FALSE);
195 int f = GetCurPort();
196 m_Reset(vd);
197 SetCurPort(f);
198 _super::SetRedraw(TRUE);
199 _super::RedrawWindow();
200 }
201
202protected:
203
210 virtual BOOL PreTranslateMessage(MSG* pMsg)
211 {
212 if ( ::IsWindow(m_toolTip) )
213 {
214 m_toolTip.RelayEvent(pMsg);
215 }
216 return _super::PreTranslateMessage(pMsg);
217 }
218
228 virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
229 {
230 if ( message == WM_DESTROY )
231 {
232 m_descList.RemoveAll();
233 m_toolTip.DestroyWindow();
234 }
235 return _super::WindowProc(message, wParam, lParam);
236 }
237
243 virtual void PreSubclassWindow(void)
244 {
245 DWORD style = _super::GetStyle();
246 ASSERT0( (style & 3) == CBS_DROPDOWNLIST, "CPortComboBox", "DropDownListになっていません" );
247 _super::PreSubclassWindow();
248// m_Reset();
249 }
250
262 virtual BOOL OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* _pResult)
263 {
264 if ( message == WM_COMMAND )
265 {
266 if ( lParam == reinterpret_cast<LPARAM>(_super::GetSafeHwnd()) && HIWORD(wParam) == CBN_SELCHANGE )
267 {
268 ASSERT ( LOWORD(wParam) == _super::GetDlgCtrlID() );
269 int f = _super::GetCurSel();
270 if ( f >= 0 )
271 {
272 f = _super::GetItemData(f);
273 m_toolTip.UpdateTipText(m_descList[f], this);
274 }
275 }
276 }
277 return _super::OnChildNotify(message, wParam, lParam, _pResult);
278 }
279
286 virtual bool IsEffectiveness(int port)
287 {
288 return true;
289 }
290
291private:
292
293 void m_Reset(const CRs232c::TDeviceVector& vd)
294 {
295 _super::ResetContent();
296 m_descList.RemoveAll();
297 m_toolTip.DestroyWindow();
298 m_toolTip.Create(this, TTS_ALWAYSTIP);
299 bool hasExtPort = ! m_extPort.IsEmpty();
300 if ( ! vd.IsEmpty() )
301 {
302 CStr s;
303 loop ( i, vd )
304 {
305 int p = vd[i].port;
306 if ( IsEffectiveness(p) )
307 {
308 s.Format(_T("COM%d"), p);
309 if ( m_isFullText )
310 {
311 s += _T(": ") + vd[i].ToString();
312 }
313 int f = _super::AddString(s);
314 _super::SetItemData(f, p);
315 m_descList[p] = vd[i].ToString();
316 }
317 }
318 _super::SetCurSel(0);
319 m_toolTip.AddTool(this, m_descList[_super::GetItemData(0)]);
320 }
321 else if ( ! hasExtPort )
322 {
323 m_toolTip.AddTool(this, _T("一つも見つかりません"));
324 }
325 //
326 if ( hasExtPort )
327 {
328 int f = _super::AddString(m_extPort);
329 _super::SetItemData(f, 0);
330 m_descList[0] = m_extPort;
331 }
332 m_toolTip.Activate(TRUE);
333 }
334
335 CSimpleMapT<int, CStr> m_descList;
336 CToolTipCtrl m_toolTip;
337 bool m_isFullText;
338 CStr m_extPort;
339};
340
341
342
343}; // MFC
344}; // TNB
#define loop(VAR, CNT)
loop構文.
Definition: TnbDef.h:343
RS232Cのアクセス関係のヘッダ
簡易配列型情報管理関係のヘッダ
RS232C ポート管理
Definition: TnbRs232c.h:84
static TDeviceVector EnumExistPortDeviceNames(void)
[取得] 存在するPort一覧
Definition: TnbRs232c.h:873
マップ型情報管理テンプレート
Definition: TnbSimpleMap.h:44
bool IsEmpty(void) const
[確認] 空チェック
Definition: TnbStr.h:528
void Format(const TYP *lpszFormat,...)
[代入] 書式付き文字列代入.
Definition: TnbStr.h:359
配列型情報管理テンプレート
Definition: TnbVector.h:75
シルアルポートComboBoxコントロール
void ResetDevice(bool isFullText=false)
[設定] デバイス設定.
void ResetDevice(const CRs232c::TDeviceVector &vd, bool isFullText=false)
[設定] デバイス設定.
virtual BOOL OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT *_pResult)
[通知] for notifications from parent
void AddExtendPort(LPCTSTR lpszName)
[設定] 拡張ポート名設定.
virtual void PreSubclassWindow(void)
[通知] subclassing/unsubclassing functions.
int GetCurPort(void) const
[取得] ポート情報取得.
virtual bool IsEffectiveness(int port)
[選択] 有効ポートチェック
virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
[通知] for processing Windows messages.
virtual BOOL PreTranslateMessage(MSG *pMsg)
[通知] for translating Windows messages in main message pump
bool SetCurPort(int port)
[選択] ポート選択.
CPortComboBox(bool isFullText=false)
コンストラクタ.
int SetCurSel(int nSelect)
[選択] 選択.
int ToInt(LPCSTR lpsz, int iBase=10)
[変換] INT変換(ASCII/SJIS用).
Definition: TnbStrLib.h:367
TNB Library
Definition: TnbDoxyTitle.txt:2
bool IsEmpty(void) const
[確認] 要素の有無確認.