ReactOS  0.4.15-dev-3173-g40ee59d
shell32_apitest_sub.cpp File Reference
#include "shelltest.h"
#include <shlwapi.h>
#include <stdio.h>
#include "SHChangeNotify.h"
Include dependency graph for shell32_apitest_sub.cpp:

Go to the source code of this file.

Functions

static BOOL OnCreate (HWND hwnd)
 
static void OnCommand (HWND hwnd, UINT id)
 
static void OnDestroy (HWND hwnd)
 
static void DoShellNotify (HWND hwnd, PIDLIST_ABSOLUTE pidl1, PIDLIST_ABSOLUTE pidl2, LONG lEvent)
 
static INT_PTR OnShellNotify (HWND hwnd, WPARAM wParam, LPARAM lParam)
 
static LRESULT OnGetNotifyFlags (HWND hwnd)
 
static void DoSetPaths (HWND hwnd)
 
static LRESULT CALLBACK WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
INT APIENTRY wWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, INT nCmdShow)
 

Variables

static HWND s_hwnd = NULL
 
static const WCHAR s_szName [] = L"SHChangeNotify testcase"
 
static INT s_nMode
 
static BYTE s_counters [TYPE_RENAMEFOLDER+1]
 
static UINT s_uRegID = 0
 
static WCHAR s_path1 [MAX_PATH]
 
static WCHAR s_path2 [MAX_PATH]
 
static LPITEMIDLIST s_pidl = NULL
 
static SHChangeNotifyEntry s_entry
 

Function Documentation

◆ DoSetPaths()

static void DoSetPaths ( HWND  hwnd)
static

Definition at line 208 of file shell32_apitest_sub.cpp.

209 {
210  WCHAR szText[MAX_PATH * 2];
212  lstrcatW(szText, L"|");
214 
215  if (FILE *fp = fopen(TEMP_FILE, "wb"))
216  {
217  fwrite(szText, (lstrlenW(szText) + 1) * sizeof(WCHAR), 1, fp);
218  fflush(fp);
219  fclose(fp);
220  }
221 }
_Check_return_opt_ _CRTIMP size_t __cdecl fwrite(_In_reads_bytes_(_Size *_Count) const void *_Str, _In_ size_t _Size, _In_ size_t _Count, _Inout_ FILE *_File)
#define lstrlenW
Definition: compat.h:609
static const WCHAR szText[]
Definition: dialog.c:139
static WCHAR s_path1[MAX_PATH]
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:34
static WCHAR s_path2[MAX_PATH]
static const WCHAR L[]
Definition: oid.c:1250
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
#define TEMP_FILE
Definition: SHChangeNotify.h:3
#define lstrcpyW
Definition: compat.h:608
_Check_return_opt_ _CRTIMP int __cdecl fflush(_Inout_opt_ FILE *_File)
LPWSTR WINAPI lstrcatW(LPWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:274

Referenced by WindowProc().

◆ DoShellNotify()

static void DoShellNotify ( HWND  hwnd,
PIDLIST_ABSOLUTE  pidl1,
PIDLIST_ABSOLUTE  pidl2,
LONG  lEvent 
)
static

Definition at line 104 of file shell32_apitest_sub.cpp.

105 {
106  if (pidl1)
108  else
109  s_path1[0] = 0;
110 
111  if (pidl2)
113  else
114  s_path2[0] = 0;
115 
116  switch (lEvent)
117  {
118  case SHCNE_RENAMEITEM:
120  break;
121  case SHCNE_CREATE:
122  s_counters[TYPE_CREATE] = 1;
123  break;
124  case SHCNE_DELETE:
125  s_counters[TYPE_DELETE] = 1;
126  break;
127  case SHCNE_MKDIR:
128  s_counters[TYPE_MKDIR] = 1;
129  break;
130  case SHCNE_RMDIR:
131  s_counters[TYPE_RMDIR] = 1;
132  break;
133  case SHCNE_MEDIAINSERTED:
134  break;
135  case SHCNE_MEDIAREMOVED:
136  break;
137  case SHCNE_DRIVEREMOVED:
138  break;
139  case SHCNE_DRIVEADD:
140  break;
141  case SHCNE_NETSHARE:
142  break;
143  case SHCNE_NETUNSHARE:
144  break;
145  case SHCNE_ATTRIBUTES:
146  break;
147  case SHCNE_UPDATEDIR:
149  break;
150  case SHCNE_UPDATEITEM:
152  break;
154  break;
155  case SHCNE_UPDATEIMAGE:
156  break;
157  case SHCNE_DRIVEADDGUI:
158  break;
159  case SHCNE_RENAMEFOLDER:
161  break;
162  case SHCNE_FREESPACE:
163  break;
165  break;
166  case SHCNE_ASSOCCHANGED:
167  break;
168  default:
169  break;
170  }
171 }
#define SHCNE_MKDIR
Definition: shlobj.h:1732
#define SHCNE_ATTRIBUTES
Definition: shlobj.h:1740
#define SHCNE_RMDIR
Definition: shlobj.h:1733
#define SHCNE_UPDATEIMAGE
Definition: shlobj.h:1744
#define SHCNE_NETUNSHARE
Definition: shlobj.h:1739
#define SHCNE_RENAMEFOLDER
Definition: shlobj.h:1746
BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath)
Definition: pidl.c:1294
#define SHCNE_RENAMEITEM
Definition: shlobj.h:1729
static WCHAR s_path1[MAX_PATH]
#define SHCNE_MEDIAREMOVED
Definition: shlobj.h:1735
static BYTE s_counters[TYPE_RENAMEFOLDER+1]
static WCHAR s_path2[MAX_PATH]
#define SHCNE_EXTENDED_EVENT
Definition: shlobj.h:1749
HANDLE lEvent
Definition: tftpd.cpp:56
#define SHCNE_FREESPACE
Definition: shlobj.h:1747
#define SHCNE_DELETE
Definition: shlobj.h:1731
#define SHCNE_UPDATEDIR
Definition: shlobj.h:1741
#define SHCNE_NETSHARE
Definition: shlobj.h:1738
#define SHCNE_MEDIAINSERTED
Definition: shlobj.h:1734
#define SHCNE_DRIVEADD
Definition: shlobj.h:1737
#define SHCNE_SERVERDISCONNECT
Definition: shlobj.h:1743
#define SHCNE_CREATE
Definition: shlobj.h:1730
#define SHCNE_UPDATEITEM
Definition: shlobj.h:1742
#define SHCNE_DRIVEADDGUI
Definition: shlobj.h:1745
#define SHCNE_DRIVEREMOVED
Definition: shlobj.h:1736
#define SHCNE_ASSOCCHANGED
Definition: shlobj.h:1750

Referenced by OnShellNotify().

◆ OnCommand()

static void OnCommand ( HWND  hwnd,
UINT  id 
)
static

Definition at line 79 of file shell32_apitest_sub.cpp.

80 {
81  switch (id)
82  {
83  case IDOK:
84  case IDCANCEL:
86  break;
87  }
88 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
#define IDOK
Definition: winuser.h:824
BOOL WINAPI DestroyWindow(_In_ HWND)
#define IDCANCEL
Definition: winuser.h:825

Referenced by WindowProc().

◆ OnCreate()

static BOOL OnCreate ( HWND  hwnd)
static

Definition at line 26 of file shell32_apitest_sub.cpp.

27 {
28  s_hwnd = hwnd;
29 
30  DoInitPaths();
31 
34 
35  INT nSources;
36  switch (s_nMode)
37  {
38  case 0:
40  nSources = SHCNRF_ShellLevel;
41  break;
42 
43  case 1:
46  break;
47 
48  case 2:
51  break;
52 
53  case 3:
56  break;
57 
58  case 4:
61  break;
62 
63  case 5:
66  s_entry.pidl = NULL;
67  break;
68 
69  default:
70  return FALSE;
71  }
72  LONG fEvents = SHCNE_ALLEVENTS;
74  1, &s_entry);
75  return s_uRegID != 0;
76 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
void DoInitPaths(void)
#define TRUE
Definition: types.h:120
#define SHCNRF_RecursiveInterrupt
Definition: shlobj.h:1776
static WCHAR s_dir1[MAX_PATH]
int32_t INT
Definition: typedefs.h:58
static INT s_nMode
#define FALSE
Definition: types.h:117
#define SHCNE_ALLEVENTS
Definition: shlobj.h:1753
long LONG
Definition: pedump.c:60
#define SHCNRF_InterruptLevel
Definition: shlobj.h:1774
static LPITEMIDLIST s_pidl
#define SHCNRF_ShellLevel
Definition: shlobj.h:1775
#define WM_SHELL_NOTIFY
PCIDLIST_ABSOLUTE pidl
Definition: shlobj.h:1725
static SHChangeNotifyEntry s_entry
#define SHCNRF_NewDelivery
Definition: shlobj.h:1777
#define NULL
Definition: types.h:112
static UINT s_uRegID
EXTERN_C ULONG WINAPI SHChangeNotifyRegister(HWND hwnd, INT fSources, LONG wEventMask, UINT uMsg, INT cItems, SHChangeNotifyEntry *lpItems)
LPITEMIDLIST WINAPI ILCreateFromPathW(LPCWSTR path)
Definition: pidl.c:982
static HWND s_hwnd

Referenced by WindowProc().

◆ OnDestroy()

static void OnDestroy ( HWND  hwnd)
static

Definition at line 91 of file shell32_apitest_sub.cpp.

92 {
94  s_uRegID = 0;
95 
97  s_pidl = NULL;
98 
99  PostQuitMessage(0);
100  s_hwnd = NULL;
101 }
VOID WINAPI CoTaskMemFree(LPVOID ptr)
Definition: ifs.c:442
static LPITEMIDLIST s_pidl
EXTERN_C BOOL WINAPI SHChangeNotifyDeregister(ULONG hNotify)
#define NULL
Definition: types.h:112
static UINT s_uRegID
static HWND s_hwnd
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)

