版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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();/*将作图区域底色设为白色*/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);/此函数在处理5-5-5模式的16位色下会出现颜色混乱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. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 双向转诊中的时间成本控制策略
- 2026年一级建造师之一建铁路工程实务考试题库300道附参考答案(满分必刷)
- 2026年一级建造师之一建铁路工程实务考试题库300道附完整答案(有一套)
- 2026年一级注册建筑师之建筑物理与建筑设备考试题库300道及完整答案(名校卷)
- 卵巢癌免疫治疗的个体化方案优化
- 2026年度中国建设银行吉林省分行校园招聘备考题库(570人)附答案
- 2025河北邯郸市教育局选调学科教研员9人备考题库附答案
- 2026年云南体育运动职业技术学院单招职业技能考试题库附答案
- 2025湖南岳阳临湘市纪委监委选调5人备考题库附答案
- 2025湖南岳阳临湘市市场监督管理局下属事业单位从市场建设服务中心选调8人备考题库附答案
- 小学生防诈骗课件
- 金太阳山西省三晋联盟山西名校2025-2026学年高一上学期11月期中联合考试语文(26-126A)(含答案)
- 软件工程专业 毕业论文
- 中国消费者:中国仍在消费不足吗?神话与真相(英文)
- 2026年1月福建省普通高中学业水平合格性考试政治仿真模拟卷01(春季高考适用)(原卷版及全解全析)
- 注意缺陷多动障碍(ADHD)基层医疗机构规范化诊疗方案
- (新版!)2024年军队文职统一考试《公共科目》真题及答案
- GB/T 46571-2025日期和时间词汇
- 品质部新员工培训
- 抖音账号内容运营方案
- 2025食品生物技术行业市场研发动态及产业化前景与投资机会研究报告
评论
0/150
提交评论