MFC课程设计之调色板.doc_第1页
MFC课程设计之调色板.doc_第2页
MFC课程设计之调色板.doc_第3页
MFC课程设计之调色板.doc_第4页
MFC课程设计之调色板.doc_第5页
免费预览已结束,剩余12页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

mfc课程设计说明书设计题目:综合调色板 所属系部: 计算机工程系 专 业: 软件工程 学 号: 102056238 姓 名: 设计日期:2011-11-28 1. 设计描述通过综合这学期的知识,最终做了个调色板。首先,此调色板可以通过控制红,绿,蓝三个滑块控件来使列表框的颜色随之变化;也可以通过点击颜色板来自己选取想要显示的颜色。其次,当关闭调色板时有对话框提示,既可以最小化到托盘,也可以直接退出程序,同时可以通过操作注册表来操作。最后,此调色板应用了皮肤设置,使之看起来更美化!2设计分析主要函数及声明:void writeregistry();void readregistry();void inquiry();bool modifytray(hwnd hwnd,uint uid);bool removetray(hwnd hwnd);bool addtray(hwnd hwnd,lpstr lpsztip);void ontimer(uint nidevent);void onregistry();ccolordlg(cwnd* pparent = null);crect listboxrect;/列表框区域int exitinstance()protected成员变量:hinstance hinstance;hicon m_hicon;int nradio,ncheck;cstring str;其他新添加的函数消息: void onhscroll(uint nsbcode, uint npos, cscrollbar* pscrollbar);void onabout();void onexit();void onopen();void onclose();void ondestroy();其中,有一个函数比较特殊,需手动添加,在colordlg.h中添加void ontraynotify(wparam wparam, lparam lparam);在colordlg.cpp中afx_msg_map(ccolordlg)与 afx_msg_map之间添加on_message(wm_icon_notify, ontraynotify),最后在colordlg.cpp中手动添加函数:void ccolordlg:ontraynotify(wparam wparam, lparam lparam)在资源视图中需要做的工作有:引入两个对话框,分别添加相应的控件,并定义其成员变量。红绿蓝控件id分别命名为idc_scrollbar_red,idc_slider_green,idc_slider_blue,编辑框命名为idc_list_box,清除注册信息命名为idc_registry。对话框成员变量: cscrollbarm_scrollred;csliderctrlm_slidergreen;csliderctrlm_sliderblue;intm_nredvalue;intm_nblue;intm_ngreen;在资源视图中引入一个菜单资源和几个icon资源 3.运行界面启动界面蓝色调色对话框退出提示托盘图标菜单 托盘图标变化关于4.源代码/ colordlg.cpp : implementation file/#include stdafx.h#include color.h#include colordlg.h#ifdef _debug#define new debug_new#undef this_filestatic char this_file = _file_;#endif/ caboutdlg dialog used for app aboutclass caboutdlg : public cdialogpublic:caboutdlg();/ dialog data/afx_data(caboutdlg)enum idd = idd_aboutbox ;/afx_data/ classwizard generated virtual function overrides/afx_virtual(caboutdlg)protected:virtual void dodataexchange(cdataexchange* pdx); / ddx/ddv support/afx_virtual/ implementationprotected:/afx_msg(caboutdlg)/afx_msgdeclare_message_map();caboutdlg:caboutdlg() : cdialog(caboutdlg:idd)/afx_data_init(caboutdlg)/afx_data_initvoid caboutdlg:dodataexchange(cdataexchange* pdx)cdialog:dodataexchange(pdx);/afx_data_map(caboutdlg)/afx_data_mapbegin_message_map(caboutdlg, cdialog)/afx_msg_map(caboutdlg)/afx_msg_mapend_message_map()/ ccolordlg dialog ccolordlg:ccolordlg(cwnd* pparent /*=null*/): cdialog(ccolordlg:idd, pparent)/afx_data_init(ccolordlg)m_nredvalue = 0;m_nblue = 0;m_ngreen = 0;/afx_data_init/ note that loadicon does not require a subsequent destroyicon in win32m_hicon = afxgetapp()-loadicon(idr_mainframe);void ccolordlg:dodataexchange(cdataexchange* pdx)cdialog:dodataexchange(pdx);/afx_data_map(ccolordlg)ddx_control(pdx, idc_scrollbar_red, m_scrollred);ddx_control(pdx, idc_slider_green, m_slidergreen);ddx_control(pdx, idc_slider_blue, m_sliderblue);ddx_scroll(pdx, idc_scrollbar_red, m_nredvalue);ddx_slider(pdx, idc_slider_blue, m_nblue);ddx_slider(pdx, idc_slider_green, m_ngreen);/afx_data_mapbegin_message_map(ccolordlg, cdialog)/afx_msg_map(ccolordlg)on_wm_syscommand()on_wm_paint()on_wm_erasebkgnd()on_wm_ctlcolor()on_bn_clicked(idd_aboutbox, onaboutbox)on_wm_hscroll()on_bn_clicked(idc_button_color, onbuttoncolor)on_command(id_about, onabout)on_command(id_exit, onexit)on_command(id_open, onopen)on_wm_close()on_wm_timer()on_wm_destroy()on_message(wm_icon_notify, ontraynotify)/by meon_bn_clicked(idc_registry, onregistry)/afx_msg_mapend_message_map()/ ccolordlg message handlersbool ccolordlg:oninitdialog()cdialog:oninitdialog();/ 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 appendmenu(mf_separator);psysmenu-appendmenu(mf_string, idm_aboutbox, straboutmenu);/ set the icon for this dialog. the framework does this automatically/ when the applications main window is not a dialogseticon(m_hicon, true);/ set big iconseticon(m_hicon, false);/ set small icon/ todo: add extra initialization herem_scrollred.setscrollrange(0,255);m_sliderblue.setrange(0,255);m_slidergreen.setrange(0,255);updatedata(false);m_scrollred.setscrollpos(m_nredvalue);m_sliderblue.setpos(m_nblue);m_slidergreen.setpos(m_ngreen);cwnd *pwnd=getdlgitem(idc_list_box);/选定列表框if(pwnd)pwnd-getclientrect(&listboxrect);/获得其区域 setwindowtext(rgb演示cc版权所有);return true; / return true unless you set the f ocus to a controlvoid ccolordlg:onsyscommand(uint nid, lparam lparam)if (nid & 0xfff0) = idm_aboutbox)caboutdlg dlgabout;dlgabout.domodal();elsecdialog:onsyscommand(nid, lparam);void ccolordlg:onpaint() if (isiconic()cpaintdc dc(this); / device context for paintingsendmessage(wm_iconerasebkgnd, (wparam) dc.getsafehdc(), 0);/ center icon in client rectangleint cxicon = getsystemmetrics(sm_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();/ the system calls this to obtain the cursor to display while the user drags/ the minimized window.void ccolordlg:onhscroll(uint nsbcode, uint npos, cscrollbar* pscrollbar) / todo: add your message handler code here and/or call defaultint nid=pscrollbar-getdlgctrlid();/获取对话框的idif(nid=idc_scrollbar_red)/若是滚动条产生水平滚动消息switch(nsbcode)case sb_lineleft: m_nredvalue-;break;case sb_lineright: m_nredvalue+;break;case sb_pageleft: m_nredvalue-=10;break;case sb_pageright: m_nredvalue+=10;break;case sb_thumbtrack: m_nredvalue=npos;break;if(m_nredvalue255)m_nredvalue=255;m_scrollred.setscrollpos(m_nredvalue);cwnd * pwnd=getdlgitem(idc_list_box);/获得列表对象cdc *pdc=pwnd-getdc();/获得列表框dccdc cachedc;cbrush brush(rgb(m_nredvalue,m_nblue,m_ngreen);cachedc.createcompatibledc(pdc);if(m_pcachebitmap=null)m_pcachebitmap=new cbitmap;m_pcachebitmap-createcompatiblebitmap(pdc,listboxrect.width(),listboxrect.height();cbitmap *poldbitmap=cachedc.selectobject(m_pcachebitmap);/将cachedc和m_pcachebitmap联系起来cachedc.fillrect(&listboxrect,&brush);/填充区域pdc-bitblt(listboxrect.left,listboxrect.top,listboxrect.width(),listboxrect.height(),&cachedc,0,0,srccopy);cachedc.selectobject(poldbitmap);cachedc.deletedc();cdialog:onhscroll(nsbcode, npos, pscrollbar);hbrush ccolordlg:onctlcolor(cdc* pdc, cwnd* pwnd, uint nctlcolor) hbrush hbr = cdialog:onctlcolor(pdc, pwnd, nctlcolor); / todo: change any attributes of the dc hereupdatedata(true);colorref color=rgb(m_nredvalue,m_ngreen,m_nblue);if (nctlcolor=ctlcolor_listbox) m_brush.detach();hbrush m_brush=createsolidbrush(color);pdc-setbkcolor(color);return(hbrush)m_brush; return hbr;void ccolordlg:onaboutbox() / todo: add your control notification handler code here caboutdlg dlg; dlg.domodal();void ccolordlg:onbuttoncolor() / todo: add your control notification handler code herebyte r,g,b;/接收颜色分量int m_nredvalue,m_nblue,m_ngreen;/标记滚动条位置colorref color;/接收颜色ccolordialog dlg;/颜色对话框if(dlg.domodal()=idok)color=dlg.getcolor();/获得颜色,赋给cr=getrvalue(color);/获得rg=getgvalue(color);/获得gb=getbvalue(color);/获得bm_nredvalue=r;m_nblue=b;m_ngreen=g;/传给整形变量,以便设定滚动条位置m_scrollred.setscrollpos(m_nredvalue);m_slidergreen.setpos(m_ngreen);m_sliderblue.setpos(m_nblue);/设定滚动条位置invalidate();bool ccolordlg:addtray(hwnd hwnd, lpstr lpsztip)notifyicondata tnid;tnid.cbsize=sizeof(notifyicondata);tnid.hwnd=hwnd;tnid.uflags=nif_message|nif_icon|nif_tip;tnid.ucallbackmessage=wm_icon_notify;tnid.hicon=afxgetapp()-loadicon(idi_icon1);strcpy(tnid.sztip,lpsztip);return shell_notifyicon(nim_add,&tnid);bool ccolordlg:removetray(hwnd hwnd)notifyicondata tnid;tnid.cbsize=sizeof(notifyicondata);tnid.hwnd=hwnd;return shell_notifyicon(nim_delete,&tnid);bool ccolordlg:modifytray(hwnd hwnd, uint uid)notifyicondata tnid;tnid.cbsize=sizeof(notifyicondata);tnid.hwnd=hwnd;tnid.uflags=nif_icon; tnid.hicon=afxgetapp()-loadicon(uid); return shell_notifyicon(nim_modify,&tnid);void ccolordlg:ontraynotify(wparam wparam, lparam lparam)if(wm_rbuttondown=lparam)cmenu menu;menu.loadmenu(idr_menu1);cpoint point;getcursorpos(&point);/得到鼠标位置cmenu *popup=menu.getsubmenu(0);popup-trackpopupmenu(tpm_leftalign|tpm_rightbutton, point.x, point.y, this);return;if(wm_lbuttondown=lparam)showwindow(sw_shownormal); setforegroundwindow();return;void ccolordlg:onabout() / todo: add your command handler code heremessagebox(开发者:程程n2011年11月,关于,mb_iconexclamation |mb_ok);void ccolordlg:onexit() / todo: add your command handler code here postquitmessage(0);void ccolordlg:onopen() / todo: add your command handler code here showwindow(sw_shownormal); setforegroundwindow();void ccolordlg:onclose() / todo: add your message handler code here and/or call defaulthkey hkey;if(error_success=regopenkeyex(hkey_local_machine,softwaretray,0,key_read,&hkey)readregistry();if(1=ncheck)if(0=nradio)postquitmessage(0);elseaddtray(m_hwnd,rgb演示);showwindow(sw_hide);settimer(1,500,null);elseinquiry();elseinquiry();regclosekey(hkey);/cdialog:onclose();void ccolordlg:ontimer(uint nidevent) / todo: add your message handler code here and/or call defaultstatic uint nids=idi_icon1,idi_icon2,idi_icon3,idi_icon4;static int nindex=1;modifytray(m_hwnd,nidsnindex);nindex=+nindex%4;cdialog:ontimer(nidevent);void ccolordlg:inquiry()cinquiry inq; inq.domodal();/打开询问对话框nradio=inq.m_n; if(inq.m_chk)/是否选择不再提示选框 ncheck=1;/标志为1 else ncheck=0;/标志为0 if(0=nradio)/选择直接退出 postquitmessage(0); else/选择返回托盘 addtray(m_hwnd,rgb演示);showwindow(sw_hide);/隐藏主窗口settimer(1,500,null); writeregistry();void ccolordlg:ondestroy() cdialog:ondestroy();/ todo: add your message handler code herekilltimer(1);removetray(m_hwnd);void ccolordlg:readregistry()hkey hkey;regopenkeyex(hkey_local_machine,softwaretray,0,key_read,&hkey); dword dwvalue;/变量的地址 regqueryvalueex(hkey,ncheck,0,null,(lpbyte)&ncheck,&dwvalue);regq

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论