[HIVESFT.INF]
[reactos.git] / dll / win32 / stobject / precomp.h
1 #pragma once
2
3 #define WIN32_NO_STATUS
4 #include <stdarg.h>
5 #include <tchar.h>
6
7 #define COBJMACROS
8 #define WIN32_NO_STATUS
9 #define _INC_WINDOWS
10 #define COM_NO_WINDOWS_H
11 #define NTOS_MODE_USER
12
13 #include <windef.h>
14 #include <winbase.h>
15 #include <winreg.h>
16 #include <winuser.h>
17 #include <wincon.h>
18 #include <ddeml.h>
19 #include <shlguid_undoc.h>
20 #include <shlwapi.h>
21 #include <shlobj.h>
22 #include <shlobj_undoc.h>
23 #include <shlwapi_undoc.h>
24 #include <tchar.h>
25 #include <strsafe.h>
26 #include <atlbase.h>
27 #include <atlcom.h>
28 #include <atlwin.h>
29
30 #include <shellapi.h>
31
32 #include <wine/debug.h>
33 #include <wine/unicode.h>
34
35 #include "resource.h"
36
37 extern const GUID CLSID_SysTray;
38
39 extern HINSTANCE g_hInstance;
40
41 #define ID_ICON_VOLUME 0x4CB
42
43 /* --------------- CSysTray callbacks ------------------------------ */
44
45 typedef CWinTraits <
46 WS_POPUP | WS_DLGFRAME | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
47 WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR | WS_EX_PALETTEWINDOW
48 > CMessageWndClass;
49
50 class CSysTray :
51 public CComCoClass<CSysTray, &CLSID_SysTray>,
52 public CComObjectRootEx<CComMultiThreadModelNoCS>,
53 public CWindowImpl<CSysTray, CWindow, CMessageWndClass>,
54 public IOleCommandTarget
55 {
56 // TODO: keep icon handlers here
57
58 HWND hwndSysTray;
59
60 static DWORD WINAPI s_SysTrayThreadProc(PVOID param);
61 HRESULT SysTrayMessageLoop();
62 HRESULT SysTrayThreadProc();
63 HRESULT CreateSysTrayThread();
64 HRESULT DestroySysTrayWindow();
65
66 HRESULT InitIcons();
67 HRESULT ShutdownIcons();
68 HRESULT UpdateIcons();
69 HRESULT ProcessIconMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);
70
71 public:
72 HRESULT NotifyIcon(INT code, UINT uId, HICON hIcon, LPCWSTR szTip);
73
74 HWND GetHWnd() { return m_hWnd; }
75
76 protected:
77 BOOL ProcessWindowMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT &lResult, DWORD dwMsgMapID = 0);
78
79 public:
80 CSysTray();
81 virtual ~CSysTray();
82
83 // *** IOleCommandTarget methods ***
84 virtual HRESULT STDMETHODCALLTYPE QueryStatus(const GUID *pguidCmdGroup, ULONG cCmds, OLECMD prgCmds [], OLECMDTEXT *pCmdText);
85 virtual HRESULT STDMETHODCALLTYPE Exec(const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut);
86
87 DECLARE_WND_CLASS_EX(_T("SystemTray_Main"), CS_GLOBALCLASS, COLOR_3DFACE)
88
89 DECLARE_REGISTRY_RESOURCEID(IDR_SYSTRAY)
90 DECLARE_NOT_AGGREGATABLE(CSysTray)
91 DECLARE_PROTECT_FINAL_CONSTRUCT()
92
93 BEGIN_COM_MAP(CSysTray)
94 COM_INTERFACE_ENTRY_IID(IID_IOleCommandTarget, IOleCommandTarget)
95 END_COM_MAP()
96
97 };
98
99 /* --------------- Icon callbacks ------------------------------ */
100
101 extern HRESULT STDMETHODCALLTYPE Volume_Init(_In_ CSysTray * pSysTray);
102 extern HRESULT STDMETHODCALLTYPE Volume_Shutdown(_In_ CSysTray * pSysTray);
103 extern HRESULT STDMETHODCALLTYPE Volume_Update(_In_ CSysTray * pSysTray);
104 extern HRESULT STDMETHODCALLTYPE Volume_Message(_In_ CSysTray * pSysTray, UINT uMsg, WPARAM wParam, LPARAM lParam);
105
106 /* --------------- Utils ------------------------------ */
107
108 static __inline ULONG
109 Win32DbgPrint(const char *filename, int line, const char *lpFormat, ...)
110 {
111 char szMsg[512];
112 char *szMsgStart;
113 const char *fname;
114 va_list vl;
115 ULONG uRet;
116
117 fname = strrchr(filename, '\\');
118 if (fname == NULL)
119 {
120 fname = strrchr(filename, '/');
121 }
122
123 if (fname == NULL)
124 fname = filename;
125 else
126 fname++;
127
128 szMsgStart = szMsg + sprintf(szMsg, "[%10lu] %s:%d: ", GetTickCount(), fname, line);
129
130 va_start(vl, lpFormat);
131 uRet = (ULONG) vsprintf(szMsgStart, lpFormat, vl);
132 va_end(vl);
133
134 OutputDebugStringA(szMsg);
135
136 return uRet;
137 }
138
139 #define DbgPrint(fmt, ...) \
140 Win32DbgPrint(__FILE__, __LINE__, fmt, ##__VA_ARGS__)
141
142 #if 1
143 #define FAILED_UNEXPECTEDLY(hr) (FAILED(hr) && (DbgPrint("Unexpected failure %08x.\n", hr), TRUE))
144 #else
145 #define FAILED_UNEXPECTEDLY(hr) FAILED(hr)
146 #endif
147