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 /* Return the path to the executable */
74 argv
= (LPWSTR
*)LocalAlloc(LMEM_FIXED
, size
);
77 len
= GetModuleFileNameW(0, (LPWSTR
)(argv
+1), (size
-sizeof(LPWSTR
))/sizeof(WCHAR
));
83 if (len
< size
) break;
85 argv
= (LPWSTR
*)LocalReAlloc(argv
, size
, 0);
87 argv
[0]=(LPWSTR
)(argv
+1);
94 /* to get a writable copy */
101 if (*cs
==0 || ((*cs
==0x0009 || *cs
==0x0020) && !in_quotes
))
105 /* skip the remaining spaces */
106 while (*cs
==0x0009 || *cs
==0x0020)
115 else if (*cs
==0x005c)
117 /* '\', count them */
120 else if ((*cs
==0x0022) && ((bcount
& 1)==0))
123 in_quotes
=!in_quotes
;
128 /* a regular character */
133 /* Allocate in a single lump, the string array, and the strings that go with it.
134 * This way the caller can make a single GlobalFree call to free both, as per MSDN.
136 argv
= (LPWSTR
*)LocalAlloc(LMEM_FIXED
, argc
*sizeof(LPWSTR
)+(wcslen(lpCmdline
)+1)*sizeof(WCHAR
));
141 cmdline
=(LPWSTR
)(argv
+argc
);
142 wcscpy(cmdline
, lpCmdline
);
150 if ((*s
==0x0009 || *s
==0x0020) && !in_quotes
)
152 /* Close the argument and copy it */
156 /* skip the remaining spaces */
159 } while (*s
==0x0009 || *s
==0x0020);
161 /* Start with a new argument */
176 /* Preceded by an even number of '\', this is half that
177 * number of '\', plus a quote which we erase.
180 in_quotes
=!in_quotes
;
185 /* Preceded by an odd number of '\', this is half that
186 * number of '\' followed by a '"'
196 /* a regular character */
212 static DWORD
shgfi_get_exe_type(LPCWSTR szFullPath
)
217 IMAGE_DOS_HEADER mz_header
;
222 status
= GetBinaryTypeW (szFullPath
, &BinaryType
);
225 if (BinaryType
== SCS_DOS_BINARY
|| BinaryType
== SCS_PIF_BINARY
)
228 hfile
= CreateFileW( szFullPath
, GENERIC_READ
, FILE_SHARE_READ
,
229 NULL
, OPEN_EXISTING
, 0, 0 );
230 if ( hfile
== INVALID_HANDLE_VALUE
)
234 * The next section is adapted from MODULE_GetBinaryType, as we need
235 * to examine the image header to get OS and version information. We
236 * know from calling GetBinaryTypeA that the image is valid and either
237 * an NE or PE, so much error handling can be omitted.
238 * Seek to the start of the file and read the header information.
241 SetFilePointer( hfile
, 0, NULL
, SEEK_SET
);
242 ReadFile( hfile
, &mz_header
, sizeof(mz_header
), &len
, NULL
);
244 SetFilePointer( hfile
, mz_header
.e_lfanew
, NULL
, SEEK_SET
);
245 ReadFile( hfile
, magic
, sizeof(magic
), &len
, NULL
);
247 if ( *(DWORD
*)magic
== IMAGE_NT_SIGNATURE
)
249 SetFilePointer( hfile
, mz_header
.e_lfanew
, NULL
, SEEK_SET
);
250 ReadFile( hfile
, &nt
, sizeof(nt
), &len
, NULL
);
251 CloseHandle( hfile
);
253 /* DLL files are not executable and should return 0 */
254 if (nt
.FileHeader
.Characteristics
& IMAGE_FILE_DLL
)
257 if (nt
.OptionalHeader
.Subsystem
== IMAGE_SUBSYSTEM_WINDOWS_GUI
)
259 return IMAGE_NT_SIGNATURE
|
260 (nt
.OptionalHeader
.MajorSubsystemVersion
<< 24) |
261 (nt
.OptionalHeader
.MinorSubsystemVersion
<< 16);
263 return IMAGE_NT_SIGNATURE
;
265 else if ( *(WORD
*)magic
== IMAGE_OS2_SIGNATURE
)
268 SetFilePointer( hfile
, mz_header
.e_lfanew
, NULL
, SEEK_SET
);
269 ReadFile( hfile
, &ne
, sizeof(ne
), &len
, NULL
);
270 CloseHandle( hfile
);
272 if (ne
.ne_exetyp
== 2)
273 return IMAGE_OS2_SIGNATURE
| (ne
.ne_expver
<< 16);
276 CloseHandle( hfile
);
280 /*************************************************************************
281 * SHELL_IsShortcut [internal]
283 * Decide if an item id list points to a shell shortcut
285 BOOL
SHELL_IsShortcut(LPCITEMIDLIST pidlLast
)
287 char szTemp
[MAX_PATH
];
291 if (_ILGetExtension(pidlLast
, szTemp
, MAX_PATH
) &&
292 HCR_MapTypeToValueA(szTemp
, szTemp
, MAX_PATH
, TRUE
))
294 if (ERROR_SUCCESS
== RegOpenKeyExA(HKEY_CLASSES_ROOT
, szTemp
, 0, KEY_QUERY_VALUE
, &keyCls
))
296 if (ERROR_SUCCESS
== RegQueryValueExA(keyCls
, "IsShortcut", NULL
, NULL
, NULL
, NULL
))
306 #define SHGFI_KNOWN_FLAGS \
307 (SHGFI_SMALLICON | SHGFI_OPENICON | SHGFI_SHELLICONSIZE | SHGFI_PIDL | \
308 SHGFI_USEFILEATTRIBUTES | SHGFI_ADDOVERLAYS | SHGFI_OVERLAYINDEX | \
309 SHGFI_ICON | SHGFI_DISPLAYNAME | SHGFI_TYPENAME | SHGFI_ATTRIBUTES | \
310 SHGFI_ICONLOCATION | SHGFI_EXETYPE | SHGFI_SYSICONINDEX | \
311 SHGFI_LINKOVERLAY | SHGFI_SELECTED | SHGFI_ATTR_SPECIFIED)
313 /*************************************************************************
314 * SHGetFileInfoW [SHELL32.@]
317 DWORD_PTR WINAPI
SHGetFileInfoW(LPCWSTR path
,DWORD dwFileAttributes
,
318 SHFILEINFOW
*psfi
, UINT sizeofpsfi
, UINT flags
)
320 WCHAR szLocation
[MAX_PATH
], szFullPath
[MAX_PATH
];
322 DWORD_PTR ret
= TRUE
;
323 DWORD dwAttributes
= 0;
324 CComPtr
<IShellFolder
> psfParent
;
325 CComPtr
<IExtractIconW
> pei
;
326 LPITEMIDLIST pidlLast
= NULL
, pidl
= NULL
;
328 BOOL IconNotYetLoaded
=TRUE
;
331 TRACE("%s fattr=0x%x sfi=%p(attr=0x%08x) size=0x%x flags=0x%x\n",
332 (flags
& SHGFI_PIDL
)? "pidl" : debugstr_w(path
), dwFileAttributes
,
333 psfi
, psfi
->dwAttributes
, sizeofpsfi
, flags
);
338 /* windows initializes these values regardless of the flags */
341 psfi
->szDisplayName
[0] = '\0';
342 psfi
->szTypeName
[0] = '\0';
346 if (!(flags
& SHGFI_PIDL
))
348 /* SHGetFileInfo should work with absolute and relative paths */
349 if (PathIsRelativeW(path
))
351 GetCurrentDirectoryW(MAX_PATH
, szLocation
);
352 PathCombineW(szFullPath
, szLocation
, path
);
356 lstrcpynW(szFullPath
, path
, MAX_PATH
);
360 if (flags
& SHGFI_EXETYPE
)
362 if (flags
!= SHGFI_EXETYPE
)
364 return shgfi_get_exe_type(szFullPath
);
368 * psfi is NULL normally to query EXE type. If it is NULL, none of the
369 * below makes sense anyway. Windows allows this and just returns FALSE
375 * translate the path into a pidl only when SHGFI_USEFILEATTRIBUTES
377 * The pidl functions fail on not existing file names
380 if (flags
& SHGFI_PIDL
)
382 pidl
= ILClone((LPCITEMIDLIST
)path
);
384 else if (!(flags
& SHGFI_USEFILEATTRIBUTES
))
386 hr
= SHILCreateFromPathW(szFullPath
, &pidl
, &dwAttributes
);
389 if ((flags
& SHGFI_PIDL
) || !(flags
& SHGFI_USEFILEATTRIBUTES
))
391 /* get the parent shellfolder */
394 hr
= SHBindToParent( pidl
, IID_IShellFolder
, (LPVOID
*)&psfParent
,
395 (LPCITEMIDLIST
*)&pidlLast
);
397 pidlLast
= ILClone(pidlLast
);
402 ERR("pidl is null!\n");
407 /* get the attributes of the child */
408 if (SUCCEEDED(hr
) && (flags
& SHGFI_ATTRIBUTES
))
410 if (!(flags
& SHGFI_ATTR_SPECIFIED
))
412 psfi
->dwAttributes
= 0xffffffff;
414 if (psfParent
!= NULL
)
415 psfParent
->GetAttributesOf(1, (LPCITEMIDLIST
*)&pidlLast
,
416 &(psfi
->dwAttributes
) );
419 /* get the displayname */
420 if (SUCCEEDED(hr
) && (flags
& SHGFI_DISPLAYNAME
))
422 if (flags
& SHGFI_USEFILEATTRIBUTES
)
424 wcscpy (psfi
->szDisplayName
, PathFindFileNameW(szFullPath
));
429 hr
= psfParent
->GetDisplayNameOf(pidlLast
,
430 SHGDN_INFOLDER
, &str
);
431 StrRetToStrNW (psfi
->szDisplayName
, MAX_PATH
, &str
, pidlLast
);
435 /* get the type name */
436 if (SUCCEEDED(hr
) && (flags
& SHGFI_TYPENAME
))
438 static const WCHAR szFile
[] = { 'F','i','l','e',0 };
439 static const WCHAR szDashFile
[] = { '-','f','i','l','e',0 };
441 if (!(flags
& SHGFI_USEFILEATTRIBUTES
))
445 _ILGetFileType(pidlLast
, ftype
, 80);
446 MultiByteToWideChar(CP_ACP
, 0, ftype
, -1, psfi
->szTypeName
, 80 );
450 if (dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
451 wcscat (psfi
->szTypeName
, szFile
);
456 wcscpy(sTemp
,PathFindExtensionW(szFullPath
));
457 if (!( HCR_MapTypeToValueW(sTemp
, sTemp
, 64, TRUE
) &&
458 HCR_MapTypeToValueW(sTemp
, psfi
->szTypeName
, 80, FALSE
)))
460 lstrcpynW (psfi
->szTypeName
, sTemp
, 64);
461 wcscat (psfi
->szTypeName
, szDashFile
);
468 if (flags
& SHGFI_OPENICON
)
469 uGilFlags
|= GIL_OPENICON
;
471 if (flags
& SHGFI_LINKOVERLAY
)
472 uGilFlags
|= GIL_FORSHORTCUT
;
473 else if ((flags
&SHGFI_ADDOVERLAYS
) ||
474 (flags
&(SHGFI_ICON
|SHGFI_SMALLICON
))==SHGFI_ICON
)
476 if (SHELL_IsShortcut(pidlLast
))
477 uGilFlags
|= GIL_FORSHORTCUT
;
480 if (flags
& SHGFI_OVERLAYINDEX
)
481 FIXME("SHGFI_OVERLAYINDEX unhandled\n");
483 if (flags
& SHGFI_SELECTED
)
484 FIXME("set icon to selected, stub\n");
486 if (flags
& SHGFI_SHELLICONSIZE
)
487 FIXME("set icon to shell size, stub\n");
489 /* get the iconlocation */
490 if (SUCCEEDED(hr
) && (flags
& SHGFI_ICONLOCATION
))
494 if (flags
& SHGFI_USEFILEATTRIBUTES
)
496 if (dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
498 wcscpy(psfi
->szDisplayName
, swShell32Name
);
499 psfi
->iIcon
= -IDI_SHELL_FOLDER
;
504 static const WCHAR p1W
[] = {'%','1',0};
505 WCHAR sTemp
[MAX_PATH
];
507 szExt
= PathFindExtensionW(szFullPath
);
508 TRACE("szExt=%s\n", debugstr_w(szExt
));
510 HCR_MapTypeToValueW(szExt
, sTemp
, MAX_PATH
, TRUE
) &&
511 HCR_GetDefaultIconW(sTemp
, sTemp
, MAX_PATH
, &psfi
->iIcon
))
513 if (lstrcmpW(p1W
, sTemp
))
514 wcscpy(psfi
->szDisplayName
, sTemp
);
517 /* the icon is in the file */
518 wcscpy(psfi
->szDisplayName
, szFullPath
);
527 hr
= psfParent
->GetUIObjectOf(0, 1,
528 (LPCITEMIDLIST
*)&pidlLast
, IID_IExtractIconW
,
529 &uDummy
, (LPVOID
*)&pei
);
532 hr
= pei
->GetIconLocation(uGilFlags
,
533 szLocation
, MAX_PATH
, &iIndex
, &uFlags
);
535 if (uFlags
& GIL_NOTFILENAME
)
539 wcscpy (psfi
->szDisplayName
, szLocation
);
540 psfi
->iIcon
= iIndex
;
546 /* get icon index (or load icon)*/
547 if (SUCCEEDED(hr
) && (flags
& (SHGFI_ICON
| SHGFI_SYSICONINDEX
)))
549 if (flags
& SHGFI_USEFILEATTRIBUTES
&& !(flags
& SHGFI_PIDL
))
551 WCHAR sTemp
[MAX_PATH
];
555 lstrcpynW(sTemp
, szFullPath
, MAX_PATH
);
557 if (dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
558 psfi
->iIcon
= SIC_GetIconIndex(swShell32Name
, -IDI_SHELL_FOLDER
, 0);
561 static const WCHAR p1W
[] = {'%','1',0};
564 szExt
= PathFindExtensionW(sTemp
);
566 HCR_MapTypeToValueW(szExt
, sTemp
, MAX_PATH
, TRUE
) &&
567 HCR_GetDefaultIconW(sTemp
, sTemp
, MAX_PATH
, &icon_idx
))
569 if (!lstrcmpW(p1W
,sTemp
)) /* icon is in the file */
570 wcscpy(sTemp
, szFullPath
);
572 if (flags
& SHGFI_SYSICONINDEX
)
574 psfi
->iIcon
= SIC_GetIconIndex(sTemp
,icon_idx
,0);
575 if (psfi
->iIcon
== -1)
581 if (flags
& SHGFI_SMALLICON
)
582 ret
= PrivateExtractIconsW( sTemp
,icon_idx
,
583 GetSystemMetrics( SM_CXSMICON
),
584 GetSystemMetrics( SM_CYSMICON
),
585 &psfi
->hIcon
, 0, 1, 0);
587 ret
= PrivateExtractIconsW( sTemp
, icon_idx
,
588 GetSystemMetrics( SM_CXICON
),
589 GetSystemMetrics( SM_CYICON
),
590 &psfi
->hIcon
, 0, 1, 0);
592 if (ret
!= 0 && ret
!= 0xFFFFFFFF)
594 IconNotYetLoaded
=FALSE
;
595 psfi
->iIcon
= icon_idx
;
603 if (!(PidlToSicIndex(psfParent
, pidlLast
, !(flags
& SHGFI_SMALLICON
),
604 uGilFlags
, &(psfi
->iIcon
))))
609 if (ret
&& (flags
& SHGFI_SYSICONINDEX
))
611 if (flags
& SHGFI_SMALLICON
)
612 ret
= (DWORD_PTR
) ShellSmallIconList
;
614 ret
= (DWORD_PTR
) ShellBigIconList
;
619 if (SUCCEEDED(hr
) && (flags
& SHGFI_ICON
) && IconNotYetLoaded
)
621 if (flags
& SHGFI_SMALLICON
)
622 psfi
->hIcon
= ImageList_GetIcon( ShellSmallIconList
, psfi
->iIcon
, ILD_NORMAL
);
624 psfi
->hIcon
= ImageList_GetIcon( ShellBigIconList
, psfi
->iIcon
, ILD_NORMAL
);
627 if (flags
& ~SHGFI_KNOWN_FLAGS
)
628 FIXME("unknown flags %08x\n", flags
& ~SHGFI_KNOWN_FLAGS
);
636 TRACE ("icon=%p index=0x%08x attr=0x%08x name=%s type=%s ret=0x%08lx\n",
637 psfi
->hIcon
, psfi
->iIcon
, psfi
->dwAttributes
,
638 debugstr_w(psfi
->szDisplayName
), debugstr_w(psfi
->szTypeName
), ret
);
644 /*************************************************************************
645 * SHGetFileInfoA [SHELL32.@]
648 * MSVBVM60.__vbaNew2 expects this function to return a value in range
649 * 1 .. 0x7fff when the function succeeds and flags does not contain
650 * SHGFI_EXETYPE or SHGFI_SYSICONINDEX (see bug 7701)
652 DWORD_PTR WINAPI
SHGetFileInfoA(LPCSTR path
,DWORD dwFileAttributes
,
653 SHFILEINFOA
*psfi
, UINT sizeofpsfi
,
657 LPWSTR temppath
= NULL
;
660 SHFILEINFOW temppsfi
;
662 if (flags
& SHGFI_PIDL
)
664 /* path contains a pidl */
665 pathW
= (LPCWSTR
)path
;
669 len
= MultiByteToWideChar(CP_ACP
, 0, path
, -1, NULL
, 0);
670 temppath
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
671 MultiByteToWideChar(CP_ACP
, 0, path
, -1, temppath
, len
);
675 if (psfi
&& (flags
& SHGFI_ATTR_SPECIFIED
))
676 temppsfi
.dwAttributes
=psfi
->dwAttributes
;
679 ret
= SHGetFileInfoW(pathW
, dwFileAttributes
, NULL
, sizeof(temppsfi
), flags
);
681 ret
= SHGetFileInfoW(pathW
, dwFileAttributes
, &temppsfi
, sizeof(temppsfi
), flags
);
685 if(flags
& SHGFI_ICON
)
686 psfi
->hIcon
=temppsfi
.hIcon
;
687 if(flags
& (SHGFI_SYSICONINDEX
|SHGFI_ICON
|SHGFI_ICONLOCATION
))
688 psfi
->iIcon
=temppsfi
.iIcon
;
689 if(flags
& SHGFI_ATTRIBUTES
)
690 psfi
->dwAttributes
=temppsfi
.dwAttributes
;
691 if(flags
& (SHGFI_DISPLAYNAME
|SHGFI_ICONLOCATION
))
693 WideCharToMultiByte(CP_ACP
, 0, temppsfi
.szDisplayName
, -1,
694 psfi
->szDisplayName
, sizeof(psfi
->szDisplayName
), NULL
, NULL
);
696 if(flags
& SHGFI_TYPENAME
)
698 WideCharToMultiByte(CP_ACP
, 0, temppsfi
.szTypeName
, -1,
699 psfi
->szTypeName
, sizeof(psfi
->szTypeName
), NULL
, NULL
);
703 HeapFree(GetProcessHeap(), 0, temppath
);
708 /*************************************************************************
709 * DuplicateIcon [SHELL32.@]
711 EXTERN_C HICON WINAPI
DuplicateIcon( HINSTANCE hInstance
, HICON hIcon
)
716 TRACE("%p %p\n", hInstance
, hIcon
);
718 if (GetIconInfo(hIcon
, &IconInfo
))
720 hDupIcon
= CreateIconIndirect(&IconInfo
);
722 /* clean up hbmMask and hbmColor */
723 DeleteObject(IconInfo
.hbmMask
);
724 DeleteObject(IconInfo
.hbmColor
);
730 /*************************************************************************
731 * ExtractIconA [SHELL32.@]
733 HICON WINAPI
ExtractIconA(HINSTANCE hInstance
, LPCSTR lpszFile
, UINT nIconIndex
)
736 INT len
= MultiByteToWideChar(CP_ACP
, 0, lpszFile
, -1, NULL
, 0);
737 LPWSTR lpwstrFile
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
739 TRACE("%p %s %d\n", hInstance
, lpszFile
, nIconIndex
);
741 MultiByteToWideChar(CP_ACP
, 0, lpszFile
, -1, lpwstrFile
, len
);
742 ret
= ExtractIconW(hInstance
, lpwstrFile
, nIconIndex
);
743 HeapFree(GetProcessHeap(), 0, lpwstrFile
);
748 /*************************************************************************
749 * ExtractIconW [SHELL32.@]
751 HICON WINAPI
ExtractIconW(HINSTANCE hInstance
, LPCWSTR lpszFile
, UINT nIconIndex
)
755 UINT cx
= GetSystemMetrics(SM_CXICON
), cy
= GetSystemMetrics(SM_CYICON
);
757 TRACE("%p %s %d\n", hInstance
, debugstr_w(lpszFile
), nIconIndex
);
759 if (nIconIndex
== 0xFFFFFFFF)
761 ret
= PrivateExtractIconsW(lpszFile
, 0, cx
, cy
, NULL
, NULL
, 0, LR_DEFAULTCOLOR
);
762 if (ret
!= 0xFFFFFFFF && ret
)
763 return (HICON
)(UINT_PTR
)ret
;
767 ret
= PrivateExtractIconsW(lpszFile
, nIconIndex
, cx
, cy
, &hIcon
, NULL
, 1, LR_DEFAULTCOLOR
);
769 if (ret
== 0xFFFFFFFF)
771 else if (ret
> 0 && hIcon
)
777 /*************************************************************************
778 * Printer_LoadIconsW [SHELL32.205]
780 EXTERN_C VOID WINAPI
Printer_LoadIconsW(LPCWSTR wsPrinterName
, HICON
* pLargeIcon
, HICON
* pSmallIcon
)
782 INT iconindex
=IDI_SHELL_PRINTERS_FOLDER
;
784 TRACE("(%s, %p, %p)\n", debugstr_w(wsPrinterName
), pLargeIcon
, pSmallIcon
);
786 /* We should check if wsPrinterName is
787 1. the Default Printer or not
789 3. a Local Printer or a Network-Printer
790 and use different Icons
792 if((wsPrinterName
!= NULL
) && (wsPrinterName
[0] != 0))
794 FIXME("(select Icon by PrinterName %s not implemented)\n", debugstr_w(wsPrinterName
));
797 if(pLargeIcon
!= NULL
)
798 *pLargeIcon
= (HICON
)LoadImageW(shell32_hInstance
,
799 (LPCWSTR
) MAKEINTRESOURCE(iconindex
), IMAGE_ICON
,
800 0, 0, LR_DEFAULTCOLOR
|LR_DEFAULTSIZE
);
802 if(pSmallIcon
!= NULL
)
803 *pSmallIcon
= (HICON
)LoadImageW(shell32_hInstance
,
804 (LPCWSTR
) MAKEINTRESOURCE(iconindex
), IMAGE_ICON
,
805 16, 16, LR_DEFAULTCOLOR
);
808 /*************************************************************************
809 * Printers_RegisterWindowW [SHELL32.213]
810 * used by "printui.dll":
811 * find the Window of the given Type for the specific Printer and
812 * return the already existent hwnd or open a new window
814 EXTERN_C BOOL WINAPI
Printers_RegisterWindowW(LPCWSTR wsPrinter
, DWORD dwType
,
815 HANDLE
* phClassPidl
, HWND
* phwnd
)
817 FIXME("(%s, %x, %p (%p), %p (%p)) stub!\n", debugstr_w(wsPrinter
), dwType
,
818 phClassPidl
, (phClassPidl
!= NULL
) ? *(phClassPidl
) : NULL
,
819 phwnd
, (phwnd
!= NULL
) ? *(phwnd
) : NULL
);
824 /*************************************************************************
825 * Printers_UnregisterWindow [SHELL32.214]
827 EXTERN_C VOID WINAPI
Printers_UnregisterWindow(HANDLE hClassPidl
, HWND hwnd
)
829 FIXME("(%p, %p) stub!\n", hClassPidl
, hwnd
);
832 /*************************************************************************/
837 LPCWSTR szOtherStuff
;
841 #define DROP_FIELD_TOP (-15)
842 #define DROP_FIELD_HEIGHT 15
844 /*************************************************************************
845 * SHAppBarMessage [SHELL32.@]
847 UINT_PTR WINAPI
SHAppBarMessage(DWORD msg
, PAPPBARDATA data
)
849 int width
=data
->rc
.right
- data
->rc
.left
;
850 int height
=data
->rc
.bottom
- data
->rc
.top
;
853 TRACE("msg=%d, data={cb=%d, hwnd=%p, callback=%x, edge=%d, rc=%s, lparam=%lx}\n",
854 msg
, data
->cbSize
, data
->hWnd
, data
->uCallbackMessage
, data
->uEdge
,
855 wine_dbgstr_rect(&data
->rc
), data
->lParam
);
860 return ABS_ALWAYSONTOP
| ABS_AUTOHIDE
;
862 case ABM_GETTASKBARPOS
:
863 GetWindowRect(data
->hWnd
, &rec
);
868 SetActiveWindow(data
->hWnd
);
871 case ABM_GETAUTOHIDEBAR
:
872 return 0; /* pretend there is no autohide bar */
875 /* cbSize, hWnd, and uCallbackMessage are used. All other ignored */
876 SetWindowPos(data
->hWnd
,HWND_TOP
,0,0,0,0,SWP_SHOWWINDOW
|SWP_NOMOVE
|SWP_NOSIZE
);
880 GetWindowRect(data
->hWnd
, &(data
->rc
));
884 FIXME("ABM_REMOVE broken\n");
885 /* FIXME: this is wrong; should it be DestroyWindow instead? */
886 /*CloseHandle(data->hWnd);*/
889 case ABM_SETAUTOHIDEBAR
:
890 SetWindowPos(data
->hWnd
,HWND_TOP
,rec
.left
+1000,rec
.top
,
891 width
,height
,SWP_SHOWWINDOW
);
895 data
->uEdge
=(ABE_RIGHT
| ABE_LEFT
);
896 SetWindowPos(data
->hWnd
,HWND_TOP
,data
->rc
.left
,data
->rc
.top
,
897 width
,height
,SWP_SHOWWINDOW
);
900 case ABM_WINDOWPOSCHANGED
:
907 /*************************************************************************
908 * SHHelpShortcuts_RunDLLA [SHELL32.@]
911 EXTERN_C DWORD WINAPI
SHHelpShortcuts_RunDLLA(DWORD dwArg1
, DWORD dwArg2
, DWORD dwArg3
, DWORD dwArg4
)
913 FIXME("(%x, %x, %x, %x) stub!\n", dwArg1
, dwArg2
, dwArg3
, dwArg4
);
917 /*************************************************************************
918 * SHHelpShortcuts_RunDLLA [SHELL32.@]
921 EXTERN_C DWORD WINAPI
SHHelpShortcuts_RunDLLW(DWORD dwArg1
, DWORD dwArg2
, DWORD dwArg3
, DWORD dwArg4
)
923 FIXME("(%x, %x, %x, %x) stub!\n", dwArg1
, dwArg2
, dwArg3
, dwArg4
);
927 /*************************************************************************
928 * SHLoadInProc [SHELL32.@]
929 * Create an instance of specified object class from within
930 * the shell process and release it immediately
932 EXTERN_C HRESULT WINAPI
SHLoadInProc (REFCLSID rclsid
)
934 CComPtr
<IUnknown
> ptr
;
936 TRACE("%s\n", debugstr_guid(&rclsid
));
938 CoCreateInstance(rclsid
, NULL
, CLSCTX_INPROC_SERVER
, IID_IUnknown
, (void **)&ptr
);
941 return DISP_E_MEMBERNOTFOUND
;
944 static VOID
SetRegTextData(HWND hWnd
, HKEY hKey
, LPCWSTR Value
, UINT uID
)
950 if( RegQueryValueExW(hKey
, Value
, NULL
, &dwType
, NULL
, &dwBufferSize
) == ERROR_SUCCESS
)
954 lpBuffer
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, dwBufferSize
);
958 if( RegQueryValueExW(hKey
, Value
, NULL
, &dwType
, (LPBYTE
)lpBuffer
, &dwBufferSize
) == ERROR_SUCCESS
)
960 SetDlgItemTextW(hWnd
, uID
, lpBuffer
);
963 HeapFree(GetProcessHeap(), 0, lpBuffer
);
969 INT_PTR CALLBACK
AboutAuthorsDlgProc( HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
975 const char* const *pstr
= SHELL_Authors
;
977 // Add the authors to the list
978 SendDlgItemMessageW( hWnd
, IDC_ABOUT_AUTHORS_LISTBOX
, WM_SETREDRAW
, FALSE
, 0 );
984 /* authors list is in utf-8 format */
985 MultiByteToWideChar( CP_UTF8
, 0, *pstr
, -1, name
, sizeof(name
)/sizeof(WCHAR
) );
986 SendDlgItemMessageW( hWnd
, IDC_ABOUT_AUTHORS_LISTBOX
, LB_ADDSTRING
, (WPARAM
)-1, (LPARAM
)name
);
990 SendDlgItemMessageW( hWnd
, IDC_ABOUT_AUTHORS_LISTBOX
, WM_SETREDRAW
, TRUE
, 0 );
998 /*************************************************************************
999 * AboutDlgProc (internal)
1001 INT_PTR CALLBACK
AboutDlgProc( HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1003 static DWORD cxLogoBmp
;
1004 static DWORD cyLogoBmp
;
1005 static HBITMAP hLogoBmp
;
1006 static HWND hWndAuthors
;
1012 ABOUT_INFO
*info
= (ABOUT_INFO
*)lParam
;
1016 const WCHAR szRegKey
[] = L
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion";
1018 MEMORYSTATUSEX MemStat
;
1019 WCHAR szAppTitle
[512];
1020 WCHAR szAppTitleTemplate
[512];
1021 WCHAR szAuthorsText
[20];
1023 // Preload the ROS bitmap
1024 hLogoBmp
= (HBITMAP
)LoadImage(shell32_hInstance
, MAKEINTRESOURCE(IDB_SHELL_ABOUT_LOGO_24BPP
), IMAGE_BITMAP
, 0, 0, LR_DEFAULTCOLOR
);
1030 GetObject( hLogoBmp
, sizeof(BITMAP
), &bmpLogo
);
1032 cxLogoBmp
= bmpLogo
.bmWidth
;
1033 cyLogoBmp
= bmpLogo
.bmHeight
;
1036 // Set App-specific stuff (icon, app name, szOtherStuff string)
1037 SendDlgItemMessageW(hWnd
, IDC_ABOUT_ICON
, STM_SETICON
, (WPARAM
)info
->hIcon
, 0);
1039 GetWindowTextW( hWnd
, szAppTitleTemplate
, sizeof(szAppTitleTemplate
) / sizeof(WCHAR
) );
1040 swprintf( szAppTitle
, szAppTitleTemplate
, info
->szApp
);
1041 SetWindowTextW( hWnd
, szAppTitle
);
1043 SetDlgItemTextW( hWnd
, IDC_ABOUT_APPNAME
, info
->szApp
);
1044 SetDlgItemTextW( hWnd
, IDC_ABOUT_OTHERSTUFF
, info
->szOtherStuff
);
1046 // Set the registered user and organization name
1047 if(RegOpenKeyExW( HKEY_LOCAL_MACHINE
, szRegKey
, 0, KEY_QUERY_VALUE
, &hRegKey
) == ERROR_SUCCESS
)
1049 SetRegTextData( hWnd
, hRegKey
, L
"RegisteredOwner", IDC_ABOUT_REG_USERNAME
);
1050 SetRegTextData( hWnd
, hRegKey
, L
"RegisteredOrganization", IDC_ABOUT_REG_ORGNAME
);
1052 RegCloseKey( hRegKey
);
1055 // Set the value for the installed physical memory
1056 MemStat
.dwLength
= sizeof(MemStat
);
1057 if( GlobalMemoryStatusEx(&MemStat
) )
1061 if (MemStat
.ullTotalPhys
> 1024 * 1024 * 1024)
1064 WCHAR szDecimalSeparator
[4];
1067 // We're dealing with GBs or more
1068 MemStat
.ullTotalPhys
/= 1024 * 1024;
1070 if (MemStat
.ullTotalPhys
> 1024 * 1024)
1072 // We're dealing with TBs or more
1073 MemStat
.ullTotalPhys
/= 1024;
1075 if (MemStat
.ullTotalPhys
> 1024 * 1024)
1077 // We're dealing with PBs or more
1078 MemStat
.ullTotalPhys
/= 1024;
1080 dTotalPhys
= (double)MemStat
.ullTotalPhys
/ 1024;
1081 wcscpy( szUnits
, L
"PB" );
1085 dTotalPhys
= (double)MemStat
.ullTotalPhys
/ 1024;
1086 wcscpy( szUnits
, L
"TB" );
1091 dTotalPhys
= (double)MemStat
.ullTotalPhys
/ 1024;
1092 wcscpy( szUnits
, L
"GB" );
1095 // We need the decimal point of the current locale to display the RAM size correctly
1096 if (GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SDECIMAL
,
1098 sizeof(szDecimalSeparator
) / sizeof(WCHAR
)) > 0)
1103 uIntegral
= (UINT
)dTotalPhys
;
1104 uDecimals
= (UCHAR
)((UINT
)(dTotalPhys
* 100) - uIntegral
* 100);
1106 // Display the RAM size with 2 decimals
1107 swprintf(szBuf
, L
"%u%s%02u %s", uIntegral
, szDecimalSeparator
, uDecimals
, szUnits
);
1112 // We're dealing with MBs, don't show any decimals
1113 swprintf( szBuf
, L
"%u MB", (UINT
)MemStat
.ullTotalPhys
/ 1024 / 1024 );
1116 SetDlgItemTextW( hWnd
, IDC_ABOUT_PHYSMEM
, szBuf
);
1119 // Add the Authors dialog
1120 hWndAuthors
= CreateDialogW( shell32_hInstance
, MAKEINTRESOURCEW(IDD_ABOUT_AUTHORS
), hWnd
, AboutAuthorsDlgProc
);
1121 LoadStringW( shell32_hInstance
, IDS_SHELL_ABOUT_AUTHORS
, szAuthorsText
, sizeof(szAuthorsText
) / sizeof(WCHAR
) );
1122 SetDlgItemTextW( hWnd
, IDC_ABOUT_AUTHORS
, szAuthorsText
);
1136 hdc
= BeginPaint(hWnd
, &ps
);
1137 hdcMem
= CreateCompatibleDC(hdc
);
1141 SelectObject(hdcMem
, hLogoBmp
);
1142 BitBlt(hdc
, 0, 0, cxLogoBmp
, cyLogoBmp
, hdcMem
, 0, 0, SRCCOPY
);
1147 EndPaint(hWnd
, &ps
);
1157 EndDialog(hWnd
, TRUE
);
1160 case IDC_ABOUT_AUTHORS
:
1162 static BOOL bShowingAuthors
= FALSE
;
1163 WCHAR szAuthorsText
[20];
1167 LoadStringW( shell32_hInstance
, IDS_SHELL_ABOUT_AUTHORS
, szAuthorsText
, sizeof(szAuthorsText
) / sizeof(WCHAR
) );
1168 ShowWindow( hWndAuthors
, SW_HIDE
);
1172 LoadStringW( shell32_hInstance
, IDS_SHELL_ABOUT_BACK
, szAuthorsText
, sizeof(szAuthorsText
) / sizeof(WCHAR
) );
1173 ShowWindow( hWndAuthors
, SW_SHOW
);
1176 SetDlgItemTextW( hWnd
, IDC_ABOUT_AUTHORS
, szAuthorsText
);
1177 bShowingAuthors
= !bShowingAuthors
;
1184 EndDialog(hWnd
, TRUE
);
1192 /*************************************************************************
1193 * ShellAboutA [SHELL32.288]
1195 BOOL WINAPI
ShellAboutA( HWND hWnd
, LPCSTR szApp
, LPCSTR szOtherStuff
, HICON hIcon
)
1198 LPWSTR appW
= NULL
, otherW
= NULL
;
1203 len
= MultiByteToWideChar(CP_ACP
, 0, szApp
, -1, NULL
, 0);
1204 appW
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1205 MultiByteToWideChar(CP_ACP
, 0, szApp
, -1, appW
, len
);
1209 len
= MultiByteToWideChar(CP_ACP
, 0, szOtherStuff
, -1, NULL
, 0);
1210 otherW
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1211 MultiByteToWideChar(CP_ACP
, 0, szOtherStuff
, -1, otherW
, len
);
1214 ret
= ShellAboutW(hWnd
, appW
, otherW
, hIcon
);
1216 HeapFree(GetProcessHeap(), 0, otherW
);
1217 HeapFree(GetProcessHeap(), 0, appW
);
1222 /*************************************************************************
1223 * ShellAboutW [SHELL32.289]
1225 BOOL WINAPI
ShellAboutW( HWND hWnd
, LPCWSTR szApp
, LPCWSTR szOtherStuff
,
1230 DLGTEMPLATE
*DlgTemplate
;
1235 // DialogBoxIndirectParamW will be called with the hInstance of the calling application, so we have to preload the dialog template
1236 hRes
= FindResourceW(shell32_hInstance
, MAKEINTRESOURCEW(IDD_ABOUT
), (LPWSTR
)RT_DIALOG
);
1240 DlgTemplate
= (DLGTEMPLATE
*)LoadResource(shell32_hInstance
, hRes
);
1245 info
.szOtherStuff
= szOtherStuff
;
1246 info
.hIcon
= hIcon
? hIcon
: LoadIconW( 0, (LPWSTR
)IDI_WINLOGO
);
1248 bRet
= DialogBoxIndirectParamW((HINSTANCE
)GetWindowLongPtrW( hWnd
, GWLP_HINSTANCE
),
1249 DlgTemplate
, hWnd
, AboutDlgProc
, (LPARAM
)&info
);
1253 /*************************************************************************
1254 * FreeIconList (SHELL32.@)
1256 EXTERN_C
void WINAPI
FreeIconList( DWORD dw
)
1258 FIXME("%x: stub\n",dw
);
1261 /*************************************************************************
1262 * SHLoadNonloadedIconOverlayIdentifiers (SHELL32.@)
1264 EXTERN_C HRESULT WINAPI
SHLoadNonloadedIconOverlayIdentifiers(VOID
)
1270 class CShell32Module
: public CComModule
1276 BEGIN_OBJECT_MAP(ObjectMap
)
1277 OBJECT_ENTRY(CLSID_ShellFSFolder
, CFSFolder
)
1278 OBJECT_ENTRY(CLSID_MyComputer
, CDrivesFolder
)
1279 OBJECT_ENTRY(CLSID_ShellDesktop
, CDesktopFolder
)
1280 OBJECT_ENTRY(CLSID_ShellItem
, CShellItem
)
1281 OBJECT_ENTRY(CLSID_ShellLink
, CShellLink
)
1282 OBJECT_ENTRY(CLSID_DragDropHelper
, CDropTargetHelper
)
1283 OBJECT_ENTRY(CLSID_ControlPanel
, CControlPanelFolder
)
1284 OBJECT_ENTRY(CLSID_AutoComplete
, CAutoComplete
)
1285 OBJECT_ENTRY(CLSID_MyDocuments
, CMyDocsFolder
)
1286 OBJECT_ENTRY(CLSID_NetworkPlaces
, CNetFolder
)
1287 OBJECT_ENTRY(CLSID_FontsFolderShortcut
, CFontsFolder
)
1288 OBJECT_ENTRY(CLSID_Printers
, CPrinterFolder
)
1289 OBJECT_ENTRY(CLSID_AdminFolderShortcut
, CAdminToolsFolder
)
1290 OBJECT_ENTRY(CLSID_RecycleBin
, CRecycleBin
)
1291 OBJECT_ENTRY(CLSID_OpenWithMenu
, COpenWithMenu
)
1292 OBJECT_ENTRY(CLSID_NewMenu
, CNewMenu
)
1293 OBJECT_ENTRY(CLSID_StartMenu
, CStartMenu
)
1294 OBJECT_ENTRY(CLSID_MenuBandSite
, CMenuBandSite
)
1297 CShell32Module gModule
;
1300 /***********************************************************************
1301 * DllGetVersion [SHELL32.@]
1303 * Retrieves version information of the 'SHELL32.DLL'
1306 * pdvi [O] pointer to version information structure.
1310 * Failure: E_INVALIDARG
1313 * Returns version of a shell32.dll from IE4.01 SP1.
1316 STDAPI
DllGetVersion(DLLVERSIONINFO
*pdvi
)
1318 /* FIXME: shouldn't these values come from the version resource? */
1319 if (pdvi
->cbSize
== sizeof(DLLVERSIONINFO
) ||
1320 pdvi
->cbSize
== sizeof(DLLVERSIONINFO2
))
1322 pdvi
->dwMajorVersion
= WINE_FILEVERSION_MAJOR
;
1323 pdvi
->dwMinorVersion
= WINE_FILEVERSION_MINOR
;
1324 pdvi
->dwBuildNumber
= WINE_FILEVERSION_BUILD
;
1325 pdvi
->dwPlatformID
= WINE_FILEVERSION_PLATFORMID
;
1326 if (pdvi
->cbSize
== sizeof(DLLVERSIONINFO2
))
1328 DLLVERSIONINFO2
*pdvi2
= (DLLVERSIONINFO2
*)pdvi
;
1331 pdvi2
->ullVersion
= MAKEDLLVERULL(WINE_FILEVERSION_MAJOR
,
1332 WINE_FILEVERSION_MINOR
,
1333 WINE_FILEVERSION_BUILD
,
1334 WINE_FILEVERSION_PLATFORMID
);
1336 TRACE("%u.%u.%u.%u\n",
1337 pdvi
->dwMajorVersion
, pdvi
->dwMinorVersion
,
1338 pdvi
->dwBuildNumber
, pdvi
->dwPlatformID
);
1343 WARN("wrong DLLVERSIONINFO size from app\n");
1344 return E_INVALIDARG
;
1348 /*************************************************************************
1349 * global variables of the shell32.dll
1350 * all are once per process
1353 HINSTANCE shell32_hInstance
;
1354 HIMAGELIST ShellSmallIconList
= 0;
1355 HIMAGELIST ShellBigIconList
= 0;
1357 void *operator new (size_t, void *buf
)
1362 /*************************************************************************
1366 * calling oleinitialize here breaks sone apps.
1368 STDAPI_(BOOL
) DllMain(HINSTANCE hInstance
, DWORD dwReason
, LPVOID fImpLoad
)
1370 TRACE("%p 0x%x %p\n", hInstance
, dwReason
, fImpLoad
);
1371 if (dwReason
== DLL_PROCESS_ATTACH
)
1373 /* HACK - the global constructors don't run, so I placement new them here */
1374 new (&gModule
) CShell32Module
;
1375 new (&_AtlWinModule
) CAtlWinModule
;
1376 new (&_AtlBaseModule
) CAtlBaseModule
;
1377 new (&_AtlComModule
) CAtlComModule
;
1379 shell32_hInstance
= hInstance
;
1380 gModule
.Init(ObjectMap
, hInstance
, NULL
);
1382 DisableThreadLibraryCalls (hInstance
);
1384 /* get full path to this DLL for IExtractIconW_fnGetIconLocation() */
1385 GetModuleFileNameW(hInstance
, swShell32Name
, MAX_PATH
);
1386 swShell32Name
[MAX_PATH
- 1] = '\0';
1388 InitCommonControlsEx(NULL
);
1391 InitChangeNotifications();
1394 else if (dwReason
== DLL_PROCESS_DETACH
)
1396 shell32_hInstance
= NULL
;
1398 FreeChangeNotifications();
1404 /***********************************************************************
1405 * DllCanUnloadNow (SHELL32.@)
1407 STDAPI
DllCanUnloadNow()
1409 return gModule
.DllCanUnloadNow();
1412 /*************************************************************************
1413 * DllGetClassObject [SHELL32.@]
1414 * SHDllGetClassObject [SHELL32.128]
1416 STDAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
*ppv
)
1420 TRACE("CLSID:%s,IID:%s\n", shdebugstr_guid(&rclsid
), shdebugstr_guid(&riid
));
1422 hResult
= gModule
.DllGetClassObject(rclsid
, riid
, ppv
);
1423 TRACE("-- pointer to class factory: %p\n", *ppv
);
1427 /***********************************************************************
1428 * DllRegisterServer (SHELL32.@)
1430 STDAPI
DllRegisterServer()
1434 hr
= gModule
.DllRegisterServer(FALSE
);
1438 hr
= gModule
.UpdateRegistryFromResource(IDR_FOLDEROPTIONS
, TRUE
, NULL
);
1442 hr
= SHELL_RegisterShellFolders();
1449 /***********************************************************************
1450 * DllUnregisterServer (SHELL32.@)
1452 STDAPI
DllUnregisterServer()
1456 hr
= gModule
.DllUnregisterServer(FALSE
);
1460 hr
= gModule
.UpdateRegistryFromResource(IDR_FOLDEROPTIONS
, FALSE
, NULL
);
1467 /*************************************************************************
1468 * DllInstall [SHELL32.@]
1472 * BOOL bInstall - TRUE for install, FALSE for uninstall
1473 * LPCWSTR pszCmdLine - command line (unused by shell32?)
1476 HRESULT WINAPI
DllInstall(BOOL bInstall
, LPCWSTR cmdline
)
1478 FIXME("%s %s: stub\n", bInstall
? "TRUE":"FALSE", debugstr_w(cmdline
));
1479 return S_OK
; /* indicate success */