www.pudn.com > 智能内码识别,支持屏幕取词翻译的程序.zip > BASICWIN.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 )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);
}