INBUTTON.CPP
上传用户:zhang8947
上传日期:2007-01-08
资源大小:1910k
文件大小:15k
- // InButton.cpp : implementation file
- //
- #include "stdafx.h"
- #include "resource.h"
- #include "cspublic.h"
- #include "cskernel.h"
- #include "basicwin.h"
- #include "inputbar.h"
- #include "iniinput.h"
- #include "addordel.h"
- #include "systemse.h"
- #include "inputset.h"
- #include "inputse1.h"
- extern CInputInit OInputInit ; //输入环境初始化对象
- #ifdef _DEBUG
- #undef THIS_FILE
- static char BASED_CODE THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CInButton
- CInButton::CInButton( void )
- {
- }
- //初始化状态按钮
- CInButton::CInButton( CPoint pos ,
- UINT uUpBitmap , UINT uDownBitmap )
- {
- m_bCaptureStatus =0 ; //初始没有获得鼠标控制权
- m_bButtonType =0 ; //为状态按钮
- if( uUpBitmap == IDB_BITMAP2 ) //西文还是中文
- //得到是西文字符还是中文字符,缺省为西文字符
- m_bStatus =GetPrivateProfileInt( "输入方法" ,
- "西文字符还是中文字符" , 1 , INI_FILE_NAME ) ;
- else if( uUpBitmap == IDB_BITMAP4 ) //是否加空格
- //得到输入汉字后是否自动加空格,缺省为不加
- m_bStatus =GetPrivateProfileInt( "输入方法" ,
- "汉字后是否加空格" , 1 , INI_FILE_NAME ) ;
- else //全角还是半角
- //得到是半角字母还是全角字母,缺省为半角字母
- m_bStatus =GetPrivateProfileInt( "输入方法" ,
- "半角字母还是全角字母" , 1 , INI_FILE_NAME ) ;
-
- m_OPos =pos ;
- m_nHeight =12 ;
- m_nWidth =m_nHeight ;
-
- m_uUpBitmapID =uUpBitmap ;
- m_uDownBitmapID =uDownBitmap ;
- }
- //初始化动作按钮
- CInButton::CInButton( CPoint pos ,
- UINT uUpBitmap , UINT uDownBitmap ,
- BOOL bFlag )
- {
- m_bCaptureStatus =0 ; //初始没有获得鼠标控制权
- m_bStatus =1 ; //初始为没有按下按钮
- m_bButtonType =bFlag ;
- m_OPos =pos ;
- m_nHeight =12 ;
- m_nWidth =m_nHeight ;
-
- m_uUpBitmapID =uUpBitmap ;
- m_uDownBitmapID =uDownBitmap ;
- }
- //初始化菜单1按钮
- CInButton::CInButton( CPoint pos , //位置
- LPCSTR lpcsString , //显示串
- UINT uMenuID )
- {
- m_bCaptureStatus =0 ; //初始没有获得鼠标控制权
- m_bStatus =1 ; //初始为没有按下按钮
- m_bButtonType =1 ; //为菜单1按钮
- m_OPos =pos ; //位置
- m_nHeight =12 ; //高度
- m_OMenuString =lpcsString ; //按钮上显示的串
- m_nWidth =m_OMenuString.GetLength()*(m_nHeight-2)/2 ; //宽度
- m_uMenuID =uMenuID ;
- }
- //初始化菜单2按钮
- CInButton::CInButton( CPoint pos , //位置
- LPCSTR lpcsString , //显示串
- HMENU hMenu )
- {
- m_bCaptureStatus =0 ; //初始没有获得鼠标控制权
- m_bStatus =1 ; //初始为没有按下按钮
- m_bButtonType =2 ; //为菜单2按钮
- m_OPos =pos ; //位置
- m_nHeight =12 ; //高度
- //按钮上显示的串
- m_OMenuString =lpcsString ;
- m_nWidth =m_OMenuString.GetLength()*(m_nHeight-2)/2 ; //宽度
- m_hMenu =hMenu ;
- }
- CInButton::~CInButton()
- {
- }
- const CInButton& CInButton::operator=( const CInButton &button )
- {
- m_bButtonType =button.m_bButtonType ; //按钮类型
- m_bCaptureStatus =button.m_bCaptureStatus ; //鼠标控制权
-
- //位置与宽度,高度
- m_OPos =button.m_OPos ;
- m_nWidth =button.m_nWidth ;
- m_nHeight =button.m_nHeight ;
- //按钮状态
- m_bStatus =button.m_bStatus ;
- switch( m_bButtonType )
- {
- case 0: //是状态按钮
- case 3: //是左翻页按钮
- case 4: //是右翻页按钮
- m_uUpBitmapID =button.m_uUpBitmapID ;
- m_uDownBitmapID =button.m_uDownBitmapID ;
- break ;
- case 1: //是菜单1
- m_OMenuString =button.m_OMenuString ; //按钮上要显示的串
- m_uMenuID =button.m_uMenuID ;
- //装入菜单资源
- // m_OMenu.LoadMenu( m_uMenuID ) ;
- break ;
- case 2: //是菜单2
- m_OMenuString =button.m_OMenuString ; //按钮上要显示的串
- m_hMenu =button.m_hMenu ;
- break ;
- default:
- AfxMessageBox( "The type of button is error" ) ;
- }
-
- return *this ;
- }
- BEGIN_MESSAGE_MAP(CInButton, CBasicWin)
- //{{AFX_MSG_MAP(CInButton)
- ON_WM_LBUTTONDOWN()
- ON_WM_PAINT()
- ON_WM_LBUTTONUP()
- ON_WM_MOUSEMOVE()
- ON_WM_LBUTTONDBLCLK()
- ON_WM_MENUCHAR()
- ON_WM_MENUSELECT()
- ON_COMMAND(ID_INPUT_SETUP, OnInputSetup)
- ON_COMMAND(ID_INPUT_GB, OnInputGb)
- ON_COMMAND(ID_INPUT_BIG5, OnInputBig5)
- ON_COMMAND(ID_INPUT_HZ, OnInputHz)
- ON_COMMAND(ID_INPUT_SHIFTJIS, OnInputShiftjis)
- ON_COMMAND(ID_INPUT_EUCJIS, OnInputEucjis)
- ON_COMMAND(ID_INPUT_KSC5601, OnInputKsc5601)
- ON_WM_RBUTTONDOWN()
- ON_WM_RBUTTONDBLCLK()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CInButton message handlers
- //创建按钮窗口
- BOOL CInButton::CreateInButton(
- LPCSTR lpszWindowName , //窗口名
- CWnd *pParentWnd , //父窗口
- UINT nID ) //ID
- {
- RECT rect ; //窗口大小
- rect.left =m_OPos.x ;
- rect.top =m_OPos.y ;
- rect.right =m_OPos.x + m_nWidth ;
- rect.bottom =m_OPos.y + m_nHeight ;
-
- //创建该窗口
- VERIFY( Create( NULL , lpszWindowName , WS_CHILD , rect ,
- pParentWnd , nID ) ) ;
- return TRUE ;
- }
- //得到当前按钮状态
- BOOL CInButton::GetStatus( void )
- {
- return m_bStatus ;
- }
- //改变按钮的显示状态
- void CInButton::ChangeButtonStatus( void )
- {
- //切换按钮状态
- if( m_bStatus ) //按钮没有按下
- m_bStatus =0 ;
- else
- m_bStatus =1 ;
- InvalidateRect( NULL , FALSE ) ;
- }
- void CInButton::OnLButtonDown(UINT nFlags, CPoint point)
- {
- CBasicWin::OnLButtonDown(nFlags, point);
- //切换按钮状态
- ChangeButtonStatus() ;
- switch( m_bButtonType )
- {
- case 0: //是状态按钮
- //切换状态按钮的状态
- if( m_uUpBitmapID == IDB_BITMAP2 ) //西文还是中文
- SetInputStatus123( 1 ) ;
- else if( m_uUpBitmapID == IDB_BITMAP4 ) //是否加空格
- SetInputStatus123( 2 ) ;
- else //全角还是半角
- SetInputStatus123( 3 ) ;
- break ;
- case 1:
- case 2: //是菜单按钮
- //显示菜单
- if( !m_bStatus ) //已按下按钮
- {
- CPoint point1( 0 , m_nHeight ) ;
- ClientToScreen( &point1 ) ; //转换为屏幕坐标
- CMenu *pMenu ;
- if( m_bButtonType == 1 ) //是菜单1
- {
- m_OMenu.DestroyMenu() ; //破坏菜单
- switch( GetOutputCode() )
- {
- case 0:
- if( !m_OMenu.LoadMenu( IDR_MENU2 ) ) //装入菜单资源
- return ;
- break ;
- case 1:
- if( !m_OMenu.LoadMenu( IDR_MENU2_1 ) ) //装入菜单资源
- return ;
- break ;
- default:
- if( !m_OMenu.LoadMenu( IDR_MENU2_2 ) ) //装入菜单资源
- return ;
- }
-
- pMenu =m_OMenu.GetSubMenu( 0 ) ; //得到菜单
-
- int n =GetInputCode() ; //得到当前输入内码
- //将该菜单项打上标记,并且无效
- pMenu->CheckMenuItem( n ,
- MF_BYPOSITION|MF_CHECKED ) ;
- pMenu->EnableMenuItem( n ,
- MF_BYPOSITION|MF_DISABLED ) ;
-
- if( GetInputMethod() ) //当前输入法不是内码输入法
- {
- //SHIFT-JIS,EUC-JIS,KSC5601输入内码无效
- pMenu->EnableMenuItem( 3 ,
- MF_BYPOSITION|MF_GRAYED ) ;
- pMenu->EnableMenuItem( 4 ,
- MF_BYPOSITION|MF_GRAYED ) ;
- pMenu->EnableMenuItem( 5 ,
- MF_BYPOSITION|MF_GRAYED ) ;
- }
- else
- {
- pMenu->EnableMenuItem( 3 ,
- MF_BYPOSITION ) ;
- pMenu->EnableMenuItem( 4 ,
- MF_BYPOSITION ) ;
- pMenu->EnableMenuItem( 5 ,
- MF_BYPOSITION ) ;
- }
- }
- else //是菜单2
- pMenu =CMenu::FromHandle( m_hMenu ) ;
-
- RECT rect ;
- GetClientRect( &rect ) ;
- ClientToScreen( &rect ) ;
- SetMenuCharFlag( 0 ) ; //标记不是按键消失鼠标的
- pMenu->TrackPopupMenu(
- TPM_LEFTBUTTON|TPM_LEFTALIGN,
- point1.x , point1.y , this , &rect ) ; //显示菜单
- }
- else
- ActiveOldWin() ; //激活以前的窗口
- break ;
- case 3:
- case 4: //是翻页按钮
- m_bCaptureStatus =1 ;
- SetCapture() ; //得到鼠标控制权
- break ;
- }
- // CBasicWin::OnLButtonDown(nFlags, point);
- }
- void CInButton::OnLButtonUp(UINT nFlags, CPoint point)
- {
- switch( m_bButtonType )
- {
- case 3:
- case 4: //是翻页按钮
- if( !m_bStatus ) //原来是下去的
- {
- //进行翻页
- CInputBar *pInputBar =(CInputBar*)GetParent() ;
- if( m_bButtonType == 3 ) //是向左按钮
- pInputBar->SendMessage( WM_USER_SCROLL_PAGE,4,0 ) ;
- else //是向右按钮
- pInputBar->SendMessage( WM_USER_SCROLL_PAGE,3,0 ) ;
-
- m_bStatus =1 ; //让按钮起来
- InvalidateRect( NULL , FALSE ) ; //重画按钮
- }
- m_bCaptureStatus =0 ;
- ReleaseCapture() ; //释放鼠标控制权
- break ;
- }
-
- CBasicWin::OnLButtonUp(nFlags, point);
- }
- void CInButton::OnMouseMove(UINT nFlags, CPoint point)
- {
- SetCursor( LoadCursor( NULL , IDC_ARROW ) ) ;
- if( !m_bCaptureStatus ) //没有鼠标控制权,不做反应
- {
- CBasicWin::OnMouseMove(nFlags, point);
- return ;
- }
- switch( m_bButtonType )
- {
- case 3:
- case 4: //是翻页按钮
- CRect rect ; //用户窗口区
- GetClientRect( &rect ) ;
- if( !rect.PtInRect( point ) ) //移出了该窗口
- {
- if( !m_bStatus ) //原来是下去的
- {
- m_bStatus =1 ; //让按钮进来
- InvalidateRect( NULL , FALSE ) ; //重画按钮
- }
- }
- else //在窗口内
- {
- if( m_bStatus ) //原来是起来的
- {
- m_bStatus =0 ; //让按钮下去
- InvalidateRect( NULL , FALSE ) ; //重画按钮
- }
- }
- break ;
- }
-
- CBasicWin::OnMouseMove(nFlags, point);
- }
- void CInButton::OnPaint()
- {
- CPaintDC dc(this); // device context for painting
- //画上按钮的边框
- RECT rect ={ 0 , 0 , m_nWidth-1 , m_nHeight-1 } ;
- if( m_bStatus ) //按钮没有按下
- DrawOneLineBox( dc.m_hDC , rect , 1 ,
- RGB(255,255,255),RGB(128,128,128),RGB(192,192,192) ) ;
- else
- DrawOneLineBox( dc.m_hDC , rect , 0 ,
- RGB(255,255,255),RGB(128,128,128),RGB(192,192,192) ) ;
- //画上按钮中的内容
- if( m_bButtonType==1 || m_bButtonType==2 ) //是菜单按钮
- {
- //创建所需要的字体
- CFont font ;
- font.CreateFont( m_nHeight-2 , //高度
- 0 , 0 , 0 , //宽度等
- FW_NORMAL ,
- FALSE , FALSE , 0 ,
- ANSI_CHARSET ,
- OUT_DEFAULT_PRECIS ,
- CLIP_DEFAULT_PRECIS ,
- DEFAULT_QUALITY ,
- DEFAULT_PITCH , NULL ) ;
- CFont *pOldFont =(CFont*)dc.SelectObject( &font ) ;
-
- dc.SetBkMode( TRANSPARENT ) ;
- TextOutString( dc.GetSafeHdc() , 1 , 1 , m_OMenuString ,
- m_OMenuString.GetLength() ) ;
- dc.SelectObject( pOldFont ) ;
- }
- else //是状态按钮
- {
- CBitmap bitmap ; //按钮上的位置
-
- if( m_bStatus ) //按钮没有按下
- bitmap.LoadBitmap( m_uUpBitmapID ) ;
- else
- bitmap.LoadBitmap( m_uDownBitmapID ) ;
-
- CDC memDC ;
- memDC.CreateCompatibleDC( (CDC*)&dc ) ; //内存显示设备
- //选入位图
- CBitmap *pOldBitmap =(CBitmap*)memDC.SelectObject( &bitmap ) ;
- dc.BitBlt( 1 , 1 , m_nWidth-2 , m_nHeight-2 ,
- &memDC , 0 , 0 , SRCCOPY ) ;
- //选出位图
- memDC.SelectObject( pOldBitmap ) ;
- }
- // Do not call CBasicWin::OnPaint() for painting messages
- }
- //改变菜单2按钮的显示内容
- void CInButton::ChangeMenuButton( int nMenu )
- {
- char sBuff[20] ;
- CMenu *pMenu =CMenu::FromHandle( m_hMenu ) ;
- m_bStatus =1 ;
- pMenu->GetMenuString( nMenu , sBuff , 20 , MF_BYPOSITION ) ;
- m_OMenuString =sBuff ;
- m_nWidth =_fstrlen( m_OMenuString )*(m_nHeight-2)/2 ; //宽度
-
- //改变INI文件,同时改变菜单项显示状态
- OInputInit.ChangeMenuStatus(
- ::GetMenuItemCount( m_hMenu )-1-nMenu ) ;
-
- InvalidateRect( NULL ) ;
- }
- BOOL CInButton::OnCommand( WPARAM wParam, LPARAM lParam )
- {
- if( m_bButtonType == 2 ) //是菜单2
- ChangeMenuButton( ::GetMenuItemCount( m_hMenu )-1-
- (wParam-100) ) ;
-
- return CBasicWin::OnCommand( wParam , lParam ) ;
- }
- void CInButton::OnLButtonDblClk(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- if( m_bStatus ) //菜单没有显示
- OnLButtonDown( nFlags , point ) ;
-
- CBasicWin::OnLButtonDblClk(nFlags, point);
- }
- LRESULT CInButton::OnMenuChar(UINT nChar, UINT nFlags, CMenu* pMenu)
- {
- // TODO: Add your message handler code here and/or call default
- SetMenuCharFlag( 0 ) ; //标记不是按键消失鼠标的
-
- return CBasicWin::OnMenuChar(nChar, nFlags, pMenu);
- }
- void CInButton::OnMenuSelect(UINT nItemID, UINT nFlags,
- HMENU hSysMenu)
- {
- static BOOL bFlag=0 ;
- if( nItemID==ID_INPUT_SETUP )
- bFlag =1 ;
- CBasicWin::OnMenuSelect(nItemID, nFlags, hSysMenu);
- if( nFlags == (UINT)0xffff && !hSysMenu ) //关闭菜单
- {
- CRect rect ; //用户窗口区
- GetClientRect( &rect ) ;
- POINT point ;
- GetCursorPos( &point ) ; //得到当前鼠标点
- ScreenToClient( &point ) ; //转成用户坐标
- if( GetMenuCharFlag() || //是按键消失鼠标的
- !rect.PtInRect( point ) ) //点不在该窗口内
- {
- m_bStatus =1 ;
- InvalidateRect( NULL ) ;
- }
- if(!bFlag)
- ActiveOldWin() ; //激活以前的窗口
- else
- bFlag =0 ;
- }
- }
- void CInButton::OnInputSetup()
- {
- // TODO: Add your command handler code here
- char sTitle[50] ;
- CInputSet *pInputSetPage ; //增、删输入法
- CInputSe1 *pInputSe1Page ; //中文输入环境设置页
- switch( GetOutputCode() )
- {
- case 0:
- strcpy( sTitle , "中文大观输入法设置" ) ;
- pInputSetPage =new CInputSet( IDD_DIALOG5 ) ;
- pInputSe1Page =new CInputSe1( IDD_DIALOG6 ) ;
- break ;
- case 1:
- strcpy( sTitle , "いゅ