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
);
727 IShellFolder_Release(psfParent
);
734 TRACE ("icon=%p index=0x%08x attr=0x%08x name=%s type=%s ret=0x%08lx\n",
735 psfi
->hIcon
, psfi
->iIcon
, psfi
->dwAttributes
,
736 debugstr_w(psfi
->szDisplayName
), debugstr_w(psfi
->szTypeName
), ret
);
741 /*************************************************************************
742 * SHGetFileInfoA [SHELL32.@]
745 * MSVBVM60.__vbaNew2 expects this function to return a value in range
746 * 1 .. 0x7fff when the function succeeds and flags does not contain
747 * SHGFI_EXETYPE or SHGFI_SYSICONINDEX (see bug 7701)
749 DWORD_PTR WINAPI
SHGetFileInfoA(LPCSTR path
,DWORD dwFileAttributes
,
750 SHFILEINFOA
*psfi
, UINT sizeofpsfi
,
754 LPWSTR temppath
= NULL
;
757 SHFILEINFOW temppsfi
;
759 if (flags
& SHGFI_PIDL
)
761 /* path contains a pidl */
762 pathW
= (LPCWSTR
)path
;
766 len
= MultiByteToWideChar(CP_ACP
, 0, path
, -1, NULL
, 0);
767 temppath
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
768 MultiByteToWideChar(CP_ACP
, 0, path
, -1, temppath
, len
);
772 if (psfi
&& (flags
& SHGFI_ATTR_SPECIFIED
))
773 temppsfi
.dwAttributes
=psfi
->dwAttributes
;
776 ret
= SHGetFileInfoW(pathW
, dwFileAttributes
, NULL
, 0, flags
);
778 ret
= SHGetFileInfoW(pathW
, dwFileAttributes
, &temppsfi
, sizeof(temppsfi
), flags
);
782 if(flags
& SHGFI_ICON
)
783 psfi
->hIcon
=temppsfi
.hIcon
;
784 if(flags
& (SHGFI_SYSICONINDEX
|SHGFI_ICON
|SHGFI_ICONLOCATION
))
785 psfi
->iIcon
=temppsfi
.iIcon
;
786 if(flags
& SHGFI_ATTRIBUTES
)
787 psfi
->dwAttributes
=temppsfi
.dwAttributes
;
788 if(flags
& (SHGFI_DISPLAYNAME
|SHGFI_ICONLOCATION
))
790 WideCharToMultiByte(CP_ACP
, 0, temppsfi
.szDisplayName
, -1,
791 psfi
->szDisplayName
, sizeof(psfi
->szDisplayName
), NULL
, NULL
);
793 if(flags
& SHGFI_TYPENAME
)
795 WideCharToMultiByte(CP_ACP
, 0, temppsfi
.szTypeName
, -1,
796 psfi
->szTypeName
, sizeof(psfi
->szTypeName
), NULL
, NULL
);
800 HeapFree(GetProcessHeap(), 0, temppath
);
805 /*************************************************************************
806 * DuplicateIcon [SHELL32.@]
808 HICON WINAPI
DuplicateIcon( HINSTANCE hInstance
, HICON hIcon
)
813 TRACE("%p %p\n", hInstance
, hIcon
);
815 if (GetIconInfo(hIcon
, &IconInfo
))
817 hDupIcon
= CreateIconIndirect(&IconInfo
);
819 /* clean up hbmMask and hbmColor */
820 DeleteObject(IconInfo
.hbmMask
);
821 DeleteObject(IconInfo
.hbmColor
);
827 /*************************************************************************
828 * ExtractIconA [SHELL32.@]
830 HICON WINAPI
ExtractIconA(HINSTANCE hInstance
, LPCSTR lpszFile
, UINT nIconIndex
)
833 INT len
= MultiByteToWideChar(CP_ACP
, 0, lpszFile
, -1, NULL
, 0);
834 LPWSTR lpwstrFile
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
836 TRACE("%p %s %d\n", hInstance
, lpszFile
, nIconIndex
);
838 MultiByteToWideChar(CP_ACP
, 0, lpszFile
, -1, lpwstrFile
, len
);
839 ret
= ExtractIconW(hInstance
, lpwstrFile
, nIconIndex
);
840 HeapFree(GetProcessHeap(), 0, lpwstrFile
);
845 /*************************************************************************
846 * ExtractIconW [SHELL32.@]
848 HICON WINAPI
ExtractIconW(HINSTANCE hInstance
, LPCWSTR lpszFile
, UINT nIconIndex
)
852 UINT cx
= GetSystemMetrics(SM_CXICON
), cy
= GetSystemMetrics(SM_CYICON
);
854 TRACE("%p %s %d\n", hInstance
, debugstr_w(lpszFile
), nIconIndex
);
856 if (nIconIndex
== (UINT
)-1)
858 ret
= PrivateExtractIconsW(lpszFile
, 0, cx
, cy
, NULL
, NULL
, 0, LR_DEFAULTCOLOR
);
859 if (ret
!= (UINT
)-1 && ret
)
860 return (HICON
)(UINT_PTR
)ret
;
864 ret
= PrivateExtractIconsW(lpszFile
, nIconIndex
, cx
, cy
, &hIcon
, NULL
, 1, LR_DEFAULTCOLOR
);
868 else if (ret
> 0 && hIcon
)
874 /*************************************************************************
875 * Printer_LoadIconsW [SHELL32.205]
877 VOID WINAPI
Printer_LoadIconsW(LPCWSTR wsPrinterName
, HICON
* pLargeIcon
, HICON
* pSmallIcon
)
879 INT iconindex
=IDI_SHELL_PRINTERS_FOLDER
;
881 TRACE("(%s, %p, %p)\n", debugstr_w(wsPrinterName
), pLargeIcon
, pSmallIcon
);
883 /* We should check if wsPrinterName is
884 1. the Default Printer or not
886 3. a Local Printer or a Network-Printer
887 and use different Icons
889 if((wsPrinterName
!= NULL
) && (wsPrinterName
[0] != 0))
891 FIXME("(select Icon by PrinterName %s not implemented)\n", debugstr_w(wsPrinterName
));
894 if(pLargeIcon
!= NULL
)
895 *pLargeIcon
= LoadImageW(shell32_hInstance
,
896 (LPCWSTR
) MAKEINTRESOURCE(iconindex
), IMAGE_ICON
,
897 0, 0, LR_DEFAULTCOLOR
|LR_DEFAULTSIZE
);
899 if(pSmallIcon
!= NULL
)
900 *pSmallIcon
= LoadImageW(shell32_hInstance
,
901 (LPCWSTR
) MAKEINTRESOURCE(iconindex
), IMAGE_ICON
,
902 16, 16, LR_DEFAULTCOLOR
);
905 /*************************************************************************
906 * Printers_RegisterWindowW [SHELL32.213]
907 * used by "printui.dll":
908 * find the Window of the given Type for the specific Printer and
909 * return the already existent hwnd or open a new window
911 BOOL WINAPI
Printers_RegisterWindowW(LPCWSTR wsPrinter
, DWORD dwType
,
912 HANDLE
* phClassPidl
, HWND
* phwnd
)
914 FIXME("(%s, %x, %p (%p), %p (%p)) stub!\n", debugstr_w(wsPrinter
), dwType
,
915 phClassPidl
, (phClassPidl
!= NULL
) ? *(phClassPidl
) : NULL
,
916 phwnd
, (phwnd
!= NULL
) ? *(phwnd
) : NULL
);
921 /*************************************************************************
922 * Printers_UnregisterWindow [SHELL32.214]
924 VOID WINAPI
Printers_UnregisterWindow(HANDLE hClassPidl
, HWND hwnd
)
926 FIXME("(%p, %p) stub!\n", hClassPidl
, hwnd
);
929 /*************************************************************************/
934 LPCWSTR szOtherStuff
;
938 #define DROP_FIELD_TOP (-15)
939 #define DROP_FIELD_HEIGHT 15
941 /*************************************************************************
942 * SHAppBarMessage [SHELL32.@]
944 UINT_PTR WINAPI
SHAppBarMessage(DWORD msg
, PAPPBARDATA data
)
946 int width
=data
->rc
.right
- data
->rc
.left
;
947 int height
=data
->rc
.bottom
- data
->rc
.top
;
950 TRACE("msg=%d, data={cb=%d, hwnd=%p, callback=%x, edge=%d, rc=%s, lparam=%lx}\n",
951 msg
, data
->cbSize
, data
->hWnd
, data
->uCallbackMessage
, data
->uEdge
,
952 wine_dbgstr_rect(&data
->rc
), data
->lParam
);
957 return ABS_ALWAYSONTOP
| ABS_AUTOHIDE
;
959 case ABM_GETTASKBARPOS
:
960 GetWindowRect(data
->hWnd
, &rec
);
965 SetActiveWindow(data
->hWnd
);
968 case ABM_GETAUTOHIDEBAR
:
969 return 0; /* pretend there is no autohide bar */
972 /* cbSize, hWnd, and uCallbackMessage are used. All other ignored */
973 SetWindowPos(data
->hWnd
,HWND_TOP
,0,0,0,0,SWP_SHOWWINDOW
|SWP_NOMOVE
|SWP_NOSIZE
);
977 GetWindowRect(data
->hWnd
, &(data
->rc
));
981 FIXME("ABM_REMOVE broken\n");
982 /* FIXME: this is wrong; should it be DestroyWindow instead? */
983 /*CloseHandle(data->hWnd);*/
986 case ABM_SETAUTOHIDEBAR
:
987 SetWindowPos(data
->hWnd
,HWND_TOP
,rec
.left
+1000,rec
.top
,
988 width
,height
,SWP_SHOWWINDOW
);
992 data
->uEdge
=(ABE_RIGHT
| ABE_LEFT
);
993 SetWindowPos(data
->hWnd
,HWND_TOP
,data
->rc
.left
,data
->rc
.top
,
994 width
,height
,SWP_SHOWWINDOW
);
997 case ABM_WINDOWPOSCHANGED
:
1004 /*************************************************************************
1005 * SHHelpShortcuts_RunDLLA [SHELL32.@]
1008 DWORD WINAPI
SHHelpShortcuts_RunDLLA(DWORD dwArg1
, DWORD dwArg2
, DWORD dwArg3
, DWORD dwArg4
)
1010 FIXME("(%x, %x, %x, %x) stub!\n", dwArg1
, dwArg2
, dwArg3
, dwArg4
);
1014 /*************************************************************************
1015 * SHHelpShortcuts_RunDLLA [SHELL32.@]
1018 DWORD WINAPI
SHHelpShortcuts_RunDLLW(DWORD dwArg1
, DWORD dwArg2
, DWORD dwArg3
, DWORD dwArg4
)
1020 FIXME("(%x, %x, %x, %x) stub!\n", dwArg1
, dwArg2
, dwArg3
, dwArg4
);
1024 /*************************************************************************
1025 * SHLoadInProc [SHELL32.@]
1026 * Create an instance of specified object class from within
1027 * the shell process and release it immediately
1029 HRESULT WINAPI
SHLoadInProc (REFCLSID rclsid
)
1033 TRACE("%s\n", debugstr_guid(rclsid
));
1035 CoCreateInstance(rclsid
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IUnknown
,&ptr
);
1038 IUnknown
* pUnk
= ptr
;
1039 IUnknown_Release(pUnk
);
1042 return DISP_E_MEMBERNOTFOUND
;
1045 static VOID
SetRegTextData(HWND hWnd
, HKEY hKey
, LPCWSTR Value
, UINT uID
)
1051 if( RegQueryValueExW(hKey
, Value
, NULL
, &dwType
, NULL
, &dwBufferSize
) == ERROR_SUCCESS
)
1053 if(dwType
== REG_SZ
)
1055 lpBuffer
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, dwBufferSize
);
1059 if( RegQueryValueExW(hKey
, Value
, NULL
, &dwType
, (LPBYTE
)lpBuffer
, &dwBufferSize
) == ERROR_SUCCESS
)
1061 SetDlgItemTextW(hWnd
, uID
, lpBuffer
);
1064 HeapFree(GetProcessHeap(), 0, lpBuffer
);
1070 INT_PTR CALLBACK
AboutAuthorsDlgProc( HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1076 const char* const *pstr
= SHELL_Authors
;
1078 // Add the authors to the list
1079 SendDlgItemMessageW( hWnd
, IDC_ABOUT_AUTHORS_LISTBOX
, WM_SETREDRAW
, FALSE
, 0 );
1085 /* authors list is in utf-8 format */
1086 MultiByteToWideChar( CP_UTF8
, 0, *pstr
, -1, name
, sizeof(name
)/sizeof(WCHAR
) );
1087 SendDlgItemMessageW( hWnd
, IDC_ABOUT_AUTHORS_LISTBOX
, LB_ADDSTRING
, (WPARAM
)-1, (LPARAM
)name
);
1091 SendDlgItemMessageW( hWnd
, IDC_ABOUT_AUTHORS_LISTBOX
, WM_SETREDRAW
, TRUE
, 0 );
1099 /*************************************************************************
1100 * AboutDlgProc (internal)
1102 static INT_PTR CALLBACK
AboutDlgProc( HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1104 static DWORD cxLogoBmp
;
1105 static DWORD cyLogoBmp
;
1106 static HBITMAP hLogoBmp
;
1107 static HWND hWndAuthors
;
1113 ABOUT_INFO
*info
= (ABOUT_INFO
*)lParam
;
1117 const WCHAR szRegKey
[] = L
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion";
1119 MEMORYSTATUSEX MemStat
;
1120 WCHAR szAppTitle
[512];
1121 WCHAR szAppTitleTemplate
[512];
1122 WCHAR szAuthorsText
[20];
1124 // Preload the ROS bitmap
1125 hLogoBmp
= (HBITMAP
)LoadImage(shell32_hInstance
, MAKEINTRESOURCE(IDB_REACTOS
), IMAGE_BITMAP
, 0, 0, LR_DEFAULTCOLOR
);
1131 GetObject( hLogoBmp
, sizeof(BITMAP
), &bmpLogo
);
1133 cxLogoBmp
= bmpLogo
.bmWidth
;
1134 cyLogoBmp
= bmpLogo
.bmHeight
;
1137 // Set App-specific stuff (icon, app name, szOtherStuff string)
1138 SendDlgItemMessageW(hWnd
, IDC_ABOUT_ICON
, STM_SETICON
, (WPARAM
)info
->hIcon
, 0);
1140 GetWindowTextW( hWnd
, szAppTitleTemplate
, sizeof(szAppTitleTemplate
) / sizeof(WCHAR
) );
1141 swprintf( szAppTitle
, szAppTitleTemplate
, info
->szApp
);
1142 SetWindowTextW( hWnd
, szAppTitle
);
1144 SetDlgItemTextW( hWnd
, IDC_ABOUT_APPNAME
, info
->szApp
);
1145 SetDlgItemTextW( hWnd
, IDC_ABOUT_OTHERSTUFF
, info
->szOtherStuff
);
1147 // Set the registered user and organization name
1148 if(RegOpenKeyExW( HKEY_LOCAL_MACHINE
, szRegKey
, 0, KEY_QUERY_VALUE
, &hRegKey
) == ERROR_SUCCESS
)
1150 SetRegTextData( hWnd
, hRegKey
, L
"RegisteredOwner", IDC_ABOUT_REG_USERNAME
);
1151 SetRegTextData( hWnd
, hRegKey
, L
"RegisteredOrganization", IDC_ABOUT_REG_ORGNAME
);
1153 RegCloseKey( hRegKey
);
1156 // Set the value for the installed physical memory
1157 MemStat
.dwLength
= sizeof(MemStat
);
1158 if( GlobalMemoryStatusEx(&MemStat
) )
1162 if (MemStat
.ullTotalPhys
> 1024 * 1024 * 1024)
1165 WCHAR szDecimalSeparator
[4];
1168 // We're dealing with GBs or more
1169 MemStat
.ullTotalPhys
/= 1024 * 1024;
1171 if (MemStat
.ullTotalPhys
> 1024 * 1024)
1173 // We're dealing with TBs or more
1174 MemStat
.ullTotalPhys
/= 1024;
1176 if (MemStat
.ullTotalPhys
> 1024 * 1024)
1178 // We're dealing with PBs or more
1179 MemStat
.ullTotalPhys
/= 1024;
1181 dTotalPhys
= (double)MemStat
.ullTotalPhys
/ 1024;
1182 wcscpy( szUnits
, L
"PB" );
1186 dTotalPhys
= (double)MemStat
.ullTotalPhys
/ 1024;
1187 wcscpy( szUnits
, L
"TB" );
1192 dTotalPhys
= (double)MemStat
.ullTotalPhys
/ 1024;
1193 wcscpy( szUnits
, L
"GB" );
1196 // We need the decimal point of the current locale to display the RAM size correctly
1197 if (GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SDECIMAL
,
1199 sizeof(szDecimalSeparator
) / sizeof(WCHAR
)) > 0)
1204 uIntegral
= (UINT
)dTotalPhys
;
1205 uDecimals
= (UCHAR
)((UINT
)(dTotalPhys
* 100) - uIntegral
* 100);
1207 // Display the RAM size with 2 decimals
1208 swprintf(szBuf
, L
"%u%s%02u %s", uIntegral
, szDecimalSeparator
, uDecimals
, szUnits
);
1213 // We're dealing with MBs, don't show any decimals
1214 swprintf( szBuf
, L
"%u MB", (UINT
)MemStat
.ullTotalPhys
/ 1024 / 1024 );
1217 SetDlgItemTextW( hWnd
, IDC_ABOUT_PHYSMEM
, szBuf
);
1220 // Add the Authors dialog
1221 hWndAuthors
= CreateDialogW( shell32_hInstance
, MAKEINTRESOURCEW(IDD_ABOUT_AUTHORS
), hWnd
, AboutAuthorsDlgProc
);
1222 LoadStringW( shell32_hInstance
, IDS_SHELL_ABOUT_AUTHORS
, szAuthorsText
, sizeof(szAuthorsText
) / sizeof(WCHAR
) );
1223 SetDlgItemTextW( hWnd
, IDC_ABOUT_AUTHORS
, szAuthorsText
);
1237 hdc
= BeginPaint(hWnd
, &ps
);
1238 hdcMem
= CreateCompatibleDC(hdc
);
1242 SelectObject(hdcMem
, hLogoBmp
);
1243 BitBlt(hdc
, 0, 0, cxLogoBmp
, cyLogoBmp
, hdcMem
, 0, 0, SRCCOPY
);
1248 EndPaint(hWnd
, &ps
);
1258 EndDialog(hWnd
, TRUE
);
1261 case IDC_ABOUT_AUTHORS
:
1263 static BOOL bShowingAuthors
= FALSE
;
1264 WCHAR szAuthorsText
[20];
1268 LoadStringW( shell32_hInstance
, IDS_SHELL_ABOUT_AUTHORS
, szAuthorsText
, sizeof(szAuthorsText
) / sizeof(WCHAR
) );
1269 ShowWindow( hWndAuthors
, SW_HIDE
);
1273 LoadStringW( shell32_hInstance
, IDS_SHELL_ABOUT_BACK
, szAuthorsText
, sizeof(szAuthorsText
) / sizeof(WCHAR
) );
1274 ShowWindow( hWndAuthors
, SW_SHOW
);
1277 SetDlgItemTextW( hWnd
, IDC_ABOUT_AUTHORS
, szAuthorsText
);
1278 bShowingAuthors
= !bShowingAuthors
;
1285 EndDialog(hWnd
, TRUE
);
1293 /*************************************************************************
1294 * ShellAboutA [SHELL32.288]
1296 BOOL WINAPI
ShellAboutA( HWND hWnd
, LPCSTR szApp
, LPCSTR szOtherStuff
, HICON hIcon
)
1299 LPWSTR appW
= NULL
, otherW
= NULL
;
1304 len
= MultiByteToWideChar(CP_ACP
, 0, szApp
, -1, NULL
, 0);
1305 appW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1306 MultiByteToWideChar(CP_ACP
, 0, szApp
, -1, appW
, len
);
1310 len
= MultiByteToWideChar(CP_ACP
, 0, szOtherStuff
, -1, NULL
, 0);
1311 otherW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1312 MultiByteToWideChar(CP_ACP
, 0, szOtherStuff
, -1, otherW
, len
);
1315 ret
= ShellAboutW(hWnd
, appW
, otherW
, hIcon
);
1317 HeapFree(GetProcessHeap(), 0, otherW
);
1318 HeapFree(GetProcessHeap(), 0, appW
);
1323 /*************************************************************************
1324 * ShellAboutW [SHELL32.289]
1326 BOOL WINAPI
ShellAboutW( HWND hWnd
, LPCWSTR szApp
, LPCWSTR szOtherStuff
,
1331 DLGTEMPLATE
*DlgTemplate
;
1336 // DialogBoxIndirectParamW will be called with the hInstance of the calling application, so we have to preload the dialog template
1337 hRes
= FindResourceW(shell32_hInstance
, MAKEINTRESOURCEW(IDD_ABOUT
), (LPWSTR
)RT_DIALOG
);
1341 DlgTemplate
= (DLGTEMPLATE
*)LoadResource(shell32_hInstance
, hRes
);
1346 info
.szOtherStuff
= szOtherStuff
;
1347 info
.hIcon
= hIcon
? hIcon
: LoadIconW( 0, (LPWSTR
)IDI_WINLOGO
);
1349 bRet
= DialogBoxIndirectParamW((HINSTANCE
)GetWindowLongPtrW( hWnd
, GWLP_HINSTANCE
),
1350 DlgTemplate
, hWnd
, AboutDlgProc
, (LPARAM
)&info
);
1354 /*************************************************************************
1355 * FreeIconList (SHELL32.@)
1357 void WINAPI
FreeIconList( DWORD dw
)
1359 FIXME("%x: stub\n",dw
);
1362 /*************************************************************************
1363 * SHLoadNonloadedIconOverlayIdentifiers (SHELL32.@)
1365 HRESULT WINAPI
SHLoadNonloadedIconOverlayIdentifiers( VOID
)