⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 skin.cpp

📁 菜单下加小图标示例,详细源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
{
m_tooltip.UpdateTipText((LPCTSTR)s, this);
}
}

void CSkin::SetToolTipText(int nText)
{
CString sText;

// Load string resource
sText.LoadString(nText);
// If string resource is not empty
if (sText.IsEmpty() == FALSE)
{
SetToolTipText(sText);
}
}*/ // End of SetTooltipText

/////////////////////////////////////////////////////////////////////////////
/*void CSkin::RelayEvent(UINT message, WPARAM wParam, LPARAM lParam)
{
// This function will create a MSG structure, fill it in a pass it to
// the ToolTip control, m_ttip.  Note that we ensure the point is in window
// coordinates (relative to the control's window).
if (NULL != m_tooltip.m_hWnd) 
{
MSG msg;
msg.hwnd = m_hWnd;
msg.message = message;
msg.wParam = wParam;
msg.lParam = lParam;
msg.time = 0;
msg.pt.x = LOWORD(lParam);
msg.pt.y = HIWORD(lParam);

m_tooltip.RelayEvent(&msg);
}
}*/

/////////////////////////////////////////////////////////////////////////////
//
//Method......: OnLButtonDblClk
//Class.......: CVxSkinButton
//
//Author......: Milan Gardian
//Created.....: MAR-2001
//
//Return value: NONE
//Parameters..: Used only to be forwarded as WM_LBUTTONDOWN message parameters
//Exceptions..: NONE
//------------
//Description :
//
//  > We do not care about doublelicks - handle this event
//    like an ordinary left-button-down event
//
//---------------------------------------------------------
void CSkin::OnLButtonDblClk(UINT flags, CPoint point)
{
	SendMessage(WM_LBUTTONDOWN, flags, MAKELPARAM(point.x, point.y));
	CButton::OnLButtonDblClk(flags, point);
}

/////////////////////////////////////////////////////////////////////////////
//
//Method......: OnLButtonDown
//Class.......: CSkin
//
//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 pressed down
//
//---------------------------------------------------------
void CSkin::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.......: CSkin
//
//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 CSkin::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)
		{
			// 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.......: CSkin
//
//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 CSkin::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.......: CSkin
//
//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 CSkin::OnMouseLeave(WPARAM, LPARAM)
{
	//ASSERT(m_tracking);
	//TRACE("* Mouse leave\n");
	m_tracking = TRUE;
	Invalidate();
	return 0;
}


/////////////////////////////////////////////////////////////////////////////
//
//Method......: OnKillFocus
//Class.......: CSkin
//
//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 CSkin::OnKillFocus(CWnd *new_wnd)
{
	if (::GetCapture() == m_hWnd)
	{
		::ReleaseCapture();
		ASSERT(!m_tracking);
		m_button_down = false;
	}
	CButton::OnKillFocus(new_wnd);
}

/////////////////////////////////////////////////////////////////////////////
//
//Method......: OnClicked
//Class.......: CSkin
//
//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 CSkin::OnClicked()
{
	if (::GetCapture() == m_hWnd)
	{
		::ReleaseCapture();
		ASSERT(!m_tracking);
	}
	m_button_down = false;
	//Invalidate();
	return FALSE;
}

/////////////////////////////////////////////////////////////////////////////
//
//Method......: OnRadioInfo
//Class.......: CSkin
//
//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 CSkin::OnRadioInfo(WPARAM wparam, LPARAM)
{
	if (m_Checked)
	{
		// only checked buttons need to be unchecked
		m_Checked = false;
		Invalidate();
	}
	return 0;
}*/


/////////////////////////////////////////////////////////////////////////////
/*
void CSkin::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.......: CSkin
//
//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 CSkin::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
		break;
	}

	Invalidate();
	return 0;
}

/////////////////////////////////////////////////////////////////////////////
/*
LRESULT CSkin::OnBMGetCheck(WPARAM wparam, LPARAM)
{
	return m_Checked;
} // returns the state for check & radio buttons*/


/////////////////////////////////////////////////////////////////////////////
//EOF

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -