TNB Library
TnbCeMfcDoubleClick.h
[詳解]
1#pragma once
11#ifndef _WIN32_WCE
12 #error TnbCeMfcDoubleClick.h is only supported on Windows CE platforms.
13#endif // _WIN32_WCE
14
15
16
17#include "TnbMfcCommon.h"
18#include "TnbTickCount.h"
19
20
21
22#ifndef _TnbDOXYGEN //Document作成用シンボル
23#ifndef STN_DBLCLK
24 #define STN_DBLCLK 1
25#endif
26#ifndef BN_DOUBLECLICKED
27 #define BN_DOUBLECLICKED 1
28#endif
29#endif // _TnbDOXYGEN
30
31
32
33//TNB Library
34namespace TNB {
35namespace MFC {
36
37
38
39#ifndef _TnbDOXYGEN //Document作成用シンボル
40_SELECTANY DWORD s_dcaDoubleClickTime = 0;
41_SELECTANY DWORD s_toleranceClickRange = TNB::CalcScaleX(10);
42#endif // _TnbDOXYGEN
43
44
45
72template<typename WND>
73class CDoubleClickAddinT : public WND
74{
75 DEFSUPER(WND);
76public:
77
79 CDoubleClickAddinT(void) : m_phase(STANDBY)
80 {
82 }
83
84
93 static void SetToleranceClickRange(DWORD d)
94 {
95 s_toleranceClickRange = d;
96 }
97
107 static void SetDoubleClickTime(DWORD t)
108 {
109 s_dcaDoubleClickTime = t;
110 }
111
118 static DWORD GetDoubleClickTime(void)
119 {
120 if ( s_dcaDoubleClickTime == 0 )
121 {
122 s_dcaDoubleClickTime = ::GetDoubleClickTime();
123 }
124 return s_dcaDoubleClickTime;
125 }
126
127protected:
128
134 virtual void PreSubclassWindow(void)
135 {
136 m_phase = STANDBY;
137 LRESULT r = SendMessage(WM_GETDLGCODE);
138 if ( (r & DLGC_STATIC) != 0 && (GetStyle() & SS_NOTIFY) == 0 )
139 {
140 m_phase = DISABLE;
141 }
142 _super::PreSubclassWindow();
143 }
144
154 virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
155 {
156 switch ( message )
157 {
158 case WM_LBUTTONDOWN:
159 if ( m_phase > STANDBY && m_IsPassed() )
160 {
161 m_phase = STANDBY;
162 }
163 if ( m_phase == STANDBY )
164 {
165 m_phase = UPWAIT;
166// m_point = CPoint(LOWORD(lParam), HIWORD(lParam));
167 m_point = CPoint(lParam);
168 m_tick.Reset();
169 }
170 else if ( m_phase == DOWNWAIT )
171 {
172 m_phase = m_Check(lParam) ? UPWAIT2 : STANDBY;
173 }
174 break;
175 case WM_LBUTTONUP:
176 if ( m_phase == UPWAIT )
177 {
178 m_phase = m_Check(lParam) ? DOWNWAIT : STANDBY;
179 }
180 else if ( m_phase == UPWAIT2 )
181 {
182 if ( m_Check(lParam) )
183 {
184 MFCLIB::SendCommandMessage(this, 1); //親へ通知
185 }
186 m_phase = STANDBY;
187 }
188 break;
189 case WM_MOUSEMOVE:
190 if ( m_phase > STANDBY && ! m_Check(lParam) )
191 {
192 m_phase = STANDBY;
193 }
194 break;
195 }
196 return _super::WindowProc(message, wParam, lParam);
197 }
198
199private:
201 enum EPhase
202 {
203 DISABLE,
204 STANDBY,
205 UPWAIT,
206 DOWNWAIT,
207 UPWAIT2,
208 };
209 // エリア無いチェック
210 bool m_IsArea(const POINT& p) const
211 {
212 DWORD x = abs(p.x - m_point.x);
213 DWORD y = abs(p.y - m_point.y);
214 return (x <= s_toleranceClickRange && y <= s_toleranceClickRange);
215 }
216 // 時間内チェック
217 bool m_IsPassed(void) const
218 {
219 return m_tick.IsPassed(s_dcaDoubleClickTime);
220 }
221 // チェック
222 bool m_Check(LPARAM lParam) const
223 {
224// return (! m_IsPassed() && m_IsArea(CPoint(LOWORD(lParam), HIWORD(lParam))));
225 return (! m_IsPassed() && m_IsArea(CPoint(lParam)));
226 }
227 CTickCount m_tick;
228 CPoint m_point;
229 int m_phase;
230};
231
232
233
234}; // MFC
235}; // TNB
236
237
MFCコントロール共通のヘッダ
経過時間管理関係のヘッダ
経過時間管理クラス
Definition: TnbTickCount.h:57
bool IsPassed(DWORD dwTime) const
[確認] 経過確認.
Definition: TnbTickCount.h:114
void Reset(void)
[設定] リセット.
Definition: TnbTickCount.h:82
ダブルクリックアドイン(CE専用).
static void SetDoubleClickTime(DWORD t)
[設定] ダブルクリック時間設定.
static DWORD GetDoubleClickTime(void)
[取得] ダブルクリック時間取得.
virtual void PreSubclassWindow(void)
[通知] subclassing/unsubclassing functions.
static void SetToleranceClickRange(DWORD d)
[設定] 許容クリック範囲設定.
virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
[通知] for processing Windows messages.
CDoubleClickAddinT(void)
コンストラクタ
LRESULT SendCommandMessage(CWnd *pCtrl, UINT cmd)
[処理] WM_COMMAND送信.
Definition: TnbMfcCommon.h:475
TNB Library
Definition: TnbDoxyTitle.txt:2