📄 xshadebutton.cpp
字号:
//Description :
// > Handle event when left button is pressed down
//---------------------------------------------------------
void CxShadeButton::OnLButtonDown(UINT nFlags, CPoint point)
{
//TRACE("* %08X: down\n", ::GetTickCount());
//Pass this message to the ToolTip control
RelayEvent(WM_LBUTTONDOWN,(WPARAM)nFlags,MAKELPARAM(LOWORD(point.x),LOWORD(point.y)));
//If we are tracking this button, cancel it
if (m_tracking) {
TRACKMOUSEEVENT t = {
sizeof(TRACKMOUSEEVENT),
TME_CANCEL | TME_LEAVE,
m_hWnd, 0
};
if (::_TrackMouseEvent(&t)) {
m_tracking = false;
}
}
//Default-process the message
CButton::OnLButtonDown(nFlags, point);
m_button_down = true;
}
/////////////////////////////////////////////////////////////////////////////
//Method......: OnLButtonUp
//Class.......: CxShadeButton
//
//Author......: Milan Gardian
//Created.....: MAR-2001
//
//Return value: NONE
//Parameters..: As follows
// > [in] nFlags: not used
// > [in] point: coordinates of the mouse pointer when this event was spawned
//Exceptions..: NONE
//------------
//Description :
//
// > Handle event when left button is released (goes up)
//---------------------------------------------------------
void CxShadeButton::OnLButtonUp(UINT nFlags, CPoint point)
{
//TRACE("* %08X: up\n", ::GetTickCount());
if (m_Style){ //track mouse for radio & check buttons
POINT p2 = point;
::ClientToScreen(m_hWnd, &p2);
HWND mouse_wnd = ::WindowFromPoint(p2);
if (mouse_wnd == m_hWnd && m_button_down == true){ // mouse is in button
if (m_Style==BS_CHECKBOX) SetCheck(m_Checked ? 0 : 1);
if (m_Style==BS_RADIOBUTTON) SetCheck(1);
}
}
//Pass this message to the ToolTip control
RelayEvent(WM_LBUTTONUP,(WPARAM)nFlags,MAKELPARAM(LOWORD(point.x),LOWORD(point.y)));
//Default-process the message
m_button_down = false;
CButton::OnLButtonUp(nFlags, point);
}
/////////////////////////////////////////////////////////////////////////////
//Method......: OnMouseMove
//Class.......: CxShadeButton
//
//Author......: Milan Gardian
//Created.....: MAR-2001
//
//Return value: NONE
//Parameters..: As follows
// > [in] nFlags: not used
// > [in] point: coordinates of the mouse pointer when this event was spawned
//Exceptions..: NONE
//------------
//Description :
// > Handle change of mouse position: see the comments in the
// method for further info.
//---------------------------------------------------------
void CxShadeButton::OnMouseMove(UINT nFlags, CPoint point)
{
//TRACE("* %08X: Mouse\n", ::GetTickCount());
//Pass this message to the ToolTip control
RelayEvent(WM_MOUSEMOVE,(WPARAM)nFlags,MAKELPARAM(LOWORD(point.x),LOWORD(point.y)));
//If we are in capture mode, button has been pressed down
//recently and not yet released - therefore check is we are
//actually over the button or somewhere else. If the mouse
//position changed considerably (e.g. we moved mouse pointer
//from the button to some other place outside button area)
//force the control to redraw
//
if ((m_button_down) && (::GetCapture() == m_hWnd)) {
POINT p2 = point;
::ClientToScreen(m_hWnd, &p2);
HWND mouse_wnd = ::WindowFromPoint(p2);
bool pressed = ((GetState() & BST_PUSHED) == BST_PUSHED);
bool need_pressed = (mouse_wnd == m_hWnd);
if (pressed != need_pressed) {
//TRACE("* %08X Redraw\n", GetTickCount());
SetState(need_pressed ? TRUE : FALSE);
Invalidate();
}
} else {
//Otherwise the button is released. That means we should
//know when we leave its area - and so if we are not tracking
//this mouse leave event yet, start now!
//
if (!m_tracking) {
TRACKMOUSEEVENT t = {
sizeof(TRACKMOUSEEVENT),
TME_LEAVE,
m_hWnd,
0
};
if (::_TrackMouseEvent(&t)) {
//TRACE("* Mouse enter\n");
m_tracking = true;
Invalidate();
}
}
}
//Forward this event to superclass
CButton::OnMouseMove(nFlags, point);
}
/////////////////////////////////////////////////////////////////////////////
//Method......: OnMouseLeave
//Class.......: CxShadeButton
//
//Author......: Milan Gardian
//Created.....: MAR-2001
//
//Return value: NULL
//Parameters..: NOT USED
//Exceptions..: NONE
//------------
//Description :
// > Handle situation when mouse cursor leaves area of this
// window (button). This event might be generated ONLY
// if we explicitely call 'TrackMouseEvent'. This is
// signalled by setting the m_tracking flag (see the assert
// precondition) - in 'OnMouseMove' method
//
// > When a mouse pointer leaves area of this button (i.e.
// when this method is invoked), presumably the look of
// the button changes (e.g. when hover/non-hover images are set)
// and therefore we force the control to redraw.
//---------------------------------------------------------
LRESULT CxShadeButton::OnMouseLeave(WPARAM, LPARAM)
{
ASSERT (m_tracking);
//TRACE("* Mouse leave\n");
m_tracking = false;
Invalidate();
return 0;
}
/////////////////////////////////////////////////////////////////////////////
//Method......: OnKillFocus
//Class.......: CxShadeButton
//
//Author......: Milan Gardian
//Created.....: MAR-2001
//
//Return value: NONE
//Parameters..: See superclass documentation
//Exceptions..: NONE
//------------
//Description :
// > If focus is killed during capture, we may no longer
// have the exclusive access to user input and therefore
// release it.
//
// > Such a situation might happens when the user left-clicks
// this button, keeps the button down and simultaneously
// presses TAB key.
//---------------------------------------------------------
void CxShadeButton::OnKillFocus(CWnd *new_wnd)
{
if (::GetCapture() == m_hWnd) {
::ReleaseCapture();
ASSERT (!m_tracking);
m_button_down = false;
}
CButton::OnKillFocus(new_wnd);
}
/////////////////////////////////////////////////////////////////////////////
//Method......: OnClicked
//Class.......: CxShadeButton
//
//Author......: Milan Gardian
//Created.....: MAR-2001
//
//Return value: FALSE (do not stop in this handler - forward to parent)
//Parameters..: NONE
//Exceptions..: NONE
//------------
//Description :
// > Keep consistency of attributes of this instance before
// submitting click event to the parent.
//
// > Currently NOT used. To use, umcomment line
// "ON_CONTROL_REFLECT_EX(BN_CLICKED, OnClicked)" in message map
// at the beginning of this file.
//---------------------------------------------------------
BOOL CxShadeButton::OnClicked()
{
if (::GetCapture() == m_hWnd) {
::ReleaseCapture();
ASSERT (!m_tracking);
}
m_button_down = false;
//Invalidate();
return FALSE;
}
/////////////////////////////////////////////////////////////////////////////
//Method......: OnRadioInfo
//Class.......: CxShadeButton
//
//Author......: Rainer Mangold
//Created.....: JUN-2001
//
//Return value: NULL
//Parameters..: WPARAM and LPARAM (LPARAM not used)
//Exceptions..: NONE
//------------
//Description :
// > Handle notification, that a Button in the same group was pushed
//---------------------------------------------------------
LRESULT CxShadeButton::OnRadioInfo(WPARAM wparam, LPARAM)
{
if (m_Checked){ //only checked buttons need to be unchecked
m_Checked = false;
if(m_tooltip.m_hWnd!=NULL)
m_tooltip.UpdateTipText((LPCTSTR)m_ToolTipUp,this);
Invalidate();
}
return 0;
}
/////////////////////////////////////////////////////////////////////////////
void CxShadeButton::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if ((m_Style)&&(nChar==' ')){ //needed stuff for check & radio buttons
if (m_Style==BS_CHECKBOX) SetCheck(m_Checked ? 0 : 1);
if (m_Style==BS_RADIOBUTTON) SetCheck(1);
}
CButton::OnKeyDown(nChar, nRepCnt, nFlags);
}
/////////////////////////////////////////////////////////////////////////////
//Method......: SetCheck
//Class.......: CxShadeButton
//
//Author......: Rainer Mangold
//Created.....: JUN-2001
//
//Return value: NONE
//Parameters..: bool
//Exceptions..: NONE
//------------
//Description :
// > Set the state of this button (pushed or not).
// Works for both, Radio and CheckBox - Buttons
//---------------------------------------------------------
LRESULT CxShadeButton::OnBMSetCheck(WPARAM wparam, LPARAM)
{
m_Checked=wparam!=0;
switch (m_Style)
{
case BS_RADIOBUTTON:
if (m_Checked) { //uncheck the other radio buttons (in the same group)
HWND hthis,hwnd2,hpwnd;
hpwnd=GetParent()->GetSafeHwnd(); //get button parent handle
hwnd2=hthis=GetSafeHwnd(); //get this button handle
if (hthis && hpwnd){ //consistency check
for( ; ; ){ //scan the buttons within the group
hwnd2=::GetNextDlgGroupItem(hpwnd,hwnd2,0);
//until we reach again this button
if ((hwnd2==hthis)||(hwnd2==NULL)) break;
//post the uncheck message
::PostMessage(hwnd2, WM_CXSHADE_RADIO, 0, 0);
}
}
}
break;
case BS_PUSHBUTTON:
m_Checked=false;
ASSERT(false); // Must be a Check or Radio button to use this function
}
//set the correct tooltip
if (m_tooltip.m_hWnd!=NULL){
m_tooltip.Pop(); //to avoid flicker
if (m_Checked && !m_ToolTipDw.IsEmpty())
m_tooltip.UpdateTipText((LPCTSTR)m_ToolTipDw,this);
else
m_tooltip.UpdateTipText((LPCTSTR)m_ToolTipUp,this);
}
Invalidate();
return 0;
}
/////////////////////////////////////////////////////////////////////////////
LRESULT CxShadeButton::OnBMGetCheck(WPARAM wparam, LPARAM)
{ return m_Checked; } //returns the state for check & radio buttons
/////////////////////////////////////////////////////////////////////////////
void CxShadeButton::SetButtonStyle(UINT nStyle, BOOL bRedraw)
{
// see PreSubclassWindow
m_IsPushLike=((nStyle & BS_PUSHLIKE)!=0);
m_flat=((nStyle & BS_FLAT)!=0);
if ((nStyle & BS_AUTOCHECKBOX)==BS_AUTOCHECKBOX)
// ||((m_Style & BS_CHECKBOX)==BS_CHECKBOX))
m_Style=BS_CHECKBOX;
else if ((nStyle & BS_AUTORADIOBUTTON)==BS_AUTORADIOBUTTON)
// ||((m_Style & BS_RADIOBUTTON)==BS_RADIOBUTTON))
m_Style=BS_RADIOBUTTON;
else { m_Style=BS_PUSHBUTTON; m_IsPushLike=true; m_Checked=false; }
//default radio & check-box has no border
if (!m_IsPushLike) m_Border = false;
if (bRedraw) Invalidate();
}
/////////////////////////////////////////////////////////////////////////////
bool CxShadeButton::SetFont(CString sFontName,long lSize, long lWeight, BYTE bItalic, BYTE bUnderline)
{
if (m_pLF==NULL) m_pLF=(LOGFONT*)calloc(1,sizeof(LOGFONT));
if (m_pLF){
strncpy(m_pLF->lfFaceName,sFontName,31);
m_pLF->lfHeight=lSize;
m_pLF->lfWeight=lWeight;
m_pLF->lfItalic=bItalic;
m_pLF->lfUnderline=bUnderline;
m_Font.DeleteObject();
if (m_Font.CreateFontIndirect(m_pLF)) return true;
}
return false;
}
/////////////////////////////////////////////////////////////////////////////
bool CxShadeButton::SetFont(LOGFONT* pNewStyle)
{
if (pNewStyle){
if (m_pLF==NULL) m_pLF=(LOGFONT*)calloc(1,sizeof(LOGFONT));
if (m_pLF){
memcpy(m_pLF,pNewStyle,sizeof(LOGFONT));
m_Font.DeleteObject();
if (m_Font.CreateFontIndirect(m_pLF)) return true;
}
}
return false;
}
/////////////////////////////////////////////////////////////////////////////
LOGFONT* CxShadeButton::GetFont()
{ return m_pLF; }
/////////////////////////////////////////////////////////////////////////////
//EOF
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -