d2d1: Implement ID2D1EffectContext_GetDpi().
[wine.git] / dlls / shell32 / shell32_main.c
blob212de7445a411e84ee852c4585400e51287a2113
1 /*
2 * Shell basics
4 * Copyright 1998 Marcus Meissner
5 * Copyright 1998 Juergen Schmied (jsch) * <juergen.schmied@metronet.de>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <stdlib.h>
23 #include <string.h>
24 #include <stdarg.h>
25 #include <stdio.h>
27 #define COBJMACROS
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winerror.h"
32 #include "winreg.h"
33 #include "dlgs.h"
34 #include "shellapi.h"
35 #include "winuser.h"
36 #include "wingdi.h"
37 #include "shlobj.h"
38 #include "rpcproxy.h"
39 #include "shlwapi.h"
40 #include "propsys.h"
41 #include "commoncontrols.h"
43 #include "pidl.h"
44 #include "shell32_main.h"
45 #include "version.h"
46 #include "shresdef.h"
47 #include "initguid.h"
48 #include "shfldr.h"
50 #include "wine/debug.h"
52 WINE_DEFAULT_DEBUG_CHANNEL(shell);
54 static DWORD shgfi_get_exe_type(LPCWSTR szFullPath)
56 BOOL status = FALSE;
57 HANDLE hfile;
58 DWORD BinaryType;
59 IMAGE_DOS_HEADER mz_header;
60 IMAGE_NT_HEADERS nt;
61 DWORD len;
62 char magic[4];
64 status = GetBinaryTypeW (szFullPath, &BinaryType);
65 if (!status)
66 return 0;
67 if (BinaryType == SCS_DOS_BINARY || BinaryType == SCS_PIF_BINARY)
68 return 0x4d5a;
70 hfile = CreateFileW( szFullPath, GENERIC_READ, FILE_SHARE_READ,
71 NULL, OPEN_EXISTING, 0, 0 );
72 if ( hfile == INVALID_HANDLE_VALUE )
73 return 0;
76 * The next section is adapted from MODULE_GetBinaryType, as we need
77 * to examine the image header to get OS and version information. We
78 * know from calling GetBinaryTypeA that the image is valid and either
79 * an NE or PE, so much error handling can be omitted.
80 * Seek to the start of the file and read the header information.
83 SetFilePointer( hfile, 0, NULL, SEEK_SET );
84 ReadFile( hfile, &mz_header, sizeof(mz_header), &len, NULL );
86 SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
87 ReadFile( hfile, magic, sizeof(magic), &len, NULL );
88 if ( *(DWORD*)magic == IMAGE_NT_SIGNATURE )
90 SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
91 ReadFile( hfile, &nt, sizeof(nt), &len, NULL );
92 CloseHandle( hfile );
93 /* DLL files are not executable and should return 0 */
94 if (nt.FileHeader.Characteristics & IMAGE_FILE_DLL)
95 return 0;
96 if (nt.OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_GUI)
98 return IMAGE_NT_SIGNATURE |
99 (nt.OptionalHeader.MajorSubsystemVersion << 24) |
100 (nt.OptionalHeader.MinorSubsystemVersion << 16);
102 return IMAGE_NT_SIGNATURE;
104 else if ( *(WORD*)magic == IMAGE_OS2_SIGNATURE )
106 IMAGE_OS2_HEADER ne;
107 SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
108 ReadFile( hfile, &ne, sizeof(ne), &len, NULL );
109 CloseHandle( hfile );
110 if (ne.ne_exetyp == 2)
111 return IMAGE_OS2_SIGNATURE | (ne.ne_expver << 16);
112 return 0;
114 CloseHandle( hfile );
115 return 0;
118 /*************************************************************************
119 * SHELL_IsShortcut [internal]
121 * Decide if an item id list points to a shell shortcut
123 BOOL SHELL_IsShortcut(LPCITEMIDLIST pidlLast)
125 char szTemp[MAX_PATH];
126 HKEY keyCls;
127 BOOL ret = FALSE;
129 if (_ILGetExtension(pidlLast, szTemp, MAX_PATH) &&
130 HCR_MapTypeToValueA(szTemp, szTemp, MAX_PATH, TRUE))
132 if (ERROR_SUCCESS == RegOpenKeyExA(HKEY_CLASSES_ROOT, szTemp, 0, KEY_QUERY_VALUE, &keyCls))
134 if (ERROR_SUCCESS == RegQueryValueExA(keyCls, "IsShortcut", NULL, NULL, NULL, NULL))
135 ret = TRUE;
137 RegCloseKey(keyCls);
141 return ret;
144 #define SHGFI_KNOWN_FLAGS \
145 (SHGFI_SMALLICON | SHGFI_OPENICON | SHGFI_SHELLICONSIZE | SHGFI_PIDL | \
146 SHGFI_USEFILEATTRIBUTES | SHGFI_ADDOVERLAYS | SHGFI_OVERLAYINDEX | \
147 SHGFI_ICON | SHGFI_DISPLAYNAME | SHGFI_TYPENAME | SHGFI_ATTRIBUTES | \
148 SHGFI_ICONLOCATION | SHGFI_EXETYPE | SHGFI_SYSICONINDEX | \
149 SHGFI_LINKOVERLAY | SHGFI_SELECTED | SHGFI_ATTR_SPECIFIED)
151 /*************************************************************************
152 * SHGetFileInfoW [SHELL32.@]
155 DWORD_PTR WINAPI SHGetFileInfoW(LPCWSTR path,DWORD dwFileAttributes,
156 SHFILEINFOW *psfi, UINT sizeofpsfi, UINT flags )
158 WCHAR szLocation[MAX_PATH], szFullPath[MAX_PATH];
159 int iIndex;
160 DWORD_PTR ret = TRUE;
161 DWORD dwAttributes = 0;
162 IShellFolder * psfParent = NULL;
163 IExtractIconW * pei = NULL;
164 LPITEMIDLIST pidlLast = NULL, pidl = NULL;
165 HRESULT hr = S_OK;
166 UINT uGilFlags = 0;
168 TRACE("%s fattr=0x%lx sfi=%p(attr=0x%08lx) size=0x%x flags=0x%x\n",
169 (flags & SHGFI_PIDL)? "pidl" : debugstr_w(path), dwFileAttributes,
170 psfi, psfi ? psfi->dwAttributes : 0, sizeofpsfi, flags);
172 if (!path)
173 return FALSE;
175 /* windows initializes these values regardless of the flags */
176 if (psfi != NULL)
178 psfi->szDisplayName[0] = '\0';
179 psfi->szTypeName[0] = '\0';
180 psfi->iIcon = 0;
183 if (!(flags & SHGFI_PIDL))
185 /* SHGetFileInfo should work with absolute and relative paths */
186 if (PathIsRelativeW(path))
188 GetCurrentDirectoryW(MAX_PATH, szLocation);
189 PathCombineW(szFullPath, szLocation, path);
191 else
193 lstrcpynW(szFullPath, path, MAX_PATH);
197 if (flags & SHGFI_EXETYPE)
199 if (flags != SHGFI_EXETYPE)
200 return 0;
201 return shgfi_get_exe_type(szFullPath);
205 * psfi is NULL normally to query EXE type. If it is NULL, none of the
206 * below makes sense anyway. Windows allows this and just returns FALSE
208 if (psfi == NULL)
209 return FALSE;
212 * translate the path into a pidl only when SHGFI_USEFILEATTRIBUTES
213 * is not specified.
214 * The pidl functions fail on not existing file names
217 if (flags & SHGFI_PIDL)
219 pidl = ILClone((LPCITEMIDLIST)path);
221 else if (!(flags & SHGFI_USEFILEATTRIBUTES))
223 hr = SHILCreateFromPathW(szFullPath, &pidl, &dwAttributes);
226 if ((flags & SHGFI_PIDL) || !(flags & SHGFI_USEFILEATTRIBUTES))
228 /* get the parent shellfolder */
229 if (pidl)
231 hr = SHBindToParent( pidl, &IID_IShellFolder, (LPVOID*)&psfParent,
232 (LPCITEMIDLIST*)&pidlLast );
233 if (SUCCEEDED(hr))
234 pidlLast = ILClone(pidlLast);
235 ILFree(pidl);
237 else
239 ERR("pidl is null!\n");
240 return FALSE;
244 /* get the attributes of the child */
245 if (SUCCEEDED(hr) && (flags & SHGFI_ATTRIBUTES))
247 if (!(flags & SHGFI_ATTR_SPECIFIED))
249 psfi->dwAttributes = 0xffffffff;
251 if (psfParent)
252 IShellFolder_GetAttributesOf( psfParent, 1, (LPCITEMIDLIST*)&pidlLast,
253 &(psfi->dwAttributes) );
256 /* get the displayname */
257 if (SUCCEEDED(hr) && (flags & SHGFI_DISPLAYNAME))
259 if (flags & SHGFI_USEFILEATTRIBUTES && !(flags & SHGFI_PIDL))
261 lstrcpyW (psfi->szDisplayName, PathFindFileNameW(szFullPath));
263 else
265 STRRET str;
266 hr = IShellFolder_GetDisplayNameOf( psfParent, pidlLast,
267 SHGDN_INFOLDER, &str);
268 StrRetToStrNW (psfi->szDisplayName, MAX_PATH, &str, pidlLast);
272 /* get the type name */
273 if (SUCCEEDED(hr) && (flags & SHGFI_TYPENAME))
275 if (!(flags & SHGFI_USEFILEATTRIBUTES) || (flags & SHGFI_PIDL))
277 char ftype[80];
279 _ILGetFileType(pidlLast, ftype, 80);
280 MultiByteToWideChar(CP_ACP, 0, ftype, -1, psfi->szTypeName, 80 );
282 else
284 if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
285 lstrcatW (psfi->szTypeName, L"Folder");
286 else
288 WCHAR sTemp[64];
290 lstrcpyW(sTemp,PathFindExtensionW(szFullPath));
291 if (sTemp[0] == 0 || (sTemp[0] == '.' && sTemp[1] == 0))
293 /* "name" or "name." => "File" */
294 lstrcpynW (psfi->szTypeName, L"File", 64);
296 else if (!( HCR_MapTypeToValueW(sTemp, sTemp, 64, TRUE) &&
297 HCR_MapTypeToValueW(sTemp, psfi->szTypeName, 80, FALSE )))
299 if (sTemp[0])
301 lstrcpynW (psfi->szTypeName, sTemp, 64);
302 lstrcatW (psfi->szTypeName, L" file");
304 else
306 lstrcpynW (psfi->szTypeName, L"File", 64);
313 /* ### icons ###*/
314 if (flags & SHGFI_OPENICON)
315 uGilFlags |= GIL_OPENICON;
317 if (flags & SHGFI_LINKOVERLAY)
318 uGilFlags |= GIL_FORSHORTCUT;
319 else if ((flags&SHGFI_ADDOVERLAYS) ||
320 (flags&(SHGFI_ICON|SHGFI_SMALLICON))==SHGFI_ICON)
322 if (SHELL_IsShortcut(pidlLast))
323 uGilFlags |= GIL_FORSHORTCUT;
326 if (flags & SHGFI_OVERLAYINDEX)
327 FIXME("SHGFI_OVERLAYINDEX unhandled\n");
329 if (flags & SHGFI_SELECTED)
330 FIXME("set icon to selected, stub\n");
332 /* get the iconlocation */
333 if (SUCCEEDED(hr) && (flags & SHGFI_ICONLOCATION ))
335 UINT uDummy,uFlags;
337 if (flags & SHGFI_USEFILEATTRIBUTES && !(flags & SHGFI_PIDL))
339 if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
341 lstrcpyW(psfi->szDisplayName, swShell32Name);
342 psfi->iIcon = -IDI_SHELL_FOLDER;
344 else
346 WCHAR* szExt;
347 WCHAR sTemp [MAX_PATH];
349 szExt = PathFindExtensionW(szFullPath);
350 TRACE("szExt=%s\n", debugstr_w(szExt));
351 if ( szExt &&
352 HCR_MapTypeToValueW(szExt, sTemp, MAX_PATH, TRUE) &&
353 HCR_GetDefaultIconW(sTemp, sTemp, MAX_PATH, &psfi->iIcon))
355 if (wcscmp(L"%1", sTemp))
356 lstrcpyW(psfi->szDisplayName, sTemp);
357 else
359 /* the icon is in the file */
360 lstrcpyW(psfi->szDisplayName, szFullPath);
363 else
364 ret = FALSE;
367 else
369 hr = IShellFolder_GetUIObjectOf(psfParent, 0, 1,
370 (LPCITEMIDLIST*)&pidlLast, &IID_IExtractIconW,
371 &uDummy, (LPVOID*)&pei);
372 if (SUCCEEDED(hr))
374 hr = IExtractIconW_GetIconLocation(pei, uGilFlags,
375 szLocation, MAX_PATH, &iIndex, &uFlags);
377 if (uFlags & GIL_NOTFILENAME)
378 ret = FALSE;
379 else
381 lstrcpyW (psfi->szDisplayName, szLocation);
382 psfi->iIcon = iIndex;
384 IExtractIconW_Release(pei);
389 /* get icon index (or load icon)*/
390 if (SUCCEEDED(hr) && (flags & (SHGFI_ICON | SHGFI_SYSICONINDEX)))
392 IImageList *icon_list;
393 SHGetImageList( (flags & SHGFI_SMALLICON) ? SHIL_SMALL : SHIL_LARGE, &IID_IImageList, (void **)&icon_list );
395 if (flags & SHGFI_USEFILEATTRIBUTES && !(flags & SHGFI_PIDL))
397 if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
398 psfi->iIcon = SIC_GetIconIndex(swShell32Name, -IDI_SHELL_FOLDER, 0);
399 else
401 WCHAR sTemp[MAX_PATH];
402 WCHAR *szExt;
403 int icon_idx = 0;
405 lstrcpynW(sTemp, szFullPath, MAX_PATH);
407 psfi->iIcon = 0;
408 szExt = PathFindExtensionW(sTemp);
409 if ( szExt &&
410 HCR_MapTypeToValueW(szExt, sTemp, MAX_PATH, TRUE) &&
411 HCR_GetDefaultIconW(sTemp, sTemp, MAX_PATH, &icon_idx))
413 if (!wcscmp(L"%1",sTemp)) /* icon is in the file */
414 lstrcpyW(sTemp, szFullPath);
416 psfi->iIcon = SIC_GetIconIndex(sTemp, icon_idx, 0);
417 if (psfi->iIcon == -1)
418 psfi->iIcon = 0;
422 else
424 if (!(PidlToSicIndex(psfParent, pidlLast, !(flags & SHGFI_SMALLICON),
425 uGilFlags, &(psfi->iIcon))))
427 ret = FALSE;
430 if (ret && (flags & SHGFI_SYSICONINDEX))
432 IImageList_AddRef( icon_list );
433 ret = (DWORD_PTR)icon_list;
435 if (ret && (flags & SHGFI_ICON))
437 if (flags & SHGFI_SHELLICONSIZE)
438 hr = IImageList_GetIcon( icon_list, psfi->iIcon, ILD_NORMAL, &psfi->hIcon );
439 else
441 int width = GetSystemMetrics( (flags & SHGFI_SMALLICON) ? SM_CXSMICON : SM_CXICON );
442 int height = GetSystemMetrics( (flags & SHGFI_SMALLICON) ? SM_CYSMICON : SM_CYICON );
443 int list_width, list_height;
445 IImageList_GetIconSize( icon_list, &list_width, &list_height );
446 if (list_width == width && list_height == height)
447 hr = IImageList_GetIcon( icon_list, psfi->iIcon, ILD_NORMAL, &psfi->hIcon );
448 else /* Use SHIL_SYSSMALL for SHFI_SMALLICONS when we implement it */
450 WCHAR buf[MAX_PATH], *file = buf;
451 DWORD size = sizeof(buf);
452 int icon_idx;
454 while ((hr = SIC_get_location( psfi->iIcon, file, &size, &icon_idx )) == E_NOT_SUFFICIENT_BUFFER)
456 if (file == buf) file = heap_alloc( size );
457 else file = heap_realloc( file, size );
458 if (!file) break;
460 if (SUCCEEDED(hr))
462 ret = PrivateExtractIconsW( file, icon_idx, width, height, &psfi->hIcon, 0, 1, 0);
463 if (ret == 0 || ret == (UINT)-1) hr = E_FAIL;
465 if (file != buf) heap_free( file );
469 IImageList_Release( icon_list );
472 if (flags & ~SHGFI_KNOWN_FLAGS)
473 FIXME("unknown flags %08x\n", flags & ~SHGFI_KNOWN_FLAGS);
475 if (psfParent)
476 IShellFolder_Release(psfParent);
478 if (hr != S_OK)
479 ret = FALSE;
481 SHFree(pidlLast);
483 TRACE ("icon=%p index=0x%08x attr=0x%08lx name=%s type=%s ret=0x%08Ix\n",
484 psfi->hIcon, psfi->iIcon, psfi->dwAttributes,
485 debugstr_w(psfi->szDisplayName), debugstr_w(psfi->szTypeName), ret);
487 return ret;
490 /*************************************************************************
491 * SHGetFileInfoA [SHELL32.@]
493 * Note:
494 * MSVBVM60.__vbaNew2 expects this function to return a value in range
495 * 1 .. 0x7fff when the function succeeds and flags does not contain
496 * SHGFI_EXETYPE or SHGFI_SYSICONINDEX (see bug 7701)
498 DWORD_PTR WINAPI SHGetFileInfoA(LPCSTR path,DWORD dwFileAttributes,
499 SHFILEINFOA *psfi, UINT sizeofpsfi,
500 UINT flags )
502 INT len;
503 LPWSTR temppath = NULL;
504 LPCWSTR pathW;
505 DWORD_PTR ret;
506 SHFILEINFOW temppsfi;
508 if (flags & SHGFI_PIDL)
510 /* path contains a pidl */
511 pathW = (LPCWSTR)path;
513 else
515 len = MultiByteToWideChar(CP_ACP, 0, path, -1, NULL, 0);
516 temppath = heap_alloc(len*sizeof(WCHAR));
517 MultiByteToWideChar(CP_ACP, 0, path, -1, temppath, len);
518 pathW = temppath;
521 if (psfi && (flags & SHGFI_ATTR_SPECIFIED))
522 temppsfi.dwAttributes=psfi->dwAttributes;
524 if (psfi == NULL)
525 ret = SHGetFileInfoW(pathW, dwFileAttributes, NULL, sizeof(temppsfi), flags);
526 else
527 ret = SHGetFileInfoW(pathW, dwFileAttributes, &temppsfi, sizeof(temppsfi), flags);
529 if (psfi)
531 if(flags & SHGFI_ICON)
532 psfi->hIcon=temppsfi.hIcon;
533 if(flags & (SHGFI_SYSICONINDEX|SHGFI_ICON|SHGFI_ICONLOCATION))
534 psfi->iIcon=temppsfi.iIcon;
535 if(flags & SHGFI_ATTRIBUTES)
536 psfi->dwAttributes=temppsfi.dwAttributes;
537 if(flags & (SHGFI_DISPLAYNAME|SHGFI_ICONLOCATION))
539 WideCharToMultiByte(CP_ACP, 0, temppsfi.szDisplayName, -1,
540 psfi->szDisplayName, sizeof(psfi->szDisplayName), NULL, NULL);
542 if(flags & SHGFI_TYPENAME)
544 WideCharToMultiByte(CP_ACP, 0, temppsfi.szTypeName, -1,
545 psfi->szTypeName, sizeof(psfi->szTypeName), NULL, NULL);
549 heap_free(temppath);
551 return ret;
554 /*************************************************************************
555 * DuplicateIcon [SHELL32.@]
557 HICON WINAPI DuplicateIcon( HINSTANCE hInstance, HICON hIcon)
559 ICONINFO IconInfo;
560 HICON hDupIcon = 0;
562 TRACE("%p %p\n", hInstance, hIcon);
564 if (GetIconInfo(hIcon, &IconInfo))
566 hDupIcon = CreateIconIndirect(&IconInfo);
568 /* clean up hbmMask and hbmColor */
569 DeleteObject(IconInfo.hbmMask);
570 DeleteObject(IconInfo.hbmColor);
573 return hDupIcon;
576 /*************************************************************************
577 * ExtractIconA [SHELL32.@]
579 HICON WINAPI ExtractIconA(HINSTANCE hInstance, const char *file, UINT nIconIndex)
581 WCHAR *fileW;
582 HICON ret;
584 TRACE("%p %s %d\n", hInstance, debugstr_a(file), nIconIndex);
586 fileW = strdupAtoW(file);
587 ret = ExtractIconW(hInstance, fileW, nIconIndex);
588 heap_free(fileW);
590 return ret;
593 /*************************************************************************
594 * ExtractIconW [SHELL32.@]
596 HICON WINAPI ExtractIconW(HINSTANCE hInstance, LPCWSTR lpszFile, UINT nIconIndex)
598 HICON hIcon = NULL;
599 UINT ret;
600 UINT cx = GetSystemMetrics(SM_CXICON), cy = GetSystemMetrics(SM_CYICON);
602 TRACE("%p %s %d\n", hInstance, debugstr_w(lpszFile), nIconIndex);
604 if (nIconIndex == (UINT)-1)
606 ret = PrivateExtractIconsW(lpszFile, 0, cx, cy, NULL, NULL, 0, LR_DEFAULTCOLOR);
607 if (ret != (UINT)-1 && ret)
608 return (HICON)(UINT_PTR)ret;
609 return NULL;
611 else
612 ret = PrivateExtractIconsW(lpszFile, nIconIndex, cx, cy, &hIcon, NULL, 1, LR_DEFAULTCOLOR);
614 if (ret == (UINT)-1)
615 return (HICON)1;
616 else if (ret > 0 && hIcon)
617 return hIcon;
619 return NULL;
622 HRESULT WINAPI SHCreateFileExtractIconW(LPCWSTR file, DWORD attribs, REFIID riid, void **ppv)
624 FIXME("%s, %lx, %s, %p\n", debugstr_w(file), attribs, debugstr_guid(riid), ppv);
625 *ppv = NULL;
626 return E_NOTIMPL;
629 /*************************************************************************
630 * Printer_LoadIconsW [SHELL32.205]
632 VOID WINAPI Printer_LoadIconsW(LPCWSTR wsPrinterName, HICON * pLargeIcon, HICON * pSmallIcon)
634 INT iconindex=IDI_SHELL_PRINTER;
636 TRACE("(%s, %p, %p)\n", debugstr_w(wsPrinterName), pLargeIcon, pSmallIcon);
638 /* We should check if wsPrinterName is
639 1. the Default Printer or not
640 2. connected or not
641 3. a Local Printer or a Network-Printer
642 and use different Icons
644 if((wsPrinterName != NULL) && (wsPrinterName[0] != 0))
646 FIXME("(select Icon by PrinterName %s not implemented)\n", debugstr_w(wsPrinterName));
649 if(pLargeIcon != NULL)
650 *pLargeIcon = LoadImageW(shell32_hInstance,
651 (LPCWSTR) MAKEINTRESOURCE(iconindex), IMAGE_ICON,
652 0, 0, LR_DEFAULTCOLOR|LR_DEFAULTSIZE);
654 if(pSmallIcon != NULL)
655 *pSmallIcon = LoadImageW(shell32_hInstance,
656 (LPCWSTR) MAKEINTRESOURCE(iconindex), IMAGE_ICON,
657 16, 16, LR_DEFAULTCOLOR);
660 /*************************************************************************
661 * Printers_RegisterWindowW [SHELL32.213]
662 * used by "printui.dll":
663 * find the Window of the given Type for the specific Printer and
664 * return the already existent hwnd or open a new window
666 BOOL WINAPI Printers_RegisterWindowW(LPCWSTR wsPrinter, DWORD dwType,
667 HANDLE * phClassPidl, HWND * phwnd)
669 FIXME("(%s, %lx, %p (%p), %p (%p)) stub!\n", debugstr_w(wsPrinter), dwType,
670 phClassPidl, (phClassPidl != NULL) ? *(phClassPidl) : NULL,
671 phwnd, (phwnd != NULL) ? *(phwnd) : NULL);
673 return FALSE;
676 /*************************************************************************
677 * Printers_UnregisterWindow [SHELL32.214]
679 VOID WINAPI Printers_UnregisterWindow(HANDLE hClassPidl, HWND hwnd)
681 FIXME("(%p, %p) stub!\n", hClassPidl, hwnd);
684 struct window_prop_store
686 IPropertyStore IPropertyStore_iface;
687 LONG ref;
690 static inline struct window_prop_store *impl_from_IPropertyStore(IPropertyStore *iface)
692 return CONTAINING_RECORD(iface, struct window_prop_store, IPropertyStore_iface);
695 static ULONG WINAPI window_prop_store_AddRef(IPropertyStore *iface)
697 struct window_prop_store *store = impl_from_IPropertyStore(iface);
698 LONG ref = InterlockedIncrement(&store->ref);
699 TRACE("returning %ld\n", ref);
700 return ref;
703 static ULONG WINAPI window_prop_store_Release(IPropertyStore *iface)
705 struct window_prop_store *store = impl_from_IPropertyStore(iface);
706 LONG ref = InterlockedDecrement(&store->ref);
707 if (!ref) heap_free(store);
708 TRACE("returning %ld\n", ref);
709 return ref;
712 static HRESULT WINAPI window_prop_store_QueryInterface(IPropertyStore *iface, REFIID iid, void **obj)
714 struct window_prop_store *store = impl_from_IPropertyStore(iface);
715 TRACE("%p, %s, %p\n", iface, debugstr_guid(iid), obj);
717 if (!obj) return E_POINTER;
718 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_IPropertyStore))
720 *obj = &store->IPropertyStore_iface;
722 else
724 FIXME("no interface for %s\n", debugstr_guid(iid));
725 *obj = NULL;
726 return E_NOINTERFACE;
729 IUnknown_AddRef((IUnknown *)*obj);
730 return S_OK;
733 static HRESULT WINAPI window_prop_store_GetCount(IPropertyStore *iface, DWORD *count)
735 FIXME("%p, %p\n", iface, count);
736 return E_NOTIMPL;
739 static HRESULT WINAPI window_prop_store_GetAt(IPropertyStore *iface, DWORD prop, PROPERTYKEY *key)
741 FIXME("%p, %lu,%p\n", iface, prop, key);
742 return E_NOTIMPL;
745 static HRESULT WINAPI window_prop_store_GetValue(IPropertyStore *iface, const PROPERTYKEY *key, PROPVARIANT *var)
747 FIXME("%p, {%s,%lu}, %p\n", iface, debugstr_guid(&key->fmtid), key->pid, var);
748 return E_NOTIMPL;
751 static HRESULT WINAPI window_prop_store_SetValue(IPropertyStore *iface, const PROPERTYKEY *key, const PROPVARIANT *var)
753 FIXME("%p, {%s,%lu}, %p\n", iface, debugstr_guid(&key->fmtid), key->pid, var);
754 return S_OK;
757 static HRESULT WINAPI window_prop_store_Commit(IPropertyStore *iface)
759 FIXME("%p\n", iface);
760 return S_OK;
763 static const IPropertyStoreVtbl window_prop_store_vtbl =
765 window_prop_store_QueryInterface,
766 window_prop_store_AddRef,
767 window_prop_store_Release,
768 window_prop_store_GetCount,
769 window_prop_store_GetAt,
770 window_prop_store_GetValue,
771 window_prop_store_SetValue,
772 window_prop_store_Commit
775 static HRESULT create_window_prop_store(IPropertyStore **obj)
777 struct window_prop_store *store;
779 if (!(store = heap_alloc(sizeof(*store)))) return E_OUTOFMEMORY;
780 store->IPropertyStore_iface.lpVtbl = &window_prop_store_vtbl;
781 store->ref = 1;
783 *obj = &store->IPropertyStore_iface;
784 return S_OK;
787 /*************************************************************************
788 * SHGetPropertyStoreForWindow [SHELL32.@]
790 HRESULT WINAPI SHGetPropertyStoreForWindow(HWND hwnd, REFIID riid, void **ppv)
792 IPropertyStore *store;
793 HRESULT hr;
795 FIXME("(%p %p %p) stub!\n", hwnd, riid, ppv);
797 if ((hr = create_window_prop_store( &store )) != S_OK) return hr;
798 hr = IPropertyStore_QueryInterface( store, riid, ppv );
799 IPropertyStore_Release( store );
800 return hr;
803 /*************************************************************************/
805 typedef struct
807 LPCWSTR szApp;
808 LPCWSTR szOtherStuff;
809 HICON hIcon;
810 HFONT hFont;
811 } ABOUT_INFO;
813 #define DROP_FIELD_TOP (-12)
815 static void paint_dropline( HDC hdc, HWND hWnd )
817 HWND hWndCtl = GetDlgItem(hWnd, IDC_ABOUT_WINE_TEXT);
818 RECT rect;
820 if (!hWndCtl) return;
821 GetWindowRect( hWndCtl, &rect );
822 MapWindowPoints( 0, hWnd, (LPPOINT)&rect, 2 );
823 rect.top += DROP_FIELD_TOP;
824 rect.bottom = rect.top + 2;
825 DrawEdge( hdc, &rect, BDR_SUNKENOUTER, BF_RECT );
828 /*************************************************************************
829 * SHHelpShortcuts_RunDLLA [SHELL32.@]
832 DWORD WINAPI SHHelpShortcuts_RunDLLA(DWORD dwArg1, DWORD dwArg2, DWORD dwArg3, DWORD dwArg4)
834 FIXME("(%lx, %lx, %lx, %lx) stub!\n", dwArg1, dwArg2, dwArg3, dwArg4);
835 return 0;
838 /*************************************************************************
839 * SHHelpShortcuts_RunDLLA [SHELL32.@]
842 DWORD WINAPI SHHelpShortcuts_RunDLLW(DWORD dwArg1, DWORD dwArg2, DWORD dwArg3, DWORD dwArg4)
844 FIXME("(%lx, %lx, %lx, %lx) stub!\n", dwArg1, dwArg2, dwArg3, dwArg4);
845 return 0;
848 /*************************************************************************
849 * SHLoadInProc [SHELL32.@]
850 * Create an instance of specified object class from within
851 * the shell process and release it immediately
853 HRESULT WINAPI SHLoadInProc (REFCLSID rclsid)
855 void *ptr = NULL;
857 TRACE("%s\n", debugstr_guid(rclsid));
859 CoCreateInstance(rclsid, NULL, CLSCTX_INPROC_SERVER, &IID_IUnknown,&ptr);
860 if(ptr)
862 IUnknown * pUnk = ptr;
863 IUnknown_Release(pUnk);
864 return S_OK;
866 return DISP_E_MEMBERNOTFOUND;
869 static void add_authors( HWND list )
871 WCHAR *strW, *start, *end;
872 HRSRC rsrc = FindResourceW( shell32_hInstance, L"AUTHORS", (LPCWSTR)RT_RCDATA );
873 char *strA = LockResource( LoadResource( shell32_hInstance, rsrc ));
874 DWORD sizeW, sizeA = SizeofResource( shell32_hInstance, rsrc );
876 if (!strA) return;
877 sizeW = MultiByteToWideChar( CP_UTF8, 0, strA, sizeA, NULL, 0 ) + 1;
878 if (!(strW = heap_alloc( sizeW * sizeof(WCHAR) ))) return;
879 MultiByteToWideChar( CP_UTF8, 0, strA, sizeA, strW, sizeW );
880 strW[sizeW - 1] = 0;
882 start = wcspbrk( strW, L"\r\n" ); /* skip the header line */
883 while (start)
885 while (*start && wcschr( L"\r\n", *start )) start++;
886 if (!*start) break;
887 end = wcspbrk( start, L"\r\n" );
888 if (end) *end++ = 0;
889 SendMessageW( list, LB_ADDSTRING, -1, (LPARAM)start );
890 start = end;
892 heap_free( strW );
895 /*************************************************************************
896 * AboutDlgProc (internal)
898 static INT_PTR CALLBACK AboutDlgProc( HWND hWnd, UINT msg, WPARAM wParam,
899 LPARAM lParam )
901 HWND hWndCtl;
903 TRACE("\n");
905 switch(msg)
907 case WM_INITDIALOG:
909 ABOUT_INFO *info = (ABOUT_INFO *)lParam;
910 WCHAR template[512], buffer[512], version[64];
911 const char *(CDECL *wine_get_build_id)(void);
913 if (info)
915 wine_get_build_id = (void *)GetProcAddress( GetModuleHandleA("ntdll.dll"),
916 "wine_get_build_id");
917 SendDlgItemMessageW(hWnd, stc1, STM_SETICON,(WPARAM)info->hIcon, 0);
918 GetWindowTextW( hWnd, template, ARRAY_SIZE(template) );
919 swprintf( buffer, ARRAY_SIZE(buffer), template, info->szApp );
920 SetWindowTextW( hWnd, buffer );
921 SetWindowTextW( GetDlgItem(hWnd, IDC_ABOUT_STATIC_TEXT1), info->szApp );
922 SetWindowTextW( GetDlgItem(hWnd, IDC_ABOUT_STATIC_TEXT2), info->szOtherStuff );
923 GetWindowTextW( GetDlgItem(hWnd, IDC_ABOUT_STATIC_TEXT3),
924 template, ARRAY_SIZE(template) );
925 if (wine_get_build_id)
927 MultiByteToWideChar( CP_UTF8, 0, wine_get_build_id(), -1, version, ARRAY_SIZE(version) );
928 swprintf( buffer, ARRAY_SIZE(buffer), template, version );
929 SetWindowTextW( GetDlgItem(hWnd, IDC_ABOUT_STATIC_TEXT3), buffer );
931 hWndCtl = GetDlgItem(hWnd, IDC_ABOUT_LISTBOX);
932 SendMessageW( hWndCtl, WM_SETREDRAW, 0, 0 );
933 SendMessageW( hWndCtl, WM_SETFONT, (WPARAM)info->hFont, 0 );
934 add_authors( hWndCtl );
935 SendMessageW( hWndCtl, WM_SETREDRAW, 1, 0 );
938 return 1;
940 case WM_PAINT:
942 PAINTSTRUCT ps;
943 HDC hDC = BeginPaint( hWnd, &ps );
944 paint_dropline( hDC, hWnd );
945 EndPaint( hWnd, &ps );
947 break;
949 case WM_COMMAND:
950 if (wParam == IDOK || wParam == IDCANCEL)
952 EndDialog(hWnd, TRUE);
953 return TRUE;
955 if (wParam == IDC_ABOUT_LICENSE)
957 MSGBOXPARAMSW params;
959 params.cbSize = sizeof(params);
960 params.hwndOwner = hWnd;
961 params.hInstance = shell32_hInstance;
962 params.lpszText = MAKEINTRESOURCEW(IDS_LICENSE);
963 params.lpszCaption = MAKEINTRESOURCEW(IDS_LICENSE_CAPTION);
964 params.dwStyle = MB_ICONINFORMATION | MB_OK;
965 params.lpszIcon = 0;
966 params.dwContextHelpId = 0;
967 params.lpfnMsgBoxCallback = NULL;
968 params.dwLanguageId = LANG_NEUTRAL;
969 MessageBoxIndirectW( &params );
971 break;
972 case WM_CLOSE:
973 EndDialog(hWnd, TRUE);
974 break;
977 return 0;
981 /*************************************************************************
982 * ShellAboutA [SHELL32.288]
984 BOOL WINAPI ShellAboutA( HWND hWnd, LPCSTR szApp, LPCSTR szOtherStuff, HICON hIcon )
986 BOOL ret;
987 LPWSTR appW = NULL, otherW = NULL;
988 int len;
990 if (szApp)
992 len = MultiByteToWideChar(CP_ACP, 0, szApp, -1, NULL, 0);
993 appW = heap_alloc( len * sizeof(WCHAR));
994 MultiByteToWideChar(CP_ACP, 0, szApp, -1, appW, len);
996 if (szOtherStuff)
998 len = MultiByteToWideChar(CP_ACP, 0, szOtherStuff, -1, NULL, 0);
999 otherW = heap_alloc( len * sizeof(WCHAR));
1000 MultiByteToWideChar(CP_ACP, 0, szOtherStuff, -1, otherW, len);
1003 ret = ShellAboutW(hWnd, appW, otherW, hIcon);
1005 heap_free(otherW);
1006 heap_free(appW);
1007 return ret;
1011 /*************************************************************************
1012 * ShellAboutW [SHELL32.289]
1014 BOOL WINAPI ShellAboutW( HWND hWnd, LPCWSTR szApp, LPCWSTR szOtherStuff,
1015 HICON hIcon )
1017 ABOUT_INFO info;
1018 LOGFONTW logFont;
1019 BOOL bRet;
1021 TRACE("\n");
1023 if (!hIcon) hIcon = LoadImageW( 0, (LPWSTR)IDI_WINLOGO, IMAGE_ICON, 48, 48, LR_SHARED );
1024 info.szApp = szApp;
1025 info.szOtherStuff = szOtherStuff;
1026 info.hIcon = hIcon;
1028 SystemParametersInfoW( SPI_GETICONTITLELOGFONT, 0, &logFont, 0 );
1029 info.hFont = CreateFontIndirectW( &logFont );
1031 bRet = DialogBoxParamW( shell32_hInstance, L"SHELL_ABOUT_MSGBOX", hWnd, AboutDlgProc, (LPARAM)&info );
1032 DeleteObject(info.hFont);
1033 return bRet;
1036 /*************************************************************************
1037 * FreeIconList (SHELL32.@)
1039 void WINAPI FreeIconList( DWORD dw )
1041 FIXME("%lx: stub\n",dw);
1044 /*************************************************************************
1045 * SHLoadNonloadedIconOverlayIdentifiers (SHELL32.@)
1047 HRESULT WINAPI SHLoadNonloadedIconOverlayIdentifiers( VOID )
1049 FIXME("stub\n");
1050 return S_OK;
1053 /***********************************************************************
1054 * DllGetVersion [SHELL32.@]
1056 * Retrieves version information of the 'SHELL32.DLL'
1058 * PARAMS
1059 * pdvi [O] pointer to version information structure.
1061 * RETURNS
1062 * Success: S_OK
1063 * Failure: E_INVALIDARG
1065 * NOTES
1066 * Returns version of a shell32.dll from IE4.01 SP1.
1069 HRESULT WINAPI DllGetVersion (DLLVERSIONINFO *pdvi)
1071 /* FIXME: shouldn't these values come from the version resource? */
1072 if (pdvi->cbSize == sizeof(DLLVERSIONINFO) ||
1073 pdvi->cbSize == sizeof(DLLVERSIONINFO2))
1075 pdvi->dwMajorVersion = WINE_FILEVERSION_MAJOR;
1076 pdvi->dwMinorVersion = WINE_FILEVERSION_MINOR;
1077 pdvi->dwBuildNumber = WINE_FILEVERSION_BUILD;
1078 pdvi->dwPlatformID = WINE_FILEVERSION_PLATFORMID;
1079 if (pdvi->cbSize == sizeof(DLLVERSIONINFO2))
1081 DLLVERSIONINFO2 *pdvi2 = (DLLVERSIONINFO2 *)pdvi;
1083 pdvi2->dwFlags = 0;
1084 pdvi2->ullVersion = MAKEDLLVERULL(WINE_FILEVERSION_MAJOR,
1085 WINE_FILEVERSION_MINOR,
1086 WINE_FILEVERSION_BUILD,
1087 WINE_FILEVERSION_PLATFORMID);
1089 TRACE("%lu.%lu.%lu.%lu\n",
1090 pdvi->dwMajorVersion, pdvi->dwMinorVersion,
1091 pdvi->dwBuildNumber, pdvi->dwPlatformID);
1092 return S_OK;
1094 else
1096 WARN("wrong DLLVERSIONINFO size from app\n");
1097 return E_INVALIDARG;
1101 /*************************************************************************
1102 * global variables of the shell32.dll
1103 * all are once per process
1106 HINSTANCE shell32_hInstance = 0;
1109 /*************************************************************************
1110 * SHELL32 DllMain
1112 * NOTES
1113 * calling oleinitialize here breaks some apps.
1115 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
1117 TRACE("%p 0x%lx %p\n", hinstDLL, fdwReason, fImpLoad);
1119 switch (fdwReason)
1121 case DLL_PROCESS_ATTACH:
1122 shell32_hInstance = hinstDLL;
1123 DisableThreadLibraryCalls(shell32_hInstance);
1125 /* get full path to this DLL for IExtractIconW_fnGetIconLocation() */
1126 GetModuleFileNameW(hinstDLL, swShell32Name, MAX_PATH);
1127 swShell32Name[MAX_PATH - 1] = '\0';
1129 InitChangeNotifications();
1130 break;
1132 case DLL_PROCESS_DETACH:
1133 if (fImpLoad) break;
1134 SIC_Destroy();
1135 FreeChangeNotifications();
1136 release_desktop_folder();
1137 release_typelib();
1138 break;
1140 return TRUE;
1143 /*************************************************************************
1144 * DllInstall [SHELL32.@]
1146 * PARAMETERS
1148 * BOOL bInstall - TRUE for install, FALSE for uninstall
1149 * LPCWSTR pszCmdLine - command line (unused by shell32?)
1152 HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline)
1154 FIXME("%s %s: stub\n", bInstall ? "TRUE":"FALSE", debugstr_w(cmdline));
1155 return S_OK; /* indicate success */
1158 /***********************************************************************
1159 * DllRegisterServer (SHELL32.@)
1161 HRESULT WINAPI DllRegisterServer(void)
1163 HRESULT hr = __wine_register_resources();
1164 if (SUCCEEDED(hr)) hr = SHELL_RegisterShellFolders();
1165 return hr;
1168 /***********************************************************************
1169 * DllUnregisterServer (SHELL32.@)
1171 HRESULT WINAPI DllUnregisterServer(void)
1173 return __wine_unregister_resources();
1176 /***********************************************************************
1177 * ExtractVersionResource16W (SHELL32.@)
1179 BOOL WINAPI ExtractVersionResource16W(LPWSTR s, DWORD d)
1181 FIXME("(%s %lx) stub!\n", debugstr_w(s), d);
1182 return FALSE;
1185 /***********************************************************************
1186 * InitNetworkAddressControl (SHELL32.@)
1188 BOOL WINAPI InitNetworkAddressControl(void)
1190 FIXME("stub\n");
1191 return FALSE;
1194 /***********************************************************************
1195 * ShellHookProc (SHELL32.@)
1197 LRESULT CALLBACK ShellHookProc(DWORD a, DWORD b, DWORD c)
1199 FIXME("Stub\n");
1200 return 0;
1203 /***********************************************************************
1204 * SHGetLocalizedName (SHELL32.@)
1206 HRESULT WINAPI SHGetLocalizedName(LPCWSTR path, LPWSTR module, UINT size, INT *res)
1208 FIXME("%s %p %u %p: stub\n", debugstr_w(path), module, size, res);
1209 return E_NOTIMPL;
1212 /***********************************************************************
1213 * SHSetUnreadMailCountW (SHELL32.@)
1215 HRESULT WINAPI SHSetUnreadMailCountW(LPCWSTR mailaddress, DWORD count, LPCWSTR executecommand)
1217 FIXME("%s %lx %s: stub\n", debugstr_w(mailaddress), count, debugstr_w(executecommand));
1218 return E_NOTIMPL;
1221 /***********************************************************************
1222 * SHEnumerateUnreadMailAccountsW (SHELL32.@)
1224 HRESULT WINAPI SHEnumerateUnreadMailAccountsW(HKEY user, DWORD idx, LPWSTR mailaddress, INT mailaddresslen)
1226 FIXME("%p %ld %p %d: stub\n", user, idx, mailaddress, mailaddresslen);
1227 return E_NOTIMPL;
1230 /***********************************************************************
1231 * SHQueryUserNotificationState (SHELL32.@)
1233 HRESULT WINAPI SHQueryUserNotificationState(QUERY_USER_NOTIFICATION_STATE *state)
1235 FIXME("%p: stub\n", state);
1236 *state = QUNS_ACCEPTS_NOTIFICATIONS;
1237 return S_OK;
1240 /***********************************************************************
1241 * SHCreateDataObject (SHELL32.@)
1243 HRESULT WINAPI SHCreateDataObject(PCIDLIST_ABSOLUTE pidl_folder, UINT count, PCUITEMID_CHILD_ARRAY pidl_array,
1244 IDataObject *object, REFIID riid, void **ppv)
1246 FIXME("%p %d %p %p %s %p: stub\n", pidl_folder, count, pidl_array, object, debugstr_guid(riid), ppv);
1247 return E_NOTIMPL;