ReactOS  0.4.14-dev-608-gd495a4f
util.cpp File Reference
#include "precomp.h"
#include <winver.h>
Include dependency graph for util.cpp:

Go to the source code of this file.

Classes

struct  _LANGCODEPAGE
 

Typedefs

typedef struct _LANGCODEPAGE LANGCODEPAGE
 
typedef struct _LANGCODEPAGEPLANGCODEPAGE
 

Functions

HRESULT IsSameObject (IN IUnknown *punk1, IN IUnknown *punk2)
 
HMENU LoadPopupMenu (IN HINSTANCE hInstance, IN LPCWSTR lpMenuName)
 
HMENU FindSubMenu (IN HMENU hMenu, IN UINT uItem, IN BOOL fByPosition)
 
BOOL GetCurrentLoggedOnUserName (OUT LPWSTR szBuffer, IN DWORD dwBufferSize)
 
BOOL FormatMenuString (IN HMENU hMenu, IN UINT uPosition, IN UINT uFlags,...)
 
BOOL GetExplorerRegValueSet (IN HKEY hKey, IN LPCWSTR lpSubKey, IN LPCWSTR lpValue)
 
BOOL GetVersionInfoString (IN LPCWSTR szFileName, IN LPCWSTR szVersionInfo, OUT LPWSTR szBuffer, IN UINT cbBufLen)
 

Typedef Documentation

◆ LANGCODEPAGE

◆ PLANGCODEPAGE

Function Documentation

◆ FindSubMenu()

HMENU FindSubMenu ( IN HMENU  hMenu,
IN UINT  uItem,
IN BOOL  fByPosition 
)

Definition at line 55 of file util.cpp.

58 {
59  MENUITEMINFOW mii;
60 
61  mii.cbSize = sizeof(mii);
62  mii.fMask = MIIM_SUBMENU;
63 
64  if (GetMenuItemInfoW(hMenu, uItem, fByPosition, &mii))
65  {
66  return mii.hSubMenu;
67  }
68 
69  return NULL;
70 }
#define MIIM_SUBMENU
Definition: winuser.h:718
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI GetMenuItemInfoW(_In_ HMENU, _In_ UINT, _In_ BOOL, _Inout_ LPMENUITEMINFOW)

Referenced by CStartMenuSite::AppendMenu().

◆ FormatMenuString()

BOOL FormatMenuString ( IN HMENU  hMenu,
IN UINT  uPosition,
IN UINT  uFlags,
  ... 
)

Definition at line 106 of file util.cpp.

110 {
111  va_list vl;
112  MENUITEMINFOW mii;
113  WCHAR szBuf[128];
114  WCHAR szBufFmt[128];
115 
116  /* Find the menu item and read the formatting string */
117  mii.cbSize = sizeof(mii);
118  mii.fMask = MIIM_STRING;
119  mii.dwTypeData = szBufFmt;
120  mii.cch = _countof(szBufFmt);
121  if (GetMenuItemInfoW(hMenu, uPosition, uFlags, &mii))
122  {
123  /* Format the string */
124  va_start(vl, uFlags);
125  _vsntprintf(szBuf,
126  _countof(szBuf) - 1,
127  szBufFmt,
128  vl);
129  va_end(vl);
130  szBuf[_countof(szBuf) - 1] = L'\0';
131 
132  /* Update the menu item */
133  mii.dwTypeData = szBuf;
134  if (SetMenuItemInfo(hMenu, uPosition, uFlags, &mii))
135  {
136  return TRUE;
137  }
138  }
139 
140  return FALSE;
141 }
#define TRUE
Definition: types.h:120
#define _countof(array)
Definition: fontsub.cpp:30
LPWSTR dwTypeData
Definition: winuser.h:3244
UINT uFlags
Definition: api.c:59
#define va_end(ap)
Definition: acmsvcex.h:90
char * va_list
Definition: acmsvcex.h:78
#define SetMenuItemInfo
Definition: winuser.h:5825
BOOL WINAPI GetMenuItemInfoW(_In_ HMENU, _In_ UINT, _In_ BOOL, _Inout_ LPMENUITEMINFOW)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define _vsntprintf
Definition: xmlstorage.h:203
static const WCHAR L[]
Definition: oid.c:1250
#define MIIM_STRING
Definition: winuser.h:722
#define va_start(ap, A)
Definition: acmsvcex.h:91

Referenced by CStartMenuSite::AppendMenu().

◆ GetCurrentLoggedOnUserName()

BOOL GetCurrentLoggedOnUserName ( OUT LPWSTR  szBuffer,
IN DWORD  dwBufferSize 
)

Definition at line 73 of file util.cpp.

