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

📄 hotkey.cpp

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

#include "stdafx.h"
#include	"resource.h"
#include	"systemse.h"
//#include "hotkey.h"
#include	"cspublic.h"

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

/////////////////////////////////////////////////////////////////////////////
// CHotKey dialog

CHotKey::CHotKey(UINT id) : CCommonPage(id)
{
	//热键数目
	m_nHotKeyNum	=3 ;
	//缺省热键值
	//0为隐藏/显示浮动条热键
	strcpy( m_HotKeyParam[0].sName , "隐藏/显示主窗口" ) ;
	m_HotKeyParam[0].bDefaultCtrl	=0 ;
	m_HotKeyParam[0].bDefaultAlt	=0 ;
	m_HotKeyParam[0].bDefaultShift	=1 ;
	m_HotKeyParam[0].nDefaultChar	=0 ;	// \,
	//1为取消/启动屏幕指取翻译
	strcpy( m_HotKeyParam[1].sName , "取消/启动屏幕指取翻译" ) ;
	m_HotKeyParam[1].bDefaultCtrl	=1 ;
	m_HotKeyParam[1].bDefaultAlt	=1 ;
	m_HotKeyParam[1].bDefaultShift	=0 ;
	m_HotKeyParam[1].nDefaultChar	=51 ;
	//2为屏幕指取辅助键
	strcpy( m_HotKeyParam[2].sName , "屏幕指取翻译辅助键" ) ;
	m_HotKeyParam[2].bDefaultCtrl	=1 ;
	m_HotKeyParam[2].bDefaultAlt	=1 ;
	m_HotKeyParam[2].bDefaultShift	=0 ;
	m_HotKeyParam[2].nDefaultChar	=0 ;
//---------------------------------------------------------------------//	

	//从INI文件中得到当前热键
	m_HotKeyParam[0].bCtrl	=GetPrivateProfileInt( "热键定义" ,
					"WinCtrl" , m_HotKeyParam[0].bDefaultCtrl , INI_FILE_NAME ) ;
	m_HotKeyParam[0].bAlt	=GetPrivateProfileInt( "热键定义" ,
					"WinAlt" , m_HotKeyParam[0].bDefaultAlt , INI_FILE_NAME ) ;
	m_HotKeyParam[0].bShift	=GetPrivateProfileInt( "热键定义" ,
					"WinShift" , m_HotKeyParam[0].bDefaultShift , INI_FILE_NAME ) ;
	m_HotKeyParam[0].nChar	=GetPrivateProfileInt( "热键定义" ,
					"WinAsc" , m_HotKeyParam[0].nDefaultChar , INI_FILE_NAME ) ;
	m_HotKeyParam[1].bCtrl	=GetPrivateProfileInt( "热键定义" ,
					"FingerCtrl" , m_HotKeyParam[1].bDefaultCtrl , INI_FILE_NAME ) ;
	m_HotKeyParam[1].bAlt	=GetPrivateProfileInt( "热键定义" ,
					"FingerAlt" , m_HotKeyParam[1].bDefaultAlt , INI_FILE_NAME ) ;
	m_HotKeyParam[1].bShift	=GetPrivateProfileInt( "热键定义" ,
					"FingerShift" , m_HotKeyParam[1].bDefaultShift , INI_FILE_NAME ) ;
	m_HotKeyParam[1].nChar	=GetPrivateProfileInt( "热键定义" ,
					"FingerAsc" , m_HotKeyParam[1].nDefaultChar , INI_FILE_NAME ) ;
	m_HotKeyParam[2].bCtrl	=GetPrivateProfileInt( "热键定义" ,
					"AidCtrl" , m_HotKeyParam[2].bDefaultCtrl , INI_FILE_NAME ) ;
	m_HotKeyParam[2].bAlt	=GetPrivateProfileInt( "热键定义" ,
					"AidAlt" , m_HotKeyParam[2].bDefaultAlt , INI_FILE_NAME ) ;
	m_HotKeyParam[2].bShift	=GetPrivateProfileInt( "热键定义" ,
					"AidShift" , m_HotKeyParam[2].bDefaultShift , INI_FILE_NAME ) ;
	m_HotKeyParam[2].nChar	=GetPrivateProfileInt( "热键定义" ,
					"AidAsc" , m_HotKeyParam[2].nDefaultChar , INI_FILE_NAME ) ;
/*	
	m_nCurrentHotKey	=GetPrivateProfileInt( "热键定义" ,
									"当前热键" , 0 , INI_FILE_NAME ) ;
	if( m_nCurrentHotKey<0 || m_nCurrentHotKey>=m_nHotKeyNum )
		m_nCurrentHotKey	=0 ;	//不合法												
	//得到当前热键值
	char	sBuff[100] ;
	for( int i=0 ; i<m_nHotKeyNum ; i++ )
	{
		wsprintf( sBuff , "热键%d的Ctrl值" , i+1 ) ;
		m_HotKeyParam[i].bCtrl	=GetPrivateProfileInt( "热键参数" ,
						sBuff , m_HotKeyParam[i].bDefaultCtrl , INI_FILE_NAME ) ;
		wsprintf( sBuff , "热键%d的Alt值" , i+1 ) ;
		m_HotKeyParam[i].bAlt	=GetPrivateProfileInt( "热键参数" ,
						sBuff , m_HotKeyParam[i].bDefaultAlt , INI_FILE_NAME ) ;
		wsprintf( sBuff , "热键%d的Shift值" , i+1 ) ;
		m_HotKeyParam[i].bShift	=GetPrivateProfileInt( "热键参数" ,
						sBuff , m_HotKeyParam[i].bDefaultShift , INI_FILE_NAME ) ;
		wsprintf( sBuff , "热键%d的Char值" , i+1 ) ;
		m_HotKeyParam[i].nChar	=GetPrivateProfileInt( "热键参数" ,
						sBuff , m_HotKeyParam[i].nDefaultChar , INI_FILE_NAME ) ;

		//设置热键值到DLL中	
//		SetHotKeyParams( i , m_HotKeyParam[i].bCtrl , 
//			m_HotKeyParam[i].bAlt , m_HotKeyParam[i].bShift ,
//			m_HotKeyParam[i].nChar ) ;
	} */
	//{{AFX_DATA_INIT(CHotKey)
	//}}AFX_DATA_INIT
}

