MFC对话框.docx

上传人:b****2 文档编号:11804425 上传时间:2023-06-02 格式:DOCX 页数:13 大小:17.40KB
下载 相关 举报
MFC对话框.docx_第1页
第1页 / 共13页
MFC对话框.docx_第2页
第2页 / 共13页
MFC对话框.docx_第3页
第3页 / 共13页
MFC对话框.docx_第4页
第4页 / 共13页
MFC对话框.docx_第5页
第5页 / 共13页
MFC对话框.docx_第6页
第6页 / 共13页
MFC对话框.docx_第7页
第7页 / 共13页
MFC对话框.docx_第8页
第8页 / 共13页
MFC对话框.docx_第9页
第9页 / 共13页
MFC对话框.docx_第10页
第10页 / 共13页
MFC对话框.docx_第11页
第11页 / 共13页
MFC对话框.docx_第12页
第12页 / 共13页
MFC对话框.docx_第13页
第13页 / 共13页
亲,该文档总共13页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

MFC对话框.docx

《MFC对话框.docx》由会员分享,可在线阅读,更多相关《MFC对话框.docx(13页珍藏版)》请在冰点文库上搜索。

MFC对话框.docx

MFC对话框

Dialogss.h代码

#if!

defined(AFX_DIALOGSS_H__A6482206_E3F1_43B8_BCE9_82287D59D005__INCLUDED_)

#defineAFX_DIALOGSS_H__A6482206_E3F1_43B8_BCE9_82287D59D005__INCLUDED_

#if_MSC_VER>1000

#pragmaonce

#endif//_MSC_VER>1000

//Dialogss.h:

headerfile

//

/////////////////////////////////////////////////////////////////////////////

//Dialogssdialog

classDialogss:

publicCDialog

{

//Construction

public:

Dialogss(CWnd*pParent=NULL);//standardconstructor

CStringstr;//设置函数之后可以改成结构体

CStringstr1;

//DialogData

//{{AFX_DATA(Dialogss)

enum{IDD=IDD_DIALOG1};

//NOTE:

theClassWizardwilladddatamembershere

//}}AFX_DATA

//Overrides

//ClassWizardgeneratedvirtualfunctionoverrides

//{{AFX_VIRTUAL(Dialogss)

protected:

virtualvoidDoDataExchange(CDataExchange*pDX);//DDX/DDVsupport

//}}AFX_VIRTUAL

//Implementation

protected:

//Generatedmessagemapfunctions

//{{AFX_MSG(Dialogss)

virtualBOOLOnInitDialog();//创建赋初值

//}}AFX_MSG

DECLARE_MESSAGE_MAP()

};

//{{AFX_INSERT_LOCATION}}

//MicrosoftVisualC++willinsertadditionaldeclarationsimmediatelybeforethepreviousline.

#endif//!

defined(AFX_DIALOGSS_H__A6482206_E3F1_43B8_BCE9_82287D59D005__INCLUDED_)

Dialogss.cpp代码

//Dialogss.cpp:

implementationfile

//

#include"stdafx.h"

#include"DialogTests.h"

#include"Dialogss.h"

#ifdef_DEBUG

#definenewDEBUG_NEW

#undefTHIS_FILE

staticcharTHIS_FILE[]=__FILE__;

#endif

/////////////////////////////////////////////////////////////////////////////

//Dialogssdialog

 

Dialogss:

:

Dialogss(CWnd*pParent/*=NULL*/)

:

CDialog(Dialogss:

:

IDD,pParent)

{

//{{AFX_DATA_INIT(Dialogss)

//NOTE:

theClassWizardwilladdmemberinitializationhere

//}}AFX_DATA_INIT

}

 

voidDialogss:

:

DoDataExchange(CDataExchange*pDX)

{

CDialog:

:

DoDataExchange(pDX);

DDX_Text(pDX,IDC_EDIT1,str);//将Edit框与变量关联

DDX_Text(pDX,IDC_EDIT3,str1);

}

 

BEGIN_MESSAGE_MAP(Dialogss,CDialog)

END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////

//Dialogssmessagehandlers

BOOLDialogss:

:

OnInitDialog()

{

CDialog:

:

OnInitDialog();

//str="11";

inti=12;

str.Format("%d",i);//string类型的转换

intj=33;

str1.Format("%d",j);

UpdateData(FALSE);//变量的值传进了文本框中

UpdateData(TRUE);//文本框中的变量传到变量中

returnTRUE;//returnTRUEunlessyousetthefocustoacontrol

//EXCEPTION:

OCXPropertyPagesshouldreturnFALSE

}

