33using System . Runtime . InteropServices ;
44using System . Windows . Forms ;
55using System . Windows . Interop ;
6+ using MemPlus . Business . LOG ;
67
78namespace MemPlus . Business . UTILS
89{
@@ -25,6 +26,10 @@ internal sealed class HotKeyController : IDisposable
2526 /// The HwndSource that can be used to retrieve messages
2627 /// </summary>
2728 private HwndSource _source ;
29+ /// <summary>
30+ /// The LogController object that can be used to add logs
31+ /// </summary>
32+ private readonly LogController _logController ;
2833 #endregion
2934
3035 #region Events
@@ -41,10 +46,17 @@ internal sealed class HotKeyController : IDisposable
4146 /// <summary>
4247 /// Initialize a new HotKeyController
4348 /// </summary>
44- internal HotKeyController ( WindowInteropHelper helper )
49+ /// <param name="helper">The WindowInteropHelper object that can be used to retrieve the Window handle</param>
50+ /// <param name="logController">The LogController object that can be used to add logs</param>
51+ internal HotKeyController ( WindowInteropHelper helper , LogController logController )
4552 {
53+ _logController = logController ;
54+ _logController ? . AddLog ( new ApplicationLog ( "Initializing HotKeyController" ) ) ;
55+
4656 _helper = helper ;
4757 _source = HwndSource . FromHwnd ( _helper . Handle ) ;
58+
59+ _logController ? . AddLog ( new ApplicationLog ( "Done initializing HotKeyController" ) ) ;
4860 }
4961
5062 /// <summary>
@@ -54,6 +66,7 @@ internal HotKeyController(WindowInteropHelper helper)
5466 /// <param name="key">The key that is associated with the hotkey</param>
5567 internal void RegisterHotKey ( uint modifier , Keys key )
5668 {
69+ _logController ? . AddLog ( new ApplicationLog ( "Registering hotkey" ) ) ;
5770 // Increment the counter.
5871 _currentId ++ ;
5972
@@ -64,6 +77,7 @@ internal void RegisterHotKey(uint modifier, Keys key)
6477
6578 if ( ! NativeMethods . RegisterHotKey ( _helper . Handle , _currentId , modifier , ( uint ) key ) )
6679 throw new Exception ( "RegisterHotKey: " , new Win32Exception ( Marshal . GetLastWin32Error ( ) ) ) ;
80+ _logController ? . AddLog ( new ApplicationLog ( "Done registering hotkey" ) ) ;
6781 }
6882
6983 private IntPtr HwndHook ( IntPtr hwnd , int msg , IntPtr wParam , IntPtr lParam , ref bool handled )
@@ -84,14 +98,17 @@ private IntPtr HwndHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref
8498 /// </summary>
8599 public void Dispose ( )
86100 {
101+ _logController ? . AddLog ( new ApplicationLog ( "Disposing all available hotkey objects and hooks" ) ) ;
87102 // Unregister all the registered hot keys.
88103 for ( int i = _currentId ; i > 0 ; i -- )
89104 {
90105 NativeMethods . UnregisterHotKey ( _helper . Handle , i ) ;
91106 }
92107 // Remove the hook from the HwndSource
93- _source . RemoveHook ( HwndHook ) ;
108+ _source ? . RemoveHook ( HwndHook ) ;
94109 _source = null ;
110+
111+ _logController ? . AddLog ( new ApplicationLog ( "Done disposing all available hotkey objects and hooks" ) ) ;
95112 }
96113 #endregion
97114 }
0 commit comments