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

📄 yctrls.cpp

📁 Windows mobile下的透明控件(皮肤控件) 当前Windows mobile下的皮肤控件还很少
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    }
}

void  CForm::SetOnMinQuit( BOOL bQuit )
{
	m_bOnMinQuit = bQuit;
}

/*********************************************************************************************
*								CCtrl														 *
*																							 *
*		YCode Y代码 YCtrl Y控件 Windows Mobile 透明控件 2008 YCtrl 1.0						 *
*			作者:卢益贵 QQ:48092788 luyigui.blog.nnsky.com									 *
*																							 *
**********************************************************************************************/
CCtrl::CCtrl()
{
	m_dwTextAlign = DT_LEFT | DT_VCENTER;
}

CCtrl::~CCtrl()
{
	
}

BOOL CCtrl::Create( CWin *pOwner, CWin *pParent,  DWORD dwCtrlID, int nLeft, int nTop, int nWidth, int nHeigth,
				    LPCWSTR lpszClassName, LPCWSTR lpszCaption )
{
	m_dwCtrlID = dwCtrlID;
	return CWin::Create( pOwner, pParent, (HMENU)dwCtrlID, nLeft, nTop, nWidth, nHeigth, lpszClassName, lpszCaption );
}

void CCtrl::CreateStyle( pCREATESTYLE pCreateStyle )
{
	CWin::CreateStyle( pCreateStyle );
	pCreateStyle->dwStyle |= (WS_CHILD | WS_VISIBLE);
}

void CCtrl::SetTextAlign( DWORD dwTextAlign )
{
	if( m_dwTextAlign != dwTextAlign )
	{
		m_dwTextAlign = dwTextAlign;
		Invalidate();
	}
}

DWORD CCtrl::GetTextAlign( void )
{
	return m_dwTextAlign;
}

void CCtrl::DrawText( HDC hdc, RECT rc, LPCWSTR lpszText, DWORD dwTextAlign )
{
	SelectFont( hdc, m_hFont );
	SetBkMode( hdc, TRANSPARENT );

	if( GetEnabled() )
	{
		::SetTextColor( hdc, m_clTextColor );
		::DrawText( hdc, lpszText, -1, &rc, dwTextAlign);
	}else
	{
		m_clTextColor = RGB( 172, 168, 153 );
		::SetTextColor( hdc, m_clTextColor );
		::DrawText( hdc, lpszText, -1, &rc, dwTextAlign);
	}
}

/*********************************************************************************************
*								CBtt														 *
*																							 *
*		YCode Y代码 YCtrl Y控件 Windows Mobile 透明控件 2008 YCtrl 1.0						 *
*			作者:卢益贵 QQ:48092788 luyigui.blog.nnsky.com									 *
*																							 *
**********************************************************************************************/
CBtt::CBtt()
{
	m_cidClassID = CID_Y_BUTTON;
	m_clColorDown = RGB( 0, 203, 203 );
	m_clColorNormal = 0xFFFF00;
	m_clColorFocus = RGB( 194, 255, 251 );
	m_dwTextAlign = DT_CENTER | DT_VCENTER;
}

CBtt::~CBtt()
{
	
}

BOOL CBtt::Create( CWin *pOwner, CWin *pParent,  DWORD dwCtrlID, int nLeft, int nTop, int nWidth, int nHeigth, LPCWSTR lpszCaption )
{
	RegClass( L"YButton" );
	return( CCtrl::Create( pOwner, pParent, dwCtrlID, nLeft, nTop, nWidth, nHeigth, L"YButton", lpszCaption) );
}

void CBtt::CreateStyle( pCREATESTYLE pCreateStyle )
{
	CCtrl::CreateStyle(pCreateStyle);
	pCreateStyle->dwStyle |= WS_TABSTOP;
}

LRESULT CBtt::WindowProc( HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam )
{
	LRESULT r;
	switch( uMsg )
    {
		case WM_KEYDOWN:
			if( 13 != wParam )
				return CCtrl::WindowProc( hWnd, uMsg, wParam, lParam );
			m_dwMouseState = MS_Y_DOWN;
			Invalidate();
			return 0;
		case WM_KEYUP:
			if( 13 != wParam )
				return CCtrl::WindowProc( hWnd, uMsg, wParam, lParam );
			SendMessage( m_hWnd, WM_LBUTTONCLICK, 0, 0);
			m_dwMouseState &= (~MS_Y_DOWN);
			Invalidate();
			return 0;
		case WM_LBUTTONDOWN:
			SetFocus( m_hWnd );
			SetCapture( m_hWnd );
			r = CCtrl::WindowProc( hWnd, uMsg, wParam, lParam );
			Invalidate();
			return r;
		case WM_LBUTTONUP:
			r = CCtrl::WindowProc( hWnd, uMsg, wParam, lParam );
			ReleaseCapture();			
			Invalidate();
			return r;
		case WM_MOUSEMOVE:
			SetCapture( m_hWnd );
			r = CCtrl::WindowProc( hWnd, uMsg, wParam, lParam );
			Invalidate();
			return r;
		case WM_MOUSELEAVE:
			if( !(m_dwMouseState & MS_Y_DOWN) )
			{
				ReleaseCapture();
				Invalidate();
			}
			return 0;
		case WM_LBUTTONCLICK:
		case WM_LBUTTONDBLCLK:
			SendMessage( m_pOwner->GetHandle(), WM_COMMAND, m_dwCtrlID, 0 );
			return 0;
		case WM_SETFOCUS:
			Invalidate();
			return 0;
		case WM_KILLFOCUS:
			Invalidate();
			return 0;
		default:
			return CCtrl::WindowProc( hWnd, uMsg, wParam, lParam );
    }
}

void CBtt::OnDraw( void )
{
	m_pParent->GetCtrlBKGND( this, m_hDC );	
	RECT rc = m_rcClientRect;
	rc.top -= 1;
	if( !GetEnabled() )
	{
		g_pApp->DrawCtrlSkin( m_hDC, &m_rcClientRect, CII_BTT_DIS, m_bStretch );

		m_clTextColor = RGB( 255, 255, 255 );
		::SetTextColor( m_hDC, m_clTextColor );
		::DrawText( m_hDC, m_pszText, -1, &rc, m_dwTextAlign );
		
		m_clTextColor = RGB( 60, 60, 60 );
		::SetTextColor( m_hDC, m_clTextColor );
		rc.left -= 1;
		rc.top -= 1;
		::DrawText( m_hDC, m_pszText, -1, &rc, m_dwTextAlign );
	}else
	{
		if( MS_Y_DOWN & m_dwMouseState )
		{
			m_clTextColor = m_clColorDown;
			rc.left += 2;
			rc.top += 2;
			g_pApp->DrawCtrlSkin( m_hDC, &m_rcClientRect, CII_BTT_DOWN, m_bStretch );
		}else
		if( (MS_Y_MOVE & m_dwMouseState) || (GetFocus() == m_hWnd) )
		{
			m_clTextColor = m_clColorFocus;
			g_pApp->DrawCtrlSkin( m_hDC, &m_rcClientRect, CII_BTT_FOCUS, m_bStretch );
		}else
		{
			m_clTextColor = m_clColorNormal;
			g_pApp->DrawCtrlSkin( m_hDC, &m_rcClientRect, CII_BTT_NORMAL, m_bStretch );
		}
		DrawText( m_hDC, rc, m_pszText, m_dwTextAlign );
	}	
}

void CBtt::SetColorNormal( COLORREF clColor )
{
	if( m_clColorNormal != clColor )
	{
		m_clColorNormal = clColor;
		Invalidate();
	}
}

void CBtt::SetColorDown( COLORREF clColor )
{
	if( m_clColorDown != clColor )
	{
		m_clColorDown = clColor;
		Invalidate();
	}
}

void CBtt::SetColorFocus( COLORREF clColor )
{
	if( m_clColorFocus != clColor )
	{
		m_clColorFocus = clColor;
		Invalidate();
	}
}

