几何尺寸与公差论坛

 找回密码
 注册
查看: 2622|回复: 5

多语言设置sample

[复制链接]
发表于 2007-7-22 17:55:13 | 显示全部楼层 |阅读模式
1.hhView.cpp
// hhView.cpp : implementation of the CHhView class
//
#include "stdafx.h"
#include "hh.h"
#include "hhDoc.h"
#include "hhView.h"
#include "MultiLanguageDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CHhView
IMPLEMENT_DYNCREATE(CHhView, CView)
BEGIN_MESSAGE_MAP(CHhView, CView)
//{{AFX_MSG_MAP(CHhView)
ON_COMMAND(ID_MENUITEM_E, OnMenuitemE)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CHhView construction/destruction
CHhView::CHhView()
{
// TODO: add construction code here
}
CHhView::~CHhView()
{
}
BOOL CHhView:reCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
//  the CREATESTRUCT cs
return CView:reCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CHhView drawing
void CHhView:oadAllLanguage()
{
CString szKey = "Language",szSection = "Setting";

CFileFind find;
bool ret = find.FindFile(g_szCurPath + "Language\\*.ini");
while(ret)
{
  ret = find.FindNextFile();
  if(find.IsDots() || find.IsDirectory()) continue;
  
  DWORD dwSize = 100;
  if(GetPrivateProfileString(szSection,szKey,"",
   szValue.GetBuffer(dwSize),dwSize,find.GetFilePath()) != 0)
  {
   m_cmbLang.AddString(szValue);
  }
  szValue.ReleaseBuffer();
}
find.Close();

DWORD dwSize = 1000;
CString szLang;
GetPrivateProfileString(szSection,szKey,"English",szLang.GetBuffer(dwSize),dwSize,g_szSettingPath);
szLang.ReleaseBuffer();

m_cmbLang.SelectString(-1,szLang);
}
void CHhView::SetMenuStrings()
{
int nCurPos = 0;
CMenu* subMenu = m_menuMain.GetSubMenu(nCurPos);

//文件菜单
m_menuMain.ModifyMenu(nCurPos,MF_BYPOSITION,nCurPos,g_LoadString("IDS_MENU_FILE"));
subMenu->ModifyMenu(ID_FILE_NEW,MF_BYCOMMAND,ID_FILE_NEW,g_LoadString("IDS_MENU_FILE_NEW"));
subMenu->ModifyMenu(ID_FILE_OPEN,MF_BYCOMMAND,ID_FILE_OPEN,g_LoadString("IDS_MENU_FILE_OPEN"));
subMenu->ModifyMenu(ID_FILE_CLOSE,MF_BYCOMMAND,ID_FILE_CLOSE,g_LoadString("IDS_MENU_FILE_CLOSE"));
subMenu->ModifyMenu(ID_FILE_EXIT,MF_BYCOMMAND,ID_FILE_EXIT,g_LoadString("IDS_MENU_FILE_EXIT"));

//编辑菜单
subMenu = m_menuMain.GetSubMenu(++nCurPos);           
m_menuMain.ModifyMenu(nCurPos,MF_BYPOSITION,nCurPos,g_LoadString("IDS_MENU_EDIT"));
subMenu->ModifyMenu(ID_EDIT_CUT,MF_BYCOMMAND,ID_EDIT_CUT,g_LoadString("IDS_MENU_EDIT_CUT"));
subMenu->ModifyMenu(ID_EDIT_COPY,MF_BYCOMMAND,ID_EDIT_COPY,g_LoadString("IDS_MENU_EDIT_COPY"));
subMenu->ModifyMenu(ID_EDIT_PASTE,MF_BYCOMMAND,ID_EDIT_PASTE,g_LoadString("IDS_MENU_EDIT_PASTE"));

//帮助菜单
subMenu = m_menuMain.GetSubMenu(++nCurPos);
m_menuMain.ModifyMenu(nCurPos,MF_BYPOSITION,nCurPos,g_LoadString("IDS_MENU_HELP"));
subMenu->ModifyMenu(ID_HELP,MF_BYCOMMAND,ID_HELP,g_LoadString("IDS_MENU_HELP_HELP"));
subMenu->ModifyMenu(ID_HELP_ABOUT,MF_BYCOMMAND,ID_HELP_ABOUT,g_LoadString("IDS_MENU_HELP_ABOUT"));

}
void CHhView::OnDraw(CDC* pDC)
{
CHhDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CHhView printing
BOOL CHhView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CHhView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CHhView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CHhView diagnostics
#ifdef _DEBUG
void CHhView::AssertValid() const
{
CView::AssertValid();
}
void CHhView:ump(CDumpContext& dc) const
{
CView:ump(dc);
}
CHhDoc* CHhView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CHhDoc)));
return (CHhDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CHhView message handlers
void CHhView::OnMenuitemE()
{
LoadLanguage(szValue);
CMultiLanguageDlg dlg;
// m_pMainWnd = &dlg;
dlg.DoModal();
}
 楼主| 发表于 2007-7-22 17:55:58 | 显示全部楼层

回复: 多语言设置sample

2.hhView.h
// hhView.h : interface of the CHhView class
//
/////////////////////////////////////////////////////////////////////////////
#if !defined(AFX_HHVIEW_H__5F292128_DDD8_4A5B_8FEF_7E6BD665B77C__INCLUDED_)
#define AFX_HHVIEW_H__5F292128_DDD8_4A5B_8FEF_7E6BD665B77C__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

extern CString szValue;
class CHhView : public CView
{
protected: // create from serialization only
CHhView();
DECLARE_DYNCREATE(CHhView)
void LoadAllLanguage();
void SetMenuStrings();
// Attributes
public:
CHhDoc* GetDocument();
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CHhView)
public:
virtual void OnDraw(CDC* pDC);  // overridden to draw this view
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CHhView();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected:
// Generated message map functions
protected:
//{{AFX_MSG(CHhView)
afx_msg void OnMenuitemE();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
#ifndef _DEBUG  // debug version in hhView.cpp
inline CHhDoc* CHhView::GetDocument()
   { return (CHhDoc*)m_pDocument; }
#endif
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_HHVIEW_H__5F292128_DDD8_4A5B_8FEF_7E6BD665B77C__INCLUDED_)
 楼主| 发表于 2007-7-22 17:57:18 | 显示全部楼层

回复: 多语言设置sample

3.MultiLanguageDlg.h
// MultiLanguageDlg.h : header file
//
#if !defined(AFX_MULTILANGUAGEDLG_H__1FE6C280_03FD_44A5_9848_543A5CE375F8__INCLUDED_)
#define AFX_MULTILANGUAGEDLG_H__1FE6C280_03FD_44A5_9848_543A5CE375F8__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
/////////////////////////////////////////////////////////////////////////////
// CMultiLanguageDlg dialog
//extern CString g_szCurPath;
//extern CString g_szSettingPath; //保存设置的文件路径
class CMultiLanguageDlg : public CDialog
{
CMenu m_menuMain;
// Construction
public:
void LoadAllLanguage();
void SetMenuStrings();
CMultiLanguageDlg(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(CMultiLanguageDlg)
enum { IDD = IDD_MULTILANGUAGE_DIALOG };
CComboBox m_cmbLang;
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMultiLanguageDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
HICON m_hIcon;
// Generated message map functions
//{{AFX_MSG(CMultiLanguageDlg)
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
afx_msg void OnSelChangeLang();
afx_msg void OnHelpAbout();
afx_msg void OnAbout();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_MULTILANGUAGEDLG_H__1FE6C280_03FD_44A5_9848_543A5CE375F8__INCLUDED_)
 楼主| 发表于 2007-7-22 17:57:50 | 显示全部楼层

回复: 多语言设置sample

4.MultiLanguageDlg.cpp
// MultiLanguageDlg.cpp : implementation file
//
#include "stdafx.h"
#include "hh.h"
#include "MultiLanguageDlg.h"
#include "CDialogTest.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

CString g_LoadString(CString szID);

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
virtual BOOL OnInitDialog();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg:oDataExchange(CDataExchange* pDX)
{
CDialog:oDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

BOOL CAboutDlg::OnInitDialog()
{
CDialog::OnInitDialog();

g_SetDialogStrings(this,IDD);

return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
/////////////////////////////////////////////////////////////////////////////
// CMultiLanguageDlg dialog
CString szValue;
static CString g_szLanguagePath; //保存语言文件的路径
static CString g_szSettingPath; //保存设置的文件路径
static CString g_szCurPath;
CMultiLanguageDlg::CMultiLanguageDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMultiLanguageDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMultiLanguageDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMultiLanguageDlg:oDataExchange(CDataExchange* pDX)
{
CDialog:oDataExchange(pDX);
//{{AFX_DATA_MAP(CMultiLanguageDlg)
DDX_Control(pDX, IDC_COMBO1, m_cmbLang);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMultiLanguageDlg, CDialog)
//{{AFX_MSG_MAP(CMultiLanguageDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_CBN_SELCHANGE(IDC_COMBO1, OnSelChangeLang)
ON_COMMAND(ID_HELP_ABOUT, OnHelpAbout)
ON_BN_CLICKED(IDC_ABOUT, OnAbout)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMultiLanguageDlg message handlers
BOOL CMultiLanguageDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon

// TODO: Add extra initialization here
//查找所有可用语言,装入下拉列表框
LoadAllLanguage();
m_menuMain.LoadMenu(IDR_MENU_MAIN);
SetMenu(&m_menuMain);
SetMenuStrings(); //设置菜单上的文字
//设置对话框上控件的语言文字
g_SetDialogStrings(this,IDD);
return TRUE; // return TRUE unless you set the focus to a control
}
void CMultiLanguageDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CMultiLanguageDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
GetDlgItem(IDC_STC_DEMO)->SetWindowText(g_LoadString("IDS_DEMO"));
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CMultiLanguageDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMultiLanguageDlg::SetMenuStrings()
{
int nCurPos = 0;
CMenu* subMenu = m_menuMain.GetSubMenu(nCurPos);
//文件菜单
m_menuMain.ModifyMenu(nCurPos,MF_BYPOSITION,nCurPos,g_LoadString("IDS_MENU_FILE"));
subMenu->ModifyMenu(ID_FILE_NEW,MF_BYCOMMAND,ID_FILE_NEW,g_LoadString("IDS_MENU_FILE_NEW"));
subMenu->ModifyMenu(ID_FILE_OPEN,MF_BYCOMMAND,ID_FILE_OPEN,g_LoadString("IDS_MENU_FILE_OPEN"));
subMenu->ModifyMenu(ID_FILE_CLOSE,MF_BYCOMMAND,ID_FILE_CLOSE,g_LoadString("IDS_MENU_FILE_CLOSE"));
subMenu->ModifyMenu(ID_FILE_EXIT,MF_BYCOMMAND,ID_FILE_EXIT,g_LoadString("IDS_MENU_FILE_EXIT"));
//编辑菜单
subMenu = m_menuMain.GetSubMenu(++nCurPos);
m_menuMain.ModifyMenu(nCurPos,MF_BYPOSITION,nCurPos,g_LoadString("IDS_MENU_EDIT"));
subMenu->ModifyMenu(ID_EDIT_CUT,MF_BYCOMMAND,ID_EDIT_CUT,g_LoadString("IDS_MENU_EDIT_CUT"));
subMenu->ModifyMenu(ID_EDIT_COPY,MF_BYCOMMAND,ID_EDIT_COPY,g_LoadString("IDS_MENU_EDIT_COPY"));
subMenu->ModifyMenu(ID_EDIT_PASTE,MF_BYCOMMAND,ID_EDIT_PASTE,g_LoadString("IDS_MENU_EDIT_PASTE"));
//帮助菜单
subMenu = m_menuMain.GetSubMenu(++nCurPos);
m_menuMain.ModifyMenu(nCurPos,MF_BYPOSITION,nCurPos,g_LoadString("IDS_MENU_HELP"));
subMenu->ModifyMenu(ID_HELP,MF_BYCOMMAND,ID_HELP,g_LoadString("IDS_MENU_HELP_HELP"));
subMenu->ModifyMenu(ID_HELP_ABOUT,MF_BYCOMMAND,ID_HELP_ABOUT,g_LoadString("IDS_MENU_HELP_ABOUT"));

}
void CMultiLanguageDlg:oadAllLanguage()
{
CString szKey = "Language",szSection = "Setting";

CFileFind find;
bool ret = find.FindFile(g_szCurPath + "Language\\*.ini");
while(ret)
{
ret = find.FindNextFile();
if(find.IsDots() || find.IsDirectory()) continue;

DWORD dwSize = 100;
if(GetPrivateProfileString(szSection,szKey,"",
szValue.GetBuffer(dwSize),dwSize,find.GetFilePath()) != 0)
{
m_cmbLang.AddString(szValue);
}
szValue.ReleaseBuffer();
}
find.Close();
DWORD dwSize = 1000;
CString szLang;
GetPrivateProfileString(szSection,szKey,"English",szLang.GetBuffer(dwSize),dwSize,g_szSettingPath);
szLang.ReleaseBuffer();
m_cmbLang.SelectString(-1,szLang);
}
void CMultiLanguageDlg::OnSelChangeLang()
{
m_cmbLang.GetLBText(m_cmbLang.GetCurSel(),szValue);
}
void CMultiLanguageDlg::OnAbout()
{
//CAboutDlg dlg;
//dlg.DoModal();
CCDialogTest *pDlg = new CCDialogTest;

pDlg->Create(IDD_DIALOG1,this);

pDlg->CenterWindow(this);
pDlg->ShowWindow(true);
//dd.DoModal();
}
void CMultiLanguageDlg::OnHelpAbout()
{
CMultiLanguageDlg::OnAbout();
}
 楼主| 发表于 2007-7-22 17:59:54 | 显示全部楼层

回复: 多语言设置sample

new3.GetMultiLanguageDlg.h
#if !defined(AFX_GETMULTILANGUAGEDLG_H__B2AB151B_BFC5_4591_B57A_98CEE78F59AD__INCLUDED_)
#define AFX_GETMULTILANGUAGEDLG_H__B2AB151B_BFC5_4591_B57A_98CEE78F59AD__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// GetMultiLanguageDlg.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CGetMultiLanguageDlg dialog
class CGetMultiLanguageDlg : public CDialog
{
// Construction
public:
CGetMultiLanguageDlg(CWnd* pParent = NULL);   // standard constructor
void LoadAllLanguage();

// Dialog Data
//{{AFX_DATA(CGetMultiLanguageDlg)
enum { IDD = IDD_DIALOG1 };
CComboBox m_cmbLang;
//}}AFX_DATA

// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CGetMultiLanguageDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(CGetMultiLanguageDlg)
virtual BOOL OnInitDialog();
afx_msg void OnSelchangeCombo1();
virtual void OnOK();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_GETMULTILANGUAGEDLG_H__B2AB151B_BFC5_4591_B57A_98CEE78F59AD__INCLUDED_)
 楼主| 发表于 2007-7-22 18:00:26 | 显示全部楼层

回复: 多语言设置sample

new4.GetMultiLanguageDlg.cpp
// GetMultiLanguageDlg.cpp : implementation file
//
#include "stdafx.h"
#include "hyh.h"
#include "GetMultiLanguageDlg.h"
#include "CDialogTwo.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CGetMultiLanguageDlg dialog
extern CString g_szLanguagePath; //保存语言文件的路径
extern CString g_szSettingPath; //保存设置的文件路径
extern CString g_szCurPath; //保存当前路径
CGetMultiLanguageDlg::CGetMultiLanguageDlg(CWnd* pParent /*=NULL*/)
: CDialog(CGetMultiLanguageDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CGetMultiLanguageDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}

void CGetMultiLanguageDlg:oDataExchange(CDataExchange* pDX)
{
CDialog:oDataExchange(pDX);
//{{AFX_DATA_MAP(CGetMultiLanguageDlg)
DDX_Control(pDX, IDC_COMBO1, m_cmbLang);
//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CGetMultiLanguageDlg, CDialog)
//{{AFX_MSG_MAP(CGetMultiLanguageDlg)
ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeCombo1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
void CGetMultiLanguageDlg:oadAllLanguage()
{
CString szKey = "Language",szSection = "Setting";

CFileFind find;
bool ret = find.FindFile(g_szCurPath + "Language\\*.ini");
while(ret)
{
ret = find.FindNextFile();
if(find.IsDots() || find.IsDirectory()) continue;

CString szValue;
DWORD dwSize = 100;
if(GetPrivateProfileString(szSection,szKey,"",
szValue.GetBuffer(dwSize),dwSize,find.GetFilePath()) != 0)
{
m_cmbLang.AddString(szValue);
}
szValue.ReleaseBuffer();
}
find.Close();

DWORD dwSize = 1000;
CString szLang;
GetPrivateProfileString(szSection,szKey,"English",szLang.GetBuffer(dwSize),dwSize,g_szSettingPath);
szLang.ReleaseBuffer();

m_cmbLang.SelectString(-1,szLang);
}
/////////////////////////////////////////////////////////////////////////////
// CGetMultiLanguageDlg message handlers
BOOL CGetMultiLanguageDlg::OnInitDialog()
{
CDialog::OnInitDialog();

//查找所有可用语言,装入下拉列表框
LoadAllLanguage();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
/*********************************************************************
* 函数名称:g_SetDialogStrings(CDialog *pDlg,UINT uDlgID)
* 说明: 当对话框运行时获取其所有可得到的字符串,并保存到语言文件中
每个控件用对话框ID和控件ID唯一标识
* 入口参数:
* CDialog *pDlg -- 对话框的指针
* UINT uDlgID -- 该对话框的ID
* 作者: Geng
*********************************************************************/
void g_SetDialogStrings(CDialog *pDlg,UINT uDlgID)
{
CString szSection = "String";
CString szKey,szText;
bool bSetText = 1; //1:从文件读,设置对话框
//0:从对话框读,保存到文件

if(bSetText) //1:从文件读,设置对话框
{
CString szDefault = "";
DWORD dwSize = 1000;
char* pData = (char*)malloc(dwSize);

//读对话框标题
szKey.Format("IDD%d_Title",uDlgID);
if(GetPrivateProfileString(szSection,szKey,szDefault,
pData,dwSize,g_szLanguagePath) != 0)
{
pDlg->SetWindowText(pData);
}

//写入各个子控件的标题文字
CWnd* pWnd = pDlg->GetWindow(GW_CHILD);
while(pWnd != NULL)
{
szKey.Format("IDD%d_%d",uDlgID,pWnd->GetDlgCtrlID());
if(GetPrivateProfileString(szSection,szKey,szDefault,
pData,dwSize,g_szLanguagePath) != 0)
{
pWnd->SetWindowText(pData);
}

pWnd = pWnd->GetWindow(GW_HWNDNEXT);
}

//释放内存
free(pData);
}
else //0:从对话框读,保存到文件
{
//写入对话框标题
szKey.Format("IDD%d_Title",uDlgID);
pDlg->GetWindowText(szText);
WritePrivateProfileString(szSection,szKey,szText,g_szLanguagePath);

//写入各个子控件的标题文字
CWnd* pWnd = pDlg->GetWindow(GW_CHILD);
while(pWnd != NULL)
{
szKey.Format("IDD%d_%d",uDlgID,pWnd->GetDlgCtrlID());
pWnd->GetWindowText(szText);
WritePrivateProfileString(szSection,szKey,szText,g_szLanguagePath);

pWnd = pWnd->GetWindow(GW_HWNDNEXT);
}
}
}
//extern CString szLanguageValue;
void CGetMultiLanguageDlg::OnSelchangeCombo1()
{
CString szValue;
m_cmbLang.GetLBText(m_cmbLang.GetCurSel(),szValue);
CHyhApp *pApp= (CHyhApp*)AfxGetApp();
pApp->languageSel= szValue;
((CHyhApp*)AfxGetApp())->LoadLanguage(szValue);

// ((CHyhApp*)AfxGetApp())->LoadLanguage(pApp->languageSel);
// view->szLanguageValue=szValue;
// ((CHyhApp*)AfxGetApp())->LoadLanguage(view->szLanguageValue);

//改变菜单语言
// SetMenuStrings();
DrawMenuBar(); //刷新菜单显示

//刷新对话框的语言显示
g_SetDialogStrings(this,IDD);
Invalidate(false);
}
void CGetMultiLanguageDlg::OnOK()
{
CHyhApp *pApp= (CHyhApp*)AfxGetApp();
// ((CHyhApp*)AfxGetApp())->LoadLanguage(pApp->languageSel);
AfxMessageBox(pApp->languageSel);
CCDialogTwo DialogTwo;
DialogTwo.DoModal();
CDialog::OnOK();
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|小黑屋|几何尺寸与公差论坛

GMT+8, 2024-12-22 13:27 , Processed in 0.044455 second(s), 20 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表