Referenced by WindowProc().

◆ OnGetNotifyFlags()

static LRESULT OnGetNotifyFlags ( HWND  hwnd)
static

Definition at line 193 of file shell32_apitest_sub.cpp.

194 {
195  if (s_uRegID == 0)
196  return 0xFFFFFFFF;
197 
198  DWORD dwFlags = 0;
199  for (size_t i = 0; i < _countof(s_counters); ++i)
200  {
201  if (s_counters[i])
202  dwFlags |= (1 << i);
203  }
204  return dwFlags;
205 }
#define _countof(array)
Definition: sndvol32.h:68
static BYTE s_counters[TYPE_RENAMEFOLDER+1]
unsigned long DWORD
Definition: ntddk_ex.h:95
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
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
static UINT s_uRegID

Referenced by WindowProc().

◆ OnShellNotify()

static INT_PTR OnShellNotify ( HWND  hwnd,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 174 of file shell32_apitest_sub.cpp.

175 {
176  LONG lEvent;
177  PIDLIST_ABSOLUTE *pidlAbsolute;
178  HANDLE hLock = SHChangeNotification_Lock((HANDLE)wParam, (DWORD)lParam, &pidlAbsolute, &lEvent);
179  if (hLock)
180  {
181  DoShellNotify(hwnd, pidlAbsolute[0], pidlAbsolute[1], lEvent);
183  }
184  else
185  {
186  pidlAbsolute = (PIDLIST_ABSOLUTE *)wParam;
187  DoShellNotify(hwnd, pidlAbsolute[0], pidlAbsolute[1], lParam);
188  }
189  return TRUE;
190 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
EXTERN_C BOOL WINAPI SHChangeNotification_Unlock(HANDLE hLock)
#define TRUE
Definition: types.h:120
WPARAM wParam
Definition: combotst.c:138
long LONG
Definition: pedump.c:60
static void DoShellNotify(HWND hwnd, PIDLIST_ABSOLUTE pidl1, PIDLIST_ABSOLUTE pidl2, LONG lEvent)
unsigned long DWORD
Definition: ntddk_ex.h:95
HANDLE lEvent
Definition: tftpd.cpp:56
EXTERN_C HANDLE WINAPI SHChangeNotification_Lock(HANDLE hTicket, DWORD dwOwnerPID, LPITEMIDLIST **lppidls, LPLONG lpwEventId)
LPARAM lParam
Definition: combotst.c:139

Referenced by WindowProc().

◆ WindowProc()

static LRESULT CALLBACK WindowProc ( HWND  hwnd,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 224 of file shell32_apitest_sub.cpp.

225 {
226  switch (uMsg)
227  {
228  case WM_CREATE:
229  return (OnCreate(hwnd) ? 0 : -1);
230 
231  case WM_COMMAND:
233  break;
234 
235  case WM_SHELL_NOTIFY:
236  return OnShellNotify(hwnd, wParam, lParam);
237 
238  case WM_DESTROY:
239  OnDestroy(hwnd);
240  break;
241 
242  case WM_GET_NOTIFY_FLAGS:
243  return OnGetNotifyFlags(hwnd);
244 
245  case WM_CLEAR_FLAGS:
246  ZeroMemory(&s_counters, sizeof(s_counters));
247  break;
248 
249  case WM_SET_PATHS:
250  DoSetPaths(hwnd);
251  break;
252 
253  default:
254  return DefWindowProcW(hwnd, uMsg, wParam, lParam);
255  }
256  return 0;
257 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
static void OnDestroy(HWND hwnd)
UINT uMsg
Definition: menu.cpp:213
static LRESULT OnGetNotifyFlags(HWND hwnd)
#define ZeroMemory
Definition: winbase.h:1664
static BOOL OnCreate(HWND hwnd)
WPARAM wParam
Definition: combotst.c:138
LRESULT WINAPI DefWindowProcW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
static void OnCommand(HWND hwnd, UINT id)
#define WM_CLEAR_FLAGS
#define WM_SET_PATHS
#define WM_DESTROY
Definition: winuser.h:1592
static BYTE s_counters[TYPE_RENAMEFOLDER+1]
#define WM_SHELL_NOTIFY
#define WM_GET_NOTIFY_FLAGS
#define WM_COMMAND
Definition: winuser.h:1723
#define WM_CREATE
Definition: winuser.h:1591
static INT_PTR OnShellNotify(HWND hwnd, WPARAM wParam, LPARAM lParam)
static void DoSetPaths(HWND hwnd)
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82

Referenced by wWinMain().

◆ wWinMain()

INT APIENTRY wWinMain ( HINSTANCE  hInstance,
HINSTANCE  hPrevInstance,
LPWSTR  lpCmdLine,
INT  nCmdShow 
)

Definition at line 260 of file shell32_apitest_sub.cpp.

264 {
265  if (lstrcmpiW(lpCmdLine, L"") == 0 || lstrcmpiW(lpCmdLine, L"TEST") == 0)
266  return 0;
267 
268  s_nMode = _wtoi(lpCmdLine);
269 
270  WNDCLASSW wc;
271  ZeroMemory(&wc, sizeof(wc));
272  wc.lpfnWndProc = WindowProc;
276  wc.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
277  wc.lpszClassName = s_szName;
278  if (!RegisterClassW(&wc))
279  return -1;
280 
282  CW_USEDEFAULT, CW_USEDEFAULT, 100, 100,
284  if (!hwnd)
285  return -1;
286 
289 
290  MSG msg;
291  while (GetMessageW(&msg, NULL, 0, 0))
292  {
295  }
296 
297  return 0;
298 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
BOOL WINAPI TranslateMessage(_In_ const MSG *)
_Check_return_ _CRTIMP int __cdecl _wtoi(_In_z_ const wchar_t *_Str)
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
BOOL WINAPI UpdateWindow(_In_ HWND)
#define ZeroMemory
Definition: winbase.h:1664
#define IDI_APPLICATION
Definition: winuser.h:699
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
#define CreateWindowW(a, b, c, d, e, f, g, h, i, j, k)
Definition: winuser.h:4292
int WINAPI lstrcmpiW(LPCWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:194
static INT s_nMode
ATOM WINAPI RegisterClassW(_In_ CONST WNDCLASSW *)
#define COLOR_3DFACE
Definition: winuser.h:919
LRESULT WINAPI DispatchMessageW(_In_ const MSG *)
WNDPROC lpfnWndProc
Definition: winuser.h:3153
#define CW_USEDEFAULT
Definition: winuser.h:225
LPCWSTR lpszClassName
Definition: winuser.h:3161
static const WCHAR s_szName[]
HICON hIcon
Definition: winuser.h:3157
static const WCHAR L[]
Definition: oid.c:1250
#define LoadCursor
Definition: winuser.h:5788
HCURSOR hCursor
Definition: winuser.h:3158
#define SW_SHOWNORMAL
Definition: winuser.h:764
HBRUSH hbrBackground
Definition: winuser.h:3159
static LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
#define NULL
Definition: types.h:112
BOOL WINAPI GetMessageW(_Out_ LPMSG, _In_opt_ HWND, _In_ UINT, _In_ UINT)
HINSTANCE hInstance
Definition: winuser.h:3156
#define msg(x)
Definition: auth_time.c:54
#define IDC_ARROW
Definition: winuser.h:682
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
#define LoadIcon
Definition: winuser.h:5789

Variable Documentation

◆ s_counters

BYTE s_counters[TYPE_RENAMEFOLDER+1]
static

Definition at line 17 of file shell32_apitest_sub.cpp.

Referenced by DoShellNotify(), OnGetNotifyFlags(), and WindowProc().

◆ s_entry

◆ s_hwnd

HWND s_hwnd = NULL
static

Definition at line 13 of file shell32_apitest_sub.cpp.

Referenced by OnCreate(), and OnDestroy().

◆ s_nMode

INT s_nMode
static

Definition at line 15 of file shell32_apitest_sub.cpp.

Referenced by OnCreate(), and wWinMain().

◆ s_path1

WCHAR s_path1[MAX_PATH]
static

Definition at line 20 of file shell32_apitest_sub.cpp.

Referenced by DoSetPaths(), and DoShellNotify().

◆ s_path2

WCHAR s_path2[MAX_PATH]
static

Definition at line 20 of file shell32_apitest_sub.cpp.

Referenced by DoSetPaths(), and DoShellNotify().

◆ s_pidl

LPITEMIDLIST s_pidl = NULL
static

Definition at line 22 of file shell32_apitest_sub.cpp.

Referenced by OnCreate(), and OnDestroy().

◆ s_szName

const WCHAR s_szName[] = L"SHChangeNotify testcase"
static

Definition at line 14 of file shell32_apitest_sub.cpp.

Referenced by wWinMain().

◆ s_uRegID

UINT s_uRegID = 0
static

Definition at line 18 of file shell32_apitest_sub.cpp.

Referenced by OnCreate(), OnDestroy(), and OnGetNotifyFlags().