-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6c7170b
Showing
14 changed files
with
479 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
#include <windows.h> | ||
#include <shellapi.h> | ||
#include <deque> | ||
#include "resource.h" | ||
|
||
LPCWSTR szWindowClass = L"CURSORCIRCLE"; | ||
HWND hWnd; | ||
NOTIFYICONDATA nid; | ||
HMENU hPopupMenu; | ||
|
||
const int circleSize = 200; | ||
const int thickness = 40; | ||
const int sleepMs = 10; | ||
const int queSize = 500 / sleepMs; | ||
std::deque<POINT> ptque; | ||
|
||
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { | ||
switch (message) { | ||
case WM_CREATE: | ||
{ | ||
// ウィンドウ | ||
HRGN hRgn = CreateEllipticRgn(0, 0, circleSize, circleSize); | ||
HRGN hRgnInner = CreateEllipticRgn(thickness, thickness, circleSize - thickness, circleSize - thickness); | ||
CombineRgn(hRgn, hRgn, hRgnInner, RGN_DIFF); | ||
SetWindowRgn(hWnd, hRgn, TRUE); // ウィンドウを赤丸の形に切り抜く | ||
SetWindowLong(hWnd, GWL_EXSTYLE, GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_LAYERED); | ||
// タスクトレイ | ||
nid.cbSize = sizeof(NOTIFYICONDATA); | ||
nid.hWnd = hWnd; | ||
nid.uID = 100; | ||
nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP; | ||
nid.uCallbackMessage = WM_USER + 1; | ||
nid.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_CURSORCIRCLE)); | ||
lstrcpy(nid.szTip, L"Cursor◎Circle"); | ||
Shell_NotifyIcon(NIM_ADD, &nid); | ||
hPopupMenu = CreatePopupMenu(); | ||
AppendMenu(hPopupMenu, MF_STRING, 1, L"Cursor◎Circle終了"); | ||
break; | ||
} | ||
case WM_USER + 1: | ||
if (lParam == WM_RBUTTONDOWN) { | ||
POINT pt; | ||
GetCursorPos(&pt); | ||
SetForegroundWindow(hWnd); | ||
TrackPopupMenu(hPopupMenu, TPM_BOTTOMALIGN | TPM_LEFTALIGN, pt.x, pt.y, 0, hWnd, NULL); | ||
} | ||
break; | ||
case WM_COMMAND: | ||
if (wParam == 1) { | ||
DestroyWindow(hWnd); | ||
} | ||
break; | ||
case WM_PAINT: | ||
{ | ||
PAINTSTRUCT ps; | ||
HDC hdc = BeginPaint(hWnd, &ps); | ||
HBRUSH hBrush = CreateSolidBrush(RGB(255, 0, 0)); | ||
RECT rect; | ||
GetClientRect(hWnd, &rect); | ||
FillRect(hdc, &rect, hBrush); | ||
DeleteObject(hBrush); | ||
SetBkMode(hdc, TRANSPARENT); | ||
EndPaint(hWnd, &ps); | ||
break; | ||
} | ||
case WM_CLOSE: | ||
DestroyWindow(hWnd); | ||
break; | ||
case WM_DESTROY: | ||
Shell_NotifyIcon(NIM_DELETE, &nid); | ||
PostQuitMessage(0); | ||
break; | ||
default: | ||
return DefWindowProc(hWnd, message, wParam, lParam); | ||
} | ||
return 0; | ||
} | ||
|
||
ATOM RegisterMyClass(HINSTANCE hInstance) { | ||
WNDCLASSEX wcex = {}; | ||
wcex.cbSize = sizeof(WNDCLASSEX); | ||
wcex.style = CS_HREDRAW | CS_VREDRAW; | ||
wcex.lpfnWndProc = WndProc; | ||
wcex.cbClsExtra = 0; | ||
wcex.cbWndExtra = 0; | ||
wcex.hInstance = hInstance; | ||
wcex.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_CURSORCIRCLE)); | ||
wcex.hCursor = nullptr; | ||
wcex.hbrBackground = (HBRUSH)COLOR_BACKGROUND; | ||
wcex.lpszMenuName = nullptr; | ||
wcex.lpszClassName = szWindowClass; | ||
wcex.hIconSm = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_SMALL)); | ||
return RegisterClassEx(&wcex); | ||
} | ||
|
||
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { | ||
RECT rect; | ||
rect.left = 0; | ||
rect.top = 0; | ||
rect.right = circleSize; | ||
rect.bottom = circleSize; | ||
AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE); // タイトルバーとウィンドウ枠を除く中身のサイズに合わせる | ||
hWnd = CreateWindowEx( | ||
WS_EX_TOOLWINDOW | WS_EX_LAYERED | WS_EX_TRANSPARENT, // クリック等のイベントをスルーする | ||
szWindowClass, nullptr, | ||
WS_OVERLAPPEDWINDOW, | ||
CW_USEDEFAULT, CW_USEDEFAULT, rect.right - rect.left, rect.bottom - rect.top, nullptr, nullptr, hInstance, nullptr); | ||
if (!hWnd) { | ||
return FALSE; | ||
} | ||
SetWindowLong(hWnd, GWL_STYLE, 0); // タイトルバーとウィンドウ枠を無くす | ||
ShowWindow(hWnd, SW_HIDE); // 初期状態は非表示で | ||
return TRUE; | ||
} | ||
|
||
int APIENTRY WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nCmdShow) { | ||
HANDLE hMutex = CreateMutex(NULL, FALSE, szWindowClass); | ||
if (hMutex == NULL) { | ||
return 1; | ||
} | ||
if (GetLastError() == ERROR_ALREADY_EXISTS) { | ||
CloseHandle(hMutex); | ||
return 1; | ||
} | ||
RegisterMyClass(hInstance); | ||
if (!InitInstance(hInstance, nCmdShow)) { | ||
CloseHandle(hMutex); | ||
return 1; | ||
} | ||
int alpha = 0, alpha_prev = 0; | ||
MSG msg{}; | ||
while (IsWindow(hWnd)) { | ||
while (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE)) { | ||
msg.message; | ||
TranslateMessage(&msg); | ||
DispatchMessage(&msg); | ||
} | ||
|
||
Sleep(sleepMs); | ||
POINT pt; | ||
BOOL gcp_result = GetCursorPos(&pt); | ||
if (!gcp_result) | ||
continue; | ||
ptque.push_back(pt); | ||
if (ptque.size() > queSize) { | ||
ptque.pop_front(); | ||
} | ||
|
||
POINT pt1{}, pt2{}; | ||
int turned = 0; | ||
for (const auto& pt0 : ptque) { | ||
if (((pt0.x - pt1.x) <= -10 && 10 <= (pt1.x - pt2.x)) || | ||
((pt1.x - pt2.x) <= -10 && 10 <= (pt0.x - pt1.x))) | ||
turned++; | ||
pt2 = pt1; | ||
pt1 = pt0; | ||
} | ||
if (turned >= (queSize / 20)) { | ||
alpha = 160; | ||
} | ||
if (alpha != 0) { | ||
SetLayeredWindowAttributes(hWnd, 0, alpha, LWA_ALPHA); // 半透明にする | ||
SetWindowPos(hWnd, HWND_TOPMOST, pt.x - circleSize / 2, pt.y - circleSize / 2, circleSize, circleSize, SWP_SHOWWINDOW | SWP_NOACTIVATE); | ||
UpdateWindow(hWnd); | ||
} | ||
else if (alpha != alpha_prev) { | ||
SetWindowPos(hWnd, HWND_BOTTOM, pt.x - circleSize / 2, pt.y - circleSize / 2, circleSize, circleSize, SWP_HIDEWINDOW | SWP_NOACTIVATE); | ||
UpdateWindow(hWnd); | ||
} | ||
alpha_prev = alpha; | ||
alpha = max(alpha - 10, 0); | ||
} | ||
CloseHandle(hMutex); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#pragma once | ||
|
||
#include "resource.h" |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.8.34408.163 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CursorCircle", "CursorCircle.vcxproj", "{CAF26211-0E8F-4AC7-9275-93644EB8CB69}" | ||
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 | ||
{CAF26211-0E8F-4AC7-9275-93644EB8CB69}.Debug|x64.ActiveCfg = Debug|x64 | ||
{CAF26211-0E8F-4AC7-9275-93644EB8CB69}.Debug|x64.Build.0 = Debug|x64 | ||
{CAF26211-0E8F-4AC7-9275-93644EB8CB69}.Debug|x86.ActiveCfg = Debug|Win32 | ||
{CAF26211-0E8F-4AC7-9275-93644EB8CB69}.Debug|x86.Build.0 = Debug|Win32 | ||
{CAF26211-0E8F-4AC7-9275-93644EB8CB69}.Release|x64.ActiveCfg = Release|x64 | ||
{CAF26211-0E8F-4AC7-9275-93644EB8CB69}.Release|x64.Build.0 = Release|x64 | ||
{CAF26211-0E8F-4AC7-9275-93644EB8CB69}.Release|x86.ActiveCfg = Release|Win32 | ||
{CAF26211-0E8F-4AC7-9275-93644EB8CB69}.Release|x86.Build.0 = Release|Win32 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {993D01D2-A244-4A85-A944-4306C3324BA9} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project DefaultTargets="Build" 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> | ||
<PropertyGroup Label="Globals"> | ||
<VCProjectVersion>17.0</VCProjectVersion> | ||
<Keyword>Win32Proj</Keyword> | ||
<ProjectGuid>{caf26211-0e8f-4ac7-9275-93644eb8cb69}</ProjectGuid> | ||
<RootNamespace>CursorCircle</RootNamespace> | ||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> | ||
</PropertyGroup> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> | ||
<ConfigurationType>Application</ConfigurationType> | ||
<UseDebugLibraries>true</UseDebugLibraries> | ||
<PlatformToolset>v143</PlatformToolset> | ||
<CharacterSet>Unicode</CharacterSet> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> | ||
<ConfigurationType>Application</ConfigurationType> | ||
<UseDebugLibraries>false</UseDebugLibraries> | ||
<PlatformToolset>v143</PlatformToolset> | ||
<WholeProgramOptimization>true</WholeProgramOptimization> | ||
<CharacterSet>Unicode</CharacterSet> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> | ||
<ConfigurationType>Application</ConfigurationType> | ||
<UseDebugLibraries>true</UseDebugLibraries> | ||
<PlatformToolset>v143</PlatformToolset> | ||
<CharacterSet>Unicode</CharacterSet> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> | ||
<ConfigurationType>Application</ConfigurationType> | ||
<UseDebugLibraries>false</UseDebugLibraries> | ||
<PlatformToolset>v143</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" /> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<SDLCheck>true</SDLCheck> | ||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
<ConformanceMode>true</ConformanceMode> | ||
</ClCompile> | ||
<Link> | ||
<SubSystem>Windows</SubSystem> | ||
<GenerateDebugInformation>true</GenerateDebugInformation> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<FunctionLevelLinking>true</FunctionLevelLinking> | ||
<IntrinsicFunctions>true</IntrinsicFunctions> | ||
<SDLCheck>true</SDLCheck> | ||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
<ConformanceMode>true</ConformanceMode> | ||
</ClCompile> | ||
<Link> | ||
<SubSystem>Windows</SubSystem> | ||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | ||
<OptimizeReferences>true</OptimizeReferences> | ||
<GenerateDebugInformation>true</GenerateDebugInformation> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<SDLCheck>true</SDLCheck> | ||
<PreprocessorDefinitions>_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
<ConformanceMode>true</ConformanceMode> | ||
</ClCompile> | ||
<Link> | ||
<SubSystem>Windows</SubSystem> | ||
<GenerateDebugInformation>true</GenerateDebugInformation> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<FunctionLevelLinking>true</FunctionLevelLinking> | ||
<IntrinsicFunctions>true</IntrinsicFunctions> | ||
<SDLCheck>true</SDLCheck> | ||
<PreprocessorDefinitions>NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
<ConformanceMode>true</ConformanceMode> | ||
</ClCompile> | ||
<Link> | ||
<SubSystem>Windows</SubSystem> | ||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | ||
<OptimizeReferences>true</OptimizeReferences> | ||
<GenerateDebugInformation>true</GenerateDebugInformation> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemGroup> | ||
<ClInclude Include="resource.h" /> | ||
<ClInclude Include="targetver.h" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ClCompile Include="CursorCircle.cpp" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ResourceCompile Include="CursorCircle.rc" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Image Include="CursorCircle.ico" /> | ||
<Image Include="small.ico" /> | ||
</ItemGroup> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | ||
<ImportGroup Label="ExtensionTargets"> | ||
</ImportGroup> | ||
</Project> |
Oops, something went wrong.