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 <wine/config.h>
24 #define WIN32_NO_STATUS
34 #include "undocshell.h"
36 #include "shell32_main.h"
39 #include <wine/debug.h>
40 #include <wine/unicode.h>
42 #include <reactos/version.h>
44 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
46 const char * const SHELL_Authors
[] = { "Copyright 1993-"COPYRIGHT_YEAR
" WINE team", "Copyright 1998-"COPYRIGHT_YEAR
" ReactOS Team", 0 };
48 /*************************************************************************
49 * CommandLineToArgvW [SHELL32.@]
51 * We must interpret the quotes in the command line to rebuild the argv
53 * - arguments are separated by spaces or tabs
54 * - quotes serve as optional argument delimiters
56 * - escaped quotes must be converted back to '"'
58 * - consecutive backslashes preceding a quote see their number halved with
59 * the remainder escaping the quote:
60 * 2n backslashes + quote -> n backslashes + quote as an argument delimiter
61 * 2n+1 backslashes + quote -> n backslashes + literal quote
62 * - backslashes that are not followed by a quote are copied literally:
65 * - in quoted strings, consecutive quotes see their number divided by three
66 * with the remainder modulo 3 deciding whether to close the string or not.
67 * Note that the opening quote must be counted in the consecutive quotes,
68 * that's the (1+) below:
69 * (1+) 3n quotes -> n quotes
70 * (1+) 3n+1 quotes -> n quotes plus closes the quoted string
71 * (1+) 3n+2 quotes -> n+1 quotes plus closes the quoted string
72 * - in unquoted strings, the first quote opens the quoted string and the
73 * remaining consecutive quotes follow the above rule.
75 LPWSTR
* WINAPI
CommandLineToArgvW(LPCWSTR lpCmdline
, int* numargs
)
86 SetLastError(ERROR_INVALID_PARAMETER
);
92 /* Return the path to the executable */
93 DWORD len
, deslen
=MAX_PATH
, size
;
95 size
= sizeof(LPWSTR
)*2 + deslen
*sizeof(WCHAR
);
98 if (!(argv
= LocalAlloc(LMEM_FIXED
, size
))) return NULL
;
99 len
= GetModuleFileNameW(0, (LPWSTR
)(argv
+2), deslen
);
105 if (len
< deslen
) break;
107 size
= sizeof(LPWSTR
)*2 + deslen
*sizeof(WCHAR
);
110 argv
[0]=(LPWSTR
)(argv
+2);
117 /* --- First count the arguments */
120 /* The first argument, the executable path, follows special rules */
123 /* The executable path ends at the next quote, no matter what */
131 /* The executable path ends at the next space, no matter what */
132 while (*s
&& *s
!=' ' && *s
!='\t')
135 /* skip to the first argument, if any */
136 while (*s
==' ' || *s
=='\t')
141 /* Analyze the remaining arguments */
145 if ((*s
==' ' || *s
=='\t') && qcount
==0)
147 /* skip to the next argument and count it if any */
148 while (*s
==' ' || *s
=='\t')
156 /* '\', count them */
164 qcount
++; /* unescaped '"' */
167 /* consecutive quotes, see comment in copying code below */
179 /* a regular character */
185 /* Allocate in a single lump, the string array, and the strings that go
186 * with it. This way the caller can make a single LocalFree() call to free
189 argv
=LocalAlloc(LMEM_FIXED
, (argc
+1)*sizeof(LPWSTR
)+(strlenW(lpCmdline
)+1)*sizeof(WCHAR
));
192 cmdline
=(LPWSTR
)(argv
+argc
+1);
193 strcpyW(cmdline
, lpCmdline
);
195 /* --- Then split and copy the arguments */
198 /* The first argument, the executable path, follows special rules */
201 /* The executable path ends at the next quote, no matter what */
215 /* The executable path ends at the next space, no matter what */
216 while (*d
&& *d
!=' ' && *d
!='\t')
222 /* close the executable path */
224 /* skip to the first argument and initialize it if any */
225 while (*s
==' ' || *s
=='\t')
229 /* There are no parameters so we are all done */
235 /* Split and copy the remaining arguments */
240 if ((*s
==' ' || *s
=='\t') && qcount
==0)
242 /* close the argument */
246 /* skip to the next one and initialize it if any */
249 } while (*s
==' ' || *s
=='\t');
262 /* Preceded by an even number of '\', this is half that
263 * number of '\', plus a quote which we erase.
270 /* Preceded by an odd number of '\', this is half that
271 * number of '\' followed by a '"'
278 /* Now count the number of consecutive quotes. Note that qcount
279 * already takes into account the opening quote if any, as well as
280 * the quote that lead us here.
296 /* a regular character */
308 static DWORD
shgfi_get_exe_type(LPCWSTR szFullPath
)
313 IMAGE_DOS_HEADER mz_header
;
318 status
= GetBinaryTypeW (szFullPath
, &BinaryType
);
321 if (BinaryType
== SCS_DOS_BINARY
|| BinaryType
== SCS_PIF_BINARY
)
324 hfile
= CreateFileW( szFullPath
, GENERIC_READ
, FILE_SHARE_READ
,
325 NULL
, OPEN_EXISTING
, 0, 0 );
326 if ( hfile
== INVALID_HANDLE_VALUE
)
330 * The next section is adapted from MODULE_GetBinaryType, as we need
331 * to examine the image header to get OS and version information. We
332 * know from calling GetBinaryTypeA that the image is valid and either
333 * an NE or PE, so much error handling can be omitted.
334 * Seek to the start of the file and read the header information.
337 SetFilePointer( hfile
, 0, NULL
, SEEK_SET
);
338 ReadFile( hfile
, &mz_header
, sizeof(mz_header
), &len
, NULL
);
340 SetFilePointer( hfile
, mz_header
.e_lfanew
, NULL
, SEEK_SET
);
341 ReadFile( hfile
, magic
, sizeof(magic
), &len
, NULL
);
342 if ( *(DWORD
*)magic
== IMAGE_NT_SIGNATURE
)
344 SetFilePointer( hfile
, mz_header
.e_lfanew
, NULL
, SEEK_SET
);
345 ReadFile( hfile
, &nt
, sizeof(nt
), &len
, NULL
);
346 CloseHandle( hfile
);
347 /* DLL files are not executable and should return 0 */
348 if (nt
.FileHeader
.Characteristics
& IMAGE_FILE_DLL
)
350 if (nt
.OptionalHeader
.Subsystem
== IMAGE_SUBSYSTEM_WINDOWS_GUI
)
352 return IMAGE_NT_SIGNATURE
|
353 (nt
.OptionalHeader
.MajorSubsystemVersion
<< 24) |
354 (nt
.OptionalHeader
.MinorSubsystemVersion
<< 16);
356 return IMAGE_NT_SIGNATURE
;
358 else if ( *(WORD
*)magic
== IMAGE_OS2_SIGNATURE
)
361 SetFilePointer( hfile
, mz_header
.e_lfanew
, NULL
, SEEK_SET
);
362 ReadFile( hfile
, &ne
, sizeof(ne
), &len
, NULL
);
363 CloseHandle( hfile
);
364 if (ne
.ne_exetyp
== 2)
365 return IMAGE_OS2_SIGNATURE
| (ne
.ne_expver
<< 16);
368 CloseHandle( hfile
);
372 /*************************************************************************
373 * SHELL_IsShortcut [internal]
375 * Decide if an item id list points to a shell shortcut
377 BOOL
SHELL_IsShortcut(LPCITEMIDLIST pidlLast
)
379 char szTemp
[MAX_PATH
];
383 if (_ILGetExtension(pidlLast
, szTemp
, MAX_PATH
) &&
384 HCR_MapTypeToValueA(szTemp
, szTemp
, MAX_PATH
, TRUE
))
386 if (ERROR_SUCCESS
== RegOpenKeyExA(HKEY_CLASSES_ROOT
, szTemp
, 0, KEY_QUERY_VALUE
, &keyCls
))
388 if (ERROR_SUCCESS
== RegQueryValueExA(keyCls
, "IsShortcut", NULL
, NULL
, NULL
, NULL
))
398 #define SHGFI_KNOWN_FLAGS \
399 (SHGFI_SMALLICON | SHGFI_OPENICON | SHGFI_SHELLICONSIZE | SHGFI_PIDL | \
400 SHGFI_USEFILEATTRIBUTES | SHGFI_ADDOVERLAYS | SHGFI_OVERLAYINDEX | \
401 SHGFI_ICON | SHGFI_DISPLAYNAME | SHGFI_TYPENAME | SHGFI_ATTRIBUTES | \
402 SHGFI_ICONLOCATION | SHGFI_EXETYPE | SHGFI_SYSICONINDEX | \
403 SHGFI_LINKOVERLAY | SHGFI_SELECTED | SHGFI_ATTR_SPECIFIED)
405 /*************************************************************************
406 * SHGetFileInfoW [SHELL32.@]
409 DWORD_PTR WINAPI
SHGetFileInfoW(LPCWSTR path
,DWORD dwFileAttributes
,
410 SHFILEINFOW
*psfi
, UINT sizeofpsfi
, UINT flags
)
412 WCHAR szLocation
[MAX_PATH
], szFullPath
[MAX_PATH
];
414 DWORD_PTR ret
= TRUE
;
415 DWORD dwAttributes
= 0;
416 IShellFolder
* psfParent
= NULL
;
417 IExtractIconW
* pei
= NULL
;
418 LPITEMIDLIST pidlLast
= NULL
, pidl
= NULL
;
420 BOOL IconNotYetLoaded
=TRUE
;
422 HIMAGELIST big_icons
, small_icons
;
424 TRACE("%s fattr=0x%x sfi=%p(attr=0x%08x) size=0x%x flags=0x%x\n",
425 (flags
& SHGFI_PIDL
)? "pidl" : debugstr_w(path
), dwFileAttributes
,
426 psfi
, psfi
->dwAttributes
, sizeofpsfi
, flags
);
431 /* windows initializes these values regardless of the flags */
434 psfi
->szDisplayName
[0] = '\0';
435 psfi
->szTypeName
[0] = '\0';
439 if (!(flags
& SHGFI_PIDL
))
441 /* SHGetFileInfo should work with absolute and relative paths */
442 if (PathIsRelativeW(path
))
444 GetCurrentDirectoryW(MAX_PATH
, szLocation
);
445 PathCombineW(szFullPath
, szLocation
, path
);
449 lstrcpynW(szFullPath
, path
, MAX_PATH
);
453 if (flags
& SHGFI_EXETYPE
)
455 if (flags
!= SHGFI_EXETYPE
)
457 return shgfi_get_exe_type(szFullPath
);
461 * psfi is NULL normally to query EXE type. If it is NULL, none of the
462 * below makes sense anyway. Windows allows this and just returns FALSE
468 * translate the path into a pidl only when SHGFI_USEFILEATTRIBUTES
470 * The pidl functions fail on not existing file names
473 if (flags
& SHGFI_PIDL
)
475 pidl
= ILClone((LPCITEMIDLIST
)path
);
477 else if (!(flags
& SHGFI_USEFILEATTRIBUTES
))
479 hr
= SHILCreateFromPathW(szFullPath
, &pidl
, &dwAttributes
);
482 if ((flags
& SHGFI_PIDL
) || !(flags
& SHGFI_USEFILEATTRIBUTES
))
484 /* get the parent shellfolder */
487 hr
= SHBindToParent( pidl
, &IID_IShellFolder
, (LPVOID
*)&psfParent
,
488 (LPCITEMIDLIST
*)&pidlLast
);
490 pidlLast
= ILClone(pidlLast
);
495 ERR("pidl is null!\n");
500 /* get the attributes of the child */
501 if (SUCCEEDED(hr
) && (flags
& SHGFI_ATTRIBUTES
))
503 if (!(flags
& SHGFI_ATTR_SPECIFIED
))
505 psfi
->dwAttributes
= 0xffffffff;
508 IShellFolder_GetAttributesOf( psfParent
, 1, (LPCITEMIDLIST
*)&pidlLast
,
509 &(psfi
->dwAttributes
) );
512 /* get the displayname */
513 if (SUCCEEDED(hr
) && (flags
& SHGFI_DISPLAYNAME
))
515 if (flags
& SHGFI_USEFILEATTRIBUTES
&& !(flags
& SHGFI_PIDL
))
517 lstrcpyW (psfi
->szDisplayName
, PathFindFileNameW(szFullPath
));
522 hr
= IShellFolder_GetDisplayNameOf( psfParent
, pidlLast
,
523 SHGDN_INFOLDER
, &str
);
524 StrRetToStrNW (psfi
->szDisplayName
, MAX_PATH
, &str
, pidlLast
);
528 /* get the type name */
529 if (SUCCEEDED(hr
) && (flags
& SHGFI_TYPENAME
))
531 static const WCHAR szFile
[] = { 'F','i','l','e',0 };
532 static const WCHAR szDashFile
[] = { '-','f','i','l','e',0 };
534 if (!(flags
& SHGFI_USEFILEATTRIBUTES
) || (flags
& SHGFI_PIDL
))
538 _ILGetFileType(pidlLast
, ftype
, 80);
539 MultiByteToWideChar(CP_ACP
, 0, ftype
, -1, psfi
->szTypeName
, 80 );
543 if (dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
544 strcatW (psfi
->szTypeName
, szFile
);
549 lstrcpyW(sTemp
,PathFindExtensionW(szFullPath
));
550 if (!( HCR_MapTypeToValueW(sTemp
, sTemp
, 64, TRUE
) &&
551 HCR_MapTypeToValueW(sTemp
, psfi
->szTypeName
, 80, FALSE
)))
553 lstrcpynW (psfi
->szTypeName
, sTemp
, 64);
554 strcatW (psfi
->szTypeName
, szDashFile
);
562 Shell_GetImageLists( &big_icons
, &small_icons
);
564 if (flags
& SHGFI_OPENICON
)
565 uGilFlags
|= GIL_OPENICON
;
567 if (flags
& SHGFI_LINKOVERLAY
)
568 uGilFlags
|= GIL_FORSHORTCUT
;
569 else if ((flags
&SHGFI_ADDOVERLAYS
) ||
570 (flags
&(SHGFI_ICON
|SHGFI_SMALLICON
))==SHGFI_ICON
)
572 if (SHELL_IsShortcut(pidlLast
))
573 uGilFlags
|= GIL_FORSHORTCUT
;
576 if (flags
& SHGFI_OVERLAYINDEX
)
577 FIXME("SHGFI_OVERLAYINDEX unhandled\n");
579 if (flags
& SHGFI_SELECTED
)
580 FIXME("set icon to selected, stub\n");
582 if (flags
& SHGFI_SHELLICONSIZE
)
583 FIXME("set icon to shell size, stub\n");
585 /* get the iconlocation */
586 if (SUCCEEDED(hr
) && (flags
& SHGFI_ICONLOCATION
))
590 if (flags
& SHGFI_USEFILEATTRIBUTES
&& !(flags
& SHGFI_PIDL
))
592 if (dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
594 lstrcpyW(psfi
->szDisplayName
, swShell32Name
);
595 psfi
->iIcon
= -IDI_SHELL_FOLDER
;
600 static const WCHAR p1W
[] = {'%','1',0};
601 WCHAR sTemp
[MAX_PATH
];
603 szExt
= PathFindExtensionW(szFullPath
);
604 TRACE("szExt=%s\n", debugstr_w(szExt
));
606 HCR_MapTypeToValueW(szExt
, sTemp
, MAX_PATH
, TRUE
) &&
607 HCR_GetIconW(sTemp
, sTemp
, NULL
, MAX_PATH
, &psfi
->iIcon
))
609 if (lstrcmpW(p1W
, sTemp
))
610 strcpyW(psfi
->szDisplayName
, sTemp
);
613 /* the icon is in the file */
614 strcpyW(psfi
->szDisplayName
, szFullPath
);
623 hr
= IShellFolder_GetUIObjectOf(psfParent
, 0, 1,
624 (LPCITEMIDLIST
*)&pidlLast
, &IID_IExtractIconW
,
625 &uDummy
, (LPVOID
*)&pei
);
628 hr
= IExtractIconW_GetIconLocation(pei
, uGilFlags
,
629 szLocation
, MAX_PATH
, &iIndex
, &uFlags
);
631 if (uFlags
& GIL_NOTFILENAME
)
635 lstrcpyW (psfi
->szDisplayName
, szLocation
);
636 psfi
->iIcon
= iIndex
;
638 IExtractIconW_Release(pei
);
643 /* get icon index (or load icon)*/
644 if (SUCCEEDED(hr
) && (flags
& (SHGFI_ICON
| SHGFI_SYSICONINDEX
)))
646 if (flags
& SHGFI_USEFILEATTRIBUTES
&& !(flags
& SHGFI_PIDL
))
648 WCHAR sTemp
[MAX_PATH
];
652 lstrcpynW(sTemp
, szFullPath
, MAX_PATH
);
654 if (dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
655 psfi
->iIcon
= SIC_GetIconIndex(swShell32Name
, -IDI_SHELL_FOLDER
, 0);
658 static const WCHAR p1W
[] = {'%','1',0};
661 szExt
= PathFindExtensionW(sTemp
);
663 HCR_MapTypeToValueW(szExt
, sTemp
, MAX_PATH
, TRUE
) &&
664 HCR_GetIconW(sTemp
, sTemp
, NULL
, MAX_PATH
, &icon_idx
))
666 if (!lstrcmpW(p1W
,sTemp
)) /* icon is in the file */
667 strcpyW(sTemp
, szFullPath
);
669 if (flags
& SHGFI_SYSICONINDEX
)
671 psfi
->iIcon
= SIC_GetIconIndex(sTemp
,icon_idx
,0);
672 if (psfi
->iIcon
== -1)
678 if (flags
& SHGFI_SMALLICON
)
679 ret
= PrivateExtractIconsW( sTemp
,icon_idx
,
680 GetSystemMetrics( SM_CXSMICON
),
681 GetSystemMetrics( SM_CYSMICON
),
682 &psfi
->hIcon
, 0, 1, 0);
684 ret
= PrivateExtractIconsW( sTemp
, icon_idx
,
685 GetSystemMetrics( SM_CXICON
),
686 GetSystemMetrics( SM_CYICON
),
687 &psfi
->hIcon
, 0, 1, 0);
688 if (ret
!= 0 && ret
!= (UINT
)-1)
690 IconNotYetLoaded
=FALSE
;
691 psfi
->iIcon
= icon_idx
;
699 if (!(PidlToSicIndex(psfParent
, pidlLast
, !(flags
& SHGFI_SMALLICON
),
700 uGilFlags
, &(psfi
->iIcon
))))
705 if (ret
&& (flags
& SHGFI_SYSICONINDEX
))
707 if (flags
& SHGFI_SMALLICON
)
708 ret
= (DWORD_PTR
)small_icons
;
710 ret
= (DWORD_PTR
)big_icons
;
715 if (SUCCEEDED(hr
) && (flags
& SHGFI_ICON
) && IconNotYetLoaded
)
717 if (flags
& SHGFI_SMALLICON
)
718 psfi
->hIcon
= ImageList_GetIcon( small_icons
, psfi
->iIcon
, ILD_NORMAL
);
720 psfi
->hIcon
= ImageList_GetIcon( big_icons
, psfi
->iIcon
, ILD_NORMAL
);
723 if (flags
& ~SHGFI_KNOWN_FLAGS
)
724 FIXME("unknown flags %08x\n", flags
& ~SHGFI_KNOWN_FLAGS
);
731 TRACE ("icon=%p index=0x%08x attr=0x%08x name=%s type=%s ret=0x%08lx\n",
732 psfi
->hIcon
, psfi
->iIcon
, psfi
->dwAttributes
,
733 debugstr_w(psfi
->szDisplayName
), debugstr_w(psfi
->szTypeName
), ret
);
738 /*************************************************************************
739 * SHGetFileInfoA [SHELL32.@]
742 * MSVBVM60.__vbaNew2 expects this function to return a value in range
743 * 1 .. 0x7fff when the function succeeds and flags does not contain
744 * SHGFI_EXETYPE or SHGFI_SYSICONINDEX (see bug 7701)
746 DWORD_PTR WINAPI
SHGetFileInfoA(LPCSTR path
,DWORD dwFileAttributes
,
747 SHFILEINFOA
*psfi
, UINT sizeofpsfi
,
751 LPWSTR temppath
= NULL
;
754 SHFILEINFOW temppsfi
;
756 if (flags
& SHGFI_PIDL
)
758 /* path contains a pidl */
759 pathW
= (LPCWSTR
)path
;
763 len
= MultiByteToWideChar(CP_ACP
, 0, path
, -1, NULL
, 0);
764 temppath
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
765 MultiByteToWideChar(CP_ACP
, 0, path
, -1, temppath
, len
);
769 if (psfi
&& (flags
& SHGFI_ATTR_SPECIFIED
))
770 temppsfi
.dwAttributes
=psfi
->dwAttributes
;
773 ret
= SHGetFileInfoW(pathW
, dwFileAttributes
, NULL
, 0, flags
);
775 ret
= SHGetFileInfoW(pathW
, dwFileAttributes
, &temppsfi
, sizeof(temppsfi
), flags
);
779 if(flags
& SHGFI_ICON
)
780 psfi
->hIcon
=temppsfi
.hIcon
;
781 if(flags
& (SHGFI_SYSICONINDEX
|SHGFI_ICON
|SHGFI_ICONLOCATION
))
782 psfi
->iIcon
=temppsfi
.iIcon
;
783 if(flags
& SHGFI_ATTRIBUTES
)
784 psfi
->dwAttributes
=temppsfi
.dwAttributes
;
785 if(flags
& (SHGFI_DISPLAYNAME
|SHGFI_ICONLOCATION
))
787 WideCharToMultiByte(CP_ACP
, 0, temppsfi
.szDisplayName
, -1,
788 psfi
->szDisplayName
, sizeof(psfi
->szDisplayName
), NULL
, NULL
);
790 if(flags
& SHGFI_TYPENAME
)
792 WideCharToMultiByte(CP_ACP
, 0, temppsfi
.szTypeName
, -1,
793 psfi
->szTypeName
, sizeof(psfi
->szTypeName
), NULL
, NULL
);
797 HeapFree(GetProcessHeap(), 0, temppath
);
802 /*************************************************************************
803 * DuplicateIcon [SHELL32.@]
805 HICON WINAPI
DuplicateIcon( HINSTANCE hInstance
, HICON hIcon
)
810 TRACE("%p %p\n", hInstance
, hIcon
);
812 if (GetIconInfo(hIcon
, &IconInfo
))
814 hDupIcon
= CreateIconIndirect(&IconInfo
);
816 /* clean up hbmMask and hbmColor */
817 DeleteObject(IconInfo
.hbmMask
);
818 DeleteObject(IconInfo
.hbmColor
);
824 /*************************************************************************
825 * ExtractIconA [SHELL32.@]
827 HICON WINAPI
ExtractIconA(HINSTANCE hInstance
, LPCSTR lpszFile
, UINT nIconIndex
)
830 INT len
= MultiByteToWideChar(CP_ACP
, 0, lpszFile
, -1, NULL
, 0);
831 LPWSTR lpwstrFile
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
833 TRACE("%p %s %d\n", hInstance
, lpszFile
, nIconIndex
);
835 MultiByteToWideChar(CP_ACP
, 0, lpszFile
, -1, lpwstrFile
, len
);
836 ret
= ExtractIconW(hInstance
, lpwstrFile
, nIconIndex
);
837 HeapFree(GetProcessHeap(), 0, lpwstrFile
);
842 /*************************************************************************
843 * ExtractIconW [SHELL32.@]
845 HICON WINAPI
ExtractIconW(HINSTANCE hInstance
, LPCWSTR lpszFile
, UINT nIconIndex
)
849 UINT cx
= GetSystemMetrics(SM_CXICON
), cy
= GetSystemMetrics(SM_CYICON
);
851 TRACE("%p %s %d\n", hInstance
, debugstr_w(lpszFile
), nIconIndex
);
853 if (nIconIndex
== (UINT
)-1)
855 ret
= PrivateExtractIconsW(lpszFile
, 0, cx
, cy
, NULL
, NULL
, 0, LR_DEFAULTCOLOR
);
856 if (ret
!= (UINT
)-1 && ret
)
857 return (HICON
)(UINT_PTR
)ret
;
861 ret
= PrivateExtractIconsW(lpszFile
, nIconIndex
, cx
, cy
, &hIcon
, NULL
, 1, LR_DEFAULTCOLOR
);
865 else if (ret
> 0 && hIcon
)
871 /*************************************************************************
872 * Printer_LoadIconsW [SHELL32.205]
874 VOID WINAPI
Printer_LoadIconsW(LPCWSTR wsPrinterName
, HICON
* pLargeIcon
, HICON
* pSmallIcon
)
876 INT iconindex
=IDI_SHELL_PRINTERS_FOLDER
;
878 TRACE("(%s, %p, %p)\n", debugstr_w(wsPrinterName
), pLargeIcon
, pSmallIcon
);
880 /* We should check if wsPrinterName is
881 1. the Default Printer or not
883 3. a Local Printer or a Network-Printer
884 and use different Icons
886 if((wsPrinterName
!= NULL
) && (wsPrinterName
[0] != 0))
888 FIXME("(select Icon by PrinterName %s not implemented)\n", debugstr_w(wsPrinterName
));
891 if(pLargeIcon
!= NULL
)
892 *pLargeIcon
= LoadImageW(shell32_hInstance
,
893 (LPCWSTR
) MAKEINTRESOURCE(iconindex
), IMAGE_ICON
,
894 0, 0, LR_DEFAULTCOLOR
|LR_DEFAULTSIZE
);
896 if(pSmallIcon
!= NULL
)
897 *pSmallIcon
= LoadImageW(shell32_hInstance
,
898 (LPCWSTR
) MAKEINTRESOURCE(iconindex
), IMAGE_ICON
,
899 16, 16, LR_DEFAULTCOLOR
);
902 /*************************************************************************
903 * Printers_RegisterWindowW [SHELL32.213]
904 * used by "printui.dll":
905 * find the Window of the given Type for the specific Printer and
906 * return the already existent hwnd or open a new window
908 BOOL WINAPI
Printers_RegisterWindowW(LPCWSTR wsPrinter
, DWORD dwType
,
909 HANDLE
* phClassPidl
, HWND
* phwnd
)
911 FIXME("(%s, %x, %p (%p), %p (%p)) stub!\n", debugstr_w(wsPrinter
), dwType
,
912 phClassPidl
, (phClassPidl
!= NULL
) ? *(phClassPidl
) : NULL
,
913 phwnd
, (phwnd
!= NULL
) ? *(phwnd
) : NULL
);
918 /*************************************************************************
919 * Printers_UnregisterWindow [SHELL32.214]
921 VOID WINAPI
Printers_UnregisterWindow(HANDLE hClassPidl
, HWND hwnd
)
923 FIXME("(%p, %p) stub!\n", hClassPidl
, hwnd
);
926 /*************************************************************************/
931 LPCWSTR szOtherStuff
;
935 #define DROP_FIELD_TOP (-15)
936 #define DROP_FIELD_HEIGHT 15
938 /*************************************************************************
939 * SHAppBarMessage [SHELL32.@]
941 UINT_PTR WINAPI
SHAppBarMessage(DWORD msg
, PAPPBARDATA data
)
943 int width
=data
->rc
.right
- data
->rc
.left
;
944 int height
=data
->rc
.bottom
- data
->rc
.top
;
947 TRACE("msg=%d, data={cb=%d, hwnd=%p, callback=%x, edge=%d, rc=%s, lparam=%lx}\n",
948 msg
, data
->cbSize
, data
->hWnd
, data
->uCallbackMessage
, data
->uEdge
,
949 wine_dbgstr_rect(&data
->rc
), data
->lParam
);
954 return ABS_ALWAYSONTOP
| ABS_AUTOHIDE
;
956 case ABM_GETTASKBARPOS
:
957 GetWindowRect(data
->hWnd
, &rec
);
962 SetActiveWindow(data
->hWnd
);
965 case ABM_GETAUTOHIDEBAR
:
966 return 0; /* pretend there is no autohide bar */
969 /* cbSize, hWnd, and uCallbackMessage are used. All other ignored */
970 SetWindowPos(data
->hWnd
,HWND_TOP
,0,0,0,0,SWP_SHOWWINDOW
|SWP_NOMOVE
|SWP_NOSIZE
);
974 GetWindowRect(data
->hWnd
, &(data
->rc
));
978 FIXME("ABM_REMOVE broken\n");
979 /* FIXME: this is wrong; should it be DestroyWindow instead? */
980 /*CloseHandle(data->hWnd);*/
983 case ABM_SETAUTOHIDEBAR
:
984 SetWindowPos(data
->hWnd
,HWND_TOP
,rec
.left
+1000,rec
.top
,
985 width
,height
,SWP_SHOWWINDOW
);
989 data
->uEdge
=(ABE_RIGHT
| ABE_LEFT
);
990 SetWindowPos(data
->hWnd
,HWND_TOP
,data
->rc
.left
,data
->rc
.top
,
991 width
,height
,SWP_SHOWWINDOW
);
994 case ABM_WINDOWPOSCHANGED
:
1001 /*************************************************************************
1002 * SHHelpShortcuts_RunDLLA [SHELL32.@]
1005 DWORD WINAPI
SHHelpShortcuts_RunDLLA(DWORD dwArg1
, DWORD dwArg2
, DWORD dwArg3
, DWORD dwArg4
)
1007 FIXME("(%x, %x, %x, %x) stub!\n", dwArg1
, dwArg2
, dwArg3
, dwArg4
);
1011 /*************************************************************************
1012 * SHHelpShortcuts_RunDLLA [SHELL32.@]
1015 DWORD WINAPI
SHHelpShortcuts_RunDLLW(DWORD dwArg1
, DWORD dwArg2
, DWORD dwArg3
, DWORD dwArg4
)
1017 FIXME("(%x, %x, %x, %x) stub!\n", dwArg1
, dwArg2
, dwArg3
, dwArg4
);
1021 /*************************************************************************
1022 * SHLoadInProc [SHELL32.@]
1023 * Create an instance of specified object class from within
1024 * the shell process and release it immediately
1026 HRESULT WINAPI
SHLoadInProc (REFCLSID rclsid
)
1030 TRACE("%s\n", debugstr_guid(rclsid
));
1032 CoCreateInstance(rclsid
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IUnknown
,&ptr
);
1035 return DISP_E_MEMBERNOTFOUND
;
1038 static VOID
SetRegTextData(HWND hWnd
, HKEY hKey
, LPCWSTR Value
, UINT uID
)
1044 if( RegQueryValueExW(hKey
, Value
, NULL
, &dwType
, NULL
, &dwBufferSize
) == ERROR_SUCCESS
)
1046 if(dwType
== REG_SZ
)
1048 lpBuffer
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, dwBufferSize
);
1052 if( RegQueryValueExW(hKey
, Value
, NULL
, &dwType
, (LPBYTE
)lpBuffer
, &dwBufferSize
) == ERROR_SUCCESS
)
1054 SetDlgItemTextW(hWnd
, uID
, lpBuffer
);
1057 HeapFree(GetProcessHeap(), 0, lpBuffer
);
1063 INT_PTR CALLBACK
AboutAuthorsDlgProc( HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1069 const char* const *pstr
= SHELL_Authors
;
1071 // Add the authors to the list
1072 SendDlgItemMessageW( hWnd
, IDC_ABOUT_AUTHORS_LISTBOX
, WM_SETREDRAW
, FALSE
, 0 );
1078 /* authors list is in utf-8 format */
1079 MultiByteToWideChar( CP_UTF8
, 0, *pstr
, -1, name
, sizeof(name
)/sizeof(WCHAR
) );
1080 SendDlgItemMessageW( hWnd
, IDC_ABOUT_AUTHORS_LISTBOX
, LB_ADDSTRING
, (WPARAM
)-1, (LPARAM
)name
);
1084 SendDlgItemMessageW( hWnd
, IDC_ABOUT_AUTHORS_LISTBOX
, WM_SETREDRAW
, TRUE
, 0 );
1092 /*************************************************************************
1093 * AboutDlgProc (internal)
1095 static INT_PTR CALLBACK
AboutDlgProc( HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1097 static DWORD cxLogoBmp
;
1098 static DWORD cyLogoBmp
;
1099 static HBITMAP hLogoBmp
;
1100 static HWND hWndAuthors
;
1106 ABOUT_INFO
*info
= (ABOUT_INFO
*)lParam
;
1110 const WCHAR szRegKey
[] = L
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion";
1112 MEMORYSTATUSEX MemStat
;
1113 WCHAR szAppTitle
[512];
1114 WCHAR szAppTitleTemplate
[512];
1115 WCHAR szAuthorsText
[20];
1117 // Preload the ROS bitmap
1118 hLogoBmp
= (HBITMAP
)LoadImage(shell32_hInstance
, MAKEINTRESOURCE(IDB_REACTOS
), IMAGE_BITMAP
, 0, 0, LR_DEFAULTCOLOR
);
1124 GetObject( hLogoBmp
, sizeof(BITMAP
), &bmpLogo
);
1126 cxLogoBmp
= bmpLogo
.bmWidth
;
1127 cyLogoBmp
= bmpLogo
.bmHeight
;
1130 // Set App-specific stuff (icon, app name, szOtherStuff string)
1131 SendDlgItemMessageW(hWnd
, IDC_ABOUT_ICON
, STM_SETICON
, (WPARAM
)info
->hIcon
, 0);
1133 GetWindowTextW( hWnd
, szAppTitleTemplate
, sizeof(szAppTitleTemplate
) / sizeof(WCHAR
) );
1134 swprintf( szAppTitle
, szAppTitleTemplate
, info
->szApp
);
1135 SetWindowTextW( hWnd
, szAppTitle
);
1137 SetDlgItemTextW( hWnd
, IDC_ABOUT_APPNAME
, info
->szApp
);
1138 SetDlgItemTextW( hWnd
, IDC_ABOUT_OTHERSTUFF
, info
->szOtherStuff
);
1140 // Set the registered user and organization name
1141 if(RegOpenKeyExW( HKEY_LOCAL_MACHINE
, szRegKey
, 0, KEY_QUERY_VALUE
, &hRegKey
) == ERROR_SUCCESS
)
1143 SetRegTextData( hWnd
, hRegKey
, L
"RegisteredOwner", IDC_ABOUT_REG_USERNAME
);
1144 SetRegTextData( hWnd
, hRegKey
, L
"RegisteredOrganization", IDC_ABOUT_REG_ORGNAME
);
1146 RegCloseKey( hRegKey
);
1149 // Set the value for the installed physical memory
1150 MemStat
.dwLength
= sizeof(MemStat
);
1151 if( GlobalMemoryStatusEx(&MemStat
) )
1155 if (MemStat
.ullTotalPhys
> 1024 * 1024 * 1024)
1158 WCHAR szDecimalSeparator
[4];
1161 // We're dealing with GBs or more
1162 MemStat
.ullTotalPhys
/= 1024 * 1024;
1164 if (MemStat
.ullTotalPhys
> 1024 * 1024)
1166 // We're dealing with TBs or more
1167 MemStat
.ullTotalPhys
/= 1024;
1169 if (MemStat
.ullTotalPhys
> 1024 * 1024)
1171 // We're dealing with PBs or more
1172 MemStat
.ullTotalPhys
/= 1024;
1174 dTotalPhys
= (double)MemStat
.ullTotalPhys
/ 1024;
1175 wcscpy( szUnits
, L
"PB" );
1179 dTotalPhys
= (double)MemStat
.ullTotalPhys
/ 1024;
1180 wcscpy( szUnits
, L
"TB" );
1185 dTotalPhys
= (double)MemStat
.ullTotalPhys
/ 1024;
1186 wcscpy( szUnits
, L
"GB" );
1189 // We need the decimal point of the current locale to display the RAM size correctly
1190 if (GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SDECIMAL
,
1192 sizeof(szDecimalSeparator
) / sizeof(WCHAR
)) > 0)
1197 uIntegral
= (UINT
)dTotalPhys
;
1198 uDecimals
= (UCHAR
)((UINT
)(dTotalPhys
* 100) - uIntegral
* 100);
1200 // Display the RAM size with 2 decimals
1201 swprintf(szBuf
, L
"%u%s%02u %s", uIntegral
, szDecimalSeparator
, uDecimals
, szUnits
);
1206 // We're dealing with MBs, don't show any decimals
1207 swprintf( szBuf
, L
"%u MB", (UINT
)MemStat
.ullTotalPhys
/ 1024 / 1024 );
1210 SetDlgItemTextW( hWnd
, IDC_ABOUT_PHYSMEM
, szBuf
);
1213 // Add the Authors dialog
1214 hWndAuthors
= CreateDialogW( shell32_hInstance
, MAKEINTRESOURCEW(IDD_ABOUT_AUTHORS
), hWnd
, AboutAuthorsDlgProc
);
1215 LoadStringW( shell32_hInstance
, IDS_SHELL_ABOUT_AUTHORS
, szAuthorsText
, sizeof(szAuthorsText
) / sizeof(WCHAR
) );
1216 SetDlgItemTextW( hWnd
, IDC_ABOUT_AUTHORS
, szAuthorsText
);
1230 hdc
= BeginPaint(hWnd
, &ps
);
1231 hdcMem
= CreateCompatibleDC(hdc
);
1235 SelectObject(hdcMem
, hLogoBmp
);
1236 BitBlt(hdc
, 0, 0, cxLogoBmp
, cyLogoBmp
, hdcMem
, 0, 0, SRCCOPY
);
1241 EndPaint(hWnd
, &ps
);
1251 EndDialog(hWnd
, TRUE
);
1254 case IDC_ABOUT_AUTHORS
:
1256 static BOOL bShowingAuthors
= FALSE
;
1257 WCHAR szAuthorsText
[20];
1261 LoadStringW( shell32_hInstance
, IDS_SHELL_ABOUT_AUTHORS
, szAuthorsText
, sizeof(szAuthorsText
) / sizeof(WCHAR
) );
1262 ShowWindow( hWndAuthors
, SW_HIDE
);
1266 LoadStringW( shell32_hInstance
, IDS_SHELL_ABOUT_BACK
, szAuthorsText
, sizeof(szAuthorsText
) / sizeof(WCHAR
) );
1267 ShowWindow( hWndAuthors
, SW_SHOW
);
1270 SetDlgItemTextW( hWnd
, IDC_ABOUT_AUTHORS
, szAuthorsText
);
1271 bShowingAuthors
= !bShowingAuthors
;
1278 EndDialog(hWnd
, TRUE
);
1286 /*************************************************************************
1287 * ShellAboutA [SHELL32.288]
1289 BOOL WINAPI
ShellAboutA( HWND hWnd
, LPCSTR szApp
, LPCSTR szOtherStuff
, HICON hIcon
)
1292 LPWSTR appW
= NULL
, otherW
= NULL
;
1297 len
= MultiByteToWideChar(CP_ACP
, 0, szApp
, -1, NULL
, 0);
1298 appW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1299 MultiByteToWideChar(CP_ACP
, 0, szApp
, -1, appW
, len
);
1303 len
= MultiByteToWideChar(CP_ACP
, 0, szOtherStuff
, -1, NULL
, 0);
1304 otherW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1305 MultiByteToWideChar(CP_ACP
, 0, szOtherStuff
, -1, otherW
, len
);
1308 ret
= ShellAboutW(hWnd
, appW
, otherW
, hIcon
);
1310 HeapFree(GetProcessHeap(), 0, otherW
);
1311 HeapFree(GetProcessHeap(), 0, appW
);
1316 /*************************************************************************
1317 * ShellAboutW [SHELL32.289]
1319 BOOL WINAPI
ShellAboutW( HWND hWnd
, LPCWSTR szApp
, LPCWSTR szOtherStuff
,
1324 DLGTEMPLATE
*DlgTemplate
;
1329 // DialogBoxIndirectParamW will be called with the hInstance of the calling application, so we have to preload the dialog template
1330 hRes
= FindResourceW(shell32_hInstance
, MAKEINTRESOURCEW(IDD_ABOUT
), (LPWSTR
)RT_DIALOG
);
1334 DlgTemplate
= (DLGTEMPLATE
*)LoadResource(shell32_hInstance
, hRes
);
1339 info
.szOtherStuff
= szOtherStuff
;
1340 info
.hIcon
= hIcon
? hIcon
: LoadIconW( 0, (LPWSTR
)IDI_WINLOGO
);
1342 bRet
= DialogBoxIndirectParamW((HINSTANCE
)GetWindowLongPtrW( hWnd
, GWLP_HINSTANCE
),
1343 DlgTemplate
, hWnd
, AboutDlgProc
, (LPARAM
)&info
);
1347 /*************************************************************************
1348 * FreeIconList (SHELL32.@)
1350 void WINAPI
FreeIconList( DWORD dw
)
1352 FIXME("%x: stub\n",dw
);
1355 /*************************************************************************
1356 * SHLoadNonloadedIconOverlayIdentifiers (SHELL32.@)
1358 HRESULT WINAPI
SHLoadNonloadedIconOverlayIdentifiers( VOID
)