下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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文化专家面试题目及答案
- 2026年沪教版适配专升本生物暑假衔接卷生命活动调节与遗传标准试卷第406套(含答案解析与可打印作答区)
- 供房借款合同范本
- 2026年鲁教版适配小升初化学月考达标卷化学方程式与计算标准试卷第459套(含答案解析与可打印作答区)
- 关于2026年合作项目延期的风险提示函5篇范文
- 阅读的力量:遨游知识的海洋小学主题班会课件
- 2026年黑龙江省绥化市网格员招聘笔试参考试题及答案详解
- 数字化转型背景下企业组织架构优化手册
- 2026年全国“动物疫病防治员”技能及理论知识考试题库(附含答案)
- 2026银行遴选面试题及答案
- 2026乌鲁木齐城市轨道集团招聘(191人)笔试参考题库及答案详解
- 2026年非遗文化赋能数字化乡村振兴现状调研报告
- 华中科技大学2026年强基计划校考(面试+体育测试)模拟试题及答案解析
- 2026年人教版高一第二学期地理期末普通高中统考试卷(附答案可下载)
- 2026贵州毕节黔西市粮油购销有限公司面向社会公开招聘工作人员3人考试模拟试题及答案详解
- 2026年四川省拟任县处级领导干部理论(任职资格考试)练习题及答案
- 会员健康档案建立维护细则
- (2026年)护理文书书写规范与质量控制课件
- 班组安全生产检查培训课件
评论
0/150
提交评论