DialogTestDlg,h代码:

//DialogTestsDlg.h:

headerfile

//

#if!

defined(AFX_DIALOGTESTSDLG_H__345AEFDD_620C_4F25_8DB0_729554CA6BD3__INCLUDED_)

#defineAFX_DIALOGTESTSDLG_H__345AEFDD_620C_4F25_8DB0_729554CA6BD3__INCLUDED_

#if_MSC_VER>1000

#pragmaonce

#endif//_MSC_VER>1000

/////////////////////////////////////////////////////////////////////////////

//CDialogTestsDlgdialog

classCDialogTestsDlg:

publicCDialog

{

//Construction

public:

CDialogTestsDlg(CWnd*pParent=NULL);//standardconstructor

//DialogData

//{{AFX_DATA(CDialogTestsDlg)

enum{IDD=IDD_DIALOGTESTS_DIALOG};

//NOTE:

theClassWizardwilladddatamembershere

//}}AFX_DATA

//ClassWizardgeneratedvirtualfunctionoverrides

//{{AFX_VIRTUAL(CDialogTestsDlg)

protected:

virtualvoidDoDataExchange(CDataExchange*pDX);//DDX/DDVsupport

//}}AFX_VIRTUAL

//Implementation

protected:

HICONm_hIcon;

//Generatedmessagemapfunctions

//{{AFX_MSG(CDialogTestsDlg)

virtualBOOLOnInitDialog();

afx_msgvoidOnSysCommand(UINTnID,LPARAMlParam);

afx_msgvoidOnPaint();

afx_msgHCURSOROnQueryDragIcon();

afx_msgvoidOnButton4();

afx_msgvoidOnButton1();

afx_msgvoidOnButton2();

//}}AFX_MSG

DECLARE_MESSAGE_MAP()

};

//{{AFX_INSERT_LOCATION}}

//MicrosoftVisualC++willinsertadditionaldeclarationsimmediatelybeforethepreviousline.

#endif//!

defined(AFX_DIALOGTESTSDLG_H__345AEFDD_620C_4F25_8DB0_729554CA6BD3__INCLUDED_)

DialogTestDlg.cpp代码

//DialogTestsDlg.cpp:

implementationfile

//

#include"stdafx.h"

#include"DialogTests.h"

#include"DialogTestsDlg.h"

#include"Dialogss.h"

#ifdef_DEBUG

#definenewDEBUG_NEW

#undefTHIS_FILE

staticcharTHIS_FILE[]=__FILE__;

#endif

/////////////////////////////////////////////////////////////////////////////

//CAboutDlgdialogusedforAppAbout

classCAboutDlg:

publicCDialog

{

public:

CAboutDlg();

//DialogData

//{{AFX_DATA(CAboutDlg)

enum{IDD=IDD_ABOUTBOX};

//}}AFX_DATA

//ClassWizardgeneratedvirtualfunctionoverrides

//{{AFX_VIRTUAL(CAboutDlg)

protected:

virtualvoidDoDataExchange(CDataExchange*pDX);//DDX/DDVsupport

//}}AFX_VIRTUAL

//Implementation

protected:

//{{AFX_MSG(CAboutDlg)

//}}AFX_MSG

DECLARE_MESSAGE_MAP()

};

CAboutDlg:

:

CAboutDlg():

CDialog(CAboutDlg:

:

IDD)

{

//{{AFX_DATA_INIT(CAboutDlg)

//}}AFX_DATA_INIT

}

voidCAboutDlg:

:

DoDataExchange(CDataExchange*pDX)

{

CDialog:

:

DoDataExchange(pDX);

//{{AFX_DATA_MAP(CAboutDlg)

//}}AFX_DATA_MAP

}

BEGIN_MESSAGE_MAP(CAboutDlg,CDialog)

//{{AFX_MSG_MAP(CAboutDlg)

//Nomessagehandlers

//}}AFX_MSG_MAP

END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////

//CDialogTestsDlgdialog

CDialogTestsDlg:

:

CDialogTestsDlg(CWnd*pParent/*=NULL*/)

:

CDialog(CDialogTestsDlg:

:

IDD,pParent)

{

//{{AFX_DATA_INIT(CDialogTestsDlg)

//NOTE:

theClassWizardwilladdmemberinitializationhere

//}}AFX_DATA_INIT

//NotethatLoadIcondoesnotrequireasubsequentDestroyIconinWin32

m_hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME);

}