75 {
76  DWORD dwType;
77  DWORD dwSize;
78 
79  /* Query the user name from the registry */
80  dwSize = (dwBufferSize * sizeof(WCHAR)) - 1;
82  L"Logon User Name",
83  0,
84  &dwType,
85  (LPBYTE)szBuffer,
86  &dwSize) == ERROR_SUCCESS &&
87  (dwSize / sizeof(WCHAR)) > 1 &&
88  szBuffer[0] != L'\0')
89  {
90  szBuffer[dwSize / sizeof(WCHAR)] = L'\0';
91  return TRUE;
92  }
93 
94  /* Fall back to GetUserName() */
95  dwSize = dwBufferSize;
96  if (!GetUserNameW(szBuffer, &dwSize))
97  {
98  szBuffer[0] = L'\0';
99  return FALSE;
100  }
101 
102  return TRUE;
103 }
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
HKEY hkExplorer
Definition: explorer.cpp:26
unsigned char * LPBYTE
Definition: typedefs.h:52
BOOL WINAPI GetUserNameW(LPWSTR lpszName, LPDWORD lpSize)
Definition: misc.c:291
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4116
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54

Referenced by CStartMenuSite::AppendMenu().

◆ GetExplorerRegValueSet()

BOOL GetExplorerRegValueSet ( IN HKEY  hKey,
IN LPCWSTR  lpSubKey,
IN LPCWSTR  lpValue 
)

Definition at line 144 of file util.cpp.

