diff --git a/ReadMe.txt b/ReadMe.txt new file mode 100644 index 0000000..844b752 --- /dev/null +++ b/ReadMe.txt @@ -0,0 +1,19 @@ +【ソフト名】音量調整ソフト +【著作権者】赤西真論 +【公開日】2016/06/08 +【種 別】ユーティリティ +【連絡先】marron.general@gmail.com +【圧縮形式】zip +【動作環境】Windows vista/7/8/10 +【開発環境】Windows10 Pro + C# + Visual Studio 2015 Community + +――――――――――――――――――――――――――――――――――――― +≪著作権および免責事項≫ + + 本ソフトはフリーソフトです。自由にご使用ください。なお,著作権は作者 +である"赤西真論"が保有しています。 + + このソフトウェアを使用したことによって生じたすべての障害・損害・不具 +合等に関しては、私と私の関係者および私の所属するいかなる団体・組織とも、 +一切の責任を負いません。各自の責任においてご使用ください。 \ No newline at end of file diff --git a/VolumeChanger.cpp b/VolumeChanger.cpp new file mode 100644 index 0000000..eaf2589 --- /dev/null +++ b/VolumeChanger.cpp @@ -0,0 +1,115 @@ +#include "stdafx.h" + +#define GetBool(buf) strcmp(buf,"True") ? TRUE : FALSE + +using namespace::Microsoft::WRL; +using namespace::Microsoft::WRL::Details; + +class ComInitializer { +private: + HRESULT m_hr; +public: + ComInitializer() { m_hr = CoInitialize(nullptr); } + ComInitializer(LPVOID pvReserved) { m_hr = CoInitialize(pvReserved); } + ~ComInitializer() { CoUninitialize(); } + operator HRESULT() const { return m_hr; } +}; + +int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) { + ComInitializer initializer; + if (FAILED(initializer)) + return -1; + + // foCX񋓃IuWFNg擾 + ComPtr deviceEnumerator; + HRESULT hr = CoCreateInstance( + __uuidof(MMDeviceEnumerator), + nullptr, + CLSCTX_INPROC_SERVER, + IID_PPV_ARGS(&deviceEnumerator)); + if (FAILED(initializer)) + RaiseException(hr); + + // ̃}`fBAo̓foCXiXs[J[j擾 + ComPtr device; + hr = deviceEnumerator->GetDefaultAudioEndpoint( + EDataFlow::eRender, + ERole::eMultimedia, + &device); + if (FAILED(initializer)) + RaiseException(hr); + + // I[fBIGh|Cg̃{[IuWFNg쐬 + ComPtr audioEndpointVolume; + hr = device->Activate( + __uuidof(IAudioEndpointVolume), + CLSCTX_INPROC_SERVER, + nullptr, + &audioEndpointVolume); + if (FAILED(hr)) + RaiseException(hr); + + // WbN܂ł̏擾 + ComPtr pDeviceTopology; + ComPtr pConnEP; + IConnector* pConnDeviceTo; + ComPtr pPart; + device->Activate(__uuidof(IDeviceTopology), CLSCTX_INPROC_SERVER, NULL, (void**)&pDeviceTopology); + pDeviceTopology->GetConnector(0, &pConnEP); + pConnEP->GetConnectedTo(&pConnDeviceTo); + pConnDeviceTo->QueryInterface(__uuidof(IPart), (void**)&pPart); + + // ʒ + ComPtr pJackDesc = NULL; + UINT nNumJacks = 0; + UINT SpeakerCount = 1; + float HeadphoneVol = 0.1; + float SpeakerVol = 0.2; + BOOL SpeakerMute = TRUE; + UINT LoopDelay = 200; + UINT oldNumJacks = 0; + // ݒ̓ǂݍ + char buf[64]; + GetPrivateProfileString(TEXT("Default"), TEXT("SpeakerCount"), TEXT("1"), buf, 64, TEXT("./setting.ini")); + SpeakerCount = atoi(buf); + GetPrivateProfileString(TEXT("Default"), TEXT("SpeakerVol"), TEXT("0.2"), buf, 64, TEXT("./setting.ini")); + SpeakerVol = atof(buf); + GetPrivateProfileString(TEXT("Default"), TEXT("SpeakerMute"), TEXT("True"), buf, 64, TEXT("./setting.ini")); + SpeakerMute = GetBool(buf); + GetPrivateProfileString(TEXT("Default"), TEXT("HeadphoneVol"), TEXT("0.1"), buf, 64, TEXT("./setting.ini")); + HeadphoneVol = atof(buf); + GetPrivateProfileString(TEXT("Default"), TEXT("LoopDelay"), TEXT("200"), buf, 64, TEXT("./setting.ini")); + LoopDelay = atoi(buf); + // C[v + while (1) { + pPart->Activate(CLSCTX_INPROC_SERVER, __uuidof(IKsJackDescription), &pJackDesc); + pJackDesc->GetJackCount(&nNumJacks); + if (nNumJacks != oldNumJacks) { + // N̏ + if (oldNumJacks == 0) { + if (nNumJacks == SpeakerCount) { + hr = audioEndpointVolume->GetMute(&SpeakerMute); + hr = audioEndpointVolume->GetMasterVolumeLevelScalar(&SpeakerVol); //Xs[J[ʂ̎擾 + } else { + hr = audioEndpointVolume->GetMasterVolumeLevelScalar(&HeadphoneVol); //wbhzʂ̎擾 + } + MessageBox(NULL, TEXT("N܂\nfoCX̔”\ł"), TEXT("VolumeChanger"), MB_OK); + } else { + if (nNumJacks == SpeakerCount) { + hr = audioEndpointVolume->GetMasterVolumeLevelScalar(&HeadphoneVol); //wbhzʂ̎擾 + hr = audioEndpointVolume->SetMute(SpeakerMute, nullptr); //~[gԂݒ + hr = audioEndpointVolume->SetMasterVolumeLevelScalar(SpeakerVol, nullptr); + } else { + hr = audioEndpointVolume->GetMute(&SpeakerMute); //Xs[J[ł̃~[gԂ擾 + hr = audioEndpointVolume->GetMasterVolumeLevelScalar(&SpeakerVol); //Xs[J[ʂ̎擾 + hr = audioEndpointVolume->SetMute(FALSE, nullptr); //~[g + hr = audioEndpointVolume->SetMasterVolumeLevelScalar(HeadphoneVol, nullptr); + } + } + oldNumJacks = nNumJacks; + } + Sleep(LoopDelay); + } + + return 0; +} \ No newline at end of file diff --git a/VolumeChanger.ico b/VolumeChanger.ico new file mode 100644 index 0000000..b3ec03b Binary files /dev/null and b/VolumeChanger.ico differ diff --git a/VolumeChanger.rc b/VolumeChanger.rc new file mode 100644 index 0000000..abffb33 Binary files /dev/null and b/VolumeChanger.rc differ diff --git a/VolumeChanger.sln b/VolumeChanger.sln new file mode 100644 index 0000000..c4f5e64 --- /dev/null +++ b/VolumeChanger.sln @@ -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}") = "VolumeChanger", "VolumeChanger.vcxproj", "{A1C56A19-9533-496D-8A58-B5CEA06AEB10}" +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 + {A1C56A19-9533-496D-8A58-B5CEA06AEB10}.Debug|x64.ActiveCfg = Debug|x64 + {A1C56A19-9533-496D-8A58-B5CEA06AEB10}.Debug|x64.Build.0 = Debug|x64 + {A1C56A19-9533-496D-8A58-B5CEA06AEB10}.Debug|x86.ActiveCfg = Debug|Win32 + {A1C56A19-9533-496D-8A58-B5CEA06AEB10}.Debug|x86.Build.0 = Debug|Win32 + {A1C56A19-9533-496D-8A58-B5CEA06AEB10}.Release|x64.ActiveCfg = Release|x64 + {A1C56A19-9533-496D-8A58-B5CEA06AEB10}.Release|x64.Build.0 = Release|x64 + {A1C56A19-9533-496D-8A58-B5CEA06AEB10}.Release|x86.ActiveCfg = Release|Win32 + {A1C56A19-9533-496D-8A58-B5CEA06AEB10}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/VolumeChanger.vcxproj b/VolumeChanger.vcxproj new file mode 100644 index 0000000..44ec749 --- /dev/null +++ b/VolumeChanger.vcxproj @@ -0,0 +1,157 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + {A1C56A19-9533-496D-8A58-B5CEA06AEB10} + Win32Proj + VolumeChanger + 8.1 + + + + Application + true + v140 + MultiByte + + + Application + false + v140 + true + MultiByte + + + Application + true + v140 + Unicode + + + Application + false + v140 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) + + + Windows + true + + + + + Use + Level3 + Disabled + _DEBUG;_WINDOWS;%(PreprocessorDefinitions) + + + Windows + true + + + + + Level3 + NotUsing + MaxSpeed + true + true + WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) + + + Windows + true + true + true + + + + + Level3 + Use + MaxSpeed + true + true + NDEBUG;_WINDOWS;%(PreprocessorDefinitions) + + + Windows + true + true + true + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/VolumeChanger.vcxproj.filters b/VolumeChanger.vcxproj.filters new file mode 100644 index 0000000..bf220a8 --- /dev/null +++ b/VolumeChanger.vcxproj.filters @@ -0,0 +1,41 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + + + + ヘッダー ファイル + + + ヘッダー ファイル + + + + + ソース ファイル + + + + + リソース ファイル + + + リソース ファイル + + + \ No newline at end of file diff --git a/small.ico b/small.ico new file mode 100644 index 0000000..b3ec03b Binary files /dev/null and b/small.ico differ diff --git a/stdafx.h b/stdafx.h new file mode 100644 index 0000000..9e275c2 --- /dev/null +++ b/stdafx.h @@ -0,0 +1,22 @@ +// stdafx.h : W̃VXe CN[h t@C̃CN[h t@CA܂ +// QƉ񐔂A‚܂ύXȂAvWFNgp̃CN[h t@C +// Lq܂B +// + +#pragma once + +#include "targetver.h" + +// Windows wb_[ t@C: +#include + +// C ^C wb_[ t@C +#include +#include +#include +#include + +// TODO: vOɕKvȒljwb_[ŎQƂĂ +#include +#include +#include \ No newline at end of file diff --git a/targetver.h b/targetver.h new file mode 100644 index 0000000..10b7ccd --- /dev/null +++ b/targetver.h @@ -0,0 +1,8 @@ +#pragma once + +// SDKDDKVer.h CN[hƁApłłʂ Windows vbgtH[`܂B + +// ȑO Windows vbgtH[pɃAvP[Vrhꍇ́AWinSDKVer.h CN[hA +// SDKDDKVer.h CN[hOɁAT|[gΏۂƂvbgtH[悤 _WIN32_WINNT }Nݒ肵܂B + +#include