From 9e545bfbbf03e0532dc091e0429945f775f5f194 Mon Sep 17 00:00:00 2001 From: setsumi Date: Sun, 26 Nov 2023 20:33:40 +1000 Subject: [PATCH] - fix: sometimes pointer doesn't appear (custom pointers related). - change: custom pointer hiding for its current position, including inactive windows then pointer is outside of active one. - better applying of "Hide after idling" interval. --- Main.cpp | 25 +++++++++++++++++++++---- Main.dfm | 27 +++++++++------------------ Main.h | 2 +- MousePuff.cbproj | 4 ++-- MousePuff.res | Bin 3120 -> 3120 bytes 5 files changed, 33 insertions(+), 25 deletions(-) diff --git a/Main.cpp b/Main.cpp index 9904b9c..de73973 100644 --- a/Main.cpp +++ b/Main.cpp @@ -16,6 +16,7 @@ HHOOK hMouseHook = NULL, hKbdHook = NULL; HCURSOR hCurBlank = NULL; HWND hWindow = NULL; bool FastTermination = false; +bool DebugMode = false; // --------------------------------------------------------------------------- String GetWindowClassPlus(HWND hwnd) @@ -125,6 +126,7 @@ void TFormMousePuff1::Save() ini->WriteInteger(L"MAIN", L"StartToTray", chkStartToTray->Checked ? 1 : 0); ini->WriteInteger(L"MAIN", L"WinPageIndex", pageControl1->TabIndex); ini->WriteInteger(L"MAIN", L"HideTrayIcon", chkHideTrayIcon->Checked ? 1 : 0); + ini->WriteInteger(L"MAIN", L"DebugMode", DebugMode ? 1 : 0); delete ini; } @@ -144,11 +146,13 @@ void TFormMousePuff1::Load() else radioBtnProgram->Checked = true; udTimeout->Position = ini->ReadInteger(L"MAIN", L"Timeout", 3); - TimerReset(); chkStartToTray->Checked = ini->ReadInteger(L"MAIN", L"StartToTray", 0) == 1; pageControl1->TabIndex = ini->ReadInteger(L"MAIN", L"WinPageIndex", 0); chkHideTrayIcon->Checked = ini->ReadInteger(L"MAIN", L"HideTrayIcon", 0) == 1; + DebugMode = ini->ReadInteger(L"MAIN", L"DebugMode", 0) == 1; delete ini; + + TimerReset(); } // --------------------------------------------------------------------------- @@ -209,8 +213,15 @@ void MyProcShowCursor(bool show) HWND hHider = FindWindow(LEASED_WNDCLASS, LEASED_WNDTITLE); if (hHider) { - HWND hTarget = GetForegroundWindow(); + POINT pt; + GetCursorPos(&pt); + HWND hTarget = GetAncestor(WindowFromPoint(pt), GA_ROOT); PostMessage(hHider, show ? WMM_SHOWPOINTER : WMM_HIDEPOINTER, (WPARAM)hTarget, 0); + if (show) + { + // do it again, sometimes above is not enough + PostMessage(hHider, WMM_SHOWPOINTER, (WPARAM)hTarget, 0); + } } } @@ -228,9 +239,9 @@ void MyShowCursor(bool show, bool force = false) visible = show; // debug sound - if (FormMousePuff1->chkDebug->Checked) + if (DebugMode) { - MessageBeep(show ? 0 : MB_ICONASTERISK); + MessageBeep(show ? 0 : MB_ICONERROR); } if (show) @@ -494,4 +505,10 @@ void __fastcall TFormMousePuff1::WndProc(TMessage& Message) } TForm::WndProc(Message); } + +// --------------------------------------------------------------------------- +void __fastcall TFormMousePuff1::editTimeoutChange(TObject *Sender) +{ + TimerReset(); +} // --------------------------------------------------------------------------- diff --git a/Main.dfm b/Main.dfm index e4cf54e..0d94516 100644 --- a/Main.dfm +++ b/Main.dfm @@ -105,7 +105,7 @@ object FormMousePuff1: TFormMousePuff1 Hint = 'Hide always' Caption = 'Global' Checked = True - TabOrder = 7 + TabOrder = 6 TabStop = True OnClick = radioBtnGlobalClick end @@ -116,7 +116,7 @@ object FormMousePuff1: TFormMousePuff1 Height = 21 Hint = 'Hide only when specific window is active' Caption = 'Program Specific' - TabOrder = 8 + TabOrder = 7 OnClick = radioBtnGlobalClick end object udTimeout: TUpDown @@ -127,7 +127,7 @@ object FormMousePuff1: TFormMousePuff1 Associate = editTimeout Min = 1 Position = 3 - TabOrder = 10 + TabOrder = 9 end object editTimeout: TEdit Left = 243 @@ -135,8 +135,9 @@ object FormMousePuff1: TFormMousePuff1 Width = 42 Height = 21 ReadOnly = True - TabOrder = 9 + TabOrder = 8 Text = '3' + OnChange = editTimeoutChange end object btnSpy: TButton Left = 301 @@ -148,16 +149,6 @@ object FormMousePuff1: TFormMousePuff1 TabOrder = 1 OnClick = btnSpyClick end - object chkDebug: TCheckBox - Left = 297 - Top = 112 - Width = 57 - Height = 25 - Caption = 'Debug sounds' - TabOrder = 4 - Visible = False - WordWrap = True - end object btnHide: TButton Left = 300 Top = 215 @@ -175,7 +166,7 @@ object FormMousePuff1: TFormMousePuff1 Height = 25 Hint = 'Help information (F1)' Caption = '?' - TabOrder = 11 + TabOrder = 10 OnClick = btnHelpClick end object btnExit: TButton @@ -194,7 +185,7 @@ object FormMousePuff1: TFormMousePuff1 Width = 134 Height = 17 Caption = 'Start minimized to tray' - TabOrder = 6 + TabOrder = 5 end object chkEnabled: TCheckBox Left = 133 @@ -211,7 +202,7 @@ object FormMousePuff1: TFormMousePuff1 Font.Style = [fsBold] ParentFont = False State = cbChecked - TabOrder = 12 + TabOrder = 11 OnClick = chkEnabledClick end object chkHideTrayIcon: TCheckBox @@ -221,7 +212,7 @@ object FormMousePuff1: TFormMousePuff1 Height = 17 Hint = 'Hint: In case of completely hidden, run program again to show' Caption = 'Hide tray icon' - TabOrder = 5 + TabOrder = 4 end object timerPuff: TTimer Enabled = False diff --git a/Main.h b/Main.h index 3819cb5..2f41320 100644 --- a/Main.h +++ b/Main.h @@ -22,7 +22,6 @@ class TFormMousePuff1 : public TForm TEdit *editTimeout; TLabel *Label3; TButton *btnSpy; - TCheckBox *chkDebug; TButton *btnHide; TButton *btnHelp; TButton *btnExit; @@ -51,6 +50,7 @@ class TFormMousePuff1 : public TForm void __fastcall FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift); void __fastcall chkEnabledClick(TObject *Sender); void __fastcall timerKbTimer(TObject *Sender); + void __fastcall editTimeoutChange(TObject *Sender); protected: void __fastcall WndProc(TMessage& Message); diff --git a/MousePuff.cbproj b/MousePuff.cbproj index cb6acf3..0b47553 100644 --- a/MousePuff.cbproj +++ b/MousePuff.cbproj @@ -138,10 +138,10 @@ true true NDEBUG;$(Defines) - CompanyName=;FileDescription=MousePuff by furniture;FileVersion=1.6.3.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.6.3.0;Comments=;ProgramID= + CompanyName=;FileDescription=MousePuff by furniture;FileVersion=1.6.4.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.6.4.0;Comments=;ProgramID= 6 requireAdministrator - 3 + 4 None diff --git a/MousePuff.res b/MousePuff.res index 42a1757bb30ca3b48da6e9dc8ffb4fe29f7c691a..121b5625949f146738de6188d378156952c28ea0 100644 GIT binary patch delta 32 ocmdlWu|Z-&87B(^8v`Q)0|U#%`kRa