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

📄 chameleonctl.cpp

📁 VC编写的变色龙按钮程序
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	RelayEvent( WM_MOUSEMOVE, (WPARAM)nFlags,
		MAKELPARAM(LOWORD(point.x), LOWORD(point.y)) );

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

void CChameleonCtrl::OnLButtonDblClk(UINT nFlags, CPoint point) 
{
	if( m_bEnabled )
	{
		//按下鼠标左键时重绘控件
		Redraw( 1, false );

		//屏蔽掉双击之后的OnLButtonUp事件
		m_bMouseDBClk = true;

		FireMouseDown( 0, 0, point.x, point.y );
	}
	
	//COleControl::OnLButtonDblClk(nFlags, point);
}

void CChameleonCtrl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	if( m_bEnabled )
	{
		USHORT usKey = nChar;
		short sShift = 0;

		m_nLastKey = nChar;

		if( m_nLastKey == 32 )
		{
			//响应空格键
			Redraw( 1, false );
		}
		else if( m_nLastKey == 39 || m_nLastKey == 40 )
		{
			//right and down arrows
			//When use in VC and VB,don't need to handle this
		}
		else if( m_nLastKey == 37 || m_nLastKey == 38 )
		{
			//left and up arrows
			//When use in VC and VB,don't need to handle this
		}

		FireKeyDown( &usKey, sShift );
	}

	//COleControl::OnKeyDown(nChar, nRepCnt, nFlags);
}

void CChameleonCtrl::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	if( m_bEnabled )
	{
		USHORT usKey = nChar;
		short sShift = 0;
	
		if( m_nLastKey == 32 && usKey == 32 )
		{
			//响应空格键
			if( m_bPress )
			{
				m_bPressState = !m_bPressState;
			}
			if( m_bPressState )
			{
				Redraw( 1, true );
			}
			else
			{
				Redraw( 0, true );
			}
			FireClick();
		}

		FireKeyUp( &usKey, sShift );
		FireKeyPress( &usKey );
	}

	//COleControl::OnKeyUp(nChar, nRepCnt, nFlags);
}

void CChameleonCtrl::OnSize(UINT nType, int cx, int cy) 
{
	if( !m_bStretch && m_lButtonType == 13 )
	{
		//在Stretch为false,且按钮类型为图片的时候,
		//将按钮设为图片的大小
		int nWidth;
		int nHeight;
		GetPictureSize( 1, nWidth, nHeight );
		if( nWidth == 0 || nHeight == 0 )
		{
			SetControlSize( 32, 32 );
		}
		else
		{
			SetControlSize( nWidth, nHeight );
		}
	}
	else
	{
		COleControl::OnSize(nType, cx, cy);
	}

	//保存按钮的大小
	GetClientRect( m_recFocusRect );
	m_nWidth = m_recFocusRect.Width();
	m_nHeight = m_recFocusRect.Height();

	//计算焦点框的大小
	if( m_lButtonType == 7 )
	{
		InflateRect( m_recFocusRect, -3, -3 );
	}
	else if( m_lButtonType == 12 )
	{
		InflateRect( m_recFocusRect, -5, -5 );
		OffsetRect( m_recFocusRect, 1, 1 );
	}
	else
	{
		InflateRect( m_recFocusRect, -4, -4 );
	}

	//根据按钮类型创建按钮绘画区域
	MakeRegion( m_rgnControl );
	SetWindowRgn( m_rgnControl, true );
}

void CChameleonCtrl::OnRButtonUp(UINT nFlags, CPoint point) 
{
	//丢弃鼠标右键和中键的响应
	//COleControl::OnRButtonUp(nFlags, point);
}

void CChameleonCtrl::OnRButtonDown(UINT nFlags, CPoint point) 
{
	//丢弃鼠标右键和中键的响应
	//COleControl::OnRButtonDown(nFlags, point);
}

void CChameleonCtrl::OnMButtonUp(UINT nFlags, CPoint point) 
{
	//丢弃鼠标右键和中键的响应
	//COleControl::OnMButtonUp(nFlags, point);
}

void CChameleonCtrl::OnMButtonDown(UINT nFlags, CPoint point) 
{
	//丢弃鼠标右键和中键的响应
	//COleControl::OnMButtonDown(nFlags, point);
}

