下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、vc+信息安全编程(4)创建windows服务microsoft windows 服务(即,以前的 nt 服务)使您能够创建在它们自己的 windows 会话中可长时光运行的可执行应用程序。这些服务可以在计算机启动时自动启动,可以暂停和重新启动而且不显示任何用户界面。这使服务十分适合在服务器上用法,或任何时候,为了不影响在同一台计算机上工作的其他用户,需要长时光运行功能时用法。还可以在不同于登录取户的特定用户帐户或默认计算机帐户的平安上下文中运行服务。请见代码注释分析windows服务ilude stdafx.h include myservice.h include myservicedlg
2、.h include winsvc.h ifdef _debug define new debug_new undef this_file ic char this_file = _file_; endif / / caboutdlg dialog us for app about class caboutdlg : public cdialog public: caboutdlg(); / dialog data /afx_data(caboutdlg) enum idd = idd_aboutbox ; /afx_data / classwizard generated virtual f
3、unction overres /afx_virtual(caboutdlg) protected: virtual void dodataexchange(cdataexchange* pdx); / ddx/ddv pport /afx_virtual / implementation protected: /afx_msg(caboutdlg) /afx_msg declare_message_map() caboutdlg:caboutdlg() : cdialog(caboutdlg:idd) /afx_data_init(caboutdlg) /afx_data_init void
4、 caboutdlg:dodataexchange(cdataexchange* pdx) cdialog:dodataexchange(pdx); /afx_data_map(caboutdlg) /afx_data_map begin_message_map(caboutdlg, cdialog) /afx_msg_map(caboutdlg) / no message handlers /afx_msg_map end_message_map() / / cmyservicedlg dialog cmyservicedlg:cmyservicedlg(cwnd* pparent /*=n
5、ull*/) : cdialog(cmyservicedlg:idd, pparent) /afx_data_init(cmyservicedlg) / note: the classwizard will a member initialization here /afx_data_init / note that loadicon does not require a subsequent desoyicon in win32 m_hicon = afxgetapp()- loadicon(idr_mainframe); void cmyservicedlg:dodataexchange(
6、cdataexchange* pdx) cdialog:dodataexchange(pdx); /afx_data_map(cmyservicedlg) / note: the classwizard will add ddx and ddv cal here /afx_data_map begin_message_map(cmyservicedlg, cdialog) /afx_msg_map(cmyservicedlg) on_wm_syscommand() on_wm_paint() on_wm_querydragicon() on_bn_clicked(idc_bservice, o
7、nbservice) on_bn_clicked(idc_bnotroot, onbnotroot) on_bn_clicked(idc_bdelser, onbdelser) /afx_msg_map end_message_map() / / cmyservicedlg message handlers bool cmyservicedlg:oninitdialog() cdialog:oninitdialog(); / add about. menu item to system menu. / idm_aboutbox must be in the system command ran
8、ge. assert(idm_aboutbox 0xfff0) = idm_aboutbox); assert(idm_aboutbox 0xf000); 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
9、_aboutbox, straboutmenu); / set the icon for this dialog. the framework does this automatically / when the appliion's main window is not a dialog seticon(m_hicon, true); / set big icon seticon(m_hicon, false); / set small icon / todo: add tra initialization here schscmanager=openscmanager(null,n
10、ull,generic_write); return true; / return true un you the focus to a control void cmyservicedlg:onsyscommand(uint nid, lparam lparam) if (nid 0xfff0) = idm_aboutbox) caboutdlg dlgabout; dlgabout.domodal(); else cdialog:onsyscommand(nid, lparam); / if you add a minimize button to your dialog, you wil
11、l need the code below / to draw the icon. for mfc applications using the document/view model, / this is automatically done for you by the framework. void cmyservicedlg:onpaint() if (isiconic() cpaintdc dc(this); / device context for painting sendmessage(wm_iconerasebkgnd, (wparam) dc.getsafehdc(), 0
12、); / center icon in client rectangle int 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 icon dc.drawicon(x, y, m_hicon); else cdialog:onpai
13、nt(); / the system calls this to obtain the cursor to display while the user drags / the minimized window. hcursor cmyservicedlg:onquerydragicon() return (hcursor) m_hicon; void cmyservicedlg:onbservice() tchar szpath512; /cstring aa; /aa.foat( %s ,szpath); /cstring *bb=aa; :getmolefilename(null,szp
14、ath,512); if(schscmanager) :afxmessagebox( open servicemanager succeed! schservice=:createservice(schscmanager, myservice , myservice ,service_all_access,service_win32_own_process,service_auto_start,service_error_normal,szpath,null,null,null,null,null); if(schservice) :afxmessagebox( create service
15、succeed! /* service_table_entry distable = myservice ,(lpservice_main_function)myservicemain, /服务程序的名称和入口点; null ,null /service_table_entry结构必需以 null 结束; startservicectrldispatcher(dispatchtable); :queryservicestatus(schservice,ssstatus); servicestatushandle=registerservicectrlhandler( ntkrnl ,cmdco
16、ntrol);*/ :closeservicehandle(schservice); else :afxmessagebox( create service failed! :closeservicehandle(schscmanager); else afxmessagebox( open servicemanager failed! void cmyservicedlg:onbnotroot() :changeserviceconfig(schservice,service_no_change,service_disabled,service_demand_start,null,null,null,null,null,null, my service void cmyservicedlg:onbdelser() schservice=:openservice(schscmanager, myservice ,delete); if(schservice) afxmessagebox( delete service succeed! :deleteservice(schservice); :closeservicehandle(schservice); else afxmess
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 电子秤渠道拓展合同协议
- 内容创作2026年文案代笔协议
- 2026年税法知识竞赛试题及答案
- 2026年学校综合治理工作总结简单版(5篇)
- 慢病高危人群中医治未病志愿服务筛查策略
- 地理信息数据交换协议
- 慢病防控:慢性病防控的医防融合实践
- 物料盘点结果确认协议
- 车厢空间空间利用合作协议
- API接口集成服务协议
- 2026渤海银行招聘面试题及答案
- 2026年呼和浩特职业学院单招职业适应性测试模拟试题及答案解析
- 北师大博士笔试题目及答案
- 2025年1月浙江省普通高中学业水平考试思想政治试卷(含答案)
- 江苏省新高考基地学校2026届高三上学期第一次大联考政治试卷(含答案)
- 年轻干细胞与再生医学的未来研究方向-洞察及研究
- 行政总厨年终述职课件
- 邵阳市纪委监委所属事业单位公开选调(招聘)工作人员10人考试题库新版
- 中英文个人贷款借款合同模板
- 2025年山东能源集团有限公司社会招聘笔试试卷及答案
- 国家开放大学电大本科《行政领导学》期末试题标准题库及答案
评论
0/150
提交评论