voidCDialogTestsDlg:

:

DoDataExchange(CDataExchange*pDX)

{

CDialog:

:

DoDataExchange(pDX);

//{{AFX_DATA_MAP(CDialogTestsDlg)

//NOTE:

theClassWizardwilladdDDXandDDVcallshere

//}}AFX_DATA_MAP

}

BEGIN_MESSAGE_MAP(CDialogTestsDlg,CDialog)

//{{AFX_MSG_MAP(CDialogTestsDlg)

ON_WM_SYSCOMMAND()

ON_WM_PAINT()

ON_WM_QUERYDRAGICON()

ON_BN_CLICKED(IDC_BUTTON4,OnButton4)

ON_BN_CLICKED(IDC_BUTTON1,OnButton1)

ON_BN_CLICKED(IDC_BUTTON2,OnButton2)

//}}AFX_MSG_MAP

END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////

//CDialogTestsDlgmessagehandlers

BOOLCDialogTestsDlg:

:

OnInitDialog()

{

CDialog:

:

OnInitDialog();

//Add"About..."menuitemtosystemmenu.

//IDM_ABOUTBOXmustbeinthesystemcommandrange.

ASSERT((IDM_ABOUTBOX&0xFFF0)==IDM_ABOUTBOX);

ASSERT(IDM_ABOUTBOX<0xF000);

CMenu*pSysMenu=GetSystemMenu(FALSE);

if(pSysMenu!

=NULL)

{

CStringstrAboutMenu;

strAboutMenu.LoadString(IDS_ABOUTBOX);

if(!

strAboutMenu.IsEmpty())

{

pSysMenu->AppendMenu(MF_SEPARATOR);

pSysMenu->AppendMenu(MF_STRING,IDM_ABOUTBOX,strAboutMenu);

}

}

//Settheiconforthisdialog.Theframeworkdoesthisautomatically

//whentheapplication'smainwindowisnotadialog

SetIcon(m_hIcon,TRUE);//Setbigicon

SetIcon(m_hIcon,FALSE);//Setsmallicon

//TODO:

Addextrainitializationhere

returnTRUE;//returnTRUEunlessyousetthefocustoacontrol

}

voidCDialogTestsDlg:

:

OnSysCommand(UINTnID,LPARAMlParam)

{

if((nID&0xFFF0)==IDM_ABOUTBOX)

{

CAboutDlgdlgAbout;

dlgAbout.DoModal();

}

else

{

CDialog:

:

OnSysCommand(nID,lParam);

}

}

voidCDialogTestsDlg:

:

OnPaint()

{

if(IsIconic())

{

CPaintDCdc(this);//devicecontextforpainting

SendMessage(WM_ICONERASEBKGND,(WPARAM)dc.GetSafeHdc(),0);

//Centericoninclientrectangle

intcxIcon=GetSystemMetrics(SM_CXICON);

intcyIcon=GetSystemMetrics(SM_CYICON);

CRectrect;

GetClientRect(&rect);

intx=(rect.Width()-cxIcon+1)/2;

inty=(rect.Height()-cyIcon+1)/2;

//Drawtheicon

dc.DrawIcon(x,y,m_hIcon);

}

else

{

CDialog:

:

OnPaint();

}

}

//Thesystemcallsthistoobtainthecursortodisplaywhiletheuserdrags

//theminimizedwindow.

HCURSORCDialogTestsDlg:

:

OnQueryDragIcon()

{

return(HCURSOR)m_hIcon;

}

voidCDialogTestsDlg:

:

OnButton4()

{

CFileDialogFileDialog(TRUE,NULL,NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,NULL,NULL);

CStringFileName;

CFileFile;

if(FileDialog.DoModal()==IDOK)

{

//实现文件名显示

FileName=FileDialog.GetFileName();

CStringffff=FileName.Left(FileName.Find('.'));

CWnd*ss=GetDlgItem(IDC_EDIT1);

ss->SetWindowText(ffff);

//SetDlgItemText(IDC_EDIT1,ffff);

File.Open(FileName.GetBuffer(_MAX_PATH),CFile:

:

modeCreate|CFile:

:

modeReadWrite);

}

}

voidCDialogTestsDlg:

:

OnButton1()

{

//CDialogdlg;

//dlg.DoModal();

Dialogssdlg;//创建对话框

dlg.DoModal();

}

voidCDialogTestsDlg:

:

OnButton2()//删除操作

{

Dialogssdlg1;

dlg1.DoModal();

}

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 解决方案 > 学习计划

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2