147 {
148  WCHAR szBuffer[MAX_PATH];
149  HKEY hkSubKey;
150  DWORD dwType, dwSize;
151  BOOL Ret = FALSE;
152 
153  StringCbCopyW(szBuffer, sizeof(szBuffer),
154  L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer");
155  if (FAILED_UNEXPECTEDLY(StringCbCatW(szBuffer, sizeof(szBuffer), L"\\")))
156  return FALSE;
157  if (FAILED_UNEXPECTEDLY(StringCbCatW(szBuffer, sizeof(szBuffer), lpSubKey)))
158  return FALSE;
159 
160  dwSize = sizeof(szBuffer);
161  if (RegOpenKeyExW(hKey,
162  szBuffer,
163  0,
165  &hkSubKey) == ERROR_SUCCESS)
166  {
167  ZeroMemory(szBuffer, sizeof(szBuffer));
168 
169  if (RegQueryValueExW(hkSubKey,
170  lpValue,
171  0,
172  &dwType,
173  (LPBYTE)szBuffer,
174  &dwSize) == ERROR_SUCCESS)
175  {
176  if ((dwType == REG_DWORD) && (dwSize == sizeof(DWORD)))
177  Ret = *((PDWORD)szBuffer) != 0;
178  else if (dwSize > 0)
179  Ret = *((PWCHAR)szBuffer) != 0;
180  }
181 
182  RegCloseKey(hkSubKey);
183  }
184  return Ret;
185 }
#define ERROR_SUCCESS
Definition: deptool.c:10
#define ZeroMemory
Definition: winbase.h:1642
uint16_t * PWCHAR
Definition: typedefs.h:54
STRSAFEAPI StringCbCatW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:342
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
unsigned int BOOL
Definition: ntddk_ex.h:94
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4116
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define FAILED_UNEXPECTEDLY(hr)
Definition: shellutils.h:71
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
DWORD * PDWORD
Definition: pedump.c:68
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
STRSAFEAPI StringCbCopyW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:166
#define REG_DWORD
Definition: sdbapi.c:596
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54

Referenced by CStartMenuSite::AppendMenu().

◆ GetVersionInfoString()

BOOL GetVersionInfoString ( IN LPCWSTR  szFileName,
IN LPCWSTR  szVersionInfo,
OUT LPWSTR  szBuffer,
IN UINT  cbBufLen 
)

Definition at line 188 of file util.cpp.

192 {
193  LPVOID lpData = NULL;
194  WCHAR szSubBlock[128];
195  WCHAR *lpszLocalBuf = NULL;
196  LANGID UserLangId;
198  DWORD dwLen;
199  DWORD dwHandle;
200  UINT cbTranslate;
201  UINT cbLen;
202  BOOL bRet = FALSE;
203  UINT i;
204 
205  dwLen = GetFileVersionInfoSizeW(szFileName, &dwHandle);
206 
207  if (dwLen > 0)
208  {
209  lpData = HeapAlloc(hProcessHeap, 0, dwLen);
210 
211  if (lpData != NULL)
212  {
213  if (GetFileVersionInfoW(szFileName,
214  0,
215  dwLen,
216  lpData) != 0)
217  {
218  UserLangId = GetUserDefaultLangID();
219 
220  VerQueryValueW(lpData,
221  L"\\VarFileInfo\\Translation",
222  (LPVOID*)&lpTranslate,
223  &cbTranslate);
224 
225  for (i = 0; i < cbTranslate / sizeof(LANGCODEPAGE); i++)
226  {
227  /* If the bottom eight bits of the language id's
228  match, use this version information (since this
229  means that the version information and the users
230  default language are the same). */
231  if (LOBYTE(lpTranslate[i].wLanguage) == LOBYTE(UserLangId))
232  {
233  wnsprintf(szSubBlock,
234  _countof(szSubBlock),
235  L"\\StringFileInfo\\%04X%04X\\%s",
236  lpTranslate[i].wLanguage,
237  lpTranslate[i].wCodePage,
238  szVersionInfo);
239 
240  if (VerQueryValueW(lpData,
241  szSubBlock,
242  (LPVOID*)&lpszLocalBuf,
243  &cbLen) != 0)
244  {
245  wcsncpy(szBuffer, lpszLocalBuf, cbBufLen / sizeof(*szBuffer));
246 
247  bRet = TRUE;
248  break;
249  }
250  }
251  }
252  }
253 
254  HeapFree(hProcessHeap, 0, lpData);
255  lpData = NULL;
256  }
257  }
258 
259  return bRet;
260 }
#define TRUE
Definition: types.h:120
#define LOBYTE(W)
Definition: jmemdos.c:487
#define _countof(array)
Definition: fontsub.cpp:30
WORD LANGID
Definition: typedefs.h:79
#define wnsprintf
Definition: shlwapi.h:1701
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
struct LANGANDCODEPAGE * lpTranslate
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
struct _LANGCODEPAGE LANGCODEPAGE
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
DWORD WINAPI GetFileVersionInfoSizeW(LPCWSTR filename, LPDWORD handle)
Definition: version.c:611
_CRTIMP wchar_t *__cdecl wcsncpy(wchar_t *_Dest, const wchar_t *_Source, size_t _Count)
unsigned int UINT
Definition: ndis.h:50
BOOL WINAPI GetFileVersionInfoW(LPCWSTR filename, DWORD handle, DWORD datasize, LPVOID data)
Definition: version.c:845
LANGID WINAPI GetUserDefaultLangID(void)
Definition: lang.c:734
#define HeapFree(x, y, z)
Definition: compat.h:402
HANDLE hProcessHeap
Definition: kbswitch.c:25
BOOL WINAPI VerQueryValueW(LPCVOID pBlock, LPCWSTR lpSubBlock, LPVOID *lplpBuffer, PUINT puLen)
Definition: version.c:1049

◆ IsSameObject()

HRESULT IsSameObject ( IN IUnknown punk1,
IN IUnknown punk2 
)

Definition at line 11 of file util.cpp.

12 {
13  HRESULT hRet;
14 
15  hRet = punk1->QueryInterface(IID_PPV_ARG(IUnknown, &punk1));
16  if (!SUCCEEDED(hRet))
17  return hRet;
18 
19  hRet = punk2->QueryInterface(IID_PPV_ARG(IUnknown, &punk2));
20 
21  punk1->Release();
22 
23  if (!SUCCEEDED(hRet))
24  return hRet;
25 
26  punk2->Release();
27 
28  /* We're dealing with the same object if the IUnknown pointers are equal */
29  return (punk1 == punk2) ? S_OK : S_FALSE;
30 }
#define IID_PPV_ARG(Itype, ppType)
#define S_FALSE
Definition: winerror.h:2357
LONG HRESULT
Definition: typedefs.h:77
#define S_OK
Definition: intsafe.h:59
#define SUCCEEDED(hr)
Definition: intsafe.h:57

Referenced by CTrayBandSite::IsTaskBand(), and CTrayBandSite::QueryBand().

◆ LoadPopupMenu()

HMENU LoadPopupMenu ( IN HINSTANCE  hInstance,
IN LPCWSTR  lpMenuName 
)

Definition at line 33 of file util.cpp.

35 {
36  HMENU hMenu, hSubMenu = NULL;
37 
38  hMenu = LoadMenuW(hInstance, lpMenuName);
39  if (hMenu != NULL)
40  {
41  hSubMenu = GetSubMenu(hMenu, 0);
42  if ((hSubMenu != NULL) &&
43  !RemoveMenu(hMenu, 0, MF_BYPOSITION))
44  {
45  hSubMenu = NULL;
46  }
47 
48  DestroyMenu(hMenu);
49  }
50 
51  return hSubMenu;
52 }
HINSTANCE hInstance
Definition: charmap.c:20
#define MF_BYPOSITION
Definition: winuser.h:203
smooth NULL
Definition: ftsmooth.c:416
HMENU WINAPI GetSubMenu(_In_ HMENU, _In_ int)
BOOL WINAPI DestroyMenu(_In_ HMENU)
BOOL WINAPI RemoveMenu(_In_ HMENU, _In_ UINT, _In_ UINT)
HMENU WINAPI LoadMenuW(_In_opt_ HINSTANCE, _In_ LPCWSTR)
static const CLSID *static CLSID *static const GUID VARIANT VARIANT *static IServiceProvider DWORD *static HMENU
Definition: ordinal.c:60

Referenced by CStartMenuSite::AppendMenu(), CTrayWindowCtxMenu::QueryContextMenu(), and SettingsPageProc().