




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、用VC6.0建一個對話框窗體,命名為Chaos在ChaosDlg.cpp文件下:BOOL CChaosDlg:OnInitDialog()CDialog:OnInitDialog();MoveWindow(0,0,1024,768,true);/ Add "About." menu item to system menu./ IDM_ABOUTBOX must be in the system command range.ASSERT(IDM_ABOUTBOX & 0xFFF0) = IDM_ABOUTBOX);ASSERT(IDM_ABOUTBOX < 0x
2、F000);CMenu* pSysMenu = GetSystemMenu(FALSE);if (pSysMenu != NULL)CString strAboutMenu;strAboutMenu.LoadString(IDS_ABOUTBOX);if (!strAboutMenu.IsEmpty()pSysMenu->AppendMenu(MF_SEPARATOR);pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);/ Set the icon for this dialog. The framework d
3、oes this automatically/ when the application's main window is not a dialogSetIcon(m_hIcon, TRUE);/ Set big iconSetIcon(m_hIcon, FALSE);/ Set small icon/角度的分界線tan_1=tan(60*pi/180.0); tan_2=tan(120*pi/180.0); tan_3=tan(240*pi/180.0); tan_4=tan(300*pi/180.0);return TRUE; / return TRUE unless you se
4、t the focus to a controlvoid CChaosDlg:OnSysCommand(UINT nID, LPARAM lParam)if (nID & 0xFFF0) = IDM_ABOUTBOX)CAboutDlg dlgAbout;dlgAbout.DoModal();elseCDialog:OnSysCommand(nID, lParam);/ If you add a minimize button to your dialog, you will need the code below/ to draw the icon. For MFC applicat
5、ions using the document/view model,/ this is automatically done for you by the framework.void CChaosDlg:OnPaint() if (IsIconic()CPaintDC dc(this); / device context for paintingSendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);/ Center icon in client rectangleint cxIcon = GetSystemMetrics(S
6、M_CXICON);int cyIcon = GetSystemMetrics(SM_CYICON);CRect rect;GetClientRect(&rect);int x = (rect.Width() - cxIcon + 1) / 2;int y = (rect.Height() - cyIcon + 1) / 2;/ Draw the icondc.DrawIcon(x, y, m_hIcon);elseCDialog:OnPaint();/*將作圖區(qū)域底色設(shè)為白色*/CRect rec;rec.left=0;rec.top=0;rec.right=767;rec.bott
7、om=767;CDC *dc;dc=this->GetDC();CBrush hbr;hbr.CreateSolidBrush(RGB(255,255,255);dc->FillRect(&rec,&hbr);/ The system calls this to obtain the cursor to display while the user drags/ the minimized window.HCURSOR CChaosDlg:OnQueryDragIcon()return (HCURSOR) m_hIcon;void CChaosDlg:OnOK()
8、/ TODO: Add extra validation hereUpdateData(TRUE);CDC *dc;dc=this->GetDC();double x0,y0,x1,y1,dx,dy;int col,row,color;/繪圖范圍是-2,2/dx=dy=4.0/767.0;for(col=0;col<=767;col+)for(row=0;row<=767;row+) x0=(double)col*dx-2;y0=(double)row*dy-2;color=judge_color_point(x0,y0);dc->SetPixel(col,767-ro
9、w,colorlistcolor);dc->MoveTo(20-1,20-1);dc->LineTo(747+1,20-1);dc->LineTo(747+1,747+1);dc->LineTo(20-1,747+1);dc->LineTo(20-1,20-1);/畫出圖形/for(col=20;col<=747;col+)for(row=20;row<=747;row+)x0=(double)(col*dx-2);/-1.0;y0=(double)(row*dy-2);/-1.0;x1=itearate_fre(x0,y0,this->m_ed
10、it1);y1=itearate_fim(x0,y0,this->m_edit1);color=judge_color_point(x1,y1);dc->SetPixel(col,767-row,colorlistcolor);x0=x1;y0=y1;UpdateData(FALSE);int CChaosDlg:judge_color_point(double x, double y)int z1;double division;if(x>0&&y>0)division=y/x;if(division<=tan_1)z1=1;elsez1=2;i
11、f(x<0&&y>=0)division=y/x;if(division<=tan_2)z1=2;elsez1=3;if(x<0&&y<0)division=y/x;if(division<=tan_3)z1=4;elsez1=5;if(x>0&&y<=0)division=y/x; if(division<=tan_4)z1=5;elsez1=0;/x坐標軸的判斷if(x=0&&y>0)z1=2;if(x=0&&y<=0)z1=5;return(z
12、1);double CChaosDlg:fre(double x, double y)double z;z=2.5*x*(1-x*x-y*y)+0.9*(x*x-y*y);return(z);double CChaosDlg:fim(double x, double y)double z;z=-1.8*x*y+2.5*y*(1-x*x-y*y);return(z);double CChaosDlg:itearate_fre(double x, double y, int n)int i;double z;double xnew,ynew;for(i=0;i<n;i+) xnew=fre(
13、x,y);ynew=fim(x,y);x=xnew;y=ynew;z=x;return(z);double CChaosDlg:itearate_fim(double x, double y, int n)int i;double z;double xnew,ynew;for(i=0;i<n;i+) xnew=fre(x,y);ynew=fim(x,y);x=xnew;y=ynew;z=y;return(z);/存圖void CChaosDlg:OnSave() int x1,x2,y1,y2;int i,j,flag;BYTE r,g,b;COLORREF clr;CClientDC
14、dc(this);flag = 0;for(i = 0;i < 768;i+)for(j = 0;j < 768;j+)clr = dc.GetPixel(i,j);r = GetRValue(clr);g = GetGValue(clr);b = GetBValue(clr);if(r != 255 | g != 255 | b != 255)flag = 1;x1 = i;break;if(flag)break;flag = 0;for(i = 767;i >=0;i-)for(j = 767;j >=0;j-)clr = dc.GetPixel(i, j);r =
15、 GetRValue(clr);g = GetGValue(clr);b = GetBValue(clr);if(r != 255 | g != 255 | b != 255)flag = 1;x2 = i;break;if(flag)break;flag = 0;for(j = 0;j < 768;j+)for(i = x1;i <= x2;i+)clr = dc.GetPixel(i, j);r = GetRValue(clr);g = GetGValue(clr);b = GetBValue(clr);if(r != 255 | g != 255 | b != 255)fla
16、g = 1;y1 = j;break;if(flag)break;flag = 0;for(j = 767;j >=0;j-)for(i = x2;i >=x1;i-)clr = dc.GetPixel(i, j);r = GetRValue(clr);g = GetGValue(clr);b = GetBValue(clr);if(r != 255 | g != 255 | b != 255)flag = 1;y2 = j;break;if(flag)break;/保存圖片CRectrect;rect.SetRect(x1,y1,x2,y2);/CClientDCdc(this)
17、; CDC memDC;/CRectrect;memDC.CreateCompatibleDC(&dc);CBitmap bm;int Width = 768;int Height = 768;bm.CreateCompatibleBitmap(&dc, Width, Height);CBitmap* pOld = memDC.SelectObject(&bm);memDC.BitBlt(0, 0, Width, Height, &dc, 0, 0, SRCCOPY);memDC.SelectObject(pOld);BITMAP btm;bm.GetBitma
18、p(&btm);DWORD size = btm.bmWidthBytes * btm.bmHeight;LPSTR lpData = (LPSTR)GlobalAllocPtr(GPTR, size);BITMAPFILEHEADER bfh;/BITMAPINFOHEADER bih;bih.biBitCount = btm.bmBitsPixel;bih.biClrImportant = 0;bih.biClrUsed = 0;bih.biCompression = 0;bih.biHeight = btm.bmHeight;bih.biPlanes = 1;bih.biSize
19、 = sizeof(BITMAPINFOHEADER);bih.biSizeImage = size;bih.biWidth = btm.bmWidth;bih.biXPelsPerMeter = 0;bih.biYPelsPerMeter = 0;GetDIBits(dc,bm,0,bih.biHeight,lpData,(BITMAPINFO*)&bih,DIB_RGB_COLORS);/bm.GetBitmapBits(size,lpData);/此函數(shù)在處理5-5-5模式的16位色下會出現(xiàn)顏色混亂bfh.bfReserved1 = bfh.bfReserved2 = 0;bfh
20、.bfType = (WORD)('M'<< 8)|'B');bfh.bfSize = 54 + size;bfh.bfOffBits = 54;CFileDialog dlg(false,_T("BMP"),_T("*.bmp"),OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,_T("*.bmp|*.bmp|*.*|*.*|");if (dlg.DoModal()!=IDOK)return;CFile bf;CString ss=dlg.GetPathNam
21、e();if(bf.Open(ss, CFile:modeCreate | CFile:modeWrite)bf.WriteHuge(&bfh, sizeof(BITMAPFILEHEADER);bf.WriteHuge(&bih, sizeof(BITMAPINFOHEADER);bf.WriteHuge(lpData, size);bf.Close();AfxMessageBox("保存成功");GlobalFreePtr(lpData);void CChaosDlg:OnButton1() / TODO: Add your control notification handler code hereCRect rec;rec.left=0;rec.top=0;rec.right=768;rec.bottom=767;CDC *dc;dc=this->GetDC();CBrush hbr;hbr.CreateSolidBrush(RGB(255,255,255);dc->FillRect(&rec,&hbr);/double x0=-0.5,y0=0.5,x1,y1,dx,dy;dx=dy=4.0/767
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 工業(yè)互聯(lián)網(wǎng)時代2025年聯(lián)邦學(xué)習(xí)隱私保護案例分析報告
- 潮玩消費市場2025年趨勢報告:價值評估與文化影響力研究
- 心中的情感旋律抒情作文12篇
- 1鄉(xiāng)村旅游民宿集群建設(shè)項目2025年人力資源配置研究報告001
- 2025年網(wǎng)絡(luò)直播行業(yè)規(guī)范化運營中的商業(yè)模式創(chuàng)新路徑優(yōu)化報告
- 房子買賣合同
- 室內(nèi)質(zhì)控月總結(jié)報告表
- 6.2人的數(shù)據(jù)分析
- 2025-2030中國薄型抽油煙機行業(yè)消費動態(tài)與競爭趨勢預(yù)測報告
- 丙綸纖維的導(dǎo)電性能研究考核試卷
- 國際教育機構(gòu)外教派遣服務(wù)協(xié)議
- 【高二下期末】廣東省東莞市2021-2022學(xué)年高二下學(xué)期期末教學(xué)質(zhì)量監(jiān)測英語試題(解析版)
- 2025年普通高等學(xué)校招生全國統(tǒng)一考試數(shù)學(xué)試題(全國二卷)(有解析)
- 呼吸病區(qū)進修管理制度
- GB/T 33490-2025展覽展示工程服務(wù)基本要求
- 中國狼瘡腎炎診治和管理指南(2025版)解讀
- 安徽省合肥四十五中學(xué)2025屆數(shù)學(xué)七下期末達標檢測試題含解析
- 足浴轉(zhuǎn)讓合同協(xié)議書
- 2022-2023學(xué)年山東省濟寧市兗州區(qū)人教版四年級下冊期末考試數(shù)學(xué)試卷(原卷版)
- 變電站二次系統(tǒng)介紹(大唐)
- 新課程標準視角下項目式學(xué)習(xí)在中小學(xué)的有效實施途徑
評論
0/150
提交評論