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

📄 macbuttons.cpp

📁 添七,棋牌游戏源代码,功能齐全,稳定,适合用于棋牌游戏开发
💻 CPP
📖 第 1 页 / 共 5 页
字号:
void CMacCheckBox::OnKeyUp(UINT nChar, UINT /*nRepCnt*/, UINT /*nFlags*/) 
//
// Return Value:	None.
//
// Parameters	:	nChar - Specifies the virtual-key code of the given key.
//						nRepCnt - Repeat count (the number of times the keystroke
//							is repeated as a result of the user holding down the key).
//						nFlags - Specifies the scan code, key-transition code, previous 
//							key state, and context code
//
// Remarks		:	The framework calls this member function when a nonsystem 
//						key is released. Checks/unchecks the button when the space bar
//						is pressed.
//
{		
	if (nChar == VK_SPACE)
	{
		m_bMouseDown = FALSE;
		m_nCheck = (m_nCheck == 0 ? 1 : 0);

		// Send notify message to parent window.
		// Added by Eric Hwang.
		GetParent()->SendMessage(WM_COMMAND, MAKEWPARAM(GetDlgCtrlID(), BN_CLICKED), (LPARAM)GetSafeHwnd());

		if (GetStyle() & BS_PUSHLIKE)
			RedrawWindow();
		else
			RedrawCheck();
	}
}	// OnKeyUp

//-------------------------------------------------------------------
//
void CMacCheckBox::OnKeyDown(UINT nChar, UINT /*nRepCnt*/, UINT /*nFlags*/) 
//
// Return Value:	None.
//
// Parameters	:	nChar - Specifies the virtual-key code of the given key.
//						nRepCnt - Repeat count (the number of times the keystroke 
//							is repeated as a result of the user holding down the key).
//						nFlags - Specifies the scan code, key-transition code, 
//							previous key state, and context code
//
// Remarks		:	The framework calls this member function when a 
//						nonsystem key is pressed.
//
{
	if (nChar == VK_SPACE)
	{
		if (!m_bMouseDown)
		{
			m_bMouseDown = TRUE;
			if (GetStyle() & BS_PUSHLIKE)
				RedrawWindow();
			else
				RedrawCheck();
		}
	}
}	// OnKeyDown

//-------------------------------------------------------------------
//
void CMacCheckBox::SetCheckStyle(int nStyle /* = CHECK_STYLE_CHECK*/)
//
// Return Value:	None.
//
// Parameters	:	nStyle - The check style to set.	Can be one of the
//							following values:
//								CHECK_STYLE_CHECK		Check mark style.
//								CHECK_STYLE_CROSS		"X" style.
//
// Remarks		:	Sets the check style.
//
{
	m_nCheckStyle = nStyle;
	RedrawCheck();
}	// SetCheckStyle

//-------------------------------------------------------------------
//
int CMacCheckBox::GetCheckStyle() const
//
// Return Value:	The current check style.
//
// Parameters	:	None.
//
// Remarks		:	Gets the current check style.
//
{
	return m_nCheckStyle;
}	// GetCheckStyle

/////////////////////////////////////////////////////////////////////////////
//
//	CMacRadioButton class, version 2.0
//
//	Copyright (c) 1999, 2000 Paul M. Meidinger (pmmeidinger@yahoo.com)
//
// Thanks to:
//		Eric Hwang <erichw@21cn.com>
//			For fixing the problem that was not sending a message
//			to the parent when the button was clicked.
//
//	History:
//		PMM	12/13/1999		Initial implementation.		
//
//		PMM	12/17/1999		Modified drawing code to use a memory DC. 
//									Added CPen member variables in an attempt to 
//									speed up drawing. Made other minor changes.
//
//		PMM	12/29/1999		Fixed a bug that was not checking the radio
//									and unchecking others when the space bar is pressed.
//									Fixed a bug that would not send a message to the parent
//									when the button was clicked (fix by Eric Hwang). Added
//									code to draw a push-like button when that style is used.
//
/////////////////////////////////////////////////////////////////////////////

//-------------------------------------------------------------------
//
CMacRadioButton::CMacRadioButton()
	: CMacButton()
//
// Return Value:	None.
//
// Parameters	:	None.
//
// Remarks		:	Standard constructor.
//
{
	m_nType = TYPE_RADIO;
}	// CMacRadioButton

//-------------------------------------------------------------------
//
CMacRadioButton::~CMacRadioButton()
//
// Return Value:	None.
//
// Parameters	:	None.
//
// Remarks		:	Destructor. Does nothing.
//
{
}	// ~CMacRadioButton


