utility.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. LICENSE
  3. -------
  4. Copyright 2005-2013 Nullsoft, Inc.
  5. All rights reserved.
  6. Redistribution and use in source and binary forms, with or without modification,
  7. are permitted provided that the following conditions are met:
  8. * Redistributions of source code must retain the above copyright notice,
  9. this list of conditions and the following disclaimer.
  10. * Redistributions in binary form must reproduce the above copyright notice,
  11. this list of conditions and the following disclaimer in the documentation
  12. and/or other materials provided with the distribution.
  13. * Neither the name of Nullsoft nor the names of its contributors may be used to
  14. endorse or promote products derived from this software without specific prior written permission.
  15. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
  16. IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  17. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  18. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  19. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  20. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  21. IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  22. OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. */
  24. #ifndef __NULLSOFT_DX9_PLUGIN_SHELL_UTILITY_H__
  25. #define __NULLSOFT_DX9_PLUGIN_SHELL_UTILITY_H__ 1
  26. #include <windows.h>
  27. #include <crtdefs.h>
  28. #include <d3d9.h>
  29. #include <d3dx9.h>
  30. #define SafeRelease(x) { if (x) {x->Release(); x=NULL;} }
  31. #define SafeDelete(x) { if (x) {delete x; x=NULL;} }
  32. #define IsNullGuid(lpGUID) ( ((int*)lpGUID)[0]==0 && ((int*)lpGUID)[1]==0 && ((int*)lpGUID)[2]==0 && ((int*)lpGUID)[3]==0 )
  33. #define DlgItemIsChecked(hDlg, nIDDlgItem) ((SendDlgItemMessage(hDlg, nIDDlgItem, BM_GETCHECK, (WPARAM) 0, (LPARAM) 0) == BST_CHECKED) ? true : false)
  34. #define CosineInterp(x) (0.5f - 0.5f*cosf((x) * 3.1415926535898f))
  35. #define InvCosineInterp(x) (acosf(1.0f - 2.0f*(x))/3.1415926535898f)
  36. float PowCosineInterp(float x, float pow);
  37. float AdjustRateToFPS(float per_frame_decay_rate_at_fps1, float fps1, float actual_fps);
  38. //int GetPrivateProfileInt - part of Win32 API
  39. #define GetPrivateProfileBoolW(w,x,y,z) ((bool)(GetPrivateProfileIntW(w,x,y,z) != 0))
  40. #define GetPrivateProfileBOOLW(w,x,y,z) ((BOOL)(GetPrivateProfileIntW(w,x,y,z) != 0))
  41. float GetPrivateProfileFloatW(wchar_t *szSectionName, wchar_t *szKeyName, float fDefault, wchar_t *szIniFile);
  42. bool WritePrivateProfileIntW(int d, wchar_t *szKeyName, wchar_t *szIniFile, wchar_t *szSectionName);
  43. bool WritePrivateProfileFloatW(float f, wchar_t *szKeyName, wchar_t *szIniFile, wchar_t *szSectionName);
  44. extern _locale_t g_use_C_locale;
  45. extern char keyMappings[8];
  46. void SetScrollLock(int bNewState, bool bPreventHandling);
  47. void RemoveExtension(wchar_t *str);
  48. void RemoveSingleAmpersands(wchar_t *str);
  49. void TextToGuid(char *str, GUID *pGUID);
  50. void GuidToText(GUID *pGUID, char *str, int nStrLen);
  51. //int GetPentiumTimeRaw(unsigned __int64 *cpu_timestamp);
  52. //double GetPentiumTimeAsDouble(unsigned __int64 frequency);
  53. #ifdef _DEBUG
  54. void OutputDebugMessage(char *szStartText, HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam); // only available in RELEASE builds!
  55. #endif
  56. void MissingDirectX(HWND hwnd);
  57. bool CheckForMMX();
  58. bool CheckForSSE();
  59. void GetDesktopFolder(char *szDesktopFolder); // should be MAX_PATH len.
  60. #include "icon_t.h"
  61. #include <shlobj.h>
  62. #include <list>
  63. BOOL DoExplorerMenu (HWND hwnd, LPCTSTR pszPath, POINT point);
  64. BOOL DoExplorerMenu (HWND hwnd, LPITEMIDLIST pidl, POINT point);
  65. UINT GetItemCount (LPITEMIDLIST pidl);
  66. LPITEMIDLIST GetNextItem (LPITEMIDLIST pidl);
  67. LPITEMIDLIST DuplicateItem (LPMALLOC pMalloc, LPITEMIDLIST pidl);
  68. void FindDesktopWindows(HWND *desktop_progman, HWND *desktopview_wnd, HWND *listview_wnd);
  69. void ExecutePidl(LPITEMIDLIST pidl, char *szPathAndFile, char *szWorkingDirectory, HWND hWnd);
  70. int GetDesktopIconSize();
  71. // handy functions for populating Combo Boxes:
  72. inline void AddItem(HWND ctrl, const wchar_t* text, DWORD itemdata) {
  73. LRESULT nPos = SendMessageW( ctrl, CB_ADDSTRING, 0, (LPARAM)text);
  74. SendMessage( ctrl, CB_SETITEMDATA, nPos, itemdata);
  75. }
  76. inline void SelectItemByPos(HWND ctrl, int pos) {
  77. SendMessage(ctrl, CB_SETCURSEL, pos, 0);
  78. }
  79. int SelectItemByValue(HWND ctrl, DWORD value);
  80. bool ReadCBValue(HWND hwnd, DWORD ctrl_id, int* pRetValue);
  81. LRESULT GetWinampVersion(HWND winamp);
  82. void* GetTextResource(UINT id, int no_fallback);
  83. HMODULE FindD3DX9(HWND winamp);
  84. intptr_t myOpenURL(HWND hwnd, wchar_t *loc);
  85. typedef HRESULT (WINAPI *D3DXCREATEFONTW)(LPDIRECT3DDEVICE9, INT, UINT, UINT, UINT, BOOL, DWORD, DWORD, DWORD, DWORD, LPCWSTR, LPD3DXFONT *);
  86. extern D3DXCREATEFONTW pCreateFontW;
  87. typedef D3DXMATRIX *(WINAPI *D3DXMATRIXMULTIPLY)(D3DXMATRIX *pOut, CONST D3DXMATRIX *pM1, CONST D3DXMATRIX *pM2);
  88. extern D3DXMATRIXMULTIPLY pMatrixMultiply;
  89. typedef D3DXMATRIX* (WINAPI *D3DXMATRIXTRANSLATION)( D3DXMATRIX *pOut, FLOAT x, FLOAT y, FLOAT z );
  90. extern D3DXMATRIXTRANSLATION pMatrixTranslation;
  91. typedef D3DXMATRIX* (WINAPI *D3DXMATRIXSCALING)( D3DXMATRIX *pOut, FLOAT sx, FLOAT sy, FLOAT sz );
  92. extern D3DXMATRIXSCALING pMatrixScaling;
  93. typedef D3DXMATRIX* (WINAPI *D3DXMATRIXROTATION)( D3DXMATRIX *pOut, FLOAT Angle );
  94. extern D3DXMATRIXROTATION pMatrixRotationX, pMatrixRotationY, pMatrixRotationZ;
  95. typedef HRESULT (WINAPI *D3DXCREATETEXTUREFROMFILEEXW)(
  96. LPDIRECT3DDEVICE9 pDevice,
  97. LPCWSTR pSrcFile,
  98. UINT Width,
  99. UINT Height,
  100. UINT MipLevels,
  101. DWORD Usage,
  102. D3DFORMAT Format,
  103. D3DPOOL Pool,
  104. DWORD Filter,
  105. DWORD MipFilter,
  106. D3DCOLOR ColorKey,
  107. D3DXIMAGE_INFO* pSrcInfo,
  108. PALETTEENTRY* pPalette,
  109. LPDIRECT3DTEXTURE9* ppTexture);
  110. extern D3DXCREATETEXTUREFROMFILEEXW pCreateTextureFromFileExW;
  111. typedef D3DXMATRIX* (WINAPI *D3DXMATRIXORTHOLH)(D3DXMATRIX *pOut, FLOAT w, FLOAT h, FLOAT zn, FLOAT zf);
  112. extern D3DXMATRIXORTHOLH pMatrixOrthoLH;
  113. typedef HRESULT (WINAPI *D3DXCOMPILESHADER)(
  114. LPCSTR pSrcData,
  115. UINT SrcDataLen,
  116. CONST D3DXMACRO* pDefines,
  117. LPD3DXINCLUDE pInclude,
  118. LPCSTR pFunctionName,
  119. LPCSTR pProfile,
  120. DWORD Flags,
  121. LPD3DXBUFFER* ppShader,
  122. LPD3DXBUFFER* ppErrorMsgs,
  123. LPD3DXCONSTANTTABLE* ppConstantTable);
  124. extern D3DXCOMPILESHADER pCompileShader;
  125. typedef D3DXMATRIX* (WINAPI *D3DXMATRIXLOOKATLH)( D3DXMATRIX *pOut, CONST D3DXVECTOR3 *pEye, CONST D3DXVECTOR3 *pAt, CONST D3DXVECTOR3 *pUp );
  126. extern D3DXMATRIXLOOKATLH pMatrixLookAtLH;
  127. typedef HRESULT (WINAPI *D3DXCREATETEXTURE)(
  128. LPDIRECT3DDEVICE9 pDevice,
  129. UINT Width,
  130. UINT Height,
  131. UINT MipLevels,
  132. DWORD Usage,
  133. D3DFORMAT Format,
  134. D3DPOOL Pool,
  135. LPDIRECT3DTEXTURE9* ppTexture);
  136. extern D3DXCREATETEXTURE pCreateTexture;
  137. #endif