Skip to content

Commit

Permalink
First, working version version
Browse files Browse the repository at this point in the history
  • Loading branch information
ITachiLab committed Sep 14, 2016
1 parent a83a2f7 commit 7bedbd0
Show file tree
Hide file tree
Showing 10 changed files with 372 additions and 0 deletions.
Binary file added bluedentist.rc
Binary file not shown.
28 changes: 28 additions & 0 deletions bluedentist.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bluedentist", "bluedentist.vcxproj", "{CFD0335B-3F99-4928-8722-2553A24BB1E2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{CFD0335B-3F99-4928-8722-2553A24BB1E2}.Debug|x64.ActiveCfg = Debug|x64
{CFD0335B-3F99-4928-8722-2553A24BB1E2}.Debug|x64.Build.0 = Debug|x64
{CFD0335B-3F99-4928-8722-2553A24BB1E2}.Debug|x86.ActiveCfg = Debug|Win32
{CFD0335B-3F99-4928-8722-2553A24BB1E2}.Debug|x86.Build.0 = Debug|Win32
{CFD0335B-3F99-4928-8722-2553A24BB1E2}.Release|x64.ActiveCfg = Release|x64
{CFD0335B-3F99-4928-8722-2553A24BB1E2}.Release|x64.Build.0 = Release|x64
{CFD0335B-3F99-4928-8722-2553A24BB1E2}.Release|x86.ActiveCfg = Release|Win32
{CFD0335B-3F99-4928-8722-2553A24BB1E2}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
172 changes: 172 additions & 0 deletions bluedentist.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\LenovoApi.cpp" />
<ClCompile Include="src\main.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="include\LenovoApi.h" />
<ClInclude Include="include\main.h" />
<ClInclude Include="include\resource.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="bluedentist.rc" />
</ItemGroup>
<ItemGroup>
<Image Include="resources\icon.ico" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{CFD0335B-3F99-4928-8722-2553A24BB1E2}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>bluedentist</RootNamespace>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>include;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>include;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<TargetName>$(ProjectName)_x86</TargetName>
<IncludePath>include;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<TargetName>$(ProjectName)_x64</TargetName>
<IncludePath>include;$(IncludePath)</IncludePath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
46 changes: 46 additions & 0 deletions bluedentist.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\LenovoApi.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="include\LenovoApi.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\resource.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\main.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="bluedentist.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
<ItemGroup>
<Image Include="resources\icon.ico">
<Filter>Resource Files</Filter>
</Image>
</ItemGroup>
</Project>
17 changes: 17 additions & 0 deletions include/LenovoApi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once
#include "Windows.h"

typedef int(__fastcall *SetBluetooth)(int, int);
typedef int(__fastcall *GetBluetoothStatus)(int*, int);

class LenovoApi {
public:
LenovoApi();
~LenovoApi();

SetBluetooth setBluetooth;
GetBluetoothStatus getBluetoothStatus;
private:
HINSTANCE apiLibrary;
};

8 changes: 8 additions & 0 deletions include/main.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once
#include <windows.h>
#include "resource.h"
#include "LenovoApi.h"

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow);
BOOL CALLBACK MyDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
void checkBluetoothStatus(HWND hDlg);
Binary file added include/resource.h
Binary file not shown.
Binary file added resources/icon.ico
Binary file not shown.
39 changes: 39 additions & 0 deletions src/LenovoApi.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "LenovoApi.h"

LenovoApi::LenovoApi() {
char libraryDir[1024];
DWORD bufferSize = 1024;
HKEY key;

RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Lenovo\\Energy Management", 0, KEY_READ + KEY_WOW64_64KEY, &key);

if (key) {
RegQueryValueExA(key, "InstallDir", NULL, NULL, (LPBYTE)libraryDir, &bufferSize);
RegCloseKey(key);

strcpy_s(libraryDir + bufferSize - 1, 24, "\LenovoEmExpandedAPI.dll");

this->apiLibrary = LoadLibraryA(libraryDir);

if (this->apiLibrary) {
this->setBluetooth = (SetBluetooth)GetProcAddress(this->apiLibrary, "SetBluetooth");
this->getBluetoothStatus = (GetBluetoothStatus)GetProcAddress(this->apiLibrary, "GetBluetoothStatus");
} else {
#ifdef _M_IX86
throw "Could not load library. Try using x64 version of Bluedentist.";
#endif

#ifdef _M_X64
throw "Could not load library. Try using x86 version of Bluedentist.";
#endif
}
} else {
throw "Could not find installation directory of Lenovo Energy Management.";
}

}


LenovoApi::~LenovoApi() {
FreeLibrary(this->apiLibrary);
}
62 changes: 62 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include "main.h"

LenovoApi *lenovoApi;

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
try {
lenovoApi = new LenovoApi();

HWND hWnd = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), NULL, (DLGPROC)MyDialog);

ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);

MSG msg;
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}

return (int)msg.wParam;
} catch (const char* exception) {
MessageBoxA(NULL, exception, "Error", MB_OK + MB_ICONERROR);
}
}

BOOL CALLBACK MyDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) {
switch (message) {
case WM_CLOSE:
DestroyWindow(hDlg);
return TRUE;
case WM_DESTROY:
PostQuitMessage(0);
return TRUE;
case WM_INITDIALOG:
checkBluetoothStatus(hDlg);
return TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDC_RADIO1) {
lenovoApi->setBluetooth(1, 0);
checkBluetoothStatus(hDlg);
}
if (LOWORD(wParam) == IDC_RADIO2) {
lenovoApi->setBluetooth(0, 0);
checkBluetoothStatus(hDlg);
}

return TRUE;
}

return FALSE;
}

void checkBluetoothStatus(HWND hDlg) {
int bluetoothStatus;
lenovoApi->getBluetoothStatus(&bluetoothStatus, 0);

if (bluetoothStatus) {
CheckDlgButton(hDlg, IDC_RADIO1, BST_CHECKED);
} else {
CheckDlgButton(hDlg, IDC_RADIO2, BST_CHECKED);
}
}

0 comments on commit 7bedbd0

Please sign in to comment.