Browse Source

开机自启动优化

zhangyang 6 years ago
parent
commit
086b6ff212

BIN
bin/Win32/Debug/zhipuzi_pos_windows/zhipuzi_pos_windows.exe


+ 26 - 0
zhipuzi_pos_windows/helper/CSystem.h

@@ -79,6 +79,32 @@ public:
         }
     }
 
+	static bool IsAutoStart()
+	{
+		HKEY hKey;
+		wstring strRegPath = L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
+
+		//1、找到系统的启动项
+		if (RegOpenKeyEx(HKEY_CURRENT_USER, strRegPath.c_str(), 0, KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS)
+		{
+			char dwValue[256];
+			DWORD dwSzType = REG_SZ;
+			DWORD dwSize = sizeof(dwValue);
+
+			if (::RegQueryValueEx(hKey, _T("智铺子收银软件"), 0, &dwSzType, (LPBYTE)&dwValue, &dwSize) != ERROR_SUCCESS)
+			{
+				return false;
+			}
+
+			//关闭注册表
+			RegCloseKey(hKey);
+
+			return true;
+		}
+
+		return false;
+	}
+
     // 判断文件是否存在
     static BOOL IsFileExist(const wstring& csFile)
     {

+ 5 - 1
zhipuzi_pos_windows/tool/CSetting.cpp

@@ -176,10 +176,14 @@ void CSetting::Init()
 
 	//ϵͳÉèÖõIJÎÊý
 	std::string setting_is_auto_start = "setting_is_auto_start";
-	if (m_paramsMap.find(setting_is_auto_start) == m_paramsMap.end())
+	if (CSystem::IsAutoStart() == true)
 	{
 		m_paramsMap[setting_is_auto_start] = "1";
 	}
+	else
+	{
+		m_paramsMap[setting_is_auto_start] = "0";
+	}
 
 	std::string setting_is_auto_login = "setting_is_auto_login";
 	if (m_paramsMap.find(setting_is_auto_login) == m_paramsMap.end())