Skip to content

Commit c0bc2b0

Browse files
committed
Issues #136 A visually more convenient way to drag a window by the mouse
1 parent a45ba17 commit c0bc2b0

File tree

16 files changed

+123
-578
lines changed

16 files changed

+123
-578
lines changed

SmartSystemMenu/Forms/MainForm.cs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ partial class MainForm : Form
2727
private GetMsgHook _getMsgHook;
2828
private ShellHook _shellHook;
2929
private CBTHook _cbtHook;
30-
private Hooks.MouseHook _mouseHook;
3130
private AboutForm _aboutForm;
3231
private SettingsForm _settingsForm;
3332
private readonly List<DimForm> _dimForms;
@@ -40,7 +39,7 @@ partial class MainForm : Form
4039
#if WIN32
4140
private SystemTrayMenu _systemTrayMenu;
4241
private HotKeyHook _hotKeyHook;
43-
private HotKeys.MouseHook _hotKeyMouseHook;
42+
private MouseHook _hotKeyMouseHook;
4443
private Process _64BitProcess;
4544
#endif
4645

@@ -105,7 +104,7 @@ protected override void OnLoad(EventArgs e)
105104
_hotKeyHook.Start(moduleName, _settings.MenuItems);
106105
}
107106

108-
_hotKeyMouseHook = new HotKeys.MouseHook();
107+
_hotKeyMouseHook = new MouseHook();
109108
_hotKeyMouseHook.Hooked += HotKeyMouseHooked;
110109
if (_settings.Closer.MouseButton != MouseButton.None)
111110
{
@@ -149,7 +148,7 @@ protected override void OnLoad(EventArgs e)
149148
}
150149
}
151150

152-
_callWndProcHook = new CallWndProcHook(Handle, MenuItemId.SC_DRAG_BY_MOUSE);
151+
_callWndProcHook = new CallWndProcHook(Handle);
153152
_callWndProcHook.SysCommand += SysCommand;
154153
_callWndProcHook.InitMenu += InitMenu;
155154
_callWndProcHook.Start();
@@ -159,27 +158,19 @@ protected override void OnLoad(EventArgs e)
159158
_getMsgHook.InitMenu += InitMenu;
160159
_getMsgHook.Start();
161160

162-
_shellHook = new ShellHook(Handle, MenuItemId.SC_DRAG_BY_MOUSE);
161+
_shellHook = new ShellHook(Handle);
163162
_shellHook.WindowCreated += WindowCreated;
164163
_shellHook.WindowDestroyed += WindowDestroyed;
165164
_shellHook.Start();
166165

167-
_cbtHook = new CBTHook(Handle, MenuItemId.SC_DRAG_BY_MOUSE);
166+
_cbtHook = new CBTHook(Handle);
168167
_cbtHook.WindowCreated += WindowCreated;
169168
_cbtHook.WindowDestroyed += WindowDestroyed;
170169
_cbtHook.MoveSize += WindowMoveSize;
171170
_cbtHook.MinMax += WindowMinMax;
172171
_cbtHook.Activate += WindowActivate;
173172
_cbtHook.Start();
174173

175-
176-
_mouseHook = new Hooks.MouseHook(Handle, MenuItemId.SC_DRAG_BY_MOUSE);
177-
var dragByMouseItemName = MenuItemId.GetName(MenuItemId.SC_DRAG_BY_MOUSE);
178-
if (_settings.MenuItems.Items.Flatten(x => x.Items).Any(x => x.Type == MenuItemType.Item && x.Name == dragByMouseItemName && x.Show))
179-
{
180-
_mouseHook.Start();
181-
}
182-
183174
Hide();
184175
}
185176

@@ -217,7 +208,6 @@ protected override void OnClosed(EventArgs e)
217208
_getMsgHook?.Stop();
218209
_shellHook?.Stop();
219210
_cbtHook?.Stop();
220-
_mouseHook?.Stop();
221211

222212
HideDimWindows();
223213

SmartSystemMenu/Hooks/CBTHook.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System.Windows.Forms;
33
using static SmartSystemMenu.Native.Constants;
44
using static SmartSystemMenu.Native.User32;
5-
5+
using static SmartSystemMenu.Native.Hooks;
66

77
namespace SmartSystemMenu.Hooks
88
{
@@ -14,7 +14,7 @@ class CBTHook : Hook
1414
public event EventHandler<WindowEventArgs> MoveSize;
1515
public event EventHandler<WindowEventArgs> Activate;
1616

17-
public CBTHook(IntPtr handle, int dragByMouseMenuItem) : base(handle, dragByMouseMenuItem)
17+
public CBTHook(IntPtr handle) : base(handle)
1818
{
1919
}
2020

@@ -29,12 +29,12 @@ protected override void OnStart()
2929
ChangeWindowMessageFilter(WM_SSM_HOOK_HCBT_ACTIVATE, MSGFLT_ADD);
3030
}
3131

