MFC中菜单设置

caidanview.cpp
// caidanView.cpp : implementation of the CCaidanView class
//

#include "stdafx.h"
#include "caidan.h"

#include "caidanDoc.h"
#include "caidanView.h"

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

/
// CCaidanView

IMPLEMENT_DYNCREATE(CCaidanView, CView)

BEGIN_MESSAGE_MAP(CCaidanView, CView)
	//{{AFX_MSG_MAP(CCaidanView)
	ON_COMMAND(ID_MENUITEM32771, OnMenuitem32771)
	//}}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()

/
// CCaidanView construction/destruction

CCaidanView::CCaidanView()
{
	// TODO: add construction code here
 strName=" ";
 y=0;
}

CCaidanView::~CCaidanView()
{
}

BOOL CCaidanView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/
// CCaidanView drawing

void CCaidanView::OnDraw(CDC* pDC)
{
	CCaidanDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	pDC->TextOut(20,y,strName);
    //CClientDC dc(this);
	//dc.TextOut(20,20,strName);
	// TODO: add draw code for native data here
}

/
// CCaidanView printing

BOOL CCaidanView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CCaidanView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CCaidanView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/
// CCaidanView diagnostics

#ifdef _DEBUG
void CCaidanView::AssertValid() const
{
	CView::AssertValid();
}

void CCaidanView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CCaidanDoc* CCaidanView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCaidanDoc)));
	return (CCaidanDoc*)m_pDocument;
}
#endif //_DEBUG

/
// CCaidanView message handlers

void CCaidanView::OnMenuitem32771() 
{
	// TODO: Add your command handler code here
	MyDialog My;
	y+=20;
	if(My.DoModal()==IDOK)
 		strName=My.m_strName+"     "+My.m_strID;
    Invalidate();
	
}
caidanview.h
// caidanView.h : interface of the CCaidanView class
//
/
#include"Mydialog.h"
#if !defined(AFX_CAIDANVIEW_H__8CFE4B1C_3EF8_4B03_801E_E6CA3E43B2BB__INCLUDED_)
#define AFX_CAIDANVIEW_H__8CFE4B1C_3EF8_4B03_801E_E6CA3E43B2BB__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000


class CCaidanView : public CView
{
protected: // create from serialization only
	CCaidanView();
	DECLARE_DYNCREATE(CCaidanView)

// Attributes
public:
	CCaidanDoc* GetDocument();

// Operations
public:
CString strName;
int y;
// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CCaidanView)
	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 ~CCaidanView();
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

protected:

// Generated message map functions
protected:
	//{{AFX_MSG(CCaidanView)
	afx_msg void OnMenuitem32771();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

#ifndef _DEBUG  // debug version in caidanView.cpp
inline CCaidanDoc* CCaidanView::GetDocument()
   { return (CCaidanDoc*)m_pDocument; }
#endif

/

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_CAIDANVIEW_H__8CFE4B1C_3EF8_4B03_801E_E6CA3E43B2BB__INCLUDED_)
caidan.cpp
// caidan.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "caidan.h"

#include "MainFrm.h"
#include "caidanDoc.h"
#include "caidanView.h"

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

/
// CCaidanApp

BEGIN_MESSAGE_MAP(CCaidanApp, CWinApp)
	//{{AFX_MSG_MAP(CCaidanApp)
	ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
	// Standard file based document commands
	ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
	ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
	// Standard print setup command
	ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP()

/
// CCaidanApp construction

CCaidanApp::CCaidanApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}

/
// The one and only CCaidanApp object

CCaidanApp theApp;

/
// CCaidanApp initialization

BOOL CCaidanApp::InitInstance()
{
	AfxEnableControlContainer();

	// Standard initialization
	// If you are not using these features and wish to reduce the size
	//  of your final executable, you should remove from the following
	//  the specific initialization routines you do not need.

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif

	// Change the registry key under which our settings are stored.
	// TODO: You should modify this string to be something appropriate
	// such as the name of your company or organization.
	SetRegistryKey(_T("Local AppWizard-Generated Applications"));

	LoadStdProfileSettings();  // Load standard INI file options (including MRU)

	// Register the application's document templates.  Document templates
	//  serve as the connection between documents, frame windows and views.

	CSingleDocTemplate* pDocTemplate;
	pDocTemplate = new CSingleDocTemplate(
		IDR_MAINFRAME,
		RUNTIME_CLASS(CCaidanDoc),
		RUNTIME_CLASS(CMainFrame),       // main SDI frame window
		RUNTIME_CLASS(CCaidanView));
	AddDocTemplate(pDocTemplate);

	// Parse command line for standard shell commands, DDE, file open
	CCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);

	// Dispatch commands specified on the command line
	if (!ProcessShellCommand(cmdInfo))
		return FALSE;

	// The one and only window has been initialized, so show and update it.
	m_pMainWnd->ShowWindow(SW_SHOW);
	m_pMainWnd->UpdateWindow();

	return TRUE;
}


