18#define BN_PUSHED_T 0x100
19#define BN_UNPUSHED_T 0x101
87 : m_shortcutKey(0), m_pushState(EP_Non), m_boHasHover(false)
88 , m_nowState(
ES_Normal), m_lastState(
EState(-1)), m_hFont(NULL), m_boInBmClick(false)
89 , m_boIsOnClickDisp(false), m_canSendDblClk(false), m_pressedMode(
PM_Unused)
101 m_shortcutKey = other.m_shortcutKey;
102 m_hFont = other.m_hFont;
129 CWnd* P = _super::GetParent();
132 P->SendMessage(DM_SETDEFID, _super::GetDlgCtrlID(), 0);
160 ASSERT(::IsWindow(m_hWnd));
161 return static_cast<UINT
>(::SendMessage(m_hWnd, BM_GETSTATE, 0, 0));
234 m_canSendDblClk = canSendDblClk;
251 return ::WindowFromPoint(po) == m_hWnd;
263 if ( ! _super::IsWindowEnabled() )
267 else if ( m_pushState == EP_Mouse )
270 CPoint po = m_curpos;
277 else if ( m_pushState != EP_Non )
281 else if ( m_boHasHover )
300 return ::GetFocus() == m_hWnd;
332 virtual BOOL
OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* _pResult)
334 if ( message == WM_COMMAND && lParam ==
reinterpret_cast<LPARAM
>(m_hWnd) )
336 ASSERTLIB( (wParam & 0xFFFF) ==
static_cast<WPARAM
>(GetDlgCtrlID()) );
337 ASSERTLIB( (BN_CLICKED * 0x10000) == 0 );
338 if ( (wParam & 0xFFFF0000) == 0 )
340 if ( ! m_boIsOnClickDisp )
346 m_boIsOnClickDisp =
false;
350 return _super::OnChildNotify(message, wParam, lParam, _pResult);
362 virtual LRESULT
WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
367 TTRACE0(
"WM_UPDATEUISTATE\n");
370 TTRACE0(
"WM_ERASEBKGND\n");
373 TTRACE0(
"WM_PRINTCLIENT\n");
375 CDC* pDC = CDC::FromHandle(
reinterpret_cast<HDC
>(wParam));
383 TTRACE0(
"WM_PAINT\n");
393 TTRACE0(
"WM_SETFOCUS\n");
398 TTRACE0(
"WM_KILLFOCUS\n");
399 if ( m_pushState != EP_Non && ! m_IsPressedLockMode() )
401 m_pushState = EP_Non;
404 m_CheckNowState(
false);
414 TTRACE0(
"WM_GETDLGCODE\n");
417 return DLGC_DEFPUSHBUTTON | DLGC_BUTTON;
419 return DLGC_UNDEFPUSHBUTTON | DLGC_BUTTON;
420 case WM_GETTEXTLENGTH:
421 TTRACE0(
"WM_GETTEXTLENGTH\n");
422 if ( m_shortcutKey != 0 )
424 return 2 *
sizeof(TCHAR);
428 TTRACE0(
"WM_GETTEXT\n");
429 if ( m_shortcutKey != 0 && wParam >= 2 )
431 TCHAR* P =
reinterpret_cast<TCHAR*
>(lParam);
433 *P++ = m_shortcutKey;
438 TTRACE2(
"WM_KEYDOWN 0x%04X,0x%04X\n",wParam,lParam);
445 TTRACE2(
"WM_KEYUP 0x%04X,0x%04X\n",wParam,lParam);
449 if ( m_IsPressedLockMode() )
456 TTRACE0(
"WM_LBUTTONDOWN\n");
459 m_curpos = CPoint(lParam);
460 m_Push(m_boInBmClick ? EP_Key : EP_Mouse);
463 TTRACE0(
"WM_LBUTTONUP\n");
464 m_Unpush(m_boInBmClick ? EP_Key : EP_Mouse);
466 case WM_LBUTTONDBLCLK:
467 TTRACE0(
"WM_LBUTTONDBLCLK\n");
468 if ( ! m_canSendDblClk )
474 m_SendCommand(BN_DBLCLK);
478 TTRACE1(
"WM_MOUSEMOVE %X\n", lParam);
479 m_curpos = CPoint(lParam);
480 if ( ! m_boHasHover && m_pushState == EP_Non )
486 m_CheckNowState(
true);
490 TTRACE0(
"WM_ENABLE\n");
491 m_CheckNowState(
true);
494 TTRACE0(
"WM_GETFONT\n");
499 f =
reinterpret_cast<HFONT
>(::SendMessage(::GetParent(m_hWnd), WM_GETFONT, 0, 0));
503 f =
reinterpret_cast<HFONT
>(::GetStockObject(SYSTEM_FONT));
505 return reinterpret_cast<LRESULT
>(f);
509 TTRACE0(
"WM_SETFONT\n");
510 m_hFont =
reinterpret_cast<HFONT
>(wParam);
517 TTRACE0(
"WM_DESTROY\n");
518 m_pushState = EP_Non;
519 m_boHasHover =
false;
521 m_lastState =
static_cast<EState>(-1);
523 m_boInBmClick =
false;
524 m_boIsOnClickDisp =
false;
527 TTRACE0(
"BM_CLICK\n");
529 m_boInBmClick =
true;
530 LRESULT r = _super::WindowProc(message, wParam, lParam);
531 m_boInBmClick =
false;
536 TTRACE0(
"BM_GETSTATE\n");
539 r |= (m_nowState ==
ES_Pushed) ? BST_PUSHED : 0;
545 TTRACE0(
"BM_SETSTATE\n");
548 m_Unpush(EP_Message);
556 TTRACE0(
"WM_MOUSEHOVER\n");
560 TTRACE0(
"WM_MOUSELEAVE\n");
567 m_CheckNowState(
true);
571 return _super::WindowProc(message, wParam, lParam);
581 _super::ModifyStyle(0, SS_NOTIFY);
582 _super::PreSubclassWindow();
583 m_CheckNowState(
false);
598 bool m_boIsOnClickDisp;
601 bool m_canSendDblClk;
606 bool m_WithPressedMessage(
void)
const
610 bool m_IsPressedLockMode(
void)
const
615 bool m_IsAlive(
void)
const
620 void m_SendCommand(UINT uCmd)
628 void m_RedrawWindow(
void)
632 _super::RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE);
636 void m_CheckNowState(
bool boRedraw)
641 if ( m_nowState != m_lastState )
643 m_lastState = m_nowState;
653 void m_HoverOn(
bool boRedraw)
656 if ( ! m_boHasHover )
659 m_CheckNowState(boRedraw);
660 m_SendCommand(BN_HILITE);
666 void m_HoverOff(
bool boRedraw)
671 m_boHasHover =
false;
672 m_CheckNowState(boRedraw);
673 m_SendCommand(BN_UNHILITE);
678 void m_Push(EPush ep)
680 if ( ! m_IsAlive() ) {
return; }
681 if ( m_pushState == EP_Non )
684 if ( ! m_IsPressedLockMode() )
686 _super::SetCapture();
687 if ( m_WithPressedMessage() )
689 m_SendCommand(BN_PUSHED_T);
694 m_SendCommand(BN_PUSHED_T);
696 m_CheckNowState(
true);
701 void m_Unpush(EPush ep)
703 if ( ! m_IsAlive() ) {
return; }
704 if ( m_pushState != ep ) {
return; }
705 m_pushState = EP_Non;
707 if ( ep != EP_Message )
709 CPoint po = m_curpos;
712 if ( ep == EP_Key || onButton )
714 m_boIsOnClickDisp =
true;
716 if ( ! m_IsAlive() ) {
return; }
718 m_CheckNowState(
false);
720 if ( m_IsPressedLockMode() || m_WithPressedMessageMode() )
722 m_SendCommand(BN_UNPUSHED_T);
724 m_SendCommand(BN_CLICKED);
727 if ( m_IsPressedLockMode() || m_WithPressedMessage() )
729 m_SendCommand(BN_UNPUSHED_T);
731 m_SendCommand(BN_CLICKED);
738 m_CheckNowState(
false);
742 void m_HoverSub(
void)
746 tme.cbSize =
sizeof (TRACKMOUSEEVENT);
747 tme.hwndTrack = m_hWnd;
748 tme.dwHoverTime = HOVER_DEFAULT;
749 tme.dwFlags = TME_HOVER | TME_LEAVE;
750 ::_TrackMouseEvent(&tme);
HWND GetSafeHwnd(void) const
[取得] ウィンドウハンドル取得.
LRESULT SendCommandMessage(CWnd *pCtrl, UINT cmd)
[処理] WM_COMMAND送信.