32-
NativeHookMethods.InitializeCbtHook(0, _handle, _dragByMouseMenuItem);
32+
InitializeCbtHook(0, _handle);
3333
}
3434

3535
protected override void OnStop()
3636
{
37-
NativeHookMethods.UninitializeCbtHook();
37+
UninitializeCbtHook();
3838
}
3939

4040
public override void ProcessWindowMessage(ref Message m)

SmartSystemMenu/Hooks/CallWndProcHook.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Windows.Forms;
33
using static SmartSystemMenu.Native.Constants;
44
using static SmartSystemMenu.Native.User32;
5+
using static SmartSystemMenu.Native.Hooks;
56

67
namespace SmartSystemMenu.Hooks
78
{
@@ -13,7 +14,7 @@ class CallWndProcHook : Hook
1314
public event EventHandler<SysCommandEventArgs> SysCommand;
1415
public event EventHandler<SysCommandEventArgs> InitMenu;
1516

16-
public CallWndProcHook(IntPtr handle, int dragByMouseMenuItem) : base(handle, dragByMouseMenuItem)
17+
public CallWndProcHook(IntPtr handle) : base(handle)
1718
{
1819
}
1920

@@ -26,12 +27,12 @@ protected override void OnStart()
2627
ChangeWindowMessageFilter(WM_SSM_HOOK_CALLWNDPROC_INITMENU, MSGFLT_ADD);
2728
}
2829

29-
NativeHookMethods.InitializeCallWndProcHook(0, _handle, _dragByMouseMenuItem);
30+
InitializeCallWndProcHook(0, _handle);
3031
}
3132

3233
protected override void OnStop()
3334
{
34-
NativeHookMethods.UninitializeCallWndProcHook();
35+
UninitializeCallWndProcHook();
3536
}
3637

3738
public override void ProcessWindowMessage(ref Message m)

SmartSystemMenu/Hooks/GetMsgHook.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,22 @@
22
using System.Windows.Forms;
33
using static SmartSystemMenu.Native.Constants;
44
using static SmartSystemMenu.Native.User32;
5+
using static SmartSystemMenu.Native.Hooks;
56

67
namespace SmartSystemMenu.Hooks
78
{
89
class GetMsgHook : Hook
910
{
1011
private IntPtr _cacheHandle;
1112
private IntPtr _cacheMessage;
13+
private int _dragByMouseMenuItem;
1214

1315
public event EventHandler<SysCommandEventArgs> SysCommand;
1416
public event EventHandler<SysCommandEventArgs> InitMenu;
1517

16-
public GetMsgHook(IntPtr handle, int dragByMouseMenuItem) : base(handle, dragByMouseMenuItem)
18+
public GetMsgHook(IntPtr handle, int dragByMouseMenuItem) : base(handle)
1719
{
20+
_dragByMouseMenuItem = dragByMouseMenuItem;
1821
}
1922

2023
protected override void OnStart()
@@ -26,12 +29,12 @@ protected override void OnStart()
2629
ChangeWindowMessageFilter(WM_SSM_HOOK_GETMSG_INITMENU, MSGFLT_ADD);
2730
}
2831

29-
NativeHookMethods.InitializeGetMsgHook(0, _handle, _dragByMouseMenuItem);
32+
InitializeGetMsgHook(0, _handle, _dragByMouseMenuItem);
3033
}
3134

3235
protected override void OnStop()
3336
{
34-
NativeHookMethods.UninitializeGetMsgHook();
37+
UninitializeGetMsgHook();
3538
}
3639

3740
public override void ProcessWindowMessage(ref Message m)

SmartSystemMenu/Hooks/Hook.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,15 @@ abstract class Hook
66
{
77
protected bool _isActive = false;
88
protected IntPtr _handle;
9-
protected int _dragByMouseMenuItem;
109

1110
public bool IsActive
1211
{
1312
get { return _isActive; }
1413
}
1514

16-
public Hook(IntPtr windowHandle, int dragByMouseMenuItem)
15+
public Hook(IntPtr windowHandle)
1716
{
1817
_handle = windowHandle;
19-
_dragByMouseMenuItem = dragByMouseMenuItem;
2018
}
2119

2220
public void Start()

SmartSystemMenu/Hooks/KeyboardHook.cs

Lines changed: 0 additions & 52 deletions
This file was deleted.

SmartSystemMenu/Hooks/KeyboardLLHook.cs

Lines changed: 0 additions & 51 deletions
This file was deleted.

SmartSystemMenu/Hooks/MouseHook.cs

Lines changed: 0 additions & 49 deletions
This file was deleted.

0 commit comments

Comments
 (0)