/*********************************************************************************************
*								CCheckBox													 *
*																							 *
*		YCode Y代码 YCtrl Y控件 Windows Mobile 透明控件 2008 YCtrl 1.0						 *
*			作者:卢益贵 QQ:48092788 luyigui.blog.nnsky.com									 *
*																							 *
**********************************************************************************************/
CCheckBox::CCheckBox()
{
	m_cidClassID = CID_Y_CHECKBOX;
	m_bChecked = FALSE;
	m_dwTextAlign = DT_RIGHT | DT_VCENTER;
}

CCheckBox::~CCheckBox()
{

}

void CCheckBox::SetChecked( BOOL bChecked )
{
	if( m_bChecked != bChecked )
	{
		m_bChecked = bChecked;
		Invalidate();
	}
}

BOOL CCheckBox::GetChecked( void )
{
	return m_bChecked;
}

LRESULT CCheckBox::WindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
	switch( uMsg )
    {
		case WM_LBUTTONCLICK:
		case WM_LBUTTONDBLCLK:
			SetChecked( !m_bChecked );
		default:
			return CBtt::WindowProc( hWnd, uMsg, wParam, lParam );
    }
}

void CCheckBox::OnDraw( void )
{
	RECT rc, rcText;
	DWORD ta;
	if( DT_RIGHT & m_dwTextAlign )
	{
		rc.left = 2;
		rc.top = 2;
		rc.right = m_nHeigth - 2;
		rc.bottom = m_nHeigth - 2;
		rcText.left = m_nHeigth;
		rcText.top = -2;
		rcText.right = m_nWidth;
		rcText.bottom = m_nHeigth;
		ta =  DT_LEFT | ((~DT_RIGHT) & m_dwTextAlign);
	}else
	{
		rc.left = m_nWidth - m_nHeigth + 2;
		rc.top = 2;
		rc.right = m_nWidth - 2;
		rc.bottom = m_nHeigth - 2;
		rcText.left = -2;
		rcText.top = 0;
		rcText.right = m_nWidth - m_nHeigth;
		rcText.bottom = m_nHeigth;
		ta =  DT_RIGHT | ((~DT_LEFT) & m_dwTextAlign);
	}
	
	m_pParent->GetCtrlBKGND( this, m_hDC );

	if( m_bChecked )
	{
		if( GetEnabled() )
			g_pApp->DrawCtrlSkin( m_hDC, &rc, CII_CHECKBOX_CHECK, m_bStretch );
		else
			g_pApp->DrawCtrlSkin( m_hDC, &rc, CII_CHECKBOX_CHECK_DIS, m_bStretch );
	}else
	{
		if( GetEnabled() )
			g_pApp->DrawCtrlSkin( m_hDC, &rc, CII_CHECKBOX_NORMAL, m_bStretch );
		else
			g_pApp->DrawCtrlSkin( m_hDC, &rc, CII_CHECKBOX_NORMAL_DIS, m_bStretch );
	}

	if( m_dwMouseState & MS_Y_DOWN )
		m_clTextColor = m_clColorDown;
	else
	if( (m_dwMouseState & MS_Y_MOVE) || (GetFocus() == m_hWnd) )
		m_clTextColor = m_clColorFocus;
	else	
		m_clTextColor = m_clColorNormal;

	DrawText( m_hDC, rcText, m_pszText, ta);
}

/*********************************************************************************************
*								CRadioBox													 *
*																							 *
*		YCode Y代码 YCtrl Y控件 Windows Mobile 透明控件 2008 YCtrl 1.0						 *
*			作者:卢益贵 QQ:48092788 luyigui.blog.nnsky.com									 *
*																							 *
**********************************************************************************************/
CRadioBox::CRadioBox()
{
	m_cidClassID = CID_Y_RADIOBOX;
	m_bChecked = FALSE;
	m_dwTextAlign = DT_RIGHT | DT_VCENTER;
}

CRadioBox::~CRadioBox()
{

}

void CRadioBox::SetChecked( BOOL bChecked )
{
	if( m_bChecked != bChecked )
	{
		m_bChecked = bChecked;
		Invalidate();

		int i;
		CWin *pCtrl;

		for( i = 0; i < m_pParent->GetCtrlCount(); i++ )
		{
			pCtrl = m_pParent->GetCtrl( i );
			if( (pCtrl != this) && (CID_Y_RADIOBOX == ((CRadioBox *)pCtrl)->GetClassID()) && ((CRadioBox *)pCtrl)->m_bChecked )
			{
				((CRadioBox *)pCtrl)->m_bChecked = FALSE;
				((CRadioBox *)pCtrl)->Invalidate();
			}
		}
	}
}

BOOL CRadioBox::GetChecked( void )
{
	return m_bChecked;
}

LRESULT CRadioBox::WindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
	switch( uMsg )
    {
		case WM_LBUTTONCLICK:
		case WM_LBUTTONDBLCLK:
			SetChecked( TRUE ); 
		default:
			return CBtt::WindowProc( hWnd, uMsg, wParam, lParam );
    }
}

void CRadioBox::OnDraw( void )
{
	RECT rc, rcText;
	DWORD ta;
	if( DT_RIGHT & m_dwTextAlign )
	{
		rc.left = 2;
		rc.top = 2;
		rc.right = m_nHeigth - 2;
		rc.bottom = m_nHeigth - 2;
		rcText.left = m_nHeigth;
		rcText.top = -2;
		rcText.right = m_nWidth;
		rcText.bottom = m_nHeigth;
		ta = DT_LEFT | ((~DT_RIGHT) & m_dwTextAlign);
	}else
	{
		rc.left = m_nWidth - m_nHeigth + 2;
		rc.top = 2;
		rc.right = m_nWidth - 2;
		rc.bottom = m_nHeigth - 2;
		rcText.left = -2;
		rcText.top = 0;
		rcText.right = m_nWidth - m_nHeigth;
		rcText.bottom = m_nHeigth;
		ta =  DT_RIGHT | ((~DT_LEFT) & m_dwTextAlign);
	}
	
	m_pParent->GetCtrlBKGND( this, m_hDC );

	if( m_bChecked )
	{
		if( GetEnabled() )
			g_pApp->DrawCtrlSkin( m_hDC, &rc, CII_RADIOBOX_CHECK, m_bStretch );
		else
			g_pApp->DrawCtrlSkin( m_hDC, &rc, CII_RADIOBOX_CHECK_DIS, m_bStretch );
	}else
	{
		if( GetEnabled() )
			g_pApp->DrawCtrlSkin( m_hDC, &rc, CII_RADIOBOX_NORMAL, m_bStretch );
		else
			g_pApp->DrawCtrlSkin( m_hDC, &rc, CII_RADIOBOX_NORMAL_DIS, m_bStretch );
	}

	if( m_dwMouseState & MS_Y_DOWN )
		m_clTextColor = m_clColorDown;
	else
	if( (m_dwMouseState & MS_Y_MOVE) || (GetFocus() == m_hWnd) )
		m_clTextColor = m_clColorFocus;
	else
		m_clTextColor = m_clColorNormal;

	DrawText( m_hDC, rcText, m_pszText, ta);
}

/*********************************************************************************************
*								CLabel														 *
*																							 *
*		YCode Y代码 YCtrl Y控件 Windows Mobile 透明控件 2008 YCtrl 1.0						 *
*			作者:卢益贵 QQ:48092788 luyigui.blog.nnsky.com									 *
*																							 *
**********************************************************************************************/
CLabel::CLabel()
{
	m_cidClassID = CID_Y_LABEL;
    m_dwTextAlign = DT_LEFT | DT_VCENTER;
}


CLabel::~CLabel()
{
	
}
 
void CLabel::OnDraw( void )
{
	m_pParent->GetCtrlBKGND( this, m_hDC );
	g_pApp->DrawCtrlSkin( m_hDC, &m_rcClientRect, CII_LABEL, m_bStretch );

	DrawText( m_hDC, m_rcClientRect, m_pszText, m_dwTextAlign);
} 

BOOL CLabel::Create( CWin *pOwner, CWin *pParent,  DWORD dwCtrlID, int nLeft, int nTop, int nWidth, int nHeigth, LPCWSTR lpszCaption )
{
	RegClass( L"YLabel" );
	return( CCtrl::Create( pOwner, pParent, dwCtrlID, nLeft, nTop, nWidth, nHeigth, L"YLabel", lpszCaption) );
}

void CLabel::SetWordWrap( BOOL bIsWrap )
{
	if( bIsWrap != (m_dwTextAlign & DT_WORDBREAK) )
	{
		if( bIsWrap )
		{
			m_dwTextAlign |= DT_WORDBREAK;
			m_dwTextAlign &= (~DT_VCENTER);
		}else
			m_dwTextAlign &= (~DT_WORDBREAK);
		Invalidate();
	}
}

/*********************************************************************************************
*								CPanel														 *
*																							 *
*		YCode Y代码 YCtrl Y控件 Windows Mobile 透明控件 2008 YCtrl 1.0						 *
*			作者:卢益贵 QQ:48092788 luyigui.blog.nnsky.com									 *
*																							 *
**********************************************************************************************/
CPanel::CPanel()
{
	m_cidClassID = CID_Y_PANEL;
    m_dwTextAlign = DT_LEFT;
	m_clBorderColor = RGB(0, 168, 198);
	if( m_hPen )
		DeleteObject( m_hPen );
	m_hPen = CreatePen( PS_SOLID, 1, m_clBorderColor );
	m_bIsGroup = FALSE;
	m_bStretch = FALSE;
}


CPanel::~CPanel()
{
	
}
 
void CPanel::OnDraw( void )
{
	m_pParent->GetCtrlBKGND( this, m_hDC );
	g_pApp->DrawCtrlSkin( m_hDC, &m_rcClientRect, CII_PANEL, m_bStretch );

	if( m_bIsGroup )
	{
		RECT rc;
		rc.left = 0;
		rc.top = 0;
		rc.right = 20;
		rc.bottom = 10;
		::DrawText( m_hDC, m_pszText, -1, &rc, DT_CALCRECT | DT_LEFT );
		if( rc.right > m_nWidth - 20 )
			rc.right = m_nWidth - 10;
		switch( m_dwTextAlign )
		{
			case DT_CENTER:
				rc.left = ((m_nWidth - 20) - rc.right) / 2;
				break;
			case DT_RIGHT:
				rc.left = m_nWidth - 10 - rc.right;
				break;
			default:
				rc.left = 10;
		}
		rc.right += rc.left;
		SelectFont( m_hDC, m_hFont );
		SetBkMode( m_hDC, TRANSPARENT );
		::SetTextColor( m_hDC, m_clTextColor );
		::DrawText( m_hDC, m_pszText, -1, &rc, DT_LEFT);
		SelectPen( m_hDC, m_hPen );
		int top = rc.bottom / 2;
		POINT p;
		MoveToEx( m_hDC, rc.left - 2, top, &p );
		LineTo( m_hDC, 0, top );
		LineTo( m_hDC, 0, m_nHeigth - 1 );
		LineTo( m_hDC, m_nWidth - 1, m_nHeigth - 1 );
		LineTo( m_hDC, m_nWidth - 1, top );
		LineTo( m_hDC, rc.right, top );
	}
} 

BOOL CPanel::Create( CWin *pOwner, CWin *pParent,  DWORD dwCtrlID, int nLeft, int nTop, int nWidth, int nHeigth, LPCWSTR lpszCaption )
{
	RegClass( L"YPanel" );
	return( CCtrl::Create( pOwner, pParent, dwCtrlID, nLeft, nTop, nWidth, nHeigth, L"YPanel", lpszCaption) );
}

void CPanel::SetStyle( BOOL bIsGroup )
{
	if( m_bIsGroup != bIsGroup )
	{
		m_bIsGroup = bIsGroup;
		if( !m_hPen )
			m_hPen = CreatePen( PS_SOLID, 1, m_clBorderColor );
		Invalidate();
	}
}

void CPanel::SetBorderColor( COLORREF clColor )
{
	if( m_clBorderColor != clColor )
	{
		m_clBorderColor = clColor;
		if( m_hPen )
			DeleteObject( m_hPen );
		m_hPen = CreatePen( PS_SOLID, 1, m_clBorderColor );
		if( m_bIsGroup )
			Invalidate();
	}
}

⌨️ 快捷键说明

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