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

📄 basicwin.cpp

📁 支持Windows 3.x、Windows 9x平台上的中文(GB、Big5)、日文(Shift JIS、EUC JIS)、韩文(KS C 5601)、HZ码的显示与输入,智能内码识别
💻 CPP
字号:
// basicwin.cpp : implementation file
//

#include "stdafx.h"
#include	"cspublic.h"
#include "basicwin.h"

static	BOOL	p_bActiveMode=1 ;	//1激活以前的窗口,0否,缺省为1

#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CBasicWin

CBasicWin::CBasicWin(void)
{
	m_hActiveWnd	=NULL ;

	m_bTimer	=0 ;
	m_nHintStatus	=0 ;	//标记hint没有显示过

	m_sHint[0][0]	='\0' ;
	m_sHint[1][0]	='\0' ;
	m_sHint[2][0]	='\0' ;

	m_bActiveMode	=1 ;
}

CBasicWin::~CBasicWin()
{
}

//设置hint内容
void	CBasicWin::SetHint( LPCSTR lpcsHint0 ,
			LPCSTR lpcsHint1 , LPCSTR lpcsHint2 )
{
	if( lpcsHint0 )
	{
		if( _fstrlen( lpcsHint0 )<MAX_HINT_LEN )
			_fstrcpy( m_sHint[0] , lpcsHint0 ) ;
	}
	if( lpcsHint1 )
	{
		if( _fstrlen( lpcsHint1 )<MAX_HINT_LEN )
			_fstrcpy( m_sHint[1] , lpcsHint1 ) ;
	}
	if( lpcsHint2 )
	{
		if( _fstrlen( lpcsHint2 )<MAX_HINT_LEN )
			_fstrcpy( m_sHint[2] , lpcsHint2 ) ;
	}
}
                                                                          
//设置是否激活以前的窗口                                                                          
void	CBasicWin::SetActiveMode( BOOL b )
{
	m_bActiveMode	=b ;
}

//激活以前的窗口
void	CBasicWin::ActiveOldWin( void )
{
	if( m_hActiveWnd )
		::SetActiveWindow( m_hActiveWnd ) ;
		
	p_bActiveMode	=1 ;
}	
	
BEGIN_MESSAGE_MAP(CBasicWin, CWnd)
	//{{AFX_MSG_MAP(CBasicWin)
	ON_WM_MOUSEACTIVATE()
	ON_WM_NCHITTEST()
	ON_WM_MOUSEMOVE()
	ON_WM_LBUTTONDOWN()
	ON_WM_RBUTTONDOWN()
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBasicWin message handlers


int CBasicWin::OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message)
{
	// TODO: Add your message handler code here and/or call default
	if( m_bActiveMode && p_bActiveMode )	//激活以前的窗口
	{
		CWnd* pActiveWnd = FromHandle(m_hActiveWnd) ;
		CWnd* pFocusWnd = GetFocus() ;
		if( pActiveWnd && !pFocusWnd )		//是32位程序
		{
			//激活原来窗口的标题栏
    		pActiveWnd->PostMessage(WM_NCACTIVATE, TRUE, 0);  
			pActiveWnd->SetActiveWindow() ;	//恢复以前的活动窗口
		}
	
		//保持原来窗口的激活状态
		return MA_NOACTIVATE;            
	}

	p_bActiveMode	=0 ;	//标记不激活以前的窗口
	return CWnd::OnMouseActivate(pDesktopWnd, nHitTest, message);
}

UINT CBasicWin::OnNcHitTest(CPoint point)
{
	// TODO: Add your message handler code here and/or call default
	//得到当前活动窗口
	CWnd	*pTempWnd	=GetActiveWindow() ;
		 	
	if( pTempWnd )		//当前有活动窗口	  
	{
		if(	pTempWnd->m_hWnd!=m_hWnd &&	//不是自身 
			!IsChild( pTempWnd ) &&
			!(pTempWnd->IsChild( this )) )
			m_hActiveWnd = pTempWnd->GetSafeHwnd() ;//m_hWnd;
	}

	return CWnd::OnNcHitTest(point);
}

void CBasicWin::OnMouseMove(UINT nFlags, CPoint point)
{
	// TODO: Add your message handler code here and/or call default
	int	nHintLen ;
	switch( GetOutputCode() )
	{
		case	0:
			nHintLen	=strlen( m_sHint[0] ) ;
			break ;
		case	1:
			nHintLen	=strlen( m_sHint[1] ) ;
			break ;
		default:
			nHintLen	=strlen( m_sHint[2] ) ;
			break ;
	}
	if( nHintLen )	//有hint内容
	{
		if( !m_nHintStatus )	//没有显示过hint
		{
			if( !m_bTimer )	//没有设上判断鼠标是否移出该窗口的时间器
			{
				m_bTimer	=1 ;
				//设上判断鼠标是否移出该窗口的时间器
				SetTimer( TIMER2_ID , TIME_TO_RECOVER , NULL ) ;
			}

			KillTimer( TIMER_ID ) ;		//破坏原来的时间器
			//记录显示位置
			m_HintPos	=point ;
			//设上新的时间器
			SetTimer( TIMER_ID , TIME_TO_WAIT_FOR_SHOW , NULL ) ;
		}
	}

	CWnd::OnMouseMove(nFlags, point);
}

void CBasicWin::OnLButtonDown(UINT nFlags, CPoint point)
{
	// TODO: Add your message handler code here and/or call default
	KillTimer( TIMER_ID ) ;		//破坏原来的时间器
	if( m_nHintStatus==1 )	//正在显示
		HideHint() ;			//消失hint

	m_nHintStatus	=2 ;	//只要有过动作,就不再显示hint
	
	CWnd::OnLButtonDown(nFlags, point);
}

void CBasicWin::OnRButtonDown(UINT nFlags, CPoint point)
{
	// TODO: Add your message handler code here and/or call default
	KillTimer( TIMER_ID ) ;		//破坏原来的时间器
	if( m_nHintStatus==1 )	//正在显示
		HideHint() ;			//消失hint

	m_nHintStatus	=2 ;	//只要有过动作,就不再显示hint
	
	CWnd::OnRButtonDown(nFlags, point);
}

void CBasicWin::OnTimer(UINT nIDEvent)
{
	// TODO: Add your message handler code here and/or call default
	if( nIDEvent==TIMER_ID )
	{
		switch( m_nHintStatus )	//判断hint的状态
		{
			case	0:		//没有显示过hint
				KillTimer( TIMER_ID ) ;		//破坏原来的时间器
				m_nHintStatus	=1 ;	//标记正在显示
				ClientToScreen( &m_HintPos ) ;	//转换成屏幕坐标
/*				switch( GetOutputCode() )
				{
					case	0:
					case	1:
*/						ShowHint( m_HintPos.x , 
							m_HintPos.y+GetSystemMetrics( SM_CYCURSOR )/2+2 ,
				 			m_sHint[0] , _fstrlen( m_sHint[0] ) ) ;	//显示hint
/*				 		break; 
					default:
						ShowHint( m_HintPos.x , 
							m_HintPos.y+GetSystemMetrics( SM_CYCURSOR )/2+2 ,
				 			m_sHint[2] , _fstrlen( m_sHint[2] ) ) ;	//显示hint
				 }
*/				//设上消失时间器
				SetTimer( TIMER_ID , TIME_TO_WAIT_FOR_HIDE , NULL ) ;
				break ;
			default:	//正在显示hint
				KillTimer( TIMER_ID ) ;		//破坏原来的时间器
				m_nHintStatus	=2 ;	//标记已经显示过了
				HideHint() ;
		}
	}
	else if( nIDEvent==TIMER2_ID )
	{
		//判断是否移出了窗口
		CRect	clientRect ;	//窗口大小
		CPoint	point ;
		//判断是否移出了窗口
		GetCursorPos( (LPPOINT)&point ) ;		//当前鼠标所在点
		ScreenToClient( &point ) ;
		GetClientRect( &clientRect ) ;		//得到该窗口大小
		if( !clientRect.PtInRect( point ) )	//已经移出该窗口
		{
			KillTimer( TIMER_ID ) ;		//破坏原来的时间器
			KillTimer( TIMER2_ID ) ;		//破坏原来的时间器
			m_bTimer	=0 ;
			m_nHintStatus	=0 ;	//标记hint没有显示过
			HideHint() ;			//消失hint
		}
	}
	
	CWnd::OnTimer(nIDEvent);
}

⌨️ 快捷键说明

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