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
23 #include "shell32_version.h"
24 #include <reactos/version.h>
26 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
28 const char * const SHELL_Authors
[] = { "Copyright 1993-"COPYRIGHT_YEAR
" WINE team", "Copyright 1998-"COPYRIGHT_YEAR
" ReactOS Team", 0 };
31 /*************************************************************************
32 * CommandLineToArgvW [SHELL32.@]
34 * We must interpret the quotes in the command line to rebuild the argv
36 * - arguments are separated by spaces or tabs
37 * - quotes serve as optional argument delimiters
39 * - escaped quotes must be converted back to '"'
41 * - an odd number of '\'s followed by '"' correspond to half that number
42 * of '\' followed by a '"' (extension of the above)
45 * - an even number of '\'s followed by a '"' correspond to half that number
46 * of '\', plus a regular quote serving as an argument delimiter (which
47 * means it does not appear in the result)
48 * 'a\\"b c"' -> 'a\b c'
49 * 'a\\\\"b c"' -> 'a\\b c'
50 * - '\' that are not followed by a '"' are copied literally
60 LPWSTR
* WINAPI
CommandLineToArgvW(LPCWSTR lpCmdline
, int* numargs
)
71 SetLastError(ERROR_INVALID_PARAMETER
);
77 /* Return the path to the executable */
78 DWORD len
, deslen
=MAX_PATH
, size
;
80 size
= sizeof(LPWSTR
) + deslen
*sizeof(WCHAR
) + sizeof(LPWSTR
);
83 if (!(argv
= (LPWSTR
*)LocalAlloc(LMEM_FIXED
, size
))) return NULL
;
84 len
= GetModuleFileNameW(0, (LPWSTR
)(argv
+1), deslen
);
90 if (len
< deslen
) break;
92 size
= sizeof(LPWSTR
) + deslen
*sizeof(WCHAR
) + sizeof(LPWSTR
);
95 argv
[0]=(LPWSTR
)(argv
+1);
101 /* to get a writable copy */
108 if (*cs
==0 || ((*cs
==0x0009 || *cs
==0x0020) && !in_quotes
))
112 /* skip the remaining spaces */
113 while (*cs
==0x0009 || *cs
==0x0020)
122 else if (*cs
==0x005c)
124 /* '\', count them */
127 else if ((*cs
==0x0022) && ((bcount
& 1)==0))
130 in_quotes
=!in_quotes
;
135 /* a regular character */
140 /* Allocate in a single lump, the string array, and the strings that go with it.
141 * This way the caller can make a single GlobalFree call to free both, as per MSDN.
143 argv
=(LPWSTR
*)LocalAlloc(LMEM_FIXED
, argc
*sizeof(LPWSTR
)+(wcslen(lpCmdline
)+1)*sizeof(WCHAR
));
146 cmdline
=(LPWSTR
)(argv
+argc
);
147 wcscpy(cmdline
, lpCmdline
);
155 if ((*s
==0x0009 || *s
==0x0020) && !in_quotes
)
157 /* Close the argument and copy it */
161 /* skip the remaining spaces */
164 } while (*s
==0x0009 || *s
==0x0020);
166 /* Start with a new argument */
181 /* Preceded by an even number of '\', this is half that
182 * number of '\', plus a quote which we erase.
185 in_quotes
=!in_quotes
;
190 /* Preceded by an odd number of '\', this is half that
191 * number of '\' followed by a '"'
201 /* a regular character */
216 static DWORD
shgfi_get_exe_type(LPCWSTR szFullPath
)
221 IMAGE_DOS_HEADER mz_header
;
226 status
= GetBinaryTypeW (szFullPath
, &BinaryType
);
229 if (BinaryType
== SCS_DOS_BINARY
|| BinaryType
== SCS_PIF_BINARY
)
232 hfile
= CreateFileW( szFullPath
, GENERIC_READ
, FILE_SHARE_READ
,
233 NULL
, OPEN_EXISTING
, 0, 0 );
234 if ( hfile
== INVALID_HANDLE_VALUE
)
238 * The next section is adapted from MODULE_GetBinaryType, as we need
239 * to examine the image header to get OS and version information. We
240 * know from calling GetBinaryTypeA that the image is valid and either
241 * an NE or PE, so much error handling can be omitted.
242 * Seek to the start of the file and read the header information.
245 SetFilePointer( hfile
, 0, NULL
, SEEK_SET
);
246 ReadFile( hfile
, &mz_header
, sizeof(mz_header
), &len
, NULL
);
248 SetFilePointer( hfile
, mz_header
.e_lfanew
, NULL
, SEEK_SET
);
249 ReadFile( hfile
, magic
, sizeof(magic
), &len
, NULL
);
251 if ( *(DWORD
*)magic
== IMAGE_NT_SIGNATURE
)
253 SetFilePointer( hfile
, mz_header
.e_lfanew
, NULL
, SEEK_SET
);
254 ReadFile( hfile
, &nt
, sizeof(nt
), &len
, NULL
);
255 CloseHandle( hfile
);
257 /* DLL files are not executable and should return 0 */
258 if (nt
.FileHeader
.Characteristics
& IMAGE_FILE_DLL
)
261 if (nt
.OptionalHeader
.Subsystem
== IMAGE_SUBSYSTEM_WINDOWS_GUI
)
263 return IMAGE_NT_SIGNATURE
|
264 (nt
.OptionalHeader
.MajorSubsystemVersion
<< 24) |
265 (nt
.OptionalHeader
.MinorSubsystemVersion
<< 16);
267 return IMAGE_NT_SIGNATURE
;
269 else if ( *(WORD
*)magic
== IMAGE_OS2_SIGNATURE
)
272 SetFilePointer( hfile
, mz_header
.e_lfanew
, NULL
, SEEK_SET
);
273 ReadFile( hfile
, &ne
, sizeof(ne
), &len
, NULL
);
274 CloseHandle( hfile
);
276 if (ne
.ne_exetyp
== 2)
277 return IMAGE_OS2_SIGNATURE
| (ne
.ne_expver
<< 16);
280 CloseHandle( hfile
);
284 /*************************************************************************
285 * SHELL_IsShortcut [internal]
287 * Decide if an item id list points to a shell shortcut
289 BOOL
SHELL_IsShortcut(LPCITEMIDLIST pidlLast
)
291 char szTemp
[MAX_PATH
];
295 if (_ILGetExtension(pidlLast
, szTemp
, MAX_PATH
) &&
296 HCR_MapTypeToValueA(szTemp
, szTemp
, MAX_PATH
, TRUE
))
298 if (ERROR_SUCCESS
== RegOpenKeyExA(HKEY_CLASSES_ROOT
, szTemp
, 0, KEY_QUERY_VALUE
, &keyCls
))
300 if (ERROR_SUCCESS
== RegQueryValueExA(keyCls
, "IsShortcut", NULL
, NULL
, NULL
, NULL
))
310 #define SHGFI_KNOWN_FLAGS \
311 (SHGFI_SMALLICON | SHGFI_OPENICON | SHGFI_SHELLICONSIZE | SHGFI_PIDL | \
312 SHGFI_USEFILEATTRIBUTES | SHGFI_ADDOVERLAYS | SHGFI_OVERLAYINDEX | \
313 SHGFI_ICON | SHGFI_DISPLAYNAME | SHGFI_TYPENAME | SHGFI_ATTRIBUTES | \
314 SHGFI_ICONLOCATION | SHGFI_EXETYPE | SHGFI_SYSICONINDEX | \
315 SHGFI_LINKOVERLAY | SHGFI_SELECTED | SHGFI_ATTR_SPECIFIED)
317 /*************************************************************************
318 * SHGetFileInfoW [SHELL32.@]
321 DWORD_PTR WINAPI
SHGetFileInfoW(LPCWSTR path
,DWORD dwFileAttributes
,
322 SHFILEINFOW
*psfi
, UINT sizeofpsfi
, UINT flags
)
324 WCHAR szLocation
[MAX_PATH
], szFullPath
[MAX_PATH
];
326 DWORD_PTR ret
= TRUE
;
327 DWORD dwAttributes
= 0;
328 CComPtr
<IShellFolder
> psfParent
;
329 CComPtr
<IExtractIconW
> pei
;
330 LPITEMIDLIST pidlLast
= NULL
, pidl
= NULL
;
332 BOOL IconNotYetLoaded
=TRUE
;
335 TRACE("%s fattr=0x%x sfi=%p(attr=0x%08x) size=0x%x flags=0x%x\n",
336 (flags
& SHGFI_PIDL
)? "pidl" : debugstr_w(path
), dwFileAttributes
,
337 psfi
, psfi
->dwAttributes
, sizeofpsfi
, flags
);
342 /* windows initializes these values regardless of the flags */
345 psfi
->szDisplayName
[0] = '\0';
346 psfi
->szTypeName
[0] = '\0';
350 if (!(flags
& SHGFI_PIDL
))
352 /* SHGetFileInfo should work with absolute and relative paths */
353 if (PathIsRelativeW(path
))
355 GetCurrentDirectoryW(MAX_PATH
, szLocation
);
356 PathCombineW(szFullPath
, szLocation
, path
);
360 lstrcpynW(szFullPath
, path
, MAX_PATH
);
364 if (flags
& SHGFI_EXETYPE
)
366 if (flags
!= SHGFI_EXETYPE
)
368 return shgfi_get_exe_type(szFullPath
);
372 * psfi is NULL normally to query EXE type. If it is NULL, none of the
373 * below makes sense anyway. Windows allows this and just returns FALSE
379 * translate the path into a pidl only when SHGFI_USEFILEATTRIBUTES
381 * The pidl functions fail on not existing file names
384 if (flags
& SHGFI_PIDL
)
386 pidl
= ILClone((LPCITEMIDLIST
)path
);
388 else if (!(flags
& SHGFI_USEFILEATTRIBUTES
))
390 hr
= SHILCreateFromPathW(szFullPath
, &pidl
, &dwAttributes
);
393 if ((flags
& SHGFI_PIDL
) || !(flags
& SHGFI_USEFILEATTRIBUTES
))
395 /* get the parent shellfolder */
398 hr
= SHBindToParent( pidl
, IID_IShellFolder
, (LPVOID
*)&psfParent
,
399 (LPCITEMIDLIST
*)&pidlLast
);
401 pidlLast
= ILClone(pidlLast
);
406 ERR("pidl is null!\n");
411 /* get the attributes of the child */
412 if (SUCCEEDED(hr
) && (flags
& SHGFI_ATTRIBUTES
))
414 if (!(flags
& SHGFI_ATTR_SPECIFIED
))
416 psfi
->dwAttributes
= 0xffffffff;
418 if (psfParent
!= NULL
)
419 psfParent
->GetAttributesOf(1, (LPCITEMIDLIST
*)&pidlLast
,
420 &(psfi
->dwAttributes
) );
423 /* get the displayname */
424 if (SUCCEEDED(hr
) && (flags
& SHGFI_DISPLAYNAME
))
426 if (flags
& SHGFI_USEFILEATTRIBUTES
)
428 wcscpy (psfi
->szDisplayName
, PathFindFileNameW(szFullPath
));
433 hr
= psfParent
->GetDisplayNameOf(pidlLast
,
434 SHGDN_INFOLDER
, &str
);
435 StrRetToStrNW (psfi
->szDisplayName
, MAX_PATH
, &str
, pidlLast
);
439 /* get the type name */
440 if (SUCCEEDED(hr
) && (flags
& SHGFI_TYPENAME
))
442 static const WCHAR szFile
[] = { 'F','i','l','e',0 };
443 static const WCHAR szDashFile
[] = { '-','f','i','l','e',0 };
445 if (!(flags
& SHGFI_USEFILEATTRIBUTES
))
449 _ILGetFileType(pidlLast
, ftype
, 80);
450 MultiByteToWideChar(CP_ACP
, 0, ftype
, -1, psfi
->szTypeName
, 80 );
454 if (dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
455 wcscat (psfi
->szTypeName
, szFile
);
460 wcscpy(sTemp
,PathFindExtensionW(szFullPath
));
461 if (!( HCR_MapTypeToValueW(sTemp
, sTemp
, 64, TRUE
) &&
462 HCR_MapTypeToValueW(sTemp
, psfi
->szTypeName
, 80, FALSE
)))
464 lstrcpynW (psfi
->szTypeName
, sTemp
, 64);
465 wcscat (psfi
->szTypeName
, szDashFile
);
472 if (flags
& SHGFI_OPENICON
)
473 uGilFlags
|= GIL_OPENICON
;
475 if (flags
& SHGFI_LINKOVERLAY
)
476 uGilFlags
|= GIL_FORSHORTCUT
;
477 else if ((flags
&SHGFI_ADDOVERLAYS
) ||
478 (flags
&(SHGFI_ICON
|SHGFI_SMALLICON
))==SHGFI_ICON
)
480 if (SHELL_IsShortcut(pidlLast
))
481 uGilFlags
|= GIL_FORSHORTCUT
;
484 if (flags
& SHGFI_OVERLAYINDEX
)
485 FIXME("SHGFI_OVERLAYINDEX unhandled\n");
487 if (flags
& SHGFI_SELECTED
)
488 FIXME("set icon to selected, stub\n");
490 if (flags
& SHGFI_SHELLICONSIZE
)
491 FIXME("set icon to shell size, stub\n");
493 /* get the iconlocation */
494 if (SUCCEEDED(hr
) && (flags
& SHGFI_ICONLOCATION
))
498 if (flags
& SHGFI_USEFILEATTRIBUTES
)
500 if (dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
502 wcscpy(psfi
->szDisplayName
, swShell32Name
);
503 psfi
->iIcon
= -IDI_SHELL_FOLDER
;
508 static const WCHAR p1W
[] = {'%','1',0};
509 WCHAR sTemp
[MAX_PATH
];
511 szExt
= PathFindExtensionW(szFullPath
);
512 TRACE("szExt=%s\n", debugstr_w(szExt
));
514 HCR_MapTypeToValueW(szExt
, sTemp
, MAX_PATH
, TRUE
) &&
515 HCR_GetDefaultIconW(sTemp
, sTemp
, MAX_PATH
, &psfi
->iIcon
))
517 if (lstrcmpW(p1W
, sTemp
))
518 wcscpy(psfi
->szDisplayName
, sTemp
);
521 /* the icon is in the file */
522 wcscpy(psfi
->szDisplayName
, szFullPath
);
531 hr
= psfParent
->GetUIObjectOf(0, 1,
532 (LPCITEMIDLIST
*)&pidlLast
, IID_IExtractIconW
,
533 &uDummy
, (LPVOID
*)&pei
);
536 hr
= pei
->GetIconLocation(uGilFlags
,
537 szLocation
, MAX_PATH
, &iIndex
, &uFlags
);
539 if (uFlags
& GIL_NOTFILENAME
)
543 wcscpy (psfi
->szDisplayName
, szLocation
);
544 psfi
->iIcon
= iIndex
;
550 /* get icon index (or load icon)*/
551 if (SUCCEEDED(hr
) && (flags
& (SHGFI_ICON
| SHGFI_SYSICONINDEX
)))
553 if (flags
& SHGFI_USEFILEATTRIBUTES
&& !(flags
& SHGFI_PIDL
))
555 WCHAR sTemp
[MAX_PATH
];
559 lstrcpynW(sTemp
, szFullPath
, MAX_PATH
);
561 if (dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
562 psfi
->iIcon
= SIC_GetIconIndex(swShell32Name
, -IDI_SHELL_FOLDER
, 0);
565 static const WCHAR p1W
[] = {'%','1',0};
568 szExt
= PathFindExtensionW(sTemp
);
570 HCR_MapTypeToValueW(szExt
, sTemp
, MAX_PATH
, TRUE
) &&
571 HCR_GetDefaultIconW(sTemp
, sTemp
, MAX_PATH
, &icon_idx
))
573 if (!lstrcmpW(p1W
,sTemp
)) /* icon is in the file */
574 wcscpy(sTemp
, szFullPath
);
576 if (flags
& SHGFI_SYSICONINDEX
)
578 psfi
->iIcon
= SIC_GetIconIndex(sTemp
,icon_idx
,0);
579 if (psfi
->iIcon
== -1)
585 if (flags
& SHGFI_SMALLICON
)
586 ret
= PrivateExtractIconsW( sTemp
,icon_idx
,
587 GetSystemMetrics( SM_CXSMICON
),
588 GetSystemMetrics( SM_CYSMICON
),
589 &psfi
->hIcon
, 0, 1, 0);
591 ret
= PrivateExtractIconsW( sTemp
, icon_idx
,
592 GetSystemMetrics( SM_CXICON
),
593 GetSystemMetrics( SM_CYICON
),
594 &psfi
->hIcon
, 0, 1, 0);
596 if (ret
!= 0 && ret
!= 0xFFFFFFFF)
598 IconNotYetLoaded
=FALSE
;
599 psfi
->iIcon
= icon_idx
;
607 if (!(PidlToSicIndex(psfParent
, pidlLast
, !(flags
& SHGFI_SMALLICON
),
608 uGilFlags
, &(psfi
->iIcon
))))
613 if (ret
&& (flags
& SHGFI_SYSICONINDEX
))
615 if (flags
& SHGFI_SMALLICON
)
616 ret
= (DWORD_PTR
) ShellSmallIconList
;
618 ret
= (DWORD_PTR
) ShellBigIconList
;
623 if (SUCCEEDED(hr
) && (flags
& SHGFI_ICON
) && IconNotYetLoaded
)
625 if (flags
& SHGFI_SMALLICON
)
626 psfi
->hIcon
= ImageList_GetIcon( ShellSmallIconList
, psfi
->iIcon
, ILD_NORMAL
);
628 psfi
->hIcon
= ImageList_GetIcon( ShellBigIconList
, psfi
->iIcon
, ILD_NORMAL
);
631 if (flags
& ~SHGFI_KNOWN_FLAGS
)
632 FIXME("unknown flags %08x\n", flags
& ~SHGFI_KNOWN_FLAGS
);
640 TRACE ("icon=%p index=0x%08x attr=0x%08x name=%s type=%s ret=0x%08lx\n",
641 psfi
->hIcon
, psfi
->iIcon
, psfi
->dwAttributes
,
642 debugstr_w(psfi
->szDisplayName
), debugstr_w(psfi
->szTypeName
), ret
);
648 /*************************************************************************
649 * SHGetFileInfoA [SHELL32.@]
652 * MSVBVM60.__vbaNew2 expects this function to return a value in range
653 * 1 .. 0x7fff when the function succeeds and flags does not contain
654 * SHGFI_EXETYPE or SHGFI_SYSICONINDEX (see bug 7701)
656 DWORD_PTR WINAPI
SHGetFileInfoA(LPCSTR path
,DWORD dwFileAttributes
,
657 SHFILEINFOA
*psfi
, UINT sizeofpsfi
,
661 LPWSTR temppath
= NULL
;
664 SHFILEINFOW temppsfi
;
666 if (flags
& SHGFI_PIDL
)
668 /* path contains a pidl */
669 pathW
= (LPCWSTR
)path
;
673 len
= MultiByteToWideChar(CP_ACP
, 0, path
, -1, NULL
, 0);
674 temppath
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
675 MultiByteToWideChar(CP_ACP
, 0, path
, -1, temppath
, len
);
679 if (psfi
&& (flags
& SHGFI_ATTR_SPECIFIED
))
680 temppsfi
.dwAttributes
=psfi
->dwAttributes
;
683 ret
= SHGetFileInfoW(pathW
, dwFileAttributes
, NULL
, sizeof(temppsfi
), flags
);
685 ret
= SHGetFileInfoW(pathW
, dwFileAttributes
, &temppsfi
, sizeof(temppsfi
), flags
);
689 if(flags
& SHGFI_ICON
)
690 psfi
->hIcon
=temppsfi
.hIcon
;
691 if(flags
& (SHGFI_SYSICONINDEX
|SHGFI_ICON
|SHGFI_ICONLOCATION
))
692 psfi
->iIcon
=temppsfi
.iIcon
;
693 if(flags
& SHGFI_ATTRIBUTES
)
694 psfi
->dwAttributes
=temppsfi
.dwAttributes
;
695 if(flags
& (SHGFI_DISPLAYNAME
|SHGFI_ICONLOCATION
))
697 WideCharToMultiByte(CP_ACP
, 0, temppsfi
.szDisplayName
, -1,
698 psfi
->szDisplayName
, sizeof(psfi
->szDisplayName
), NULL
, NULL
);
700 if(flags
& SHGFI_TYPENAME
)
702 WideCharToMultiByte(CP_ACP
, 0, temppsfi
.szTypeName
, -1,
703 psfi
->szTypeName
, sizeof(psfi
->szTypeName
), NULL
, NULL
);
707 HeapFree(GetProcessHeap(), 0, temppath
);
712 /*************************************************************************
713 * DuplicateIcon [SHELL32.@]
715 EXTERN_C HICON WINAPI
DuplicateIcon( HINSTANCE hInstance
, HICON hIcon
)
720 TRACE("%p %p\n", hInstance
, hIcon
);
722 if (GetIconInfo(hIcon
, &IconInfo
))
724 hDupIcon
= CreateIconIndirect(&IconInfo
);
726 /* clean up hbmMask and hbmColor */
727 DeleteObject(IconInfo
.hbmMask
);
728 DeleteObject(IconInfo
.hbmColor
);
734 /*************************************************************************
735 * ExtractIconA [SHELL32.@]
737 HICON WINAPI
ExtractIconA(HINSTANCE hInstance
, LPCSTR lpszFile
, UINT nIconIndex
)
740 INT len
= MultiByteToWideChar(CP_ACP
, 0, lpszFile
, -1, NULL
, 0);
741 LPWSTR lpwstrFile
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
743 TRACE("%p %s %d\n", hInstance
, lpszFile
, nIconIndex
);
745 MultiByteToWideChar(CP_ACP
, 0, lpszFile
, -1, lpwstrFile
, len
);
746 ret
= ExtractIconW(hInstance
, lpwstrFile
, nIconIndex
);
747 HeapFree(GetProcessHeap(), 0, lpwstrFile
);
752 /*************************************************************************
753 * ExtractIconW [SHELL32.@]
755 HICON WINAPI
ExtractIconW(HINSTANCE hInstance
, LPCWSTR lpszFile
, UINT nIconIndex
)
759 UINT cx
= GetSystemMetrics(SM_CXICON
), cy
= GetSystemMetrics(SM_CYICON
);
761 TRACE("%p %s %d\n", hInstance
, debugstr_w(lpszFile
), nIconIndex
);
763 if (nIconIndex
== 0xFFFFFFFF)
765 ret
= PrivateExtractIconsW(lpszFile
, 0, cx
, cy
, NULL
, NULL
, 0, LR_DEFAULTCOLOR
);
766 if (ret
!= 0xFFFFFFFF && ret
)
767 return (HICON
)(UINT_PTR
)ret
;
771 ret
= PrivateExtractIconsW(lpszFile
, nIconIndex
, cx
, cy
, &hIcon
, NULL
, 1, LR_DEFAULTCOLOR
);
773 if (ret
== 0xFFFFFFFF)
775 else if (ret
> 0 && hIcon
)
781 /*************************************************************************
782 * Printer_LoadIconsW [SHELL32.205]
784 EXTERN_C VOID WINAPI
Printer_LoadIconsW(LPCWSTR wsPrinterName
, HICON
* pLargeIcon
, HICON
* pSmallIcon
)
786 INT iconindex
=IDI_SHELL_PRINTERS_FOLDER
;
788 TRACE("(%s, %p, %p)\n", debugstr_w(wsPrinterName
), pLargeIcon
, pSmallIcon
);
790 /* We should check if wsPrinterName is
791 1. the Default Printer or not
793 3. a Local Printer or a Network-Printer
794 and use different Icons
796 if((wsPrinterName
!= NULL
) && (wsPrinterName
[0] != 0))
798 FIXME("(select Icon by PrinterName %s not implemented)\n", debugstr_w(wsPrinterName
));
801 if(pLargeIcon
!= NULL
)
802 *pLargeIcon
= (HICON
)LoadImageW(shell32_hInstance
,
803 (LPCWSTR
) MAKEINTRESOURCE(iconindex
), IMAGE_ICON
,
804 0, 0, LR_DEFAULTCOLOR
|LR_DEFAULTSIZE
);
806 if(pSmallIcon
!= NULL
)
807 *pSmallIcon
= (HICON
)LoadImageW(shell32_hInstance
,
808 (LPCWSTR
) MAKEINTRESOURCE(iconindex
), IMAGE_ICON
,
809 16, 16, LR_DEFAULTCOLOR
);
812 /*************************************************************************
813 * Printers_RegisterWindowW [SHELL32.213]
814 * used by "printui.dll":
815 * find the Window of the given Type for the specific Printer and
816 * return the already existent hwnd or open a new window
818 EXTERN_C BOOL WINAPI
Printers_RegisterWindowW(LPCWSTR wsPrinter
, DWORD dwType
,
819 HANDLE
* phClassPidl
, HWND
* phwnd
)
821 FIXME("(%s, %x, %p (%p), %p (%p)) stub!\n", debugstr_w(wsPrinter
), dwType
,
822 phClassPidl
, (phClassPidl
!= NULL
) ? *(phClassPidl
) : NULL
,
823 phwnd
, (phwnd
!= NULL
) ? *(phwnd
) : NULL
);
828 /*************************************************************************
829 * Printers_UnregisterWindow [SHELL32.214]
831 EXTERN_C VOID WINAPI
Printers_UnregisterWindow(HANDLE hClassPidl
, HWND hwnd
)
833 FIXME("(%p, %p) stub!\n", hClassPidl
, hwnd
);
836 /*************************************************************************/
841 LPCWSTR szOtherStuff
;
845 #define DROP_FIELD_TOP (-15)
846 #define DROP_FIELD_HEIGHT 15
848 /*************************************************************************
849 * SHAppBarMessage [SHELL32.@]
851 UINT_PTR WINAPI
SHAppBarMessage(DWORD msg
, PAPPBARDATA data
)
853 int width
=data
->rc
.right
- data
->rc
.left
;
854 int height
=data
->rc
.bottom
- data
->rc
.top
;
857 TRACE("msg=%d, data={cb=%d, hwnd=%p, callback=%x, edge=%d, rc=%s, lparam=%lx}\n",
858 msg
, data
->cbSize
, data
->hWnd
, data
->uCallbackMessage
, data
->uEdge
,
859 wine_dbgstr_rect(&data
->rc
), data
->lParam
);
864 return ABS_ALWAYSONTOP
| ABS_AUTOHIDE
;
866 case ABM_GETTASKBARPOS
:
867 GetWindowRect(data
->hWnd
, &rec
);
872 SetActiveWindow(data
->hWnd
);
875 case ABM_GETAUTOHIDEBAR
:
876 return 0; /* pretend there is no autohide bar */
879 /* cbSize, hWnd, and uCallbackMessage are used. All other ignored */
880 SetWindowPos(data
->hWnd
,HWND_TOP
,0,0,0,0,SWP_SHOWWINDOW
|SWP_NOMOVE
|SWP_NOSIZE
);
884 GetWindowRect(data
->hWnd
, &(data
->rc
));
888 FIXME("ABM_REMOVE broken\n");
889 /* FIXME: this is wrong; should it be DestroyWindow instead? */
890 /*CloseHandle(data->hWnd);*/
893 case ABM_SETAUTOHIDEBAR
:
894 SetWindowPos(data
->hWnd
,HWND_TOP
,rec
.left
+1000,rec
.top
,
895 width
,height
,SWP_SHOWWINDOW
);
899 data
->uEdge
=(ABE_RIGHT
| ABE_LEFT
);
900 SetWindowPos(data
->hWnd
,HWND_TOP
,data
->rc
.left
,data
->rc
.top
,
901 width
,height
,SWP_SHOWWINDOW
);
904 case ABM_WINDOWPOSCHANGED
:
911 /*************************************************************************
912 * SHHelpShortcuts_RunDLLA [SHELL32.@]
915 EXTERN_C DWORD WINAPI
SHHelpShortcuts_RunDLLA(DWORD dwArg1
, DWORD dwArg2
, DWORD dwArg3
, DWORD dwArg4
)
917 FIXME("(%x, %x, %x, %x) stub!\n", dwArg1
, dwArg2
, dwArg3
, dwArg4
);
921 /*************************************************************************
922 * SHHelpShortcuts_RunDLLA [SHELL32.@]
925 EXTERN_C DWORD WINAPI
SHHelpShortcuts_RunDLLW(DWORD dwArg1
, DWORD dwArg2
, DWORD dwArg3
, DWORD dwArg4
)
927 FIXME("(%x, %x, %x, %x) stub!\n", dwArg1
, dwArg2
, dwArg3
, dwArg4
);
931 /*************************************************************************
932 * SHLoadInProc [SHELL32.@]
933 * Create an instance of specified object class from within
934 * the shell process and release it immediately
936 EXTERN_C HRESULT WINAPI
SHLoadInProc (REFCLSID rclsid
)
938 CComPtr
<IUnknown
> ptr
;
940 TRACE("%s\n", debugstr_guid(&rclsid
));
942 CoCreateInstance(rclsid
, NULL
, CLSCTX_INPROC_SERVER
, IID_IUnknown
, (void **)&ptr
);
945 return DISP_E_MEMBERNOTFOUND
;
948 static VOID
SetRegTextData(HWND hWnd
, HKEY hKey
, LPCWSTR Value
, UINT uID
)
954 if( RegQueryValueExW(hKey
, Value
, NULL
, &dwType
, NULL
, &dwBufferSize
) == ERROR_SUCCESS
)
958 lpBuffer
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, dwBufferSize
);
962 if( RegQueryValueExW(hKey
, Value
, NULL
, &dwType
, (LPBYTE
)lpBuffer
, &dwBufferSize
) == ERROR_SUCCESS
)
964 SetDlgItemTextW(hWnd
, uID
, lpBuffer
);
967 HeapFree(GetProcessHeap(), 0, lpBuffer
);
973 INT_PTR CALLBACK
AboutAuthorsDlgProc( HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
979 const char* const *pstr
= SHELL_Authors
;
981 // Add the authors to the list
982 SendDlgItemMessageW( hWnd
, IDC_ABOUT_AUTHORS_LISTBOX
, WM_SETREDRAW
, FALSE
, 0 );
988 /* authors list is in utf-8 format */
989 MultiByteToWideChar( CP_UTF8
, 0, *pstr
, -1, name
, sizeof(name
)/sizeof(WCHAR
) );
990 SendDlgItemMessageW( hWnd
, IDC_ABOUT_AUTHORS_LISTBOX
, LB_ADDSTRING
, (WPARAM
)-1, (LPARAM
)name
);
994 SendDlgItemMessageW( hWnd
, IDC_ABOUT_AUTHORS_LISTBOX
, WM_SETREDRAW
, TRUE
, 0 );
1002 /*************************************************************************
1003 * AboutDlgProc (internal)
1005 INT_PTR CALLBACK
AboutDlgProc( HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1007 static DWORD cxLogoBmp
;
1008 static DWORD cyLogoBmp
;
1009 static HBITMAP hLogoBmp
;
1010 static HWND hWndAuthors
;
1016 ABOUT_INFO
*info
= (ABOUT_INFO
*)lParam
;
1020 const WCHAR szRegKey
[] = L
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion";
1022 MEMORYSTATUSEX MemStat
;
1023 WCHAR szAppTitle
[512];
1024 WCHAR szAppTitleTemplate
[512];
1025 WCHAR szAuthorsText
[20];
1027 // Preload the ROS bitmap
1028 hLogoBmp
= (HBITMAP
)LoadImage(shell32_hInstance
, MAKEINTRESOURCE(IDB_SHELL_ABOUT_LOGO_24BPP
), IMAGE_BITMAP
, 0, 0, LR_DEFAULTCOLOR
);
1034 GetObject( hLogoBmp
, sizeof(BITMAP
), &bmpLogo
);
1036 cxLogoBmp
= bmpLogo
.bmWidth
;
1037 cyLogoBmp
= bmpLogo
.bmHeight
;
1040 // Set App-specific stuff (icon, app name, szOtherStuff string)
1041 SendDlgItemMessageW(hWnd
, IDC_ABOUT_ICON
, STM_SETICON
, (WPARAM
)info
->hIcon
, 0);
1043 GetWindowTextW( hWnd
, szAppTitleTemplate
, sizeof(szAppTitleTemplate
) / sizeof(WCHAR
) );
1044 swprintf( szAppTitle
, szAppTitleTemplate
, info
->szApp
);
1045 SetWindowTextW( hWnd
, szAppTitle
);
1047 SetDlgItemTextW( hWnd
, IDC_ABOUT_APPNAME
, info
->szApp
);
1048 SetDlgItemTextW( hWnd
, IDC_ABOUT_OTHERSTUFF
, info
->szOtherStuff
);
1050 // Set the registered user and organization name
1051 if(RegOpenKeyExW( HKEY_LOCAL_MACHINE
, szRegKey
, 0, KEY_QUERY_VALUE
, &hRegKey
) == ERROR_SUCCESS
)
1053 SetRegTextData( hWnd
, hRegKey
, L
"RegisteredOwner", IDC_ABOUT_REG_USERNAME
);
1054 SetRegTextData( hWnd
, hRegKey
, L
"RegisteredOrganization", IDC_ABOUT_REG_ORGNAME
);
1056 RegCloseKey( hRegKey
);
1059 // Set the value for the installed physical memory
1060 MemStat
.dwLength
= sizeof(MemStat
);
1061 if( GlobalMemoryStatusEx(&MemStat
) )
1065 if (MemStat
.ullTotalPhys
> 1024 * 1024 * 1024)
1068 WCHAR szDecimalSeparator
[4];
1071 // We're dealing with GBs or more
1072 MemStat
.ullTotalPhys
/= 1024 * 1024;
1074 if (MemStat
.ullTotalPhys
> 1024 * 1024)
1076 // We're dealing with TBs or more
1077 MemStat
.ullTotalPhys
/= 1024;
1079 if (MemStat
.ullTotalPhys
> 1024 * 1024)
1081 // We're dealing with PBs or more
1082 MemStat
.ullTotalPhys
/= 1024;
1084 dTotalPhys
= (double)MemStat
.ullTotalPhys
/ 1024;
1085 wcscpy( szUnits
, L
"PB" );
1089 dTotalPhys
= (double)MemStat
.ullTotalPhys
/ 1024;
1090 wcscpy( szUnits
, L
"TB" );
1095 dTotalPhys
= (double)MemStat
.ullTotalPhys
/ 1024;
1096 wcscpy( szUnits
, L
"GB" );
1099 // We need the decimal point of the current locale to display the RAM size correctly
1100 if (GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SDECIMAL
,
1102 sizeof(szDecimalSeparator
) / sizeof(WCHAR
)) > 0)
1107 uIntegral
= (UINT
)dTotalPhys
;
1108 uDecimals
= (UCHAR
)((UINT
)(dTotalPhys
* 100) - uIntegral
* 100);
1110 // Display the RAM size with 2 decimals
1111 swprintf(szBuf
, L
"%u%s%02u %s", uIntegral
, szDecimalSeparator
, uDecimals
, szUnits
);
1116 // We're dealing with MBs, don't show any decimals
1117 swprintf( szBuf
, L
"%u MB", (UINT
)MemStat
.ullTotalPhys
/ 1024 / 1024 );
1120 SetDlgItemTextW( hWnd
, IDC_ABOUT_PHYSMEM
, szBuf
);
1123 // Add the Authors dialog
1124 hWndAuthors
= CreateDialogW( shell32_hInstance
, MAKEINTRESOURCEW(IDD_ABOUT_AUTHORS
), hWnd
, AboutAuthorsDlgProc
);
1125 LoadStringW( shell32_hInstance
, IDS_SHELL_ABOUT_AUTHORS
, szAuthorsText
, sizeof(szAuthorsText
) / sizeof(WCHAR
) );
1126 SetDlgItemTextW( hWnd
, IDC_ABOUT_AUTHORS
, szAuthorsText
);
1140 hdc
= BeginPaint(hWnd
, &ps
);
1141 hdcMem
= CreateCompatibleDC(hdc
);
1145 SelectObject(hdcMem
, hLogoBmp
);
1146 BitBlt(hdc
, 0, 0, cxLogoBmp
, cyLogoBmp
, hdcMem
, 0, 0, SRCCOPY
);
1151 EndPaint(hWnd
, &ps
);
1161 EndDialog(hWnd
, TRUE
);
1164 case IDC_ABOUT_AUTHORS
:
1166 static BOOL bShowingAuthors
= FALSE
;
1167 WCHAR szAuthorsText
[20];
1171 LoadStringW( shell32_hInstance
, IDS_SHELL_ABOUT_AUTHORS
, szAuthorsText
, sizeof(szAuthorsText
) / sizeof(WCHAR
) );
1172 ShowWindow( hWndAuthors
, SW_HIDE
);
1176 LoadStringW( shell32_hInstance
, IDS_SHELL_ABOUT_BACK
, szAuthorsText
, sizeof(szAuthorsText
) / sizeof(WCHAR
) );
1177 ShowWindow( hWndAuthors
, SW_SHOW
);
1180 SetDlgItemTextW( hWnd
, IDC_ABOUT_AUTHORS
, szAuthorsText
);
1181 bShowingAuthors
= !bShowingAuthors
;
1188 EndDialog(hWnd
, TRUE
);
1196 /*************************************************************************
1197 * ShellAboutA [SHELL32.288]
1199 BOOL WINAPI
ShellAboutA( HWND hWnd
, LPCSTR szApp
, LPCSTR szOtherStuff
, HICON hIcon
)
1202 LPWSTR appW
= NULL
, otherW
= NULL
;
1207 len
= MultiByteToWideChar(CP_ACP
, 0, szApp
, -1, NULL
, 0);
1208 appW
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1209 MultiByteToWideChar(CP_ACP
, 0, szApp
, -1, appW
, len
);
1213 len
= MultiByteToWideChar(CP_ACP
, 0, szOtherStuff
, -1, NULL
, 0);
1214 otherW
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1215 MultiByteToWideChar(CP_ACP
, 0, szOtherStuff
, -1, otherW
, len
);
1218 ret
= ShellAboutW(hWnd
, appW
, otherW
, hIcon
);
1220 HeapFree(GetProcessHeap(), 0, otherW
);
1221 HeapFree(GetProcessHeap(), 0, appW
);
1226 /*************************************************************************
1227 * ShellAboutW [SHELL32.289]
1229 BOOL WINAPI
ShellAboutW( HWND hWnd
, LPCWSTR szApp
, LPCWSTR szOtherStuff
,
1234 DLGTEMPLATE
*DlgTemplate
;
1239 // DialogBoxIndirectParamW will be called with the hInstance of the calling application, so we have to preload the dialog template
1240 hRes
= FindResourceW(shell32_hInstance
, MAKEINTRESOURCEW(IDD_ABOUT
), (LPWSTR
)RT_DIALOG
);
1244 DlgTemplate
= (DLGTEMPLATE
*)LoadResource(shell32_hInstance
, hRes
);
1249 info
.szOtherStuff
= szOtherStuff
;
1250 info
.hIcon
= hIcon
? hIcon
: LoadIconW( 0, (LPWSTR
)IDI_WINLOGO
);
1252 bRet
= DialogBoxIndirectParamW((HINSTANCE
)GetWindowLongPtrW( hWnd
, GWLP_HINSTANCE
),
1253 DlgTemplate
, hWnd
, AboutDlgProc
, (LPARAM
)&info
);
1257 /*************************************************************************
1258 * FreeIconList (SHELL32.@)
1260 EXTERN_C
void WINAPI
FreeIconList( DWORD dw
)
1262 FIXME("%x: stub\n",dw
);
1265 /*************************************************************************
1266 * SHLoadNonloadedIconOverlayIdentifiers (SHELL32.@)
1268 EXTERN_C HRESULT WINAPI
SHLoadNonloadedIconOverlayIdentifiers(VOID
)
1274 class CShell32Module
: public CComModule
1280 BEGIN_OBJECT_MAP(ObjectMap
)
1281 OBJECT_ENTRY(CLSID_ShellFSFolder
, CFSFolder
)
1282 OBJECT_ENTRY(CLSID_MyComputer
, CDrivesFolder
)
1283 OBJECT_ENTRY(CLSID_ShellDesktop
, CDesktopFolder
)
1284 OBJECT_ENTRY(CLSID_ShellItem
, CShellItem
)
1285 OBJECT_ENTRY(CLSID_ShellLink
, CShellLink
)
1286 OBJECT_ENTRY(CLSID_DragDropHelper
, CDropTargetHelper
)
1287 OBJECT_ENTRY(CLSID_ControlPanel
, CControlPanelFolder
)
1288 OBJECT_ENTRY(CLSID_AutoComplete
, CAutoComplete
)
1289 OBJECT_ENTRY(CLSID_MyDocuments
, CMyDocsFolder
)
1290 OBJECT_ENTRY(CLSID_NetworkPlaces
, CNetFolder
)
1291 OBJECT_ENTRY(CLSID_FontsFolderShortcut
, CFontsFolder
)
1292 OBJECT_ENTRY(CLSID_Printers
, CPrinterFolder
)
1293 OBJECT_ENTRY(CLSID_AdminFolderShortcut
, CAdminToolsFolder
)
1294 OBJECT_ENTRY(CLSID_RecycleBin
, CRecycleBin
)
1295 OBJECT_ENTRY(CLSID_OpenWithMenu
, COpenWithMenu
)
1296 OBJECT_ENTRY(CLSID_NewMenu
, CNewMenu
)
1297 OBJECT_ENTRY(CLSID_StartMenu
, CStartMenu
)
1298 OBJECT_ENTRY(CLSID_MenuBandSite
, CMenuBandSite
)
1301 CShell32Module gModule
;
1304 /***********************************************************************
1305 * DllGetVersion [SHELL32.@]
1307 * Retrieves version information of the 'SHELL32.DLL'
1310 * pdvi [O] pointer to version information structure.
1314 * Failure: E_INVALIDARG
1317 * Returns version of a shell32.dll from IE4.01 SP1.
1320 STDAPI
DllGetVersion(DLLVERSIONINFO
*pdvi
)
1322 /* FIXME: shouldn't these values come from the version resource? */
1323 if (pdvi
->cbSize
== sizeof(DLLVERSIONINFO
) ||
1324 pdvi
->cbSize
== sizeof(DLLVERSIONINFO2
))
1326 pdvi
->dwMajorVersion
= WINE_FILEVERSION_MAJOR
;
1327 pdvi
->dwMinorVersion
= WINE_FILEVERSION_MINOR
;
1328 pdvi
->dwBuildNumber
= WINE_FILEVERSION_BUILD
;
1329 pdvi
->dwPlatformID
= WINE_FILEVERSION_PLATFORMID
;
1330 if (pdvi
->cbSize
== sizeof(DLLVERSIONINFO2
))
1332 DLLVERSIONINFO2
*pdvi2
= (DLLVERSIONINFO2
*)pdvi
;
1335 pdvi2
->ullVersion
= MAKEDLLVERULL(WINE_FILEVERSION_MAJOR
,
1336 WINE_FILEVERSION_MINOR
,
1337 WINE_FILEVERSION_BUILD
,
1338 WINE_FILEVERSION_PLATFORMID
);
1340 TRACE("%u.%u.%u.%u\n",
1341 pdvi
->dwMajorVersion
, pdvi
->dwMinorVersion
,
1342 pdvi
->dwBuildNumber
, pdvi
->dwPlatformID
);
1347 WARN("wrong DLLVERSIONINFO size from app\n");
1348 return E_INVALIDARG
;
1352 /*************************************************************************
1353 * global variables of the shell32.dll
1354 * all are once per process
1357 HINSTANCE shell32_hInstance
;
1358 HIMAGELIST ShellSmallIconList
= 0;
1359 HIMAGELIST ShellBigIconList
= 0;
1361 void *operator new (size_t, void *buf
)
1366 /*************************************************************************
1370 * calling oleinitialize here breaks sone apps.
1372 STDAPI_(BOOL
) DllMain(HINSTANCE hInstance
, DWORD dwReason
, LPVOID fImpLoad
)
1374 TRACE("%p 0x%x %p\n", hInstance
, dwReason
, fImpLoad
);
1375 if (dwReason
== DLL_PROCESS_ATTACH
)
1377 /* HACK - the global constructors don't run, so I placement new them here */
1378 new (&gModule
) CShell32Module
;
1379 new (&_AtlWinModule
) CAtlWinModule
;
1380 new (&_AtlBaseModule
) CAtlBaseModule
;
1381 new (&_AtlComModule
) CAtlComModule
;
1383 shell32_hInstance
= hInstance
;
1384 gModule
.Init(ObjectMap
, hInstance
, NULL
);
1386 DisableThreadLibraryCalls (hInstance
);
1388 /* get full path to this DLL for IExtractIconW_fnGetIconLocation() */
1389 GetModuleFileNameW(hInstance
, swShell32Name
, MAX_PATH
);
1390 swShell32Name
[MAX_PATH
- 1] = '\0';
1392 InitCommonControlsEx(NULL
);
1395 InitChangeNotifications();
1398 else if (dwReason
== DLL_PROCESS_DETACH
)
1400 shell32_hInstance
= NULL
;
1402 FreeChangeNotifications();
1408 /***********************************************************************
1409 * DllCanUnloadNow (SHELL32.@)
1411 STDAPI
DllCanUnloadNow()
1413 return gModule
.DllCanUnloadNow();
1416 /*************************************************************************
1417 * DllGetClassObject [SHELL32.@]
1418 * SHDllGetClassObject [SHELL32.128]
1420 STDAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
*ppv
)
1424 TRACE("CLSID:%s,IID:%s\n", shdebugstr_guid(&rclsid
), shdebugstr_guid(&riid
));
1426 hResult
= gModule
.DllGetClassObject(rclsid
, riid
, ppv
);
1427 TRACE("-- pointer to class factory: %p\n", *ppv
);
1431 /***********************************************************************
1432 * DllRegisterServer (SHELL32.@)
1434 STDAPI
DllRegisterServer()
1438 hr
= gModule
.DllRegisterServer(FALSE
);
1442 hr
= gModule
.UpdateRegistryFromResource(IDR_FOLDEROPTIONS
, TRUE
, NULL
);
1446 hr
= SHELL_RegisterShellFolders();
1453 /***********************************************************************
1454 * DllUnregisterServer (SHELL32.@)
1456 STDAPI
DllUnregisterServer()
1460 hr
= gModule
.DllUnregisterServer(FALSE
);
1464 hr
= gModule
.UpdateRegistryFromResource(IDR_FOLDEROPTIONS
, FALSE
, NULL
);
1471 /*************************************************************************
1472 * DllInstall [SHELL32.@]
1476 * BOOL bInstall - TRUE for install, FALSE for uninstall
1477 * LPCWSTR pszCmdLine - command line (unused by shell32?)
1480 HRESULT WINAPI
DllInstall(BOOL bInstall
, LPCWSTR cmdline
)
1482 FIXME("%s %s: stub\n", bInstall
? "TRUE":"FALSE", debugstr_w(cmdline
));
1483 return S_OK
; /* indicate success */