vc 写的服务程序,想要让他暂停,该怎么做?

zhusuguo 2010-08-27 03:44:22
想要将写好的VC程序添加上服务,让他能开机后在后台以服务的形式运行
并且最小化到托盘

现在还有很多问题不能解决,希望大虾们帮帮忙...万分感谢

1。服务已经添加上,现在想要实现能让程序暂停的功能,点击一下“暂停按钮”,能让服务暂停运行

2。开机后怎么让他自动运行

3。怎么最小化到托盘


我是新手来的,希望大虾们不吝赐教!多谢多谢了
...全文
252 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
xun_jing 2010-08-28
  • 打赏
  • 举报
回复
BOOL ControlService(
SC_HANDLE hService, // handle to service
DWORD dwControl, // control code
LPSERVICE_STATUS lpServiceStatus // status information
);
dwControl 赋值为SERVICE_CONTROL_PAUSE 暂停
即 Notifies a service that it should pause. The hService handle must have SERVICE_PAUSE_CONTINUE access.

SC_HANDLE CreateService(
SC_HANDLE hSCManager, // handle to SCM database
LPCTSTR lpServiceName, // name of service to start
LPCTSTR lpDisplayName, // display name
DWORD dwDesiredAccess, // type of access to service
DWORD dwServiceType, // type of service
DWORD dwStartType, // when to start service
DWORD dwErrorControl, // severity of service failure
LPCTSTR lpBinaryPathName, // name of binary file
LPCTSTR lpLoadOrderGroup, // name of load ordering group
LPDWORD lpdwTagId, // tag identifier
LPCTSTR lpDependencies, // array of dependency names
LPCTSTR lpServiceStartName, // account name
LPCTSTR lpPassword // account password
);

dwStartType 赋值为SERVICE_AUTO_START 开机自动运行
即A service started automatically by the service control manager during system startup.

关于托盘可参考
http://www.vckbase.com/document/viewdoc/?id=996
http://www.vckbase.com/document/viewdoc/?id=492
pshchao 2010-08-28
  • 打赏
  • 举报
回复
自动运行,写注册表程序。

最小化托盘,不难实现,网上有代码
TerryP 2010-08-28
  • 打赏
  • 举报
回复
托盘这个上网搜一下就ok啦
nantianlhl 2010-08-27
  • 打赏
  • 举报
回复
用楼上的方法添加托盘处理,然后调用微软提供的Sc命令实现服务的注册及暂停
charleswangchaoyu 2010-08-27
  • 打赏
  • 举报
回复
最小化到托盘:
在服务程序的初始化函数中添加下面几句
NOTIFYICONDATA tnd;
tnd.cbSize = sizeof(NOTIFYICONDATA);
tnd.hWnd = this->m_hWnd;
tnd.uID = IDR_MAINFRAME;
tnd.uFlags = NIF_MESSAGE|NIF_ICON|NIF_TIP;
tnd.uCallbackMessage = WM_TRAY;
tnd.hIcon = LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_MAINFRAME));

Shell_NotifyIcon(NIM_ADD,&tnd);
dengzikun 2010-08-27
  • 打赏
  • 举报
回复
开机运行,写服务时用一个AUTO_START参数。
托盘网上很多参考代码。
dengzikun 2010-08-27
  • 打赏
  • 举报
回复
1。暂停整个服务进程,用微软的服务管理API。
2。暂停服务内部的业务处理,发消息通知内部处理线程。
oldforest 2010-08-27
  • 打赏
  • 举报
回复
1、ControlService(hService,SERVICE_CONTROL_STOP,&returnStatus) 这样可以让服务停止
2、StartService(hService,nArgCount,&lpServiceArgVectors) 这样可以让服务启动
3、这个网上示例代码一大堆
fengrx 2010-08-27
  • 打赏
  • 举报
回复
你查下服务的停止、启动相关的东东就可以了,,,

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