You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
2.5 KiB
C++

#include "StdAfx.h"
#include "ApplicationPriority.h"
#include "PropertieMgr.h"
#include "Propertie.h"
#include "LogMgr.h"
#include "AuthorityMgr.h"
CAppPriorityMgr *gAppPriorityMgr = new CAppPriorityMgr;
CAppPriorityMgr::CAppPriorityMgr(void)
{
m_bGetHighestPriority = false;//是否在打开软件时获取最高优先级
}
CAppPriorityMgr::~CAppPriorityMgr(void)
{
}
CMFCPropertyGridProperty *CAppPriorityMgr::CreatGridProperty()
{
CString PropertyName;//属性名称
CString Description;//描述
CString Path = _T("AppPriority");//存储路径
CString Name;
CString GroupName;
CString ModuleName;
//-------------------------------------------------------------------------------//
PropertyName = _T("程序优先级");
GroupName = PropertyName;
CMFCPropertyGridProperty* pGroup = new CMFCPropertyGridProperty(PropertyName);
//-------------------------------------------------------------------------------//
if(gAuthorityMgr->CheckAuthority(_Authority_Factory))
{
//添加属性变量映射
Name = _T("m_bGetHighestPriority");//变量名字
CPropertie *pPropertie = new CPropertie;
pPropertie->SetpVal((void*)&m_bGetHighestPriority);
pPropertie->SetType(_PROP_TYPE_BOOL);
pPropertie->SetpModule(this);
pPropertie->SetPath(Path);
pPropertie->SetName(Name);
pPropertie->WriteRead(true);//读取保存的属性
//添加属性显示
PropertyName = _T("最高优先级");
Description = _T("是否将程序优先级提升致系统最高级别,设置后需要重启软件");
pPropertie->SetGroupName(GroupName);
pPropertie->SetShowName(PropertyName);
CMFCPropertyGridProperty* p = new CMFCPropertyGridProperty(PropertyName, (_variant_t)m_bGetHighestPriority, Description);
pGroup->AddSubItem(p);
gDevicePropertieMgr.Insert(p, pPropertie);
}
//-------------------------------------------------------------------------------//
return pGroup;
}
void CAppPriorityMgr::OnAppInitialize()
{
if(m_bGetHighestPriority)
{
//获取最高权限
GetHighestPriority();
}
}
//获取最高权限
void CAppPriorityMgr::GetHighestPriority()
{
//提升当前程序的优先级
if(SetPriorityClass( GetCurrentProcess(), REALTIME_PRIORITY_CLASS ))
{
gLogMgr->WriteDebugLog("Func---->CAppPriorityMgr : GetHighestPriority : OK");
}
else
{
gLogMgr->WriteDebugLog("Err---->CAppPriorityMgr : GetHighestPriority : Err");
}
}