VC程序設(shè)計(jì)試題作業(yè)_第1頁(yè)
VC程序設(shè)計(jì)試題作業(yè)_第2頁(yè)
VC程序設(shè)計(jì)試題作業(yè)_第3頁(yè)
VC程序設(shè)計(jì)試題作業(yè)_第4頁(yè)
VC程序設(shè)計(jì)試題作業(yè)_第5頁(yè)
已閱讀5頁(yè),還剩19頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、word四、使用MFC編寫(xiě)帶菜單和工具欄的文本框編輯程序,支持復(fù)制、剪切和粘貼功能,以及文件翻開(kāi)、保存功能。(20分)資源列表:編程資源資源類(lèi)別標(biāo)題ID關(guān)聯(lián)變量類(lèi)型關(guān)聯(lián)變量名稱(chēng)MENU菜單IDR_MENU1MENUDIALOG對(duì)話(huà)框NotePadIDD_NOTEPAD_DIALOGDIALOGCNotePadDlg菜單-翻開(kāi)子菜單翻開(kāi)ID_FILE_OPENCFileDialog filedlg菜單-保存子菜單保存ID_FILE_SAVECFile file菜單-另存為子菜單另存為ID_FILE_SAVE_ASCFileDialog CFilefiledlgfile菜單-退出子菜單退出ID_F

2、ILE_EXITEndDialogEndDialog菜單-復(fù)制子菜單復(fù)制ID_EDIT_COPYCEdit *pEdit菜單-粘貼子菜單粘貼ID_EDIT_PASTECEdit *pEdit菜單-剪切子菜單剪切ID_EDIT_CUTCEdit *pEdit菜單-刪除子菜單刪除ID_EDIT_CLEARCEdit *pEdit菜單-撤銷(xiāo)子菜單撤銷(xiāo)ID_EDIT_UNDOCEdit *pEdit程序運(yùn)行效果:主界面:翻開(kāi)、保存、另存為效果:復(fù)制、粘貼、剪切效果:除此之外還實(shí)現(xiàn)了全選功能、刪除功能,可以全選文本內(nèi)容和刪除內(nèi)容,還實(shí)現(xiàn)了撤銷(xiāo)等功能。程序主要代碼:/重載OnClose()實(shí)現(xiàn)X的退出功能

3、void CNotePadDlg:OnClose() OnFileExit();/這里調(diào)用菜單下的退出函數(shù)/EndDialog(IDCANCEL);/CDialog:OnClose();/實(shí)現(xiàn)菜單欄目下 復(fù)制的功能void CNotePadDlg:OnEditCopy() CEdit * pEdit = (CEdit*)GetDlgItem(IDC_TEXT); pEdit->Copy();/實(shí)現(xiàn)菜單欄目下 刪除的功能void CNotePadDlg:OnEditClear() CEdit * pEdit = (CEdit*)GetDlgItem(IDC_TEXT);pEdit->

4、Clear();/實(shí)現(xiàn)菜單欄目下 撤銷(xiāo)的功能void CNotePadDlg:OnEditUndo() CEdit* pEdit = (CEdit*)GetDlgItem(IDC_TEXT);pEdit ->Undo();/實(shí)現(xiàn)菜單欄目下 剪切的功能void CNotePadDlg:OnEditCut() CEdit* pEdit = (CEdit*)GetDlgItem(IDC_TEXT);pEdit ->Cut();/實(shí)現(xiàn)菜單欄目下 全選的功能void CNotePadDlg:OnEditSelectAll() CEdit* pEdit = (CEdit*)GetDlgItem

5、(IDC_TEXT);pEdit ->SetSel(0,-1);/實(shí)現(xiàn)菜單欄目下 粘貼的功能void CNotePadDlg:OnEditPaste() CEdit* pEdit = (CEdit*)GetDlgItem(IDC_TEXT);pEdit ->Paste();/實(shí)現(xiàn)菜單欄目下 時(shí)間的功能void CNotePadDlg:OnEditDate() CTime t = CTime:GetCurrentTime();CString str = t.Format("%Y年%m月%d日 %H:%M:%S");CEdit* pEdit = (CEdit*)Ge

6、tDlgItem(IDC_TEXT);pEdit ->ReplaceSel( str,TRUE);/實(shí)現(xiàn)移動(dòng)窗口大小的功能;記得修改窗口屬性當(dāng)中的值void CNotePadDlg:OnSize(UINT nType, int cx, int cy) CDialog:OnSize(nType, cx, cy);CWnd* pEdit = GetDlgItem(IDC_TEXT);if(pEdit)pEdit->MoveWindow(0,0,cx,cy);/實(shí)現(xiàn)菜單下退出的功能void CNotePadDlg:OnFileExit() if(Prompt() = 0) /如果等于0,

7、代表選擇了取消,那么不關(guān)閉對(duì)話(huà)框/不做任何處理else/如果不等于0 那么代表選擇了 否 直接關(guān)閉對(duì)話(huà)框EndDialog(IDCANCEL);/實(shí)現(xiàn)菜單欄目下翻開(kāi)的功能void CNotePadDlg:OnFileOpen() /過(guò)濾器LPCTSTR szFilter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*|"/翻開(kāi)一個(gè)文件選擇對(duì)話(huà)框 TRUE代表 翻開(kāi)文件CFileDialog filedlg(TRUE,"txt","11",OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST,sz

8、Filter);if(IDCANCEL= filedlg.DoModal()return;/翻開(kāi)文件并顯示到IDC_TEXT當(dāng)中OpenFile(filedlg.GetPathName(),filedlg.GetFileName();/實(shí)現(xiàn)菜單欄目下保存的功能void CNotePadDlg:OnFileSave() /如果要保存的文件是第一次保存,那么就轉(zhuǎn)換到 另存為if(m_szCurrentFile.GetLength() = 0)OnFileSaveAs();return;CFile file;if(file.Open(m_szCurrentFile,CFile:modeWrite|C

9、File:modeCreate) = 0)OnFileSaveAs();return;CString szText;GetDlgItemText(IDC_TEXT,szText);/得到Edit控件里面的內(nèi)容file.Write(szText,szText.GetLength();/寫(xiě)入file對(duì)象file.Close();/關(guān)閉對(duì)象CEdit* pEdit = (CEdit*)GetDlgItem(IDC_TEXT) ;pEdit ->SetModify(FALSE);/FALSE表示文本沒(méi)有改變;這里直接保存,點(diǎn)擊退出的時(shí)候不要再提示改變/實(shí)現(xiàn)菜單欄目下另存為的功能void CNot

10、ePadDlg:OnFileSaveAs() LPCTSTR szFilter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*|"/初始化文件對(duì)話(huà)框 FALSE代表保存文件CFileDialog filedlg(FALSE,"txt","11",OFN_OVERWRITEPROMPT|OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST|OFN_CREATEPROMPT,szFilter);/翻開(kāi)文件對(duì)話(huà)框if(IDCANCEL = filedlg.DoModal()return;/得到文件對(duì)話(huà)

11、框中選擇文件的路徑名CString szFile = filedlg.GetPathName();/聲明一個(gè)CFile對(duì)象CFile file;/翻開(kāi)文件if( file.Open(szFile,CFile:modeWrite|CFile:modeCreate) = 0)MessageBox(filedlg.GetFileName()+"保存文件時(shí)失敗!", NULL,MB_ICONEXCLAMATION);return;/當(dāng)前文件為該文件,保存下來(lái)m_szCurrentFile = szFile;CString strText;/得到IDC_TEXT控件里面的內(nèi)容 Get

12、DlgItemText(IDC_TEXT,strText);/文件寫(xiě)入,第一個(gè)參數(shù)是要寫(xiě)入的內(nèi)容,第二個(gè)是寫(xiě)入內(nèi)容的長(zhǎng)度f(wàn)ile.Write(strText,strText.GetLength();file.Flush();/上面的解釋跟去除了,我看這個(gè)就明白了,相信你也一樣file.Close();/關(guān)閉文件,刪除對(duì)象!CEdit* pEdit = (CEdit*)GetDlgItem(IDC_TEXT);pEdit ->SetModify(FALSE);SetTitle();/處理文件修改的情況BOOL CNotePadDlg:Prompt()CEdit* pEdit = (CEdi

13、t*)GetDlgItem(IDC_TEXT);if(pEdit->GetModify()/如果文件被修改CString str;if(m_szCurrentFile.IsEmpty()/如果當(dāng)前的文件為空,那么str= 無(wú)標(biāo)題str = "無(wú)標(biāo)題"elsestr = m_szCurrentFile; /否那么就是 現(xiàn)在翻開(kāi)文件的Pathint nRet = MessageBox(str+"rn已經(jīng)被修改,是否保存?","提示消息",MB_YESNOCANCEL|MB_ICONEXCLAMATION);if(IDCANCEL =

14、 nRet)/如果選擇了 取消,那么不做任何處理,也不關(guān)閉對(duì)話(huà)框(在退出函數(shù)中做處理)return FALSE;if(IDNO = nRet) /如果選擇了 否 直接關(guān)閉對(duì)話(huà)框在退出函數(shù)當(dāng)中做處理return TRUE;else/如果選擇了 是 保存文件 OnFileSave();return TRUE;/設(shè)置上面的標(biāo)題void CNotePadDlg:SetTitle()CString str;if(m_szCurrentFile.IsEmpty()str = "無(wú)標(biāo)題"elsestr = m_szCurrentFile;int i = str.ReverseFind(&

15、#39;'); /反向找到 if(i > 0)str = str.Mid(i+1); /從位置處 截出str后面的內(nèi)容SetWindowText(str);.word五、使用API編寫(xiě)繪圖程序如下列圖。(20分)要求:在“形狀列表框中選擇要繪制圖形,在“筆顏色下拉列表框選擇畫(huà)筆的顏色,在“刷子顏色下拉列表框中選擇畫(huà)刷的顏色。在“線(xiàn)型組合框選擇畫(huà)筆的線(xiàn)型,在“填充類(lèi)型中選擇畫(huà)刷填充類(lèi)型。單擊“繪圖 按鈕按照前面的選項(xiàng)繪制圖形,單擊“退出按鈕退出程序。資源列表:資源名稱(chēng)資源類(lèi)別標(biāo)題ID號(hào)關(guān)聯(lián)變量消息響應(yīng)函數(shù)變量類(lèi)型變量名稱(chēng)繪圖形狀 列表框控件形狀I(lǐng)DC_LIST1CStringm_D

16、rawType;afx_msg void OnSelchangeList1();筆顏色下拉框控件筆顏色I(xiàn)DC_COMBO1CStringm_outColorafx_msg void onRadioBtnGroup1Clicked();刷子顏色下拉框控件刷子顏色I(xiàn)DC_COMBO2CStringm_inColorafx_msg void onRadioBtnGroup2Clicked();線(xiàn)型Radio button實(shí)線(xiàn)IDM_LINE_STYLE_SOLIDIntm_penTypeafx_msg void onRadioBtnGroup1Clicked();Radio button虛線(xiàn)IDM_

17、LINE_STYLE_DASHRadio button點(diǎn)線(xiàn)IDM_LINE_STYLE_DOTRadio button點(diǎn)劃線(xiàn)IDM_LINE_STYLE_DASHDOT填充類(lèi)型Radio button實(shí)體刷子PS_SOLIDIntm_brushTypeafx_msg void onRadioBtnGroup2Clicked();Radio button交叉線(xiàn)HS_CROSSRadio button主對(duì)角線(xiàn)型HS_FDIAGONALRadio button附對(duì)角線(xiàn)型HS_BDIAGONAL程序運(yùn)行效果:以黑色為背景繪制線(xiàn):繪制圓:繪制矩形:繪制圓角矩形程序代碼:變量定義局部:protected:

18、HICON m_hIcon;CBrush m_brush;/用于自定義顏色CDC m_memDC;/屏幕DC兼容的內(nèi)存DCCBitmap m_Bmp;/位圖CWnd* m_pDrawWnd;/用于保存靜態(tài)文本框的對(duì)象指針/ 初始化和雙緩沖相關(guān)的數(shù)據(jù)void InitialDBB();/雙緩沖內(nèi)存上繪圖void DrawOnMem();/在靜態(tài)區(qū)域畫(huà)圖void DrawOnStaticArea();/更改顏色的消息響應(yīng)函數(shù)afx_msg HBRUSH OnCtlColor(CDC *pDC, CWnd *pWnd, UINT nCtlColor);/ 生成的消息映射函數(shù)virtual BOOL

19、OnInitDialog();afx_msg void OnSysCommand(UINT nID, LPARAM lParam);afx_msg void OnPaint();afx_msg HCURSOR OnQueryDragIcon();DECLARE_MESSAGE_MAP()public:/ 控制筆顏色的下拉框列表變量CComboBox m_Combobox1;/ 控制刷子顏色的下拉框列表變量CComboBox m_Combobox2;/ 形狀列表CListBox m_ShapeList;/ 畫(huà)筆類(lèi)型,即輪廓索引int m_penType;/ 畫(huà)刷類(lèi)型,即填充顏色類(lèi)型int m_b

20、rushType;afx_msg void OnBnClickedOk();afx_msg void OnBnClickedCancel();afx_msg void onRadioBtnGroup1Clicked();afx_msg void onRadioBtnGroup2Clicked();/ 繪制的圖形類(lèi)型CString m_DrawType;afx_msg void OnSelchangeList1();afx_msg void OnCbnSelchangeCombo1();afx_msg void OnCbnSelchangeCombo2();/bool變量,用于控制繪圖按鈕點(diǎn)擊后

21、繪圖bool isDraw;/ 外輪廓顏色CString m_outColor;/ 內(nèi)填充顏色CString m_inColor;COLORREF outColor;COLORREF inColor;CPen myPen;CBrush myBrush;其他主要代碼:/雙緩沖內(nèi)存上繪圖void CfiveDlg:DrawOnMem()CRect rect;/畫(huà)圖局部-if (isDraw = true)CBrush* pOldBrush = m_memDC.SelectObject(&myBrush);/設(shè)置繪制圖形CRect drawRect;drawRect.left = rect.

22、left + 30;drawRect.right = rect.right - 30;drawRect.top = rect.top + 30;drawRect.bottom = rect.bottom - 30;if(m_DrawType = "Circle")m_memDC.Ellipse(drawRect); /畫(huà)橢圓if (m_DrawType = "Rectangle")m_memDC.Rectangle(drawRect); /畫(huà)矩形if (m_DrawType = "Line") /畫(huà)線(xiàn)m_memDC.MoveTo(re

23、ct.right - 40, rect.bottom - 40);m_memDC.LineTo(rect.left + 40, rect.top + 40);if (m_DrawType = "RoundRectangle") /畫(huà)圓角矩形CRect r;r = CRect(CPoint(40, 40), CSize(150, 12);m_memDC.RoundRect(drawRect, CPoint(50, 50); /CPoint(50, 50)表示圓角的幅度m_memDC.SelectObject(pOldPen);m_memDC.SelectObject(pOld

24、Brush);/在靜態(tài)區(qū)域畫(huà)圖void CfiveDlg:DrawOnStaticArea()CWnd* pWnd = GetDlgItem(IDC_STATIC);/獲得靜態(tài)文本框的窗口對(duì)象CRect rect;pWnd->GetClientRect(&rect);CDC* pDC = pWnd->GetDC();/DrawOnMem();/ 一次性的將內(nèi)存設(shè)備環(huán)境上繪制完畢的圖形"貼"到屏幕上pDC->BitBlt(0, 0, rect.Width(), rect.Height(), &m_memDC, 0, 0, SRCCOPY);p

25、Wnd->ReleaseDC(pDC);/繪圖按鈕void CfiveDlg:OnBnClickedOk()/ TODO: 在此添加控件通知處理程序代碼isDraw = true;/點(diǎn)擊繪制按鈕后,才繪制圖形OnSelchangeList1();OnCbnSelchangeCombo1();OnCbnSelchangeCombo2();onRadioBtnGroup1Clicked();onRadioBtnGroup2Clicked();Invalidate(); /重繪窗口/*CDialogEx:OnOK();*/取消按鈕void CfiveDlg:OnBnClickedCancel(

26、)/ TODO: 在此添加控件通知處理程序代碼isDraw = false;CDialogEx:OnCancel();/radio畫(huà)筆樣式切換選擇事件void CfiveDlg:onRadioBtnGroup1Clicked()/ TODO: 在此添加控件通知處理程序代碼UpdateData(true);/更新界面值到變量中,必須有這句話(huà),值才變化switch (m_penType)case 0:myPen.CreatePen(PS_SOLID, 3, outColor);break;case 1:myPen.CreatePen(PS_DASH, 3, outColor);break;case

27、 2:myPen.CreatePen(PS_DOT, 3, outColor);break;case 3:myPen.CreatePen(PS_DASHDOT, 3, outColor);break;default:break;/radio刷子樣式切換選擇事件void CfiveDlg:onRadioBtnGroup2Clicked()/ TODO: 在此添加控件通知處理程序代碼UpdateData(true);/更新界面值到變量中,必須有這句話(huà),值才變化switch (m_brushType)case 0:myBrush.CreateSolidBrush(inColor);break;cas

28、e 1:myBrush.CreateHatchBrush(HS_CROSS, inColor);break;case 2:myBrush.CreateHatchBrush(HS_FDIAGONAL, inColor);break;case 3:myBrush.CreateHatchBrush(HS_BDIAGONAL, inColor);break;/listBox切換選擇事件void CfiveDlg:OnSelchangeList1()/ TODO: 在此添加控件通知處理程序代碼CString strText;int nCurSel;nCurSel = m_ShapeList.GetCur

29、Sel(); / 獲取當(dāng)前選中列表項(xiàng)m_ShapeList.GetText(nCurSel, strText); / 獲取選中列表項(xiàng)的字符串m_DrawType = strText; /賦給變量/combobox1畫(huà)筆顏色切換選擇事件void CfiveDlg:OnCbnSelchangeCombo1()/ TODO: 在此添加控件通知處理程序代碼CString strText;int nCurSel;nCurSel = m_Combobox1.GetCurSel(); / 獲取當(dāng)前選中列表項(xiàng)m_Combobox1.GetLBText(nCurSel, strText); / 獲取選中列表項(xiàng)的

30、字符串m_outColor = strText;if (m_outColor = "Red")outColor = RGB(255, 0, 0);else if (m_outColor = "Blue")outColor = RGB(0, 0, 255);else if (m_outColor = "Green")outColor = RGB(0, 255, 0);elseoutColor = RGB(0, 0, 0);/combobox2刷子顏色切換選擇事件void CfiveDlg:OnCbnSelchangeCombo2()/

31、TODO: 在此添加控件通知處理程序代碼CString strText;int nCurSel;nCurSel = m_Combobox2.GetCurSel(); / 獲取當(dāng)前選中列表項(xiàng)m_Combobox2.GetLBText(nCurSel, strText); / 獲取選中列表項(xiàng)的字符串m_inColor = strText;if (m_inColor = "Red")inColor = RGB(255, 0, 0);else if (m_inColor = "Blue")inColor = RGB(0, 0, 255);else if (m_i

32、nColor = "Green")inColor = RGB(0, 255, 0);elseinColor = RGB(0, 0, 0);六、編寫(xiě)MFC單因子y=f(x) 測(cè)試數(shù)據(jù)處理程序, 要求有數(shù)據(jù)輸入、保存、讀入和繪圖功能,使用菜單和加速鍵特性,坐標(biāo)軸依據(jù)數(shù)據(jù)分布而確定。(20分)典型繪圖效果如下:注意:所有編程題要求為 1) 代碼要有注釋?zhuān)阌诶斫?,?guī)格要正確。 2) 要列出程序界面和運(yùn)行效果。3) 列表顯示所有編程資源,包括名稱(chēng),標(biāo)題,ID號(hào),資源類(lèi)別,關(guān)聯(lián)變量類(lèi)型,關(guān)聯(lián)變量名稱(chēng),消息響應(yīng)函數(shù)名稱(chēng)。 4)程序界面和運(yùn)行效果可打印,其它全部手寫(xiě),打印者扣分。資源列表

33、:資源類(lèi)名資源類(lèi)別標(biāo)題ID號(hào)關(guān)聯(lián)變量消息響應(yīng)函數(shù)變量類(lèi)型變量名稱(chēng)CTestDataDrawView子菜單翻開(kāi)txt數(shù)據(jù)ID_FILE_OPENCFileDialogdlgvoid CTestDataDrawView:OnFileOpen()CStringfilePathNameCStringfileNameCTestDataDrawView子菜單另存為txtID_FILE_SAVE_ASCFileDialogdlgvoid CTestDataDrawView:OnFileSaveAs()CStringfilePathNameCStringfileNameCTestDataDrawView子菜單

34、添加數(shù)據(jù)ID_MENUITEM32771AddTestDatadlgvoid CTestDataDrawView:OAddTestData()CTestDataDrawView子菜單去除數(shù)據(jù)ID_MENUITEM32772/void CTestDataDrawView:OnDataClear()CTestDataDrawView子菜單頁(yè)面范圍設(shè)置ID_MENUITEM32773ViewSetdlgvoid CTestDataDrawView:OnViewSet()CTestDataDrawView子菜單數(shù)據(jù)樣式設(shè)置ID_MENUITEM32774StyleSetdlgvoid CTestDat

35、aDrawView:OnStyleSet()AddTestData對(duì)話(huà)框添加測(cè)試數(shù)據(jù)IDD_DIALOG1doubleInPutX對(duì)話(huà)框“添加按鈕對(duì)應(yīng)的消息響應(yīng)函數(shù):void AddTestData:OnAdd()doubleInPutYViewSet對(duì)話(huà)框頁(yè)面范圍設(shè)置IDD_DIALOG2doublev_xmin,v_xmax對(duì)話(huà)框“確定按鈕對(duì)應(yīng)的消息響應(yīng)函數(shù):void ViewSet:OnOK()doublev_ymin,v_ymaxStyleSet對(duì)話(huà)框數(shù)據(jù)顏色設(shè)置IDD_DIALOG3COLORREFSetColor對(duì)話(huà)框“點(diǎn)顏色按鈕對(duì)應(yīng)消息響應(yīng)函數(shù)void StyleSet:OnDa

36、taColor()對(duì)話(huà)框“確定按鈕對(duì)應(yīng)的消息響應(yīng)函數(shù):void StyleSet:OnOK()COLORREFs_colorIntS_r.word程序運(yùn)行效果:圖:程序運(yùn)行界面圖:第一步 頁(yè)面范圍設(shè)置圖:第二步 添加測(cè)試數(shù)據(jù)圖:添加題目中的5個(gè)數(shù)據(jù)效果圖圖:設(shè)置點(diǎn)數(shù)據(jù)的半徑和顏色圖:將點(diǎn)數(shù)據(jù)保存為txt格式文件圖:去除數(shù)據(jù)圖:翻開(kāi)保存的txt文件源代碼:void CTestDataDrawView:OAddTestData() / TODO: Add your command handler code hereAddTestData dlg;if(IDOK = dlg.DoModal()if

37、(dlg.InPutX > pro->xMin && dlg.InPutX < pro->xMax && dlg.InPutY > pro->yMin && dlg.InPutY < pro->yMax)pro->xArray.push_back(dlg.InPutX);pro->yArray.push_back(dlg.InPutY);elseMessageBox("數(shù)值超出范圍");return;Invalidate();void CTestDataDrawVie

38、w:OnViewSet() / TODO: Add your command handler code hereViewSet dlg;if(IDOK = dlg.DoModal()pro->xMin = dlg.v_xmin;pro->xMax = dlg.v_xmax;pro->yMin = dlg.v_ymin;pro->yMax = dlg.v_ymax;Invalidate();void CTestDataDrawView:OnStyleSet() / TODO: Add your command handler code hereDataStyleSet d

39、lgs;StyleSet dlg;if(IDOK = dlg.DoModal()pro->m_Color = dlg.s_color;pro->radius = dlg.s_r;Invalidate();void CTestDataDrawView:OnDataClear() / TODO: Add your command handler code herepro->xArray.clear();pro->yArray.clear();Invalidate();void CTestDataDrawView:OnFileOpen() / TODO: Add your c

40、ommand handler code hereCFileDialog dlg(TRUE);dlg.m_ofn.lpstrDefExt="txt"dlg.m_ofn.lpstrFilter="Drawing Files(*.txt)0*.txt0" if(dlg.DoModal()!=IDOK)return;CString filePathName=dlg.GetFileName();CString fileName = filePathName.GetBuffer(filePathName.GetLength();pro->ReadFromTex

41、tFile(fileName);Invalidate();void CTestDataDrawView:OnFileSaveAs() / TODO: Add your command handler code hereCFileDialog dlg(FALSE);dlg.m_ofn.lpstrDefExt="txt"dlg.m_ofn.lpstrFilter="Drawing Files(*.txt)0*.txt0" if(dlg.DoModal()!=IDOK)return;CString filePathName=dlg.GetFileName();

42、CString fileName = filePathName.GetBuffer(filePathName.GetLength();pro->WriteToTextFile(fileName);#pragma once#include<vector>using namespace std;class CMyTestDataDrawView;/點(diǎn)坐標(biāo)為實(shí)際坐標(biāo)class projectpublic:CString m_projectName;/4int projectNameLength;BOOL m_projectDisplay;/4std:vector<double

43、> yArray;std:vector<double> xArray;int activeLayerIndex;/當(dāng)前激活圖層序號(hào)4RECT rect; / 繪圖區(qū)域大小double xMin, xMax, yMin, yMax; / 數(shù)據(jù)區(qū)域大小double xLower; / x下限double xUpper; / x上限double yLower; /y下限double yUpper; /y上限COLORREF m_Color;/color of an project CRect m_EnclosingRect; / int radius;public:project(

44、);project();void Draw(CDC *pDC);void SetRect(RECT rec); / 設(shè)置繪圖區(qū)域int GetActiveLayerIndex()return activeLayerIndex;void WriteToTextFile(CString filename);void ReadFromTextFile(CString filename);#include "stdafx.h"#include "TestDataDraw.h"#include "project.h"#include "

45、;TestDataDrawView.h"#include <fstream>project:project()m_projectName = "myproject"m_projectDisplay = TRUE;activeLayerIndex = 0;xMax = 100;xMin = 0;yMax = 100;yMin = 0;m_Color = RGB(255,0,0);/color of an project radius = 5;project:project()int num = xArray.size();if (num>0)dou

46、ble x = NULL;double y = NULL;for (int i=num-1; i>-1; i-)x = xArray.at(i);y = yArray.at(i);xArray.clear();yArray.clear();void project:SetRect(RECT rec)rect = rec;void project:Draw(CDC *pDC)CPen *newPen = new CPen(0, 1, RGB(0, 0, 0);CPen *oldPen = pDC->SelectObject(newPen);LOGFONT font;font.lfHe

47、ight = -20;font.lfEscapement = 0;font.lfItalic = 1;font.lfWeight = FW_BOLD; /加粗font.lfUnderline = 0; / 不加下劃線(xiàn)font.lfStrikeOut = 0; / 無(wú)刪除線(xiàn)font.lfCharSet = 0; / 選擇字符集pDC->SelectObject(CreateFontIndirect(&font);pDC->SetBkMode(0);int x, y;/- 繪制坐標(biāo)軸 -/font.lfHeight = -16;font.lfCharSet = 134;pDC-

48、>SelectObject(CreateFontIndirect(&font);/* y軸pDC->MoveTo(rect.left + (rect.right - rect.left)/2, rect.bottom - 50);pDC->LineTo(rect.left + (rect.right - rect.left)/2, rect.top + 50);pDC->TextOut(rect.left + (rect.right - rect.left)/2, rect.top + 30, "Y");/ 箭頭pDC->MoveTo(

49、rect.left + (rect.right - rect.left)/2, rect.top + 50);pDC->LineTo(rect.left + (rect.right - rect.left)/2 + 5 , rect.top + 60);pDC->MoveTo(rect.left + (rect.right - rect.left)/2, rect.top + 50);pDC->LineTo(rect.left + (rect.right - rect.left)/2 -5, rect.top + 60);/* x軸pDC->MoveTo( rect.l

50、eft + 60, rect.bottom - (rect.bottom - rect.top)/2);pDC->LineTo(rect.right - 60, rect.bottom - (rect.bottom - rect.top)/2);pDC->TextOut(rect.right - 50, rect.bottom - (rect.bottom - rect.top)/2 , "X");/ 箭頭pDC->MoveTo(rect.right - 60, rect.bottom - (rect.bottom - rect.top)/2);pDC-&

51、gt;LineTo(rect.right - 70, rect.bottom - (rect.bottom - rect.top)/2 + 5);pDC->MoveTo(rect.right - 60, rect.bottom - (rect.bottom - rect.top)/2);pDC->LineTo(rect.right - 70, rect.bottom - (rect.bottom - rect.top)/2 - 5);/ 標(biāo)尺int i = 0;/x軸標(biāo)尺for (x = rect.left + 60;x<rect.right - 60;x = x+20 )i

52、nt h = i%2 3 : 6;y=rect.bottom - (rect.bottom - rect.top)/2;pDC->MoveTo(x,y);y=rect.bottom - (rect.bottom - rect.top)/2 - h;pDC->LineTo(x,y);i+;int j = 0;/Y軸標(biāo)尺for (y = rect.bottom - 50;y>rect.top + 50;y = y-20)int h = j%2 3 : 6;x=rect.left + (rect.right - rect.left)/2;pDC->MoveTo(x,y);x=rect.left + (rect.right - rect.left)/2 + h;pDC->LineTo(x,y);j+;pDC->SelectObject(oldPen);delete newP

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論