bt.cpp

来自「可以快捷开关PPC蓝牙 BT 0 关闭 BT 1 开启 BT 2 恢复上次」· C++ 代码 · 共 70 行

CPP
70
字号
// BT.cpp : 定义应用程序的入口点。
//

#include "stdafx.h"
#include "BT.h"
#include <bthutil.h>
#include <string.h>
#include <wchar.h>

int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPTSTR    lpCmdLine,
                   int       nCmdShow)
{
	LONG lRet;
	HKEY hkey;
	DWORD dwModeC;
	DWORD dwModeL;
	DWORD dwSize;
	TCHAR *strParm1;
	TCHAR *strParm2;

	dwSize = sizeof(DWORD);
	if (BthGetMode(&dwModeC) == ERROR_SUCCESS)
	{
		lRet = RegCreateKeyEx(HKEY_CURRENT_USER,_T("MY\\BT"),NULL,NULL,NULL,KEY_ALL_ACCESS,NULL,&hkey,NULL);
		if (lRet == ERROR_SUCCESS)
		{
			lRet = RegQueryValueEx(hkey, _T("LastStauts"), 0, NULL, (LPBYTE)&dwModeL, &dwSize);
			if (lRet != ERROR_SUCCESS)
				dwModeL = dwModeC;

			RegSetValueEx(hkey, _T("LastStauts"), 0, REG_DWORD, (LPBYTE)& dwModeC,dwSize);
			RegCloseKey(hkey);
		}

		strParm1 = _tcstok(lpCmdLine,_T(" "));
		strParm2 = _tcstok(NULL,_T(" "));

		if (strParm1 == NULL || _tcscmp(strParm1, _T("3")) == 0)
		{
			if (dwModeC != BTH_POWER_OFF)
				dwModeC = BTH_POWER_OFF;
			else
			{
				if (strParm2 != NULL)
					dwModeC = BTH_DISCOVERABLE;
				else
					dwModeC = BTH_CONNECTABLE;
			}
		}
		else if (_tcscmp(strParm1, _T("0"))  == 0)
			dwModeC = BTH_POWER_OFF;
		else if (_tcscmp(strParm1, _T("1"))  == 0)
		{
			if (strParm2 != NULL)
				dwModeC = BTH_DISCOVERABLE;
			else
				dwModeC = BTH_CONNECTABLE;
		}
		else if (_tcscmp(strParm1, _T("2")) == 0)
		{
			dwModeC = dwModeL;
		}

		BthSetMode(dwModeC);
	}

	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?