@@ -23,28 +23,24 @@ public unsafe partial class SystemTrayManager : IDisposable
23
23
24
24
private HWND _hWnd = default ;
25
25
private WNDPROC ? _wndProc ;
26
- private bool _isInitialized ;
27
26
private uint _dwTaskbarRestartMsgId ;
28
27
private bool _isShown ;
29
28
30
- public void Initialize ( string szWndClassName , string szToolTip , HICON hIcon , Guid id , uint dwCallbackMsgId , Action < uint > callback )
29
+ public static SystemTrayManager CreateIcon ( string szWndClassName , string szToolTip , HICON hIcon , Guid id , uint dwCallbackMsgId , Action < uint > callback )
31
30
{
32
- _szWndClassName = szWndClassName ;
33
- _szToolTip = szToolTip ;
34
- _hIcon = hIcon ;
35
- _id = id ;
36
- _dwCallbackMsgId = dwCallbackMsgId ;
37
- _callback = callback ;
38
-
39
- _isInitialized = true ;
31
+ return new ( )
32
+ {
33
+ _szWndClassName = szWndClassName ,
34
+ _szToolTip = szToolTip ,
35
+ _hIcon = hIcon ,
36
+ _id = id ,
37
+ _dwCallbackMsgId = dwCallbackMsgId ,
38
+ _callback = callback ,
39
+ } ;
40
40
}
41
41
42
- public bool CreateIcon ( )
42
+ private bool CreateIcon ( )
43
43
{
44
- // Not expected usage
45
- if ( ! _isInitialized )
46
- throw new InvalidOperationException ( $ "{ nameof ( SystemTrayManager ) } is not initialized. Call { nameof ( Initialize ) } () before using this method.") ;
47
-
48
44
if ( _hWnd . IsNull )
49
45
_hWnd = CreateIconWindow ( _szWndClassName ) ;
50
46
@@ -135,7 +131,7 @@ private LRESULT WndProc(HWND hWnd, uint uMsg, WPARAM wParam, LPARAM lParam)
135
131
136
132
return default ;
137
133
}
138
- else if ( uMsg == _dwTaskbarRestartMsgId && _isInitialized )
134
+ else if ( uMsg == _dwTaskbarRestartMsgId )
139
135
{
140
136
DeleteIcon ( ) ;
141
137
CreateIcon ( ) ;
0 commit comments