📄 svclistview.cpp
字号:
// Copyright E骾n O'Callaghan 2008 - 2008.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include "StdAfx.hpp"
#include "SvcListView.hpp"
#include "ListStateMachine.hpp"
void SvcListViewCtrl::OnShowWindow(UINT, INT)
{
WTL::CMenuHandle menu;
BOOL menu_created = menu.LoadMenu(IDR_SVC_MENU);
InitialSetup(menu);
SetExtendedListViewStyle(WS_EX_CLIENTEDGE|LVS_EX_FULLROWSELECT|LVS_EX_HEADERDRAGDROP|
LVS_EX_DOUBLEBUFFER|LVS_EX_CHECKBOXES);
SetSortListViewExtendedStyle(SORTLV_USESHELLBITMAPS, SORTLV_USESHELLBITMAPS);
boost::array<std::wstring, 7> names = {L"Display Name", L"Service Type",
L"Current State", L"Start Type", L"Service Start Name", L"Pathname", L"Description"};
boost::array<int, 7> widths = {100,110,60,60,60,60,60};
boost::array<bool, 7> visible = {true,true,true,true,true,true,true};
for (int i=0, e=7; i < e; ++i)
{
AddColumn(names[i].c_str(), i, visible[i], widths[i]);
}
SetColumnOrderState();
SetSort(false);
iniClass::LoadSettings();
state_machine_.initiate();
SetMsgHandled(false);
}
void SvcListViewCtrl::set_item_settings_text(unsigned iItem, const nt_service::service_settings& settings)
{
WTLx::notification_lock<listClass> lock(*this);
SetItemText(iItem, 2,
nt_service::dwCurrentState_to_string(settings.dwCurrentState()).c_str());
SetItemText(iItem, 3,
nt_service::dwStartType_to_string(settings.dwStartType()).c_str());
}
void SvcListViewCtrl::reset_item_settings_text(unsigned iItem)
{
WTLx::notification_lock<listClass> lock(*this);
SetItemText(iItem, 2, L"(no change)");
SetItemText(iItem, 3, L"(no change)");
}
void SvcListViewCtrl::reset_display_item_text(unsigned iItem, service_ptr svc_p)
{
WTLx::notification_lock<listClass> lock(*this);
SetItemText(iItem, 2, svc_p->dwCurrentState().second.c_str());
SetItemText(iItem, 3, svc_p->dwStartType().second.c_str());
}
int SvcListViewCtrl::add_and_list_service(service_ptr svc_p)
{
assert(svc_p);
services_.push_back(std::make_pair(svc_p, nt_service::service_settings(*svc_p, false, false)));
return list_service(*svc_p, services_.size()-1);
}
int SvcListViewCtrl::list_service(nt_service& svc, size_t i)
{
WTLx::notification_lock<listClass> lock(*this);
LVFINDINFO findInfo;
findInfo.flags = LVFI_STRING;
std::wstring name = svc.lpServiceDisplayName();
findInfo.psz = const_cast<LPTSTR>(name.c_str());
int item_pos = FindItem(&findInfo, -1);
if (item_pos < 0)
item_pos = AddItem(GetItemCount(), 0, name.c_str(), -1);
if (i != -1) SetItemData(item_pos, i);
AddItem(item_pos, 1, svc.dwServiceType().second.c_str());
AddItem(item_pos, 2, svc.dwCurrentState().second.c_str());
AddItem(item_pos, 3, svc.dwStartType().second.c_str());
AddItem(item_pos, 4, svc.lpServiceStartName().c_str());
AddItem(item_pos, 5, svc.lpBinaryPathName().c_str());
AddItem(item_pos, 6, svc.lpDescription().c_str());
return item_pos;
}
void SvcListViewCtrl::update_with_settings(std::set<nt_service::service_settings> s_settings)
{
logger.post(new event_type(event_logger::debug,
wformat(L"Displaying %1% service settings.") % s_settings.size()));
foreach(const winstl::listview_sequence::sequence_value_type val,
std::make_pair(const_begin(), const_end()))
{
WTLx::notification_lock<listClass> lock(*this);
service_ptr svc_p = services_[val.data()].first;
int item_pos = val.index();
std::set<nt_service::service_settings>::const_iterator ss_i =
s_settings.find(nt_service::service_settings(*svc_p, false, false));
if (ss_i != s_settings.end())
{
services_[val.data()].second = *ss_i;
set_item_settings_text(item_pos, *ss_i);
if (!(ss_i->is_inherited()))
SetCheckState(item_pos, true);
else
SetCheckState(item_pos, false);
}
else
if (services_[val.data()].second)
{
services_[val.data()].second.reset();
SetCheckState(item_pos, false);
reset_item_settings_text(item_pos);
}
}
InvalidateRect(NULL, true);
}
void SvcListViewCtrl::reset_display_services()
{
WTLx::notification_lock<listClass> lock(*this);
foreach(const winstl::listview_sequence::sequence_value_type val,
std::make_pair(const_begin(), const_end()))
{
WTLx::notification_lock<listClass> lock(*this);
service_ptr svc_p = services_[val.data()].first;
int item_pos = val.index();
if (services_[val.data()].second)
{
services_[val.data()].second.reset();
}
SetCheckState(item_pos, false);
reset_display_item_text(item_pos, svc_p);
}
InvalidateRect(NULL, true);
}
bool SvcListViewCtrl::overview_mode() { return state_machine_.is_overview_mode(); }
void SvcListViewCtrl::set_overview_mode(bool ob)
{
if (ob)
state_machine_.process_event(ev_switch_to_overview());
else
state_machine_.process_event(ev_switch_to_profile());
}
void SvcListViewCtrl::display_all_services()
{
nt_service_control_manager_ptr sc(new nt_service_control_manager(NULL, SERVICES_ACTIVE_DATABASE, SC_MANAGER_ALL_ACCESS));
enum_services_sequence ess(sc, SC_ENUM_PROCESS_INFO, SERVICE_WIN32, SERVICE_STATE_ALL);
for (enum_services_sequence::const_iterator i = ess.begin(), e = ess.end(); i != e; ++i)
{
try
{
add_and_list_service(service_ptr(new nt_service(*i, SERVICE_QUERY_STATUS|SERVICE_QUERY_CONFIG)));
aux::wlog() << boost::wformat(L"Service queried. Name: %1%, Display Name: %2%")
% (*i).lpServiceName() % (*i).lpDisplayName();
}
catch(const nt_service_exception& e)
{
std::wstring e_str = nt_service_erorr_to_string(e.error());
logger.post(new event_type(event_logger::critical,
wformat(L"Error: %1%! Service: %2%.") % e_str % (*i).lpDisplayName()));
}
catch(const std::exception& e)
{
logger.post(new event_type(event_logger::critical,
wformat(L"Exception: %1%! Service: %2%.") % aux::from_utf8_safe(e.what())
% (*i).lpDisplayName()));
}
}
InvalidateRect(NULL, true);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -