时间: 2021-07-31 作者:daque
作家:徐景周载入示例源码(http://www.csdn.net/cnshare/soft/9/9199.shtm) 当你想要运用其余运用步调中的美丽图标时,该如何办呢?大概就会用到少许图标索取东西吧!那么,你领会它们是如何实行的,想不想本人发端也做一个符合本人的图标索取东西呢?底下,就让我用我往日做过的一个东西<轻轻快松抓图标>来报告你吧!它不妨索取百般文献中的图标资源,并可将其生存为图标(ico)、位图(bmp)两种方法。步调运转后界面如次:在上头的例程中,我调整出一个图标类cicons和与之相称的一个位图类cdib,个中囊括icons.h、icons.cpp、dib.h和dib.cpp四个文献。在你的工程市直接介入这四个文献后,挪用其类涵数,既可做出你本人的图标东西来。底下让咱们来看看怎样来简直用它们来实行:1、索取并表露出图标到左侧列表框中。代码实行如次://读取百般资源里面图标并表露在左侧列表框中void ciconsnapdlg::onok() { cfiledialog filedialog( true,"*.ico",null,null,"资源文献(*.ico,*.bmp,*.exe,*.dll,*.icl)|*.ico;*.bmp;*.exe;*.dll;*.icl||");if (filedialog.domodal() == idok) { szopenfilename=filedialog.getpathname(); szopenfileextname= filedialog.getfileext (); szopenfileextname.makelower (); m_list.resetcontent (); //选清空左侧图标列表框 //读取并表露icon文献 if(szopenfileextname =="ico") { lpir=picons->readiconfromicofile (szopenfilename); hicon hicon; hicon=extracticon(afxgetinstancehandle(),szopenfilename,0); if(hicon!=null) m_list.addstring (szopenfilename); cstatic* pstatic = (cstatic*) getdlgitem(idc_icons); pstatic->seticon (hicon); } else if(szopenfileextname == "bmp") //读取并表露bmp文献 { picons->iconimagefrombmpfile (szopenfilename,&lpir->iconimages[0],true); hicon hicon; hicon=picons->makeiconfromresource (&lpir->iconimages [0]); if(hicon!=null) m_list.addstring (szopenfilename); cstatic* pstatic = (cstatic*) getdlgitem(idc_icons); pstatic->seticon (hicon); } else //读取并表露exe、dll等资源文献 { hinstance hlibrary; // load the dll/exe - note: must be a 32bit exe/dll for this to work if( (hlibrary = loadlibraryex( szopenfilename, null, load_library_as_datafile )) == null ) { // failed to load - abort messagebox( szopenfilename+ "文献载入缺点,必需是win32的文献!", "缺点", mb_ok ); return; } // store the info edii.szfilename =szopenfilename; edii.hinstance = hlibrary; // fill in the listbox with the icons available if( ! enumresourcenames( edii.hinstance, rt_group_icon, (enumresnameproc )myenumprocedure, (lparam)getsafehwnd()) ) { messagebox( "陈列图标资源名时堕落!", "缺点", mb_ok ); return; } } m_list.setcursel (0); if( m_list.getcount() == 0 ) { messagebox( "此文献中没有图标资源!", "缺点", mb_ok ); //无图标资源,置生存和复制按钮为失效状况 m_copy.enablewindow (false); m_saveas.enablewindow (false); return; } //有图标资源,置生存和复制按钮为灵验状况 m_copy.enablewindow (true); m_saveas.enablewindow (true); //革新挪用onpaint来表露图标 invalidaterect(null,true);} }在onpaint()涵数中介入底下代码用来简直表露索取出的图标或位图资源。//按照左侧图标列表,运用onpaint()来革新右侧相映图标lptstr lpiconid;hicon hicon;if((lpiconid=(lptstr)m_list.getitemdata(m_list.getcursel()))!=(lptstr)lb_err ){ if(szopenfileextname=="exe"||szopenfileextname=="dll"||szopenfileextname=="icl") { hicon=picons->geticonfrominstance(edii.hinstance,lpiconid); cstatic* pstatic = (cstatic*) getdlgitem(idc_icons); pstatic->seticon (hicon); }}2、怎样将索取出的图标资源生存为ico或bmp方法。//生存图标资源为ico或bmp方法文献void ciconsnapdlg::onbuttonsaveas() { lptstr lpiconid; cfiledialog filedialog( false,"*.ico",null,null,"图标文献(*.ico)|*.ico|位图文献(*.bmp)|*.bmp||"); if (filedialog.domodal() == idok) { szsavefilename=filedialog.getpathname(); szsavefileextname= filedialog.getfileext (); szsavefileextname.makelower (); if(szopenfileextname=="exe"||szopenfileextname=="dll"||szopenfileextname=="icl") if((lpiconid=(lptstr)m_list.getitemdata (m_list.getcursel()))!= (lptstr)lb_err) lpir=picons->readiconfromexefile (szopenfilename,lpiconid); if(szsavefileextname=="bmp") { if(lpir!=null && m_list.getcount ()>0) { beginwaitcursor(); picons->iconimagetobmpfile (szsavefilename,&lpir->iconimages [0]); endwaitcursor(); } else messagebox( "没有可生存的图标资源!", "缺点", mb_ok ); } else if(szsavefileextname=="ico") { if(lpir!=null && m_list.getcount ()>0) { beginwaitcursor(); picons->writeicontoicofile (lpir,szsavefilename); endwaitcursor(); } else messagebox( "没有可生存的图标资源!", "缺点", mb_ok ); } }}之上代码的精细实行,请鄙人载后源码后,提防参看既可。接洽办法:地方:陕西省西安市处事路2号院六单位邮政编码:710082作家email:jingzhou_xu@163.net将来处事室(future studio)