/////////////////////////////////////////////////////////////////////////////
// CChameleonCtrl::AboutBox - Display an "About" box to the user

void CChameleonCtrl::AboutBox()
{
	CDialog dlgAbout(IDD_ABOUTBOX_CHAMELEON);
	dlgAbout.DoModal();
}


/////////////////////////////////////////////////////////////////////////////
// CChameleonCtrl message handlers

void CChameleonCtrl::OnBackColorChanged()
{
	if( IsWindow( m_hWnd ) )
	{
		Redraw( m_nStatus, true );
	}
}

void CChameleonCtrl::OnForeColorChanged()
{
	if( IsWindow( m_hWnd ) )
	{
		Redraw( m_nStatus, true );
	}
}

void CChameleonCtrl::OnTextChanged()
{
	CString strCaption = InternalGetText();
	int nFind = strCaption.Find( "&" );
	if( nFind != -1 )
	{
		if( strCaption.GetLength() > nFind + 1 )
		{
			m_ucAccessKey = (BYTE)strCaption.GetAt( nFind + 1 );
		}
		else
		{
			m_ucAccessKey = 0;
		}
	}
	else
	{
		m_ucAccessKey = 0;
	}

	if( IsWindow( m_hWnd ) )
	{
		Redraw( m_nStatus, true );
	}
}

void CChameleonCtrl::OnEnabledChanged()
{
	if( IsWindow( m_hWnd ) )
	{
		Redraw( m_nStatus, true );
	}
}

void CChameleonCtrl::OnFontChanged()
{
	if( IsWindow( m_hWnd ) )
	{
		Redraw( m_nStatus, true );
	}
}

long CChameleonCtrl::GetMousePointer() 
{
	return m_lMousePointer;
}

void CChameleonCtrl::SetMousePointer(long nNewValue) 
{
	m_lMousePointer = nNewValue;
	if( ( m_lMousePointer < 0 || m_lMousePointer > 15 )
		&& m_lMousePointer != 99 )
	{
		m_lMousePointer = 0;
	}

	SetModifiedFlag();
}

LPPICTUREDISP CChameleonCtrl::GetMouseIcon() 
{
	return m_phdMouseIcon.GetPictureDispatch();
}

void CChameleonCtrl::SetMouseIcon(LPPICTUREDISP newValue) 
{
	m_phdMouseIcon.SetPictureDispatch(newValue);

	SetModifiedFlag();
}

LPPICTUREDISP CChameleonCtrl::GetPicture() 
{
	return m_phdPicture.GetPictureDispatch();
}

void CChameleonCtrl::SetPicture(LPPICTUREDISP newValue) 
{
	m_phdPicture.SetPictureDispatch(newValue);
	if( IsWindow( m_hWnd ) )
	{
		Redraw( m_nStatus, true );
	}

	SetModifiedFlag();
}

long CChameleonCtrl::GetButtonType() 
{
	return m_lButtonType;
}

void CChameleonCtrl::SetButtonType(long newValue) 
{
	m_lButtonType = newValue;
	if( m_lButtonType < 1 || m_lButtonType > 13 )
	{
		m_lButtonType = 3;
	}

	if( IsWindow( m_hWnd ) )
	{
		MakeRegion( m_rgnControl );
		SetWindowRgn( m_rgnControl, true );

		Redraw( m_nStatus, true );
	}

	SetModifiedFlag();
}

long CChameleonCtrl::GetColorScheme() 
{
	return m_lColorScheme;
}

void CChameleonCtrl::SetColorScheme(long nNewValue) 
{
	m_lColorScheme = nNewValue;
	if( m_lButtonType < 1 || m_lButtonType > 4 )
	{
		m_lButtonType = 1;
	}

	if( IsWindow( m_hWnd ) )
	{
		Redraw( m_nStatus, true );
	}

	SetModifiedFlag();
}

BOOL CChameleonCtrl::GetPress() 
{
	return m_bPress;
}

void CChameleonCtrl::SetPress(BOOL bNewValue) 
{
	m_bPress = bNewValue;
	if( IsWindow( m_hWnd ) )
	{
		Redraw( m_nStatus, true );
	}

	SetModifiedFlag();
}

