attrs if SHGetDesktopFolder shfDesktop NOERROR and SHILCreateFromPath

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
attrs := 0;
if (SHGetDesktopFolder(shfDesktop) = NOERROR) and
(SHILCreateFromPath(PChar(Path), iidl, attrs) = S_OK)
then try
if (shfDesktop.BindToObject(iidl, nil, IID_IShellFolder, shfSelected) = S_OK) and
(shfSelected.CreateViewObject(Handle, IID_IContextMenu, icm) = S_OK)
then begin
menu := CreatePopupMenu;
if menu <> 0
then try
if HResultSeverity(icm.QueryContextMenu(menu, 0, 0, 0, 0)) = SEVERITY_SUCCESS
then begin
hDir := CreateFile(PChar(Path), FILE_LIST_DIRECTORY, FILE_SHARE_WRITE or FILE_SHARE_READ,
nil, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS or FILE_FLAG_OVERLAPPED, 0);
if hDir <> INVALID_HANDLE_VALUE
then try
Overlapped.hEvent := CreateEvent(nil, False, False, nil);
if Overlapped.hEvent <>0
then try
if ReadDirectoryChanges(hDir, pBuf, BufSize, False,
FILE_NOTIFY_CHANGE_DIR_NAME,
nil, Overlapped, nil)
then begin
ZeroMemory(@cmici, SizeOf(cmici));
cmici.cbSize := SizeOf(cmici);
cmici.lpVerb := CMDSTR_NEWFOLDERA;
cmici.fMask := CMIC_MASK_ASYNCOK;
if icm.InvokeCommand(cmici) = NOERROR
then begin
end;
end;
finally
CloseHandle(Overlapped.hEvent)
end;
finally
CloseHandle(hDir)
end;
end;
finally
DestroyMenu(menu)
end;
end;
finally
CoTaskMemFree(iidl)
end;
end;