Visual C++ Programming class1group2Word格式.docx
《Visual C++ Programming class1group2Word格式.docx》由会员分享,可在线阅读,更多相关《Visual C++ Programming class1group2Word格式.docx(14页珍藏版)》请在冰豆网上搜索。
Ascanbeseenfromthefiguretherearetwopagesinthepropertysheet.Thefirstpagecontainsradiobuttonstochoosetheshapetodrawandthepenwithwhichtodrawit.ThetwopagesarecreatedusingtheResourceEditor.TheOKandCancelbuttonsareprovidedbythepropertysheetandhencehavenotbeencreatedusingtheResourceEditor.
Wehavederivedtwoclasses,firstpageandsecondpagefromCPropertyPagetorepresentthetwopagesofthepropertysheet.Likewise,wehavederivedtheclassmypropertysheetfromCPropertyPage.Otherthanthesewehavethenormalmyframeandmyappclasses.
Whenthe‘sheet’menuitemisselectedthesheet()functionofthemyframeclassgetscalled.
TheDomodal()functioncreatesthetabbeddialogbox
Whenthedialogboxappearsthe‘Apply’buttonisdehighlightedandhencecannotbechosen.InthisfunctiontheSetmodified()functioniscalledwiththeTRUEparametertoenablethe‘Apply’button.
Atthisstagetheusercanexercisefourchoices:
HemaychoosetheOK,Cancel,orApplybuttonortabtothenextpageinthepropertysheet.
Themyframe:
:
draw()functioniscalledtodrawtheselectedshapeusingthevaluessetupinthemyframeclassvariables.
Thesecondpage:
OnOK()worksonsimilarlinesasoutlinedin(g)above.
Oncethedesiredshapehasbeendrawnandthedialogboxdismissedthevariablesassociatedwiththecontrolsinthetwopagesarenolongerexisting.Now,iftheuserminimizesthewindowandthenmaximizesit,theOnpaint()handlerandinturnthemyframe:
draw()functionwouldgetcalled.Anassertionerrorislikelytooccurinthedraw()functionsincethevariablesofthetwopagesintothecorrespondingvariablesofmyframeinthefirstpage:
OnOK(),secondpage:
OnOK()andmypropertysheet:
OnApplyNow()functions.Alsonotethatmyframevariablesneedtobepubliceventhoughtheyareusedinmyframe:
draw()function,sincetheyaresetupinfirstpage,secondpageandmypropertysheetclass.
HardwareandSoftware
Hardware
Processor:
AMDalthon64x25600+at2900mhz
Ram:
3GBwith800mhz
Displayadapter:
DVI
Monitorsize:
20
Keyboard:
108keys
Software
Operatingsystem:
Windows7
Database:
Accesesversion
ProgrammingLanguage:
VC++
IDE:
Visualstudio
Screenshot
\
SourceCode
#include"
stdafx.h"
Properties.h"
PropertiesDlg.h"
#ifdef_DEBUG
#definenewDEBUG_NEW
#undefTHIS_FILE
staticcharTHIS_FILE[]=__FILE__;
#endif
secdondpage.h"
firstpage.h"
firstpagem_d1;
secdondpagem_d2;
intwidth=0;
inttype=99;
inttake=0;
classCAboutDlg:
publicCDialog
{
public:
CAboutDlg();
enum{IDD=IDD_ABOUTBOX};
protected:
virtualvoidDoDataExchange(CDataExchange*pDX);
//DDX/DDVsupport
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg:
CAboutDlg():
CDialog(CAboutDlg:
IDD)
}
voidCAboutDlg:
DoDataExchange(CDataExchange*pDX)
CDialog:
DoDataExchange(pDX);
BEGIN_MESSAGE_MAP(CAboutDlg,CDialog)
END_MESSAGE_MAP()
CPropertiesDlg:
CPropertiesDlg(CWnd*pParent/*=NULL*/)
:
CDialog(CPropertiesDlg:
IDD,pParent)
m_hIcon=AfxGetApp()->
LoadIcon(IDR_MAINFRAME);
voidCPropertiesDlg:
DDX_Control(pDX,IDC_TAB,m_tab);
BEGIN_MESSAGE_MAP(CPropertiesDlg,CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_NOTIFY(TCN_SELCHANGE,IDC_TAB,OnSelchangeTab)
ON_BN_CLICKED(IDC_APPLY1,OnApply1)
ON_BN_CLICKED(IDC_APPLY,OnApply)
ON_BN_CLICKED(ID_CANCEL1,OnCancel1)
BOOLCPropertiesDlg:
OnInitDialog()
OnInitDialog();
m_tab.InsertItem(0,"
Objects"
);
m_tab.InsertItem(1,"
Dialog"
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);
AppendMenu(MF_STRING,IDM_ABOUTBOX,strAboutMenu);
}
}
SetIcon(m_hIcon,TRUE);
//Setbigicon
SetIcon(m_hIcon,FALSE);
//Setsmallicon
m_d1.Create(IDD_DIALOG2,GetDlgItem(IDC_TAB));
m_d2.Create(IDD_DIALOG1,GetDlgItem(IDC_TAB));
CRectrs;
m_tab.GetClientRect(&
rs);
rs.top+=20;
rs.bottom-=20;
rs.left+=20;
rs.right-=20;
m_d1.MoveWindow(&
m_d2.MoveWindow(&
m_d1.ShowWindow(true);
m_d2.ShowWindow(false);
returnTRUE;
OnSysCommand(UINTnID,LPARAMlParam)
if((nID&
0xFFF0)==IDM_ABOUTBOX)
CAboutDlgdlgAbout;
dlgAbout.DoModal();
else
CDialog:
OnSysCommand(nID,lParam);
OnPaint()
if(IsIconic())
CPaintDCdc(this);
//devicecontextforpainting
SendMessage(WM_ICONERASEBKGND,(WPARAM)dc.GetSafeHdc(),0);
intcxIcon=GetSystemMetrics(SM_CXICON);
intcyIcon=GetSystemMetrics(SM_CYICON);
CRectrect;
GetClientRect(&
rect);
intx=(rect.Width()-cxIcon+1)/2;
inty=(rect.Height()-cyIcon+1)/2;
dc.DrawIcon(x,y,m_hIcon);
OnPaint();
HCURSORCPropertiesDlg:
OnQueryDragIcon()
return(HCURSOR)m_hIcon;
OnSelchangeTab(NMHDR*pNMHDR,LRESULT*pResult)
intCurSel=m_tab.GetCurSel();
switch(CurSel)
case0:
m_d1.ShowWindow(true);
m_d2.ShowWindow(false);
break;
case1:
m_d2.ShowWindow(true);
m_d1.ShowWindow(false);
take=0;
*pResult=0;
OnApply1()
{
m_d2.ShowWindow(true);
if(m_d1.ShowWindow(false))
SetForegroundWindow(m_d2.m_hWnd);
CDC*pDC=m_d2.GetDC();
CPenpen(PS_SOLID,width,RGB(180,180,180));
pDC->
SelectObject(&
pen);
switch(type)
case0:
pDC->
MoveTo(50,50);
LineTo(180,180);
break;
case1:
Rectangle(CRect(30,30,180,180));
case2:
Ellipse(CRect(20,20,150,150));
case3:
CPointp1(30,40),p2(40,140),p3(80,160);
CPointppt[3]={p1,p2,p3};
Polygon(ppt,3);
OnCancel()
OnCancel();
OnApply()
if(take==0)
OnApply1();
if(type==99)
MessageBox("
pleaseselectvalues"
"
error"
0);
OnCancel1()
((CButton*)m_d1.GetDlgItem(IDC_RADIO1))->
SetCheck(0);
((CButton*)m_d1.GetDlgItem(IDC_RADIO2))->
((CButton*)m_d1.GetDlgItem(IDC_RADIO3))->
((CButton*)m_d1.GetDlgItem(IDC_RADIO4))->
((CButton*)m_d1.GetDlgItem(IDC_RADIO5))->
((CButton*)m_d1.GetDlgItem(IDC_RADIO6))->
((CButton*)m_d1.GetDlgItem(IDC_RADIO7))->
((CButton*)m_d1.GetDlgItem(IDC_RADIO8))->
type=99;
References
[1]WangYujian--VisualC++Object-orientedprogrammingtutorial.
[2]Sams--TeachYourselfVisualC++In21Days
[3]TanHaoqiang--VisualC++Programming