void CHotKey::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CHotKey)
	DDX_Control(pDX, IDC_COMBO1, m_Char);
	DDX_Control(pDX, IDC_LIST1, m_HotKeyName);
	DDX_Check(pDX, IDC_CHECK1, m_bCtrl);
	DDX_Check(pDX, IDC_CHECK2, m_bAlt);
	DDX_Check(pDX, IDC_CHECK3, m_bShift);
	//}}AFX_DATA_MAP
}

//设置当前热键值
void CHotKey::SetCurrentHotKeyParam( void )
{
	m_bCtrl =m_HotKeyParam[m_nCurrentHotKey].bCtrl ;
	m_bAlt =m_HotKeyParam[m_nCurrentHotKey].bAlt ;
	m_bShift =m_HotKeyParam[m_nCurrentHotKey].bShift ;
	m_Char.SetCurSel( m_HotKeyParam[m_nCurrentHotKey].nChar ) ;

	UpdateData( FALSE ) ;
}

//设置为缺省值
void CHotKey::SetDefaultParam( int n )
{
	m_bCtrl	=m_HotKeyParam[n].bCtrl	=
				m_HotKeyParam[n].bDefaultCtrl ;
	m_bAlt	=m_HotKeyParam[n].bAlt	=
				m_HotKeyParam[n].bDefaultAlt ;
	m_bShift =m_HotKeyParam[n].bShift	=
				m_HotKeyParam[n].bDefaultShift ;
	m_HotKeyParam[n].nChar	=
				m_HotKeyParam[n].nDefaultChar ;
	
	if( n == m_nCurrentHotKey )
	{
		UpdateData( FALSE ) ;	//设置热键值
		m_Char.SetCurSel( m_HotKeyParam[n].nChar ) ;
	}
}

BEGIN_MESSAGE_MAP(CHotKey, CPropertyPage)
	//{{AFX_MSG_MAP(CHotKey)
	ON_BN_CLICKED(IDC_BUTTON1, OnSetCurrentDefault)
	ON_BN_CLICKED(IDC_BUTTON2, OnSetAllDefault)
	ON_LBN_SELCHANGE(IDC_LIST1, OnChangeHotKey)
	ON_CBN_SELCHANGE(IDC_COMBO1, OnSelectChar)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CHotKey message handlers

BOOL CHotKey::OnInitDialog()
{
	CCommonPage::OnInitDialog();
	
	// TODO: Add extra initialization here
	//设置热键名称列表
	for( int i=0 ; i<m_nHotKeyNum ; i++ )
		m_HotKeyName.AddString( m_HotKeyParam[i].sName ) ;

	//标记当前热键
	m_HotKeyName.SetCurSel( m_nCurrentHotKey ) ;
		
	//设置当前热键值
	SetCurrentHotKeyParam() ;
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CHotKey::OnSetCurrentDefault()
{
	// TODO: Add your control notification handler code here
	SetDefaultParam( m_nCurrentHotKey ) ;
}

void CHotKey::OnSetAllDefault()
{
	// TODO: Add your control notification handler code here
	for( int i=0 ; i<m_nHotKeyNum ; i++ )
		SetDefaultParam( i ) ;	
}

void CHotKey::OnChangeHotKey()
{
	// TODO: Add your control notification handler code here
	int	n=m_HotKeyName.GetCurSel() ;
	if( n!=m_nCurrentHotKey )
	{
		UpdateData() ;	//取出数据
	
		m_HotKeyParam[m_nCurrentHotKey].bCtrl	=m_bCtrl ;
		m_HotKeyParam[m_nCurrentHotKey].bAlt	=m_bAlt ;
		m_HotKeyParam[m_nCurrentHotKey].bShift	=m_bShift ;
		m_HotKeyParam[m_nCurrentHotKey].nChar	=
				m_Char.GetCurSel() ;

		m_nCurrentHotKey	=n ;
		SetCurrentHotKeyParam() ;
	}
}

void CHotKey::OnOK()
{
	// TODO: Add extra validation here
	//得到当前热键值
	m_HotKeyParam[m_nCurrentHotKey].bCtrl	=m_bCtrl ;
	m_HotKeyParam[m_nCurrentHotKey].bAlt	=m_bAlt ;
	m_HotKeyParam[m_nCurrentHotKey].bShift	=m_bShift ;
	m_HotKeyParam[m_nCurrentHotKey].nChar	=
			m_Char.GetCurSel() ;

	char	sBuff[100] ;

	//存储当前热键
	wsprintf( sBuff , "%d" , m_HotKeyParam[0].bCtrl ) ; 
	WritePrivateProfileString( "热键定义" , "WinCtrl" , sBuff , INI_FILE_NAME ) ;
	wsprintf( sBuff , "%d" , m_HotKeyParam[0].bAlt ) ; 
	WritePrivateProfileString( "热键定义" , "WinAlt" , sBuff , INI_FILE_NAME ) ;
	wsprintf( sBuff , "%d" , m_HotKeyParam[0].bShift ) ; 
	WritePrivateProfileString( "热键定义" , "WinShift" , sBuff , INI_FILE_NAME ) ;
	wsprintf( sBuff , "%d" , m_HotKeyParam[0].nChar ) ; 
	WritePrivateProfileString( "热键定义" , "WinAsc" , sBuff , INI_FILE_NAME ) ;

	wsprintf( sBuff , "%d" , m_HotKeyParam[1].bCtrl ) ; 
	WritePrivateProfileString( "热键定义" , "FingerCtrl" , sBuff , INI_FILE_NAME ) ;
	wsprintf( sBuff , "%d" , m_HotKeyParam[1].bAlt ) ; 
	WritePrivateProfileString( "热键定义" , "FingerAlt" , sBuff , INI_FILE_NAME ) ;
	wsprintf( sBuff , "%d" , m_HotKeyParam[1].bShift ) ; 
	WritePrivateProfileString( "热键定义" , "FingerShift" , sBuff , INI_FILE_NAME ) ;
	wsprintf( sBuff , "%d" , m_HotKeyParam[1].nChar ) ; 
	WritePrivateProfileString( "热键定义" , "FingerAsc" , sBuff , INI_FILE_NAME ) ;

	wsprintf( sBuff , "%d" , m_HotKeyParam[2].bCtrl ) ; 
	WritePrivateProfileString( "热键定义" , "AidCtrl" , sBuff , INI_FILE_NAME ) ;
	wsprintf( sBuff , "%d" , m_HotKeyParam[2].bAlt ) ; 
	WritePrivateProfileString( "热键定义" , "AidAlt" , sBuff , INI_FILE_NAME ) ;
	wsprintf( sBuff , "%d" , m_HotKeyParam[2].bShift ) ; 
	WritePrivateProfileString( "热键定义" , "AidShift" , sBuff , INI_FILE_NAME ) ;
	wsprintf( sBuff , "%d" , m_HotKeyParam[2].nChar ) ; 
	WritePrivateProfileString( "热键定义" , "AidAsc" , sBuff , INI_FILE_NAME ) ;
/*
	wsprintf( sBuff1 , "%d" , m_nCurrentHotKey ) ;
	WritePrivateProfileString( "热键参数" , "当前热键" , sBuff1 , 
			INI_FILE_NAME ) ;
	for( int i=0 ; i<m_nHotKeyNum ; i++ )
	{
		//改变INI文件中的内容
		wsprintf( sBuff1 , "热键%d的Ctrl值" , i+1 ) ;
		wsprintf( sBuff2 , "%d" , m_HotKeyParam[i].bCtrl ) ;
		WritePrivateProfileString( "热键参数" , sBuff1 , sBuff2 , 
					INI_FILE_NAME ) ;
		wsprintf( sBuff1 , "热键%d的Alt值" , i+1 ) ;
		wsprintf( sBuff2 , "%d" , m_HotKeyParam[i].bAlt ) ;
		WritePrivateProfileString( "热键参数" , sBuff1 , sBuff2 , 
					INI_FILE_NAME ) ;
		wsprintf( sBuff1 , "热键%d的Shift值" , i+1 ) ;
		wsprintf( sBuff2 , "%d" , m_HotKeyParam[i].bShift ) ;
		WritePrivateProfileString( "热键参数" , sBuff1 , sBuff2 , 
					INI_FILE_NAME ) ;
		wsprintf( sBuff1 , "热键%d的Char值" , i+1 ) ;
		wsprintf( sBuff2 , "%d" , m_HotKeyParam[i].nChar ) ;
		WritePrivateProfileString( "热键参数" , sBuff1 , sBuff2 , 
					INI_FILE_NAME ) ;

		//设置热键值到DLL中	
		SetHotKeyParams( i , m_HotKeyParam[i].bCtrl , 
			m_HotKeyParam[i].bAlt , m_HotKeyParam[i].bShift ,
			m_HotKeyParam[i].nChar ) ;
	}
*/	
	CPropertyPage::OnOK();
}

void CHotKey::OnSelectChar()
{
	// TODO: Add your control notification handler code here
	m_HotKeyParam[m_nCurrentHotKey].nChar	=m_Char.GetCurSel() ;
}

⌨️ 快捷键说明

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