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
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值