BEGIN_MESSAGE_MAP(CMacRadioButton, CMacButton)
	//{{AFX_MSG_MAP(CMacRadioButton)
	ON_WM_LBUTTONUP()
	ON_WM_LBUTTONDOWN()
	ON_WM_MOUSEMOVE()
	ON_WM_LBUTTONDBLCLK()
	ON_WM_SYSCOLORCHANGE()
	ON_WM_KEYDOWN()
	ON_WM_KEYUP()
	ON_WM_SETFOCUS()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMacRadioButton message handlers

//-------------------------------------------------------------------
//
void CMacRadioButton::DrawItem(LPDRAWITEMSTRUCT lpDIS) 
//
// Return Value:	None.
//
// Parameters	:	lpDIS - A long pointer to a DRAWITEMSTRUCT structure.
//
// Remarks		:	Called by the framework when a visual aspect of an 
//						owner-drawn button has changed.
//
{
	DrawButton(lpDIS);
}	// DrawItem

//-------------------------------------------------------------------
//
BOOL CMacRadioButton::PreTranslateMessage(MSG* pMsg) 
//
// Return Value:	Nonzero if the message was translated and should not 
//						be dispatched; 0 if the message was not translated 
//						and should be dispatched.
//
// Parameters	:	pMsg - Points to a MSG structure that contains the 
//							message to process.
//
// Remarks		:	Used by class CWinApp to translate window messages 
//						before they are dispatched to theTranslateMessage 
//						andDispatchMessage Windows functions. Catches the 
//						WM_KEYDOWN message and handles the up, down, left
//						and right arrows.
//
{
	if (pMsg->message == WM_KEYDOWN)
	{
		if (pMsg->wParam == VK_DOWN || pMsg->wParam == VK_UP ||
			 pMsg->wParam == VK_LEFT || pMsg->wParam == VK_RIGHT)
		{
			UncheckOtherRadios();

			// Get the previous/next button and check it.
			CWnd *pParent = GetParent();
			ASSERT(pParent);

			CWnd *pWnd = pParent->GetNextDlgGroupItem((CWnd *)this, (pMsg->wParam == VK_LEFT || pMsg->wParam == VK_UP ? TRUE : FALSE));
			if (pWnd && (((CButton*)pWnd)->GetButtonStyle() & BS_AUTORADIOBUTTON) && ((CMacRadioButton *)pWnd)->m_nType == TYPE_RADIO)
			{
				((CMacRadioButton *)pWnd)->SetCheck(1);

				// Send notify message to parent window.
				// Added by Eric Hwang.
				pParent->SendMessage(WM_COMMAND, MAKEWPARAM(pWnd->GetDlgCtrlID(), BN_CLICKED), (LPARAM)pWnd->GetSafeHwnd());
			}
			SetCheck(0);
			return FALSE;
		}
	}
	return CMacButton::PreTranslateMessage(pMsg);
}	// PreTranslateMessage

//-------------------------------------------------------------------
//
void CMacRadioButton::OnLButtonUp(UINT /*nFlags*/, CPoint point) 
//
// Return Value:	None.
//
// Parameters	:	nFlags - Indicates whether various virtual keys are down. 
//						point - Specifies the x- and y-coordinate of the cursor. 
//							These coordinates are always relative to the upper-left 
//							corner of the window.
//
// Remarks		:	The framework calls this member function when the user 
//						releases the left mouse button. Checks to see if the mouse
//						was released over the button. If so, check it and uncheck others.
//
{
	ReleaseCapture();

	UINT nStyle = GetStyle();

	CRect rect;
	GetClientRect(rect);
	if (rect.PtInRect(point))
	{
		if (!m_nCheck)
			m_nCheck = 1;

		// Uncheck all other radios in the group
		if ((nStyle & BS_AUTORADIOBUTTON) && m_nCheck)
		{
			UncheckOtherRadios();
		}

		// Send notify message to parent window.
		// Added by Eric Hwang
		GetParent()->SendMessage(WM_COMMAND, MAKEWPARAM(GetDlgCtrlID(), BN_CLICKED), (LPARAM)GetSafeHwnd());
	}

	m_bMouseDown = FALSE;

	if (nStyle & BS_PUSHLIKE)
		RedrawWindow();
	else
		RedrawCheck();

//	CMacButton::OnLButtonUp(nFlags, point);
}	// OnLButtonUp

//-------------------------------------------------------------------
//
void CMacRadioButton::OnLButtonDown(UINT /*nFlags*/, CPoint /*point*/) 
//
// Return Value:	None.
//
// Parameters	:	nFlags - Indicates whether various virtual keys are down. 
//						point - Specifies the x- and y-coordinate of the cursor. 
//							These coordinates are always relative to the upper-left 
//							corner of the window.
//
// Remarks		:	The framework calls this member function when the user 
//						presses the left mouse button. Sets focus to this button,
//						captures the mouse, and redraws the check.
//
{
	m_bMouseDown = TRUE;
	SetFocus();
	SetCapture();

	if (GetStyle() & BS_PUSHLIKE)
		RedrawWindow();
	else
		RedrawCheck();
//	CMacButton::OnLButtonDown(nFlags, point);
}	// OnLButtonDown