/
// 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)
		// No message handlers
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

// App command to run the dialog
void CCaidanApp::OnAppAbout()
{
	CAboutDlg aboutDlg;
	aboutDlg.DoModal();
}

/
// CCaidanApp message handlers

Mydialog.cpp
// MyDialog.cpp : implementation file
//

#include "stdafx.h"
#include "caidan.h"
#include "MyDialog.h"

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

/
// MyDialog dialog


MyDialog::MyDialog(CWnd* pParent /*=NULL*/)
	: CDialog(MyDialog::IDD, pParent)
{
	//{{AFX_DATA_INIT(MyDialog)
	m_strName = _T("");
	m_strID="";
	//}}AFX_DATA_INIT
}


void MyDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(MyDialog)
	DDX_Control(pDX, IDC_EDIT2, m_strXuehao);
	DDX_Text(pDX, IDC_EDIT1, m_strName);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(MyDialog, CDialog)
	//{{AFX_MSG_MAP(MyDialog)
	ON_EN_CHANGE(IDC_EDIT2, OnChangeEdit2)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/
// MyDialog message handlers

void MyDialog::OnChangeEdit2() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	
}

void MyDialog::OnOK() 
{

	// TODO: Add extra validation here
	//
//  /*1*/m_strXuehao.GetWindowText(m_strID);
//	/*2*/CWnd *pw=GetDlgItem(IDC_EDIT2);
//	     pw->GetWindowText(m_strID);*/
    /*3*/	this->GetDlgItemText(IDC_EDIT2,m_strID);
	CDialog::OnOK();
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
MFC(Microsoft Foundation Class),可以使用资源文件和应用程序框架来实现语言设置。以下是一些常用的设置方法: 1. 通过资源文件设置语言 通过资源文件可以实现 MFC 应用程序的本地化。在 MFC ,可以通过将字符串资源、对话框资源、菜单资源等放置在不同的语言目录下来实现多语言支持。例如,将文资源放在“zh-CN”目录下,将英文资源放在“en-US”目录下。 在设置语言时,可以使用 LoadString 或者 LoadMenu 函数来加载相应语言的资源。例如,在 OnInitDialog 函数通过以下代码加载文字符串资源: ```cpp CString strText; strText.LoadString(IDS_HELLO_WORLD); m_staticText.SetWindowText(strText); ``` 其,IDS_HELLO_WORLD 是字符串资源的 ID,m_staticText 是控件的变量名。 2. 通过应用程序框架设置语言 MFC 应用程序框架提供了一些类来帮助设置语言。例如,可以使用 CWinAppEx 类的 PreTranslateMessage 函数来拦截并处理 WM_INPUTLANGCHANGE 消息,以实现语言切换。具体可以在 CWinAppEx 的派生类添加以下代码: ```cpp BOOL CMyApp::PreTranslateMessage(MSG* pMsg) { if (pMsg->message == WM_INPUTLANGCHANGE) { // 获取当前输入语言 LANGID langID = LOWORD(pMsg->wParam); if (langID == MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED)) { // 设置文 AfxSetResourceHandle(GetModuleHandle(_T("zh-CN"))); } else if (langID == MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)) { // 设置为英文 AfxSetResourceHandle(GetModuleHandle(_T("en-US"))); } } return CWinAppEx::PreTranslateMessage(pMsg); } ``` 其,LANG_CHINESE 和 LANG_ENGLISH 分别表示文和英文,SUBLANG_CHINESE_SIMPLIFIED 和 SUBLANG_ENGLISH_US 分别表示简体文和美式英文。 以上是一些常用的 MFC 设置语言的方法,您可以根据实际情况进行选择和调整。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值