MFC課程設(shè)計之調(diào)色板_第1頁
MFC課程設(shè)計之調(diào)色板_第2頁
MFC課程設(shè)計之調(diào)色板_第3頁
MFC課程設(shè)計之調(diào)色板_第4頁
MFC課程設(shè)計之調(diào)色板_第5頁
已閱讀5頁,還剩12頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、mfc課程設(shè)計說明書設(shè)計題目:綜合調(diào)色板 所屬系部: 計算機工程系 專 業(yè): 軟件工程 學(xué) 號: 102056238 姓 名: 設(shè)計日期:2011-11-28 1. 設(shè)計描述通過綜合這學(xué)期的知識,最終做了個調(diào)色板。首先,此調(diào)色板可以通過控制紅,綠,藍(lán)三個滑塊控件來使列表框的顏色隨之變化;也可以通過點擊顏色板來自己選取想要顯示的顏色。其次,當(dāng)關(guān)閉調(diào)色板時有對話框提示,既可以最小化到托盤,也可以直接退出程序,同時可以通過操作注冊表來操作。最后,此調(diào)色板應(yīng)用了皮膚設(shè)置,使之看起來更美化!2設(shè)計分析主要函數(shù)及聲明:void writeregistry();void readregistry();voi

2、d 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;/列表框區(qū)域int exitinstance()protected成員變量:hinstance hinstance;hicon m_hicon;int nradio,ncheck;c

3、string str;其他新添加的函數(shù)消息: void onhscroll(uint nsbcode, uint npos, cscrollbar* pscrollbar);void onabout();void onexit();void onopen();void onclose();void ondestroy();其中,有一個函數(shù)比較特殊,需手動添加,在colordlg.h中添加void ontraynotify(wparam wparam, lparam lparam);在colordlg.cpp中afx_msg_map(ccolordlg)與 afx_msg_map之間添加on_m

4、essage(wm_icon_notify, ontraynotify),最后在colordlg.cpp中手動添加函數(shù):void ccolordlg:ontraynotify(wparam wparam, lparam lparam)在資源視圖中需要做的工作有:引入兩個對話框,分別添加相應(yīng)的控件,并定義其成員變量。紅綠藍(lán)控件id分別命名為idc_scrollbar_red,idc_slider_green,idc_slider_blue,編輯框命名為idc_list_box,清除注冊信息命名為idc_registry。對話框成員變量: cscrollbarm_scrollred;cslider

5、ctrlm_slidergreen;csliderctrlm_sliderblue;intm_nredvalue;intm_nblue;intm_ngreen;在資源視圖中引入一個菜單資源和幾個icon資源 3.運行界面啟動界面藍(lán)色調(diào)色對話框退出提示托盤圖標(biāo)菜單 托盤圖標(biāo)變化關(guān)于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

6、_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

7、* 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)/a

8、fx_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 doe

9、s 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_con

10、trol(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_

11、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

12、_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_

13、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

14、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);/獲得其

15、區(qū)域 setwindowtext(rgb演示cc版權(quán)所有);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()cpain

16、tdc 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 = (r

17、ect.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

18、 code here and/or call defaultint nid=pscrollbar-getdlgctrlid();/獲取對話框的idif(nid=idc_scrollbar_red)/若是滾動條產(chǎn)生水平滾動消息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_thumbtrac

19、k: 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

20、=new cbitmap;m_pcachebitmap-createcompatiblebitmap(pdc,listboxrect.width(),listboxrect.height();cbitmap *poldbitmap=cachedc.selectobject(m_pcachebitmap);/將cachedc和m_pcachebitmap聯(lián)系起來cachedc.fillrect(&listboxrect,&brush);/填充區(qū)域pdc-bitblt(listboxrect.left,listboxrect.top,listboxrect.width(),listboxrect.

21、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 hereupdated

22、ata(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

23、; dlg.domodal();void ccolordlg:onbuttoncolor() / todo: add your control notification handler code herebyte r,g,b;/接收顏色分量int m_nredvalue,m_nblue,m_ngreen;/標(biāo)記滾動條位置colorref color;/接收顏色ccolordialog dlg;/顏色對話框if(dlg.domodal()=idok)color=dlg.getcolor();/獲得顏色,賦給cr=getrvalue(color);/獲得rg=getgvalue(color);/獲

24、得gb=getbvalue(color);/獲得bm_nredvalue=r;m_nblue=b;m_ngreen=g;/傳給整形變量,以便設(shè)定滾動條位置m_scrollred.setscrollpos(m_nredvalue);m_slidergreen.setpos(m_ngreen);m_sliderblue.setpos(m_nblue);/設(shè)定滾動條位置invalidate();bool ccolordlg:addtray(hwnd hwnd, lpstr lpsztip)notifyicondata tnid;tnid.cbsize=sizeof(notifyicondata);t

25、nid.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.hwn

26、d=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);待添加的隱藏文字內(nèi)容3void ccolordlg:ontrayn

27、otify(wparam wparam, lparam lparam)if(wm_rbuttondown=lparam)cmenu menu;menu.loadmenu(idr_menu1);cpoint point;getcursorpos(&point);/得到鼠標(biāo)位置cmenu *popup=menu.getsubmenu(0);popup-trackpopupmenu(tpm_leftalign|tpm_rightbutton, point.x, point.y, this);return;if(wm_lbuttondown=lparam)showwindow(sw_shownorma

28、l); setforegroundwindow();return;void ccolordlg:onabout() / todo: add your command handler code heremessagebox(開發(fā)者:程程n2011年11月,關(guān)于,mb_iconexclamation |mb_ok);void ccolordlg:onexit() / todo: add your command handler code here postquitmessage(0);void ccolordlg:onopen() / todo: add your command handler

29、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);elseadd

30、tray(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=

31、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;/標(biāo)志為1 else ncheck=0;/標(biāo)志為0 if(0=nradio)/選擇直接退出 postquitmessage(0); else/選擇返回托盤 addtray(m_hwnd,rgb演示);showwindow(sw_h

32、ide);/隱藏主窗口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,(

溫馨提示

  • 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)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論