TNB Library
TnbMfcCursorControl.h
[詳解]
1#pragma once
13#include "TnbDef.h"
14
15
16
17#ifndef __AFX_H__
18 #error
19#endif
20
21
22
23//TNB Library
24namespace TNB {
25namespace MFC {
26
27
28
56template<typename TYP = CStatic>
57class CCursorControlAddinT : public TYP
58{
59 DEFSUPER(TYP);
60public:
61
63 CCursorControlAddinT(void) : m_normalCursor(NULL), m_hoverCursor(NULL), m_pushedCursor(NULL)
64 , m_boHasHover(false), m_boIsPushed(false), m_boIsEnable(true)
65 {
66 #ifdef IDC_HAND
67 m_hoverCursor = ::LoadCursor(NULL, IDC_HAND);
68 #endif
69 }
70
75 void SetHoverCursor(HCURSOR h)
76 {
77 m_hoverCursor = h;
78 }
79
84 void SetPushedCursor(HCURSOR h)
85 {
86 m_pushedCursor = h;
87 }
88
94 template<typename T>
96 {
97 m_hoverCursor = other.m_hoverCursor;
98 m_pushedCursor = other.m_pushedCursor;
99 }
100
107 void SpecialCursor(HCURSOR h)
108 {
109 m_boIsEnable = false;
110 ::SetCursor(h);
111 }
112
117 void ResetCursor(void)
118 {
119 m_boIsEnable = true;
120 }
121
122protected:
123
133 virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
134 {
135 switch ( message )
136 {
137 case WM_LBUTTONDOWN:
138 case WM_LBUTTONDBLCLK:
139 if ( ! m_boIsPushed )
140 {
141 m_boIsPushed = true;
142 m_CheckNowState();
143 }
144 break;
145 case WM_LBUTTONUP:
146 if ( m_boIsPushed )
147 {
148 m_boIsPushed = false;
149 m_CheckNowState();
150 }
151 break;
152 case WM_MOUSEMOVE:
153 case WM_MOUSEHOVER:
154 if ( ! m_boHasHover )
155 {
156 m_boHasHover = true;
157 m_HoverSub();
158 }
159 m_CheckNowState();
160 break;
161 case WM_MOUSELEAVE:
162 if ( m_boHasHover )
163 {
164 m_boHasHover = false;
165 m_CheckNowState();
166 }
167 break;
168 case WM_ENABLE:
169 m_CheckNowState();
170 break;
171 case WM_DESTROY:
172 m_boHasHover = false;
173 m_boIsPushed = false;
174 m_CheckNowState();
175 break;
176 }
177 return _super::WindowProc(message, wParam, lParam);
178 }
179
180private:
181
182 HCURSOR m_normalCursor;
183 HCURSOR m_hoverCursor;
184 HCURSOR m_pushedCursor;
185 bool m_boHasHover;
186 bool m_boIsPushed;
187 bool m_boIsEnable;
189 void m_HoverSub(void)
190 {
191 TRACKMOUSEEVENT tme;
192 tme.cbSize = sizeof (TRACKMOUSEEVENT);
193 tme.hwndTrack = m_hWnd;
194 tme.dwHoverTime = HOVER_DEFAULT;
195 tme.dwFlags = TME_HOVER | TME_LEAVE;
196 ::_TrackMouseEvent(&tme);
197 }
199 void m_CheckNowState(void)
200 {
201 if ( ! m_boIsEnable ) { return; }
202 if ( m_normalCursor == NULL )
203 {
204 m_normalCursor = ::GetCursor();
205 ::SetClassLongPtr(m_hWnd, GCLP_HCURSOR, NULL); //Winに関連している CursorをNULL化
206 }
207 HCURSOR h = m_normalCursor;
208 if ( _super::IsWindowEnabled() )
209 {
210 if ( m_boIsPushed && m_pushedCursor != NULL )
211 {
212 h = m_pushedCursor;
213 }
214 else if ( m_boHasHover && m_hoverCursor != NULL )
215 {
216 h = m_hoverCursor;
217 }
218 }
219 ::SetCursor(h);
220 }
221};
222
223
224
225}; //MFC
226}; //TNB
227
228
229
TNBライブラリの定義ヘッダ
マウスカーソル制御クラス
void SetHoverCursor(HCURSOR h)
[設定] ホバー状態のカーソル設定.
CCursorControlAddinT(void)
コンストラクタ
void CopyCursorState(const CCursorControlAddinT< T > &other)
[設定] カーソル設定コピー.
void ResetCursor(void)
[設定] 特殊カーソルモード解除.
void SpecialCursor(HCURSOR h)
[設定] 特殊カーソルモード.
void SetPushedCursor(HCURSOR h)
[設定] 押下状態のカーソル設定.
virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
[通知] for processing Windows messages.
TNB Library
Definition: TnbDoxyTitle.txt:2