//-------------------------------------------------------------------
//
void CMacRadioButton::OnMouseMove(UINT nFlags, CPoint point) 
//
// Return Value:	None.
//
// Parameters	:	nFlags - Indicates whether various virtual keys are down. 
//						point - Specifies the x- and y-coordinate of the cursor. 
//							These coordinates are always relative to the upper-left 
//							corner of the window.
//
// Remarks		:	The framework calls this member function when the 
//						mouse cursor moves. Checks to see if the mouse is over
//						the button, and redraws the check if it is, but wasn't previously.
//
{
	if (GetCapture() != this)
		return;

	BOOL bWasMouseDown = m_bMouseDown;

	CRect rect;
	GetClientRect(rect);
	m_bMouseDown = rect.PtInRect(point);

	if (bWasMouseDown != m_bMouseDown)
	{
		if (GetStyle() & BS_PUSHLIKE)
			RedrawWindow();
		else
			RedrawCheck();
	}

	CMacButton::OnMouseMove(nFlags, point);
}	// OnMouseMove

//-------------------------------------------------------------------
//
void CMacRadioButton::OnLButtonDblClk(UINT /*nFlags*/, CPoint point) 
//
// Return Value:	None.
//
// Parameters	:	nFlags - Indicates whether various virtual keys are down.
//						point - Specifies the x- and y-coordinate of the cursor. 
//							These coordinates are always relative to the upper-left
//							 corner of the window.
//
// Remarks		:	The framework calls this member function when the user 
//						double-clicks the left mouse button. The WM_LBUTTONDOWN
//						message is sent to simulate a single click.
//
{
	SendMessage(WM_LBUTTONDOWN, 0, MAKELPARAM(point.x, point.y));	
}	// OnLButtonDblClk

//-------------------------------------------------------------------
//
void CMacRadioButton::OnKeyUp(UINT nChar, UINT /*nRepCnt*/, UINT /*nFlags*/) 
//
// Return Value:	None.
//
// Parameters	:	nChar - Specifies the virtual-key code of the given key.
//						nRepCnt - Repeat count (the number of times the keystroke 
//							is repeated as a result of the user holding down the key).
//						nFlags - Specifies the scan code, key-transition code, 
//							previous key state, and context code
//
// Remarks		:	The framework calls this member function when a 
//						nonsystem key is released. 
//
{
	if (nChar == VK_SPACE)
	{
		m_nCheck = 1;

		// Send notify message to parent window.
		// Added by Eric Hwang.
		GetParent()->SendMessage(WM_COMMAND, MAKEWPARAM(GetDlgCtrlID(), BN_CLICKED), (LPARAM)GetSafeHwnd());

		UncheckOtherRadios();
		m_bMouseDown = FALSE;
		if (GetStyle() & BS_PUSHLIKE)
			RedrawWindow();
		else
			RedrawCheck();
	}
}	// OnKeyUp

//-------------------------------------------------------------------
//
void CMacRadioButton::OnKeyDown(UINT nChar, UINT /*nRepCnt*/, UINT /*nFlags*/) 
//
// Return Value:	None.
//
// Parameters	:	nChar - Specifies the virtual-key code of the given key.
//						nRepCnt - Repeat count (the number of times the keystroke 
//							is repeated as a result of the user holding down the key).
//						nFlags - Specifies the scan code, key-transition code, 
//							previous key state, and context code
//
// Remarks		:	The framework calls this member function when a 
//						nonsystem key is pressed.
//
{
	if (nChar == VK_SPACE)
	{
		if (!m_bMouseDown)
		{
			m_bMouseDown = TRUE;
			if (GetStyle() & BS_PUSHLIKE)
				RedrawWindow();
			else
				RedrawCheck();
		}
	}
}	// OnKeyDown

//-------------------------------------------------------------------
//
void CMacRadioButton::OnSysColorChange() 
//
// Return Value:	None.
//
// Parameters	:	None.
//
// Remarks		:	The framework calls this member function for all 
//						top-level windows when a change is made in the 
//						system color setting
//
{
	CMacButton::OnSysColorChange();
	
	GetColors();
	CreatePens();
}	// OnSysColorChange

//-------------------------------------------------------------------
//
void CMacRadioButton::UncheckOthe

⌨️ 快捷键说明

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