Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

532 lines
16 KiB

  1. #ifndef _UTIL_H_
  2. #define _UTIL_H_
  3. int IsVK_TABCycler(MSG *pMsg);
  4. BOOL IsVK_CtlTABCycler(MSG *pMsg);
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. BOOL __cdecl _FormatMessage(LPCWSTR szTemplate, LPWSTR szBuf, UINT cchBuf, ...);
  9. HRESULT IUnknown_FileSysChange(IUnknown* punk, DWORD dwEvent, LPCITEMIDLIST* ppidl);
  10. HRESULT QueryService_SID_IBandProxy(IUnknown * punkParent, REFIID riid, IBandProxy ** ppbp, void **ppvObj);
  11. HRESULT CreateIBandProxyAndSetSite(IUnknown * punkParent, REFIID riid, IBandProxy ** ppbp, void **ppvObj);
  12. DWORD GetPreferedDropEffect(IDataObject *pdtobj);
  13. HRESULT _SetPreferedDropEffect(IDataObject *pdtobj, DWORD dwEffect);
  14. #ifdef DEBUG
  15. int SearchDWP(DWORD_PTR *pdwBuf, int cbBuf, DWORD_PTR dwVal);
  16. #endif
  17. #define REGVALUE_STREAMSA "Streams"
  18. #define REGVALUE_STREAMS TEXT(REGVALUE_STREAMSA)
  19. #define SZ_REGKEY_TYPEDCMDMRU TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\RunMRU")
  20. #define SZ_REGKEY_TYPEDURLMRU TEXT("Software\\Microsoft\\Internet Explorer\\TypedURLs")
  21. #define SZ_REGVAL_MRUENTRY TEXT("url%lu")
  22. #define SZ_REGKEY_INETCPL_POLICIES TEXT("Software\\Policies\\Microsoft\\Internet Explorer\\Control Panel")
  23. #define SZ_REGVALUE_RESETWEBSETTINGS TEXT("ResetWebSettings")
  24. #define SZ_REGKEY_IE_POLICIES TEXT("Software\\Policies\\Microsoft\\Internet Explorer\\Main")
  25. #define SZ_REGVALUE_IEREPAIR TEXT("Repair IE Option")
  26. #define SZ_REGKEY_ACTIVE_SETUP TEXT("Software\\Microsoft\\Active Setup")
  27. #define SZ_REGVALUE_DISABLE_REPAIR TEXT("DisableRepair")
  28. #if 0
  29. BOOL IsIERepairOn();
  30. #endif
  31. BOOL IsResetWebSettingsEnabled(void);
  32. HRESULT GetMRUEntry(HKEY hKey, DWORD dwMRUIndex, LPTSTR pszMRUEntry, DWORD cchMRUEntry, LPITEMIDLIST * ppidl);
  33. extern UINT g_cfURL;
  34. extern UINT g_cfHIDA;
  35. extern UINT g_cfFileDescA;
  36. extern UINT g_cfFileDescW;
  37. extern UINT g_cfFileContents;
  38. extern const CLSID g_clsidNull; // for those that want a NULL clsid.
  39. void InitClipboardFormats();
  40. // raymondc's futile attempt to reduce confusion
  41. //
  42. // EICH_KBLAH = a registry key named blah
  43. // EICH_SBLAH = a win.ini section named blah
  44. #define EICH_UNKNOWN 0xFFFFFFFF
  45. #define EICH_KINET 0x00000002
  46. #define EICH_KINETMAIN 0x00000004
  47. #define EICH_KWIN 0x00000008
  48. #define EICH_KWINPOLICY 0x00000010
  49. #define EICH_KWINEXPLORER 0x00000020
  50. #define EICH_SSAVETASKBAR 0x00000040
  51. #define EICH_SWINDOWMETRICS 0x00000080
  52. #define EICH_SPOLICY 0x00000100
  53. #define EICH_SSHELLMENU 0x00000200
  54. #define EICH_KWINEXPLSMICO 0x00000400
  55. #define EICH_SWINDOWS 0x00000800
  56. DWORD SHIsExplorerIniChange(WPARAM wParam, LPARAM lParam);
  57. #define GEN_DEBUGSTRW(str) ((str) ? (str) : L"<Null Str>")
  58. #define GEN_DEBUGSTRA(str) ((str) ? (str) : "<Null Str>")
  59. #ifdef UNICODE
  60. #define GEN_DEBUGSTR GEN_DEBUGSTRW
  61. #else // UNICODE
  62. #define GEN_DEBUGSTR GEN_DEBUGSTRA
  63. #endif // UNICODE
  64. void _InitAppGlobals();
  65. BOOL _InitComCtl32();
  66. void* DataObj_GetDataOfType(IDataObject* pdtobj, UINT cfType, STGMEDIUM *pstg);
  67. HRESULT RootCreateFromPath(LPCTSTR pszPath, LPITEMIDLIST * ppidl);
  68. extern DEFFOLDERSETTINGS g_dfs;
  69. STDAPI_(void) SaveDefaultFolderSettings(UINT flags);
  70. STDAPI_(void) GetCabState(CABINETSTATE *pcs);
  71. //-------------------------------------------------------------------------
  72. //*** Reg_GetStrs -- read registry strings into struct fields
  73. struct regstrs
  74. {
  75. LPTSTR name; // registry name
  76. int off; // struct offset
  77. };
  78. BOOL ViewIDFromViewMode(UINT uViewMode, SHELLVIEWID *pvid);
  79. void Reg_GetStrs(HKEY hkey, const struct regstrs *tab, TCHAR *szBuf, int cchBuf, void *pv);
  80. HRESULT DropOnMailRecipient(IDataObject *pdtobj, DWORD grfKeyState);
  81. HRESULT SendDocToMailRecipient(LPCITEMIDLIST pidl, UINT uiCodePage, DWORD grfKeyState, IUnknown *pUnkSite);
  82. #ifdef DEBUG
  83. void Dbg_DumpMenu(LPCTSTR psz, HMENU hmenu);
  84. #else
  85. #define Dbg_DumpMenu(psz, hmenu)
  86. #endif
  87. extern const LARGE_INTEGER c_li0;
  88. extern BOOL g_fNewNotify;
  89. // FEATURE: Need to handle two different implementations of SHChangeRegister...
  90. typedef ULONG (* PFNSHCHANGENOTIFYREGISTER)(HWND hwnd, int fSources, LONG fEvents, UINT wMsg, int cEntries, SHChangeNotifyEntry *pshcne);
  91. typedef BOOL (* PFNSHCHANGENOTIFYDEREGISTER)(unsigned long ulID);
  92. ULONG RegisterNotify(HWND hwnd, UINT nMsg, LPCITEMIDLIST pidl, DWORD dwEvents, UINT uFlags, BOOL fRecursive);
  93. int PropBag_ReadInt4(IPropertyBag* pPropBag, LPWSTR pszKey, int iDefault);
  94. HINSTANCE HinstShdocvw();
  95. HINSTANCE HinstShell32();
  96. extern const VARIANT c_vaEmpty;
  97. #define PVAREMPTY ((VARIANT*)&c_vaEmpty)
  98. BOOL ILIsBrowsable(LPCITEMIDLIST pidl, BOOL *pfISFolder);
  99. STDAPI_(LPITEMIDLIST) IEILCreate(UINT cbSize);
  100. BOOL GetInfoTipEx(IShellFolder* psf, DWORD dwFlags, LPCITEMIDLIST pidl, LPTSTR pszText, int cchTextMax);
  101. BOOL IsBrowsableShellExt(LPCITEMIDLIST pidl);
  102. void OpenFolderPidl(LPCITEMIDLIST pidl);
  103. void OpenFolderPath(LPCTSTR pszPath);
  104. int WINAPI _SHHandleUpdateImage( LPCITEMIDLIST pidlExtra );
  105. extern BOOL g_fICWCheckComplete;
  106. BOOL CheckSoftwareUpdateUI( HWND hwndOwner, IShellBrowser *pisb );
  107. BOOL CheckRunICW(LPCTSTR);
  108. #ifdef DEBUG
  109. LPTSTR Dbg_PidlStr(LPCITEMIDLIST pidl, LPTSTR pszBuffer, DWORD cchBufferSize);
  110. #else // DEBUG
  111. #define Dbg_PidlStr(pidl, pszBuffer, cchBufferSize) ((LPTSTR)NULL)
  112. #endif // DEBUG
  113. HRESULT SavePidlAsLink(IUnknown* punkSite, IStream *pstm, LPCITEMIDLIST pidl);
  114. HRESULT LoadPidlAsLink(IUnknown* punkSite, IStream *pstm, LPITEMIDLIST *ppidl);
  115. #define ADJUST_TO_WCHAR_POS 0
  116. #define ADJUST_TO_TCHAR_POS 1
  117. int AdjustECPosition(char *psz, int iPos, int iType);
  118. BOOL ExecItemFromFolder(HWND hwnd, LPCSTR pszVerb, IShellFolder* psf, LPCITEMIDLIST pidlItem);
  119. // See if a give URL is actually present as an installed entry
  120. STDAPI_(BOOL) CallCoInternetQueryInfo(LPCTSTR pszURL, QUERYOPTION QueryOption);
  121. #define UrlIsInstalledEntry(pszURL) CallCoInternetQueryInfo(pszURL, QUERY_IS_INSTALLEDENTRY)
  122. BOOL IsSubscribableA(LPCSTR pszUrl);
  123. BOOL IsSubscribableW(LPCWSTR pwzUrl);
  124. HRESULT IURLQualifyW(IN LPCWSTR pcwzURL, DWORD dwFlags, OUT LPWSTR pwzTranslatedURL, LPBOOL pbWasSearchURL, LPBOOL pbWasCorrected);
  125. #ifdef UNICODE
  126. #define IsSubscribable IsSubscribableW
  127. #define IURLQualifyT IURLQualifyW
  128. #else // UNICODE
  129. #define IsSubscribable IsSubscribableA
  130. #define IURLQualifyT IURLQualifyA
  131. #endif // UNICODE
  132. #define IURLQualifyA IURLQualify
  133. HDPA GetSortedIDList(LPITEMIDLIST pidl);
  134. void FreeSortedIDList(HDPA hdpa);
  135. //#define StopWatch StopWatchT
  136. int GetColorComponent(LPSTR *ppsz);
  137. COLORREF RegGetColorRefString( HKEY hkey, LPTSTR RegValue, COLORREF Value);
  138. LRESULT SetHyperlinkCursor(IShellFolder* pShellFolder, LPCITEMIDLIST pidl);
  139. HRESULT StrCmpIWithRoot(LPCTSTR szDispNameIn, BOOL fTotalStrCmp, LPTSTR * ppszCachedRoot);
  140. STDAPI UpdateSubscriptions();
  141. enum TRI_STATE
  142. {
  143. TRI_UNKNOWN = 2,
  144. TRI_TRUE = TRUE,
  145. TRI_FALSE = FALSE
  146. };
  147. LONG OpenRegUSKey(LPCTSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult);
  148. HWND GetTrayWindow();
  149. #define STREAMSIZE_UNKNOWN 0xFFFFFFFF
  150. HRESULT SaveStreamHeader(IStream *pstm, DWORD dwSignature, DWORD dwVersion, DWORD dwSize);
  151. HRESULT LoadStreamHeader(IStream *pstm, DWORD dwSignature, DWORD dwStartVersion, DWORD dwEndVersion, DWORD * pdwSize, DWORD * pdwVersionOut);
  152. // _FrameTrack flags
  153. #define TRACKHOT 0x0001
  154. #define TRACKEXPAND 0x0002
  155. #define TRACKNOCHILD 0x0004
  156. void FrameTrack(HDC hdc, LPRECT prc, UINT uFlags);
  157. #ifdef __cplusplus
  158. //+-------------------------------------------------------------------------
  159. // This function scans the document for the given HTML tag and returns the
  160. // result in a collection.
  161. //--------------------------------------------------------------------------
  162. interface IHTMLDocument2;
  163. interface IHTMLElementCollection;
  164. HRESULT GetDocumentTags(IHTMLDocument2* pHTMLDocument, LPOLESTR pszTagName, IHTMLElementCollection** ppTagsCollection);
  165. // CMenuList: a small class that tracks whether a given hmenu belongs
  166. // to the frame or the object, so the messages can be
  167. // dispatched correctly.
  168. class CMenuList
  169. {
  170. public:
  171. CMenuList(void);
  172. ~CMenuList(void);
  173. void Set(HMENU hmenuShared, HMENU hmenuFrame);
  174. void AddMenu(HMENU hmenu);
  175. void RemoveMenu(HMENU hmenu);
  176. BOOL IsObjectMenu(HMENU hmenu);
  177. #ifdef DEBUG
  178. void Dump(LPCTSTR pszMsg);
  179. #endif
  180. private:
  181. HDSA _hdsa;
  182. };
  183. };
  184. #endif
  185. #ifdef __cplusplus
  186. class CAssociationList
  187. {
  188. public:
  189. //
  190. // WARNING: We don't want a destructor on this because then it can't
  191. // be a global object without bringing in the CRT main. So
  192. // we can't free the DSA in a destructor. The DSA memory will be
  193. // freed by the OS when the process detaches. If this
  194. // class is ever dynamically allocated (ie not a static) then
  195. // we will need to free the DSA.
  196. //
  197. // ~CAssociationList();
  198. BOOL Add(DWORD dwKey, LPVOID lpData);
  199. void Delete(DWORD dwKey);
  200. HRESULT Find(DWORD dwKey, LPVOID* ppData);
  201. protected:
  202. int FindEntry(DWORD dwKey);
  203. struct ASSOCDATA
  204. {
  205. DWORD dwKey;
  206. LPVOID lpData;
  207. };
  208. HDSA _hdsa;
  209. };
  210. #endif
  211. STDAPI_(void) DrawMenuItem(DRAWITEMSTRUCT* pdi, LPCTSTR lpszMenuText, UINT iIcon);
  212. STDAPI_(LRESULT) MeasureMenuItem(MEASUREITEMSTRUCT *lpmi, LPCTSTR lpszMenuText);
  213. void FireEventSz(LPCTSTR szEvent);
  214. #ifndef UNICODE
  215. void FireEventSzW(LPCWSTR szEvent);
  216. #else
  217. #define FireEventSzW FireEventSz
  218. #endif
  219. // comctl32.dll doesn't really implement Str_SetPtrW.
  220. STDAPI_(BOOL) Str_SetPtrPrivateW(WCHAR * UNALIGNED * ppwzCurrent, LPCWSTR pwzNew);
  221. // This function is similar to Str_SetPtrPrivateW but it is compatible with API's
  222. // that use LocalAlloc for string memory
  223. STDAPI_(BOOL) SetStr(WCHAR * UNALIGNED * ppwzCurrent, LPCWSTR pwzNew);
  224. // Review chrisny: this can be moved into an object easily to handle generic droptarget, dropcursor
  225. // , autoscrool, etc. . .
  226. STDAPI_(void) _DragEnter(HWND hwndTarget, const POINTL ptStart, IDataObject *pdtObject);
  227. STDAPI_(void) _DragMove(HWND hwndTarget, const POINTL ptStart);
  228. #define Str_SetPtrW Str_SetPtrPrivateW
  229. STDAPI_(BOOL) _MenuCharMatch(LPCTSTR lpsz, TCHAR ch, BOOL fIgnoreAmpersand);
  230. STDAPI GetNavigateTarget(IShellFolder *psf, LPCITEMIDLIST pidl, LPITEMIDLIST *ppidl, DWORD *pdwAttribs);
  231. STDAPI_(BOOL) DoDragDropWithInternetShortcut(IOleCommandTarget *pcmdt, LPITEMIDLIST pidl, HWND hwnd);
  232. STDAPI_(BSTR) SysAllocStringA(LPCSTR);
  233. #ifdef UNICODE
  234. #define SysAllocStringT(psz) SysAllocString(psz)
  235. #else
  236. #define SysAllocStringT(psz) SysAllocStringA(psz)
  237. #endif
  238. void EnableOKButton(HWND hDlg, int id, LPTSTR pszText);
  239. BOOL IsExplorerWindow(HWND hwnd);
  240. BOOL IsFolderWindow(HWND hwnd);
  241. STDAPI_(BOOL) WasOpenedAsBrowser(IUnknown *punkSite);
  242. STDAPI_(HWND) GetTopLevelAncestor(HWND hWnd);
  243. STDAPI SHNavigateToFavorite(IShellFolder* psf, LPCITEMIDLIST pidl, IUnknown* punkSite, DWORD dwFlags);
  244. STDAPI SHGetTopBrowserWindow(IUnknown* punk, HWND* phwnd);
  245. STDAPI_(void) UpdateButtonArray(TBBUTTON *ptbDst, const TBBUTTON *ptbSrc, int ctb, LONG_PTR lStrOffset);
  246. STDAPI_(BOOL) DoesAppWantUrl(LPCTSTR pszCmdLine);
  247. STDAPI SHCreateThreadRef(LONG *pcRef, IUnknown **ppunk);
  248. BOOL ILIsFolder(LPCITEMIDLIST pidl);
  249. HRESULT URLToCacheFile(LPCWSTR pszUrl, LPWSTR pszFile, int cchFile);
  250. #ifdef DEBUG
  251. void DebugDumpPidl(DWORD dwDumpFlag, LPTSTR pszOutputString, LPCITEMIDLIST pidl);
  252. #else
  253. #define DebugDumpPidl(p, q, w)
  254. #endif
  255. STDAPI_(LPITEMIDLIST) SafeILClone(LPCITEMIDLIST pidl);
  256. #define ILClone SafeILClone
  257. WPARAM AnsiWparamToUnicode(WPARAM wParam);
  258. HMONITOR GetPrimaryMonitor();
  259. BOOL GetMonitorRects(HMONITOR hMon, LPRECT prc, BOOL bWork);
  260. #define GetMonitorRect(hMon, prc) \
  261. GetMonitorRects((hMon), (prc), FALSE)
  262. #define GetMonitorWorkArea(hMon, prc) \
  263. GetMonitorRects((hMon), (prc), TRUE)
  264. #define IsMonitorValid(hMon) \
  265. GetMonitorRects((hMon), NULL, TRUE)
  266. #define GetNumberOfMonitors() \
  267. GetSystemMetrics(SM_CMONITORS)
  268. void SHOutlineRect(HDC hdc, const RECT* prc, COLORREF cr);
  269. //------------------------------------------------------------------------
  270. typedef struct tagBMPCACHE
  271. {
  272. HBITMAP hbmp;
  273. COLORREF cr3D;
  274. } BMPCACHE;
  275. //------------------------------------------------------------------------
  276. // determine background settings and source for toolbar,
  277. // load bitmap (file/resource) and update cache
  278. HBITMAP LoadToolbarBackBmp(LPTSTR * ppszBitmap, BMPCACHE * pbmpCache, BOOL fInternet);
  279. UINT MapClsidToID(REFCLSID rclsid);
  280. VOID StripDecorations(PTSTR psz, BOOL fStripAmp);
  281. LPCTSTR UnescapeDoubleAmpersand(LPTSTR pszTitle);
  282. // Create mask from given bitmap, use color at pixel (x/y) as transparent color
  283. HBITMAP CreateMaskBitmap(HDC hdc, int x, int y, HBITMAP hbmpImage);
  284. // draw bitmap transparently; on Win2K and up, one could use MaskBlt()
  285. BOOL DrawTransparentBitmap(HDC hdc, int x, int y, HBITMAP hbmpImage, HBITMAP hbmpMask);
  286. BOOL DrawTransparentBitmapPart(HDC hdc, int x, int y, int dx, int dy, HBITMAP hbmpImage, HBITMAP hbmpMask);
  287. BOOL DrawAlphaBitmap(HDC hdc, int x, int y, int dx, int dy, HBITMAP hbmpImage);
  288. STDAPI_(IDeskBand *) FindBandByClsidBS(IBandSite *pbs, REFCLSID clsid);
  289. HIMAGELIST CreateImageList(HINSTANCE hi, LPCTSTR lpbmp, int cx, int cGrow, COLORREF crMask,
  290. UINT uType, UINT uFlags, BOOL bUseNewMirroringSupport);
  291. #ifdef __cplusplus
  292. //------------------------------------------------------------------------
  293. // ref count base class for non-COM classes
  294. class CRefCount
  295. {
  296. public:
  297. CRefCount() : _cRef(0) {};
  298. ULONG AddRef(void)
  299. {
  300. return InterlockedIncrement(&_cRef);
  301. }
  302. ULONG Release(void)
  303. {
  304. ASSERT( 0 != _cRef );
  305. ULONG cRef = InterlockedDecrement(&_cRef);
  306. if ( 0 == cRef )
  307. {
  308. delete this;
  309. }
  310. return cRef;
  311. }
  312. protected:
  313. virtual ~CRefCount() {};
  314. long _cRef;
  315. };
  316. //------------------------------------------------------------------------
  317. // smart pointer for non-COM classes
  318. template <class T>
  319. class _NoAddRefReleaseOnCRefPtr : public T
  320. {
  321. private:
  322. STDMETHOD_(ULONG, AddRef)()=0;
  323. STDMETHOD_(ULONG, Release)()=0;
  324. };
  325. //------------------------------------------------------------------------
  326. template<class T>
  327. class CRefPtr
  328. {
  329. public:
  330. CRefPtr()
  331. {
  332. _p = NULL;
  333. }
  334. CRefPtr(T* p)
  335. {
  336. _p = p;
  337. if (_p != NULL)
  338. _p->AddRef();
  339. }
  340. CRefPtr(const CRefPtr<T>& p)
  341. {
  342. _p = p;
  343. if (_p != NULL)
  344. _p->AddRef();
  345. }
  346. ~CRefPtr()
  347. {
  348. if (_p)
  349. _p->Release();
  350. }
  351. void Release()
  352. {
  353. T* pTemp = _p;
  354. if (pTemp)
  355. {
  356. _p = NULL;
  357. pTemp->Release();
  358. }
  359. }
  360. operator T*() const
  361. {
  362. return (T*)_p;
  363. }
  364. T& operator*() const
  365. {
  366. ASSERT(_p != NULL);
  367. return *_p;
  368. }
  369. //The assert on operator& usually indicates a bug. If this is really
  370. //what is needed, however, take the address of the p member explicitly.
  371. T** operator&()
  372. {
  373. ASSERT(_p == NULL);
  374. return &_p;
  375. }
  376. _NoAddRefReleaseOnCRefPtr<T>* operator->() const
  377. {
  378. ASSERT(_p != NULL);
  379. return (_NoAddRefReleaseOnCRefPtr<T>*)_p;
  380. }
  381. T* operator=(T* p)
  382. {
  383. if (p != NULL)
  384. p->AddRef();
  385. if (_p)
  386. (_p)->Release();
  387. _p = p;
  388. return p;
  389. }
  390. T* operator=(const CRefPtr<T>& p)
  391. {
  392. if (p != NULL)
  393. p->AddRef();
  394. if (_p)
  395. (_p)->Release();
  396. _p = p;
  397. return p;
  398. }
  399. bool operator!() const
  400. {
  401. return (_p == NULL);
  402. }
  403. bool operator<(T* pT) const
  404. {
  405. return _p < pT;
  406. }
  407. bool operator==(T* pT) const
  408. {
  409. return _p == pT;
  410. }
  411. T* Detach()
  412. {
  413. T* pt = _p;
  414. _p = NULL; // no release here, hand out live ptr!
  415. return pt;
  416. }
  417. private:
  418. T *_p;
  419. };
  420. #endif // __cplusplus
  421. #endif // _UTIL_H_