2 * PROJECT: ReactOS system libraries
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: dll\win32\stobject\csystray.cpp
5 * PURPOSE: Systray shell service object implementation
6 * PROGRAMMERS: David Quintana <gigaherz@gmail.com>
11 WINE_DEFAULT_DEBUG_CHANNEL(stobject
);
13 SysTrayIconHandlers_t g_IconHandlers
[] = {
14 { Volume_Init
, Volume_Shutdown
, Volume_Update
, Volume_Message
}
16 const int g_NumIcons
= _countof(g_IconHandlers
);
18 const GUID CLSID_SysTray
= { 0x35CEC8A3, 0x2BE6, 0x11D2, { 0x87, 0x73, 0x92, 0xE2, 0x20, 0x52, 0x41, 0x53 } };
20 CSysTray::CSysTray() {}
21 CSysTray::~CSysTray() {}
23 HRESULT
CSysTray::InitIcons()
25 for (int i
= 0; i
< g_NumIcons
; i
++)
27 HRESULT hr
= g_IconHandlers
[i
].pfnInit(this);
35 HRESULT
CSysTray::ShutdownIcons()
37 for (int i
= 0; i
< g_NumIcons
; i
++)
39 HRESULT hr
= g_IconHandlers
[i
].pfnShutdown(this);
47 HRESULT
CSysTray::UpdateIcons()
49 for (int i
= 0; i
< g_NumIcons
; i
++)
51 HRESULT hr
= g_IconHandlers
[i
].pfnUpdate(this);
59 HRESULT
CSysTray::ProcessIconMessage(UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
61 for (int i
= 0; i
< g_NumIcons
; i
++)
63 HRESULT hr
= g_IconHandlers
[i
].pfnMessage(this, uMsg
, wParam
, lParam
);
74 HRESULT
CSysTray::NotifyIcon(INT code
, UINT uId
, HICON hIcon
, LPCWSTR szTip
)
77 nim
.cbSize
= sizeof(NOTIFYICONDATA
);
78 nim
.uFlags
= NIF_ICON
| NIF_STATE
| NIF_TIP
;
81 nim
.uCallbackMessage
= uId
;
85 nim
.uVersion
= NOTIFYICON_VERSION
;
87 StringCchCopy(nim
.szTip
, _countof(nim
.szTip
), szTip
);
90 BOOL ret
= Shell_NotifyIcon(code
, &nim
);
91 return ret
? S_OK
: E_FAIL
;
94 DWORD WINAPI
CSysTray::s_SysTrayThreadProc(PVOID param
)
96 CSysTray
* st
= (CSysTray
*) param
;
97 return st
->SysTrayThreadProc();
100 HRESULT
CSysTray::SysTrayMessageLoop()
105 while ((ret
= GetMessage(&msg
, NULL
, 0, 0)) != 0)
110 TranslateMessage(&msg
);
111 DispatchMessage(&msg
);
117 HRESULT
CSysTray::SysTrayThreadProc()
119 WCHAR strFileName
[MAX_PATH
];
120 GetModuleFileNameW(g_hInstance
, strFileName
, MAX_PATH
);
121 HMODULE hLib
= LoadLibraryW(strFileName
);
123 CoInitializeEx(NULL
, COINIT_DISABLE_OLE1DDE
| COINIT_APARTMENTTHREADED
);
127 HRESULT ret
= SysTrayMessageLoop();
131 FreeLibraryAndExitThread(hLib
, ret
);
134 HRESULT
CSysTray::CreateSysTrayThread()
136 DbgPrint("CSysTray Init TODO: Initialize tray icon handlers.\n");
138 HANDLE hThread
= CreateThread(NULL
, 0, s_SysTrayThreadProc
, this, 0, NULL
);
140 CloseHandle(hThread
);
145 HRESULT
CSysTray::DestroySysTrayWindow()
152 // *** IOleCommandTarget methods ***
153 HRESULT STDMETHODCALLTYPE
CSysTray::QueryStatus(const GUID
*pguidCmdGroup
, ULONG cCmds
, OLECMD prgCmds
[], OLECMDTEXT
*pCmdText
)
159 HRESULT STDMETHODCALLTYPE
CSysTray::Exec(const GUID
*pguidCmdGroup
, DWORD nCmdID
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
161 if (!IsEqualGUID(*pguidCmdGroup
, CGID_ShellServiceObject
))
166 case OLECMDID_NEW
: // init
167 return CreateSysTrayThread();
168 case OLECMDID_SAVE
: // shutdown
169 return DestroySysTrayWindow();
174 BOOL
CSysTray::ProcessWindowMessage(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, LRESULT
&lResult
, DWORD dwMsgMapID
)
185 SetTimer(1, 2000, NULL
);
195 DbgPrint("SysTray message received %u (%08p %08p)\n", uMsg
, wParam
, lParam
);
197 hr
= ProcessIconMessage(uMsg
, wParam
, lParam
);