BOOL CChameleonCtrl::GetShowFocusRect() 
{
	return m_bShowFocusRect;
}

void CChameleonCtrl::SetShowFocusRect(BOOL bNewValue) 
{
	m_bShowFocusRect = bNewValue;
	if( IsWindow( m_hWnd ) )
	{
		Redraw( m_nStatus, true );
	}

	SetModifiedFlag();
}

BOOL CChameleonCtrl::GetStretch() 
{
	return m_bStretch;
}

void CChameleonCtrl::SetStretch(BOOL bNewValue) 
{
	CRect recClient;

	m_bStretch = bNewValue;
	if( IsWindow( m_hWnd ) )
	{
		GetClientRect( recClient );
		OnSize( 0, recClient.Width(), recClient.Height() );

		Redraw( m_nStatus, true );
	}

	SetModifiedFlag();
}

BSTR CChameleonCtrl::GetToolTipText() 
{
	return m_strTipText.AllocSysString();
}

void CChameleonCtrl::SetToolTipText(LPCTSTR lpszNewValue) 
{
	m_strTipText = lpszNewValue;

	if( AmbientUserMode() && m_ttpMes.m_hWnd != NULL )
	{
		if( m_strTipText.GetLength() > 0 )
		{
			m_ttpMes.Activate( true );
			m_ttpMes.UpdateTipText( m_strTipText, this );
		}
		else
		{
			m_ttpMes.Activate( false );
		}
	}

	SetModifiedFlag();
}

OLE_COLOR CChameleonCtrl::GetBackOverColor() 
{
	return m_lBackOverColor;
}

void CChameleonCtrl::SetBackOverColor(OLE_COLOR nNewValue) 
{
	m_lBackOverColor = nNewValue;
	if( IsWindow( m_hWnd ) )
	{
		Redraw( m_nStatus, true );
	}

	SetModifiedFlag();
}

OLE_COLOR CChameleonCtrl::GetForeOverColor() 
{
	return m_lForeOverColor;
}

void CChameleonCtrl::SetForeOverColor(OLE_COLOR nNewValue) 
{
	m_lForeOverColor = nNewValue;
	if( IsWindow( m_hWnd ) )
	{
		Redraw( m_nStatus, true );
	}

	SetModifiedFlag();
}

long CChameleonCtrl::GetTextEffect() 
{
	return m_lTextEffect;
}

void CChameleonCtrl::SetTextEffect(long nNewValue) 
{
	m_lTextEffect = nNewValue;
	if( m_lTextEffect < 0 || m_lTextEffect > 3 )
	{
		m_lTextEffect = 0;
	}

	if( IsWindow( m_hWnd ) )
	{
		Redraw( m_nStatus, true );
	}

	SetModifiedFlag();
}

BOOL CChameleonCtrl::GetHandPointer() 
{
	return m_bHandPointer;
}

void CChameleonCtrl::SetHandPointer(BOOL bNewValue) 
{
	m_bHandPointer = bNewValue;

	SetModifiedFlag();
}

LPPICTUREDISP CChameleonCtrl::GetDownPicture() 
{
	return m_phdDownPicture.GetPictureDispatch();
}

void CChameleonCtrl::SetDownPicture(LPPICTUREDISP newValue) 
{
	m_phdDownPicture.SetPictureDispatch(newValue);

	SetModifiedFlag();
}

LPPICTUREDISP CChameleonCtrl::GetOverPicture() 
{
	return m_phdOverPicture.GetPictureDispatch();

	return NULL;
}

void CChameleonCtrl::SetOverPicture(LPPICTUREDISP newValue) 
{
	m_phdOverPicture.SetPictureDispatch(newValue);

	SetModifiedFlag();
}

LPPICTUREDISP CChameleonCtrl::GetDisablePicture() 
{
	return m_phdDisablePicture.GetPictureDispatch();

	return NULL;
}

void CChameleonCtrl::SetDisablePicture(LPPICTUREDISP newValue) 
{
	m_phdDisablePicture.SetPictureDispatch(newValue);

	SetModifiedFlag();

⌨️ 快捷键说明

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