
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 新形势下新型农村集体经济的实践路径研究
- 2025至2030中国游戏出版行业项目调研及市场前景预测评估报告
- 2025至2030时髦行业发展趋势分析与未来投资战略咨询研究报告
- 2025至2030中国谷物行业发展趋势分析与未来投资战略咨询研究报告
- 2025至2030中国超声理疗设备行业发展趋势分析与未来投资战略咨询研究报告
- 2025至2030铝质气雾罐行业市场深度调研及供需格局及有效策略与实施路径评估报告
- 2025至2030成品油产业运行态势及投资规划深度研究报告
- 2025至2030红茶行业市场产业运行态势及投资规划深度研究报告
- 2025至2030中国体育场馆行业发展趋势分析与未来投资战略咨询研究报告
- 县级博物馆建设实施方案
- 三兄弟分田地宅基地协议书范文
- 跨学科主题学习-美化校园 2024-2025学年七年级地理上册新教材教学课件(人教版2024)
- TZJFS 015-2024 环境责任险风险评估技术规范
- 外研版初中英语1-6册单词表
- 江苏省徐州市2023-2024学年八年级下学期期末数学试卷(含答案解解)
- 房地产开发股东权益维护
- 中国绝经管理与绝经激素治疗指南(2023版)解读
- 汽车美容店工作计划书
- 华师专业英语词汇表
- 社区工作者招聘考试历年真题库含备考资料
- 绿化养护工作日记录表
评论
0/150
提交评论