📄 mainfrm.cpp
字号:
// MainFrm.cpp : CMainFrame 类的实现
//
#include "stdafx.h"
#include "LmCrypt.h"
#include "DesDialog.h"
#include "MainFrm.h"
#include ".\mainfrm.h"
#include "SimpSub.h"
#include "DESDlg.h"
#include "CHGPlaceDlg.h"
#include "MD5Dlg.h"
#include "LmIdearDlg.h"
#include "MixedCSDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
typedef struct LANGINFO_DEF {
int Count;
LANGID LangID;
} LANGINFO;
typedef LANGINFO *PLANGINFO;
// CMainFrame
IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
ON_WM_CREATE()
// 全局帮助命令
ON_COMMAND(ID_HELP_FINDER, CMDIFrameWnd::OnHelpFinder)
ON_COMMAND(ID_HELP, CMDIFrameWnd::OnHelp)
ON_COMMAND(ID_CONTEXT_HELP, CMDIFrameWnd::OnContextHelp)
ON_COMMAND(ID_DEFAULT_HELP, CMDIFrameWnd::OnHelpFinder)
ON_COMMAND(ID_SIMP_SUBSTITUTE, OnSubstitute)
ON_COMMAND(ID_DES_ENC, OnDesEnc)
ON_COMMAND(ID_DES_SAMPLE, OnDesSample)
ON_COMMAND(ID_CHANGE_PLACE_V, OnChangePlaceV)
ON_COMMAND(ID_MD5, OnMd5)
ON_COMMAND(ID_IDEAR, OnIdear)
ON_COMMAND(ID_AES, OnAes)
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR, // 状态行指示器
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
// CMainFrame 构造/析构
CMainFrame::CMainFrame()
{
// TODO: 在此添加成员初始化代码
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
GetUserDefaultLCID();
::GetUserDefaultLangID();
// ::GetUserDefaultUILanguage();
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("未能创建工具栏\n");
return -1; // 未能创建
}
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("未能创建状态栏\n");
return -1; // 未能创建
}
// TODO: 如果不需要工具栏可停靠,则删除这三行
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
m_wndMDITabs.Create(this, MT_TOP|MT_IMAGES);
//OnMenuChangelang();
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CMDIFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: 在此处通过修改 CREATESTRUCT cs 来修改窗口类或
// 样式
//MyRegisterClass(hInstance);
// Perform application initialization:
//if (!InitInstance (hInstance, nCmdShow))
//{
// return FALSE;
//}
return TRUE;
}
// CMainFrame 诊断
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CMDIFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CMDIFrameWnd::Dump(dc);
}
#endif //_DEBUG
// CMainFrame 消息处理程序
LANGID CMainFrame::DetectLanguage() {
#define MAX_KEY_BUFFER 80
OSVERSIONINFO VersionInfo;
LANGID uiLangID = 0;
HKEY hKey;
DWORD Type, BuffLen = MAX_KEY_BUFFER;
TCHAR LangKeyValue[MAX_KEY_BUFFER];
VersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if( !GetVersionEx(&VersionInfo) )
return(0);
switch( VersionInfo.dwPlatformId ) {
// On Windows NT, Windows 2000 or higher
case VER_PLATFORM_WIN32_NT:
if( VersionInfo.dwMajorVersion >= 5) // Windows 2000 or higher
uiLangID = ::GetUserDefaultLangID();
else { // for NT4 check the language of ntdll.dll
uiLangID = GetNTDLLNativeLangID();
if (uiLangID == 1033) { // special processing for Honkong SAR version of NT4
if (IsHongKongVersion()) {
uiLangID = 3076;
}
}
}
break;
// On Windows 95, Windows 98 or Windows ME
case VER_PLATFORM_WIN32_WINDOWS:
// Open the registry key for the UI language
if( RegOpenKeyEx(HKEY_CURRENT_USER,_T("Default\\Control Panel\\Desktop\\ResourceLocale"), 0,
KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS ) {
// Get the type of the default key
if( RegQueryValueEx(hKey, NULL, NULL, &Type, NULL, NULL) == ERROR_SUCCESS
&& Type == REG_SZ ) {
// Read the key value
if( RegQueryValueEx(hKey, NULL, NULL, &Type, (LPBYTE)LangKeyValue, &BuffLen)
== ERROR_SUCCESS ) {
uiLangID = _ttoi(LangKeyValue);
}
}
RegCloseKey(hKey);
}
break;
}
if (uiLangID == 0) {
uiLangID = GetUserDefaultLangID();
}
// Return the found language ID.
return (uiLangID);
}
// Populates the list of languages in the selection dialog
// according to the subdirectories named with decimal LCID
int CMainFrame::PopulateLanguages(HWND hwndCombo) {
/*TCHAR CurrentDirectory[MAX_PATH];
int AvailableLangID;
TCHAR AvailableLangName[MAX_LANGNAME];
WIN32_FIND_DATA FindFileData;
HANDLE hDir;
int i = 0;
int j;
int CurrentIndex = 0;
// Retrieve the current directory name
if( GetCurrentDirectory(MAX_PATH, CurrentDirectory)) {
if( _tcsclen(CurrentDirectory) < MAX_PATH-4 )
_tcscat(CurrentDirectory, _T("\\*.*"));
}
else
return 0;
// Loop through all directories and populate the drop-down list for the
// language selection
hDir = FindFirstFile(CurrentDirectory, &FindFileData);
if( hDir == INVALID_HANDLE_VALUE ) {
FindClose(hDir);
return 0;
}
// SendMessage(hwndCombo, CB_RESETCONTENT, 0, 0);
do {
if( FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) {
if( AvailableLangID = _ttoi(FindFileData.cFileName) ) {
if( GetLocaleInfo(AvailableLangID,LOCALE_SNATIVELANGNAME,AvailableLangName,MAX_LANGNAME)) {
/// CurrentIndex = SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM)AvailableLangName);
// SendMessage(hwndCombo, CB_SETITEMDATA, (WPARAM)CurrentIndex, (LPARAM)AvailableLangID);
i++;
}
}
}
} while ( FindNextFile(hDir, &FindFileData) );
FindClose(hDir);
// To set the current selection we have to loop through the combo box
// because the addition sorted the combo box alphabetically
for(j=0 ; j<=i ; j++) {
// if( UILanguage == SendMessage(hwndCombo, CB_GETITEMDATA, j, 0) )
// SendMessage(hwndCombo, CB_SETCURSEL, (WPARAM)j, 0);
}
return i;*/
return 1;
}
// Loads the satellite DLL specified for the language DesiredLanguage
HMODULE CMainFrame::LoadSatelliteDLL(LANGID DesiredLanguage) {
TCHAR BaseDirectory[MAX_PATH];
TCHAR SatellitePath[MAX_PATH];
TCHAR buffer[100];
HMODULE hDLL;
// Get the base directory for the satellite DLL search
if( GetCurrentDirectory(MAX_PATH, BaseDirectory)) {
_tcscat(BaseDirectory, _T("\\"));
}
else
return NULL;
// First try to load the library with the fully specified language
_tcscpy(SatellitePath, BaseDirectory);
_itot(DesiredLanguage,buffer,10);
_tcscat(SatellitePath, buffer);
_tcscat(SatellitePath, _T("\\LmCrypt.dll"));
if( hDLL = LoadLibrary(SatellitePath) )
return hDLL;
else { // try the primary language ID
_tcscpy(SatellitePath, BaseDirectory);
DesiredLanguage = PRIMARYLANGID(DesiredLanguage);
_itot(DesiredLanguage,buffer,10);
_tcscat(SatellitePath, buffer);
_tcscat(SatellitePath, _T("\\LmCrypt.dll"));
if( hDLL = LoadLibrary(SatellitePath) )
return hDLL;
else
return NULL;
}
}
// The following functions contain code to
// detect the language in which the initial
// user interface should be displayed
BOOL CALLBACK EnumLangProc(HANDLE hModule, LPCTSTR lpszType, LPCTSTR lpszName,
WORD wIDLanguage, LONG_PTR lParam)
{
PLANGINFO LangInfo;
LangInfo = (PLANGINFO) lParam;
LangInfo->Count++;
LangInfo->LangID = wIDLanguage;
return (TRUE); // continue enumeration
}
// Detects the language of ntdll.dll with some specific processing for
// the Hongkong SAR version
LANGID CMainFrame::GetNTDLLNativeLangID()
{
LANGINFO LangInfo;
LPCTSTR Type = (LPCTSTR) ((LPVOID)((WORD)16));
LPCTSTR Name = (LPCTSTR) 1;
ZeroMemory(&LangInfo,sizeof(LangInfo));
// Get the HModule for ntdll.
HMODULE hMod = GetModuleHandle(_T("ntdll.dll"));
if (hMod==NULL) {
return(0);
}
BOOL result = EnumResourceLanguages(hMod, Type, Name, (ENUMRESLANGPROC)EnumLangProc, (LONG_PTR) &LangInfo);
if (!result || (LangInfo.Count > 2) || (LangInfo.Count < 1) ) {
return (0);
}
return (LangInfo.LangID);
}
// Checks if NT4 system is Hongkong SAR version
BOOL CMainFrame::IsHongKongVersion()
{
/*
HMODULE hMod;
BOOL bRet=FALSE;
typedef BOOL (WINAPI *IMMRELEASECONTEXT)(HWND,HIMC);
IMMRELEASECONTEXT pImmReleaseContext;
hMod = LoadLibrary(_T("imm32.dll"));
if (hMod) {
pImmReleaseContext = (IMMRELEASECONTEXT)GetProcAddress(hMod,"ImmReleaseContext");
if (pImmReleaseContext) {
bRet = pImmReleaseContext(NULL,NULL);
}
FreeLibrary(hMod);
}
return (bRet);*/
return true;
}
void CMainFrame::OnMenuChangelang()
{
MSG msg;
HACCEL hAccelTable;
//HWND hMainWindow =this->GetSafeHwnd;
CMenu * hNewMenu;
CMenu * hNewMenuWin;
HMENU hMenu,hMenuWin;
UILanguage = DetectLanguage();
if(UILanguage==2052)
UILanguage=1033;
else
UILanguage=2052;
CLmCryptApp * p_app=(CLmCryptApp *)AfxGetApp();
p_app->i_MenuIni=1;
hSatDLL = LoadSatelliteDLL(UILanguage);
//if( hSatDLL == NULL ) hSatDLL = hInstance;
// Initialize global strings
LoadString(hSatDLL, IDR_LmCryptTYPE, szTitle, MAX_LOADSTRING);
LoadString(hSatDLL, IDR_MAINFRAME, szWindowClass, MAX_LOADSTRING);
hAccelTable = LoadAccelerators(hSatDLL, (LPCTSTR)IDR_MAINFRAME);
//UILanguage = (LANGID)NewUILanguage;
//hSatDLL = LoadSatelliteDLL(UILanguage);
if( hSatDLL == NULL ) hSatDLL = hInst;
// Redraw the client area of the main window
InvalidateRect(NULL,TRUE);
UpdateWindow();
// Update the caption of the main window
//LoadString(hSatDLL, IDR_LmCryptTYPE, szTitle, MAX_LOADSTRING);
//::SendMessage(this->GetSafeHwnd(),WM_SETTEXT, NULL, (LPARAM)szTitle);
// Load the localized menu
//hNewMenu=AfxGetMainWnd()->GetMenu();
//hNewMenu->DestroyMenu();
//::DestroyMenu(m_hMenuDefault);
hMenu = LoadMenu(hSatDLL,(LPCTSTR)IDR_MAINFRAME);
hNewMenu=CMenu::FromHandle(hMenu);
hMenuWin = LoadMenu(hSatDLL,(LPCTSTR)IDR_LmCryptTYPE);
hNewMenuWin=CMenu::FromHandle(hMenuWin);
//hNewMenu->LoadMenu(IDR_MAINFRAME);
//AfxGetMainWnd()->SetMenu();
//AfxGetMainWnd()->SetMenu(
SetMenu( hNewMenu);
//MDISetMenu(hNewMenuWin,NULL);
DrawMenuBar();
}
void CMainFrame::OnMenuChangeType()
{
HACCEL hAccelTable;
//HWND hMainWindow =this->GetSafeHwnd;
CMenu * hNewMenu;
HMENU hMenu;
UILanguage = DetectLanguage();
if(UILanguage==2052)
UILanguage=1033;
else
UILanguage=2052;
hSatDLL = LoadSatelliteDLL(UILanguage);
//if( hSatDLL == NULL ) hSatDLL = hInstance;
// Initialize global strings
LoadString(hSatDLL, IDR_LmCryptTYPE, szTitle, MAX_LOADSTRING);
LoadString(hSatDLL, IDR_MAINFRAME, szWindowClass, MAX_LOADSTRING);
hAccelTable = LoadAccelerators(hSatDLL, (LPCTSTR)IDR_MAINFRAME);
//UILanguage = (LANGID)NewUILanguage;
//hSatDLL = LoadSatelliteDLL(UILanguage);
if( hSatDLL == NULL ) hSatDLL = hInst;
// Redraw the client area of the main window
InvalidateRect(NULL,TRUE);
UpdateWindow();
// Update the caption of the main window
//LoadString(hSatDLL, IDR_LmCryptTYPE, szTitle, MAX_LOADSTRING);
//::SendMessage(this->GetSafeHwnd(),WM_SETTEXT, NULL, (LPARAM)szTitle);
// Load the localized menu
//hNewMenu=AfxGetMainWnd()->GetMenu();
//hNewMenu->DestroyMenu();
//::DestroyMenu(m_hMenuDefault);
hMenu = LoadMenu(hSatDLL,(LPCTSTR)IDR_LmCryptTYPE);
hNewMenu=CMenu::FromHandle(hMenu);
//hNewMenu->LoadMenu(IDR_MAINFRAME);
//AfxGetMainWnd()->SetMenu();
SetMenu( hNewMenu);
/*
// Resource handle to bitmap.
HRSRC hRes;
// Global handles to bitmap resource.
HGLOBAL hData, hLockedData;
CMenu m_menu;
// Find the resource handle.
hRes = ::FindResource(hSatDLL,
MAKEINTRESOURCE(IDR_LmCryptTYPE), RT_MENU);
hRes = ::FindResource(hSatDLL,
MAKEINTRESOURCE(IDR_MAINFRAME), RT_MENU);
if (hRes != NULL)
{
// Lock and Load (or Load and Lock).
if (((hData = ::LoadResource(hSatDLL,
hRes)) != NULL) &&
((hLockedData = (HGLOBAL)::LockResource(hData)) != NULL))
{
m_menu.CreateMenu();
// Free the resource.
::FreeResource(hLockedData);
}
}*/
}
void CMainFrame::OnSubstitute()
{
CSimpSub SipSub;
SipSub.DoModal();
}
void CMainFrame::OnDes()
{
CDesDialog Desdia;
Desdia.DoModal();
}
void CMainFrame::OnDesDec()
{
}
void CMainFrame::OnDesEnc()
{
CDesDialog Desdia;
Desdia.DoModal();
}
void CMainFrame::OnDesSample()
{
// TODO: 在此添加命令处理程序代码
CDESDlg Desdl;
Desdl.DoModal();
}
void CMainFrame::OnChangePlaceV()
{
CCHGPlaceDlg CpDlg;
CpDlg.DoModal();
// TODO: 在此添加命令处理程序代码
}
void CMainFrame::OnMd5()
{
CMD5Dlg MD5dlg;
MD5dlg.DoModal();
}
void CMainFrame::OnUpdateFrameTitle(BOOL bAddToTitle)
{
CMDIFrameWnd::OnUpdateFrameTitle(bAddToTitle);
m_wndMDITabs.Update();
/*
CWnd* Wnd = AfxGetMainWnd();
Wnd->SendMessage(WM_COMMAND, ID_NEWFILE, 0);
*/
}
void CMainFrame::OnIdear()
{
CLmIdearDlg idearDlg;
idearDlg.DoModal();
}
void CMainFrame::OnAes()
{
CMixedCSDlg aesDlg;
aesDlg.DoModal();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -