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
;
423 TRACE("%s fattr=0x%x sfi=%p(attr=0x%08x) size=0x%x flags=0x%x\n",
424 (flags
& SHGFI_PIDL
)? "pidl" : debugstr_w(path
), dwFileAttributes
,
425 psfi
, psfi
->dwAttributes
, sizeofpsfi
, flags
);
430 /* windows initializes these values regardless of the flags */
433 psfi
->szDisplayName
[0] = '\0';
434 psfi
->szTypeName
[0] = '\0';
438 if (!(flags
& SHGFI_PIDL
))
440 /* SHGetFileInfo should work with absolute and relative paths */
441 if (PathIsRelativeW(path
))
443 GetCurrentDirectoryW(MAX_PATH
, szLocation
);
444 PathCombineW(szFullPath
, szLocation
, path
);
448 lstrcpynW(szFullPath
, path
, MAX_PATH
);
452 if (flags
& SHGFI_EXETYPE
)
454 if (flags
!= SHGFI_EXETYPE
)
456 return shgfi_get_exe_type(szFullPath
);
460 * psfi is NULL normally to query EXE type. If it is NULL, none of the
461 * below makes sense anyway. Windows allows this and just returns FALSE
467 * translate the path into a pidl only when SHGFI_USEFILEATTRIBUTES
469 * The pidl functions fail on not existing file names
472 if (flags
& SHGFI_PIDL
)
474 pidl
= ILClone((LPCITEMIDLIST
)path
);
476 else if (!(flags
& SHGFI_USEFILEATTRIBUTES
))
478 hr
= SHILCreateFromPathW(szFullPath
, &pidl
, &dwAttributes
);
481 if ((flags
& SHGFI_PIDL
) || !(flags
& SHGFI_USEFILEATTRIBUTES
))
483 /* get the parent shellfolder */
486 hr
= SHBindToParent( pidl
, &IID_IShellFolder
, (LPVOID
*)&psfParent
,
487 (LPCITEMIDLIST
*)&pidlLast
);
489 pidlLast
= ILClone(pidlLast
);
494 ERR("pidl is null!\n");
499 /* get the attributes of the child */
500 if (SUCCEEDED(hr
) && (flags
& SHGFI_ATTRIBUTES
))
502 if (!(flags
& SHGFI_ATTR_SPECIFIED
))
504 psfi
->dwAttributes
= 0xffffffff;
507 IShellFolder_GetAttributesOf( psfParent
, 1, (LPCITEMIDLIST
*)&pidlLast
,
508 &(psfi
->dwAttributes
) );
511 /* get the displayname */
512 if (SUCCEEDED(hr
) && (flags
& SHGFI_DISPLAYNAME
))
514 if (flags
& SHGFI_USEFILEATTRIBUTES
&& !(flags
& SHGFI_PIDL
))
516 lstrcpyW (psfi
->szDisplayName
, PathFindFileNameW(szFullPath
));
521 hr
= IShellFolder_GetDisplayNameOf( psfParent
, pidlLast
,
522 SHGDN_INFOLDER
, &str
);
523 StrRetToStrNW (psfi
->szDisplayName
, MAX_PATH
, &str
, pidlLast
);
527 /* get the type name */
528 if (SUCCEEDED(hr
) && (flags
& SHGFI_TYPENAME
))
530 static const WCHAR szFile
[] = { 'F','i','l','e',0 };
531 static const WCHAR szDashFile
[] = { '-','f','i','l','e',0 };
533 if (!(flags
& SHGFI_USEFILEATTRIBUTES
) || (flags
& SHGFI_PIDL
))
537 _ILGetFileType(pidlLast
, ftype
, 80);
538 MultiByteToWideChar(CP_ACP
, 0, ftype
, -1, psfi
->szTypeName
, 80 );
542 if (dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
543 strcatW (psfi
->szTypeName
, szFile
);
548 lstrcpyW(sTemp
,PathFindExtensionW(szFullPath
));
549 if (!( HCR_MapTypeToValueW(sTemp
, sTemp
, 64, TRUE
) &&
550 HCR_MapTypeToValueW(sTemp
, psfi
->szTypeName
, 80, FALSE
)))
552 lstrcpynW (psfi
->szTypeName
, sTemp
, 64);
553 strcatW (psfi
->szTypeName
, szDashFile
);
560 if (flags
& SHGFI_OPENICON
)
561 uGilFlags
|= GIL_OPENICON
;
563 if (flags
& SHGFI_LINKOVERLAY
)
564 uGilFlags
|= GIL_FORSHORTCUT
;
565 else if ((flags
&SHGFI_ADDOVERLAYS
) ||
566 (flags
&(SHGFI_ICON
|SHGFI_SMALLICON
))==SHGFI_ICON
)
568 if (SHELL_IsShortcut(pidlLast
))
569 uGilFlags
|= GIL_FORSHORTCUT
;
572 if (flags
& SHGFI_OVERLAYINDEX
)
573 FIXME("SHGFI_OVERLAYINDEX unhandled\n");
575 if (flags
& SHGFI_SELECTED
)
576 FIXME("set icon to selected, stub\n");
578 if (flags
& SHGFI_SHELLICONSIZE
)
579 FIXME("set icon to shell size, stub\n");
581 /* get the iconlocation */
582 if (SUCCEEDED(hr
) && (flags
& SHGFI_ICONLOCATION
))
586 if (flags
& SHGFI_USEFILEATTRIBUTES
&& !(flags
& SHGFI_PIDL
))
588 if (dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
590 lstrcpyW(psfi
->szDisplayName
, swShell32Name
);
591 psfi
->iIcon
= -IDI_SHELL_FOLDER
;
596 static const WCHAR p1W
[] = {'%','1',0};
597 WCHAR sTemp
[MAX_PATH
];
599 szExt
= PathFindExtensionW(szFullPath
);
600 TRACE("szExt=%s\n", debugstr_w(szExt
));
602 HCR_MapTypeToValueW(szExt
, sTemp
, MAX_PATH
, TRUE
) &&
603 HCR_GetIconW(sTemp
, sTemp
, NULL
, MAX_PATH
, &psfi
->iIcon
))
605 if (lstrcmpW(p1W
, sTemp
))
606 strcpyW(psfi
->szDisplayName
, sTemp
);
609 /* the icon is in the file */
610 strcpyW(psfi
->szDisplayName
, szFullPath
);
619 hr
= IShellFolder_GetUIObjectOf(psfParent
, 0, 1,
620 (LPCITEMIDLIST
*)&pidlLast
, &IID_IExtractIconW
,
621 &uDummy
, (LPVOID
*)&pei
);
624 hr
= IExtractIconW_GetIconLocation(pei
, uGilFlags
,
625 szLocation
, MAX_PATH
, &iIndex
, &uFlags
);
627 if (uFlags
& GIL_NOTFILENAME
)
631 lstrcpyW (psfi
->szDisplayName
, szLocation
);
632 psfi
->iIcon
= iIndex
;
634 IExtractIconW_Release(pei
);
639 /* get icon index (or load icon)*/
640 if (SUCCEEDED(hr
) && (flags
& (SHGFI_ICON
| SHGFI_SYSICONINDEX
)))
642 if (flags
& SHGFI_USEFILEATTRIBUTES
&& !(flags
& SHGFI_PIDL
))
644 WCHAR sTemp
[MAX_PATH
];
648 lstrcpynW(sTemp
, szFullPath
, MAX_PATH
);
650 if (dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
651 psfi
->iIcon
= SIC_GetIconIndex(swShell32Name
, -IDI_SHELL_FOLDER
, 0);
654 static const WCHAR p1W
[] = {'%','1',0};
657 szExt
= PathFindExtensionW(sTemp
);
659 HCR_MapTypeToValueW(szExt
, sTemp
, MAX_PATH
, TRUE
) &&
660 HCR_GetIconW(sTemp
, sTemp
, NULL
, MAX_PATH
, &icon_idx
))
662 if (!lstrcmpW(p1W
,sTemp
)) /* icon is in the file */
663 strcpyW(sTemp
, szFullPath
);
665 if (flags
& SHGFI_SYSICONINDEX
)
667 psfi
->iIcon
= SIC_GetIconIndex(sTemp
,icon_idx
,0);
668 if (psfi
->iIcon
== -1)
674 if (flags
& SHGFI_SMALLICON
)
675 ret
= PrivateExtractIconsW( sTemp
,icon_idx
,
676 GetSystemMetrics( SM_CXSMICON
),
677 GetSystemMetrics( SM_CYSMICON
),
678 &psfi
->hIcon
, 0, 1, 0);
680 ret
= PrivateExtractIconsW( sTemp
, icon_idx
,
681 GetSystemMetrics( SM_CXICON
),
682 GetSystemMetrics( SM_CYICON
),
683 &psfi
->hIcon
, 0, 1, 0);
684 if (ret
!= 0 && ret
!= (UINT
)-1)
686 IconNotYetLoaded
=FALSE
;
687 psfi
->iIcon
= icon_idx
;
695 if (!(PidlToSicIndex(psfParent
, pidlLast
, !(flags
& SHGFI_SMALLICON
),
696 uGilFlags
, &(psfi
->iIcon
))))
701 if (ret
&& (flags
& SHGFI_SYSICONINDEX
))
703 if (flags
& SHGFI_SMALLICON
)
704 ret
= (DWORD_PTR
) ShellSmallIconList
;
706 ret
= (DWORD_PTR
) ShellBigIconList
;
711 if (SUCCEEDED(hr
) && (flags
& SHGFI_ICON
) && IconNotYetLoaded
)
713 if (flags
& SHGFI_SMALLICON
)
714 psfi
->hIcon
= ImageList_GetIcon( ShellSmallIconList
, psfi
->iIcon
, ILD_NORMAL
);
716 psfi
->hIcon
= ImageList_GetIcon( ShellBigIconList
, psfi
->iIcon
, ILD_NORMAL
);
719 if (flags
& ~SHGFI_KNOWN_FLAGS
)
720 FIXME("unknown flags %08x\n", flags
& ~SHGFI_KNOWN_FLAGS
);
727 TRACE ("icon=%p index=0x%08x attr=0x%08x name=%s type=%s ret=0x%08lx\n",
728 psfi
->hIcon
, psfi
->iIcon
, psfi
->dwAttributes
,
729 debugstr_w(psfi
->szDisplayName
), debugstr_w(psfi
->szTypeName
), ret
);
734 /*************************************************************************
735 * SHGetFileInfoA [SHELL32.@]
738 * MSVBVM60.__vbaNew2 expects this function to return a value in range
739 * 1 .. 0x7fff when the function succeeds and flags does not contain
740 * SHGFI_EXETYPE or SHGFI_SYSICONINDEX (see bug 7701)
742 DWORD_PTR WINAPI
SHGetFileInfoA(LPCSTR path
,DWORD dwFileAttributes
,
743 SHFILEINFOA
*psfi
, UINT sizeofpsfi
,
747 LPWSTR temppath
= NULL
;
750 SHFILEINFOW temppsfi
;
752 if (flags
& SHGFI_PIDL
)
754 /* path contains a pidl */
755 pathW
= (LPCWSTR
)path
;
759 len
= MultiByteToWideChar(CP_ACP
, 0, path
, -1, NULL
, 0);
760 temppath
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
761 MultiByteToWideChar(CP_ACP
, 0, path
, -1, temppath
, len
);
765 if (psfi
&& (flags
& SHGFI_ATTR_SPECIFIED
))
766 temppsfi
.dwAttributes
=psfi
->dwAttributes
;
769 ret
= SHGetFileInfoW(pathW
, dwFileAttributes
, NULL
, 0, flags
);
771 ret
= SHGetFileInfoW(pathW
, dwFileAttributes
, &temppsfi
, sizeof(temppsfi
), flags
);
775 if(flags
& SHGFI_ICON
)
776 psfi
->hIcon
=temppsfi
.hIcon
;
777 if(flags
& (SHGFI_SYSICONINDEX
|SHGFI_ICON
|SHGFI_ICONLOCATION
))
778 psfi
->iIcon
=temppsfi
.iIcon
;
779 if(flags
& SHGFI_ATTRIBUTES
)
780 psfi
->dwAttributes
=temppsfi
.dwAttributes
;
781 if(flags
& (SHGFI_DISPLAYNAME
|SHGFI_ICONLOCATION
))
783 WideCharToMultiByte(CP_ACP
, 0, temppsfi
.szDisplayName
, -1,
784 psfi
->szDisplayName
, sizeof(psfi
->szDisplayName
), NULL
, NULL
);
786 if(flags
& SHGFI_TYPENAME
)
788 WideCharToMultiByte(CP_ACP
, 0, temppsfi
.szTypeName
, -1,
789 psfi
->szTypeName
, sizeof(psfi
->szTypeName
), NULL
, NULL
);
793 HeapFree(GetProcessHeap(), 0, temppath
);
798 /*************************************************************************
799 * DuplicateIcon [SHELL32.@]
801 HICON WINAPI
DuplicateIcon( HINSTANCE hInstance
, HICON hIcon
)
806 TRACE("%p %p\n", hInstance
, hIcon
);
808 if (GetIconInfo(hIcon
, &IconInfo
))
810 hDupIcon
= CreateIconIndirect(&IconInfo
);
812 /* clean up hbmMask and hbmColor */
813 DeleteObject(IconInfo
.hbmMask
);
814 DeleteObject(IconInfo
.hbmColor
);
820 /*************************************************************************
821 * ExtractIconA [SHELL32.@]
823 HICON WINAPI
ExtractIconA(HINSTANCE hInstance
, LPCSTR lpszFile
, UINT nIconIndex
)
826 INT len
= MultiByteToWideChar(CP_ACP
, 0, lpszFile
, -1, NULL
, 0);
827 LPWSTR lpwstrFile
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
829 TRACE("%p %s %d\n", hInstance
, lpszFile
, nIconIndex
);
831 MultiByteToWideChar(CP_ACP
, 0, lpszFile
, -1, lpwstrFile
, len
);
832 ret
= ExtractIconW(hInstance
, lpwstrFile
, nIconIndex
);
833 HeapFree(GetProcessHeap(), 0, lpwstrFile
);
838 /*************************************************************************
839 * ExtractIconW [SHELL32.@]
841 HICON WINAPI
ExtractIconW(HINSTANCE hInstance
, LPCWSTR lpszFile
, UINT nIconIndex
)
845 UINT cx
= GetSystemMetrics(SM_CXICON
), cy
= GetSystemMetrics(SM_CYICON
);
847 TRACE("%p %s %d\n", hInstance
, debugstr_w(lpszFile
), nIconIndex
);
849 if (nIconIndex
== (UINT
)-1)
851 ret
= PrivateExtractIconsW(lpszFile
, 0, cx
, cy
, NULL
, NULL
, 0, LR_DEFAULTCOLOR
);
852 if (ret
!= (UINT
)-1 && ret
)
853 return (HICON
)(UINT_PTR
)ret
;
857 ret
= PrivateExtractIconsW(lpszFile
, nIconIndex
, cx
, cy
, &hIcon
, NULL
, 1, LR_DEFAULTCOLOR
);
861 else if (ret
> 0 && hIcon
)
867 /*************************************************************************
868 * Printer_LoadIconsW [SHELL32.205]
870 VOID WINAPI
Printer_LoadIconsW(LPCWSTR wsPrinterName
, HICON
* pLargeIcon
, HICON
* pSmallIcon
)
872 INT iconindex
=IDI_SHELL_PRINTERS_FOLDER
;
874 TRACE("(%s, %p, %p)\n", debugstr_w(wsPrinterName
), pLargeIcon
, pSmallIcon
);
876 /* We should check if wsPrinterName is
877 1. the Default Printer or not
879 3. a Local Printer or a Network-Printer
880 and use different Icons
882 if((wsPrinterName
!= NULL
) && (wsPrinterName
[0] != 0))
884 FIXME("(select Icon by PrinterName %s not implemented)\n", debugstr_w(wsPrinterName
));
887 if(pLargeIcon
!= NULL
)
888 *pLargeIcon
= LoadImageW(shell32_hInstance
,
889 (LPCWSTR
) MAKEINTRESOURCE(iconindex
), IMAGE_ICON
,
890 0, 0, LR_DEFAULTCOLOR
|LR_DEFAULTSIZE
);
892 if(pSmallIcon
!= NULL
)
893 *pSmallIcon
= LoadImageW(shell32_hInstance
,
894 (LPCWSTR
) MAKEINTRESOURCE(iconindex
), IMAGE_ICON
,
895 16, 16, LR_DEFAULTCOLOR
);
898 /*************************************************************************
899 * Printers_RegisterWindowW [SHELL32.213]
900 * used by "printui.dll":
901 * find the Window of the given Type for the specific Printer and
902 * return the already existent hwnd or open a new window
904 BOOL WINAPI
Printers_RegisterWindowW(LPCWSTR wsPrinter
, DWORD dwType
,
905 HANDLE
* phClassPidl
, HWND
* phwnd
)
907 FIXME("(%s, %x, %p (%p), %p (%p)) stub!\n", debugstr_w(wsPrinter
), dwType
,
908 phClassPidl
, (phClassPidl
!= NULL
) ? *(phClassPidl
) : NULL
,
909 phwnd
, (phwnd
!= NULL
) ? *(phwnd
) : NULL
);
914 /*************************************************************************
915 * Printers_UnregisterWindow [SHELL32.214]
917 VOID WINAPI
Printers_UnregisterWindow(HANDLE hClassPidl
, HWND hwnd
)
919 FIXME("(%p, %p) stub!\n", hClassPidl
, hwnd
);
922 /*************************************************************************/
927 LPCWSTR szOtherStuff
;
931 #define DROP_FIELD_TOP (-15)
932 #define DROP_FIELD_HEIGHT 15
934 /*************************************************************************
935 * SHAppBarMessage [SHELL32.@]
937 UINT_PTR WINAPI
SHAppBarMessage(DWORD msg
, PAPPBARDATA data
)
939 int width
=data
->rc
.right
- data
->rc
.left
;
940 int height
=data
->rc
.bottom
- data
->rc
.top
;
943 TRACE("msg=%d, data={cb=%d, hwnd=%p, callback=%x, edge=%d, rc=%s, lparam=%lx}\n",
944 msg
, data
->cbSize
, data
->hWnd
, data
->uCallbackMessage
, data
->uEdge
,
945 wine_dbgstr_rect(&data
->rc
), data
->lParam
);
950 return ABS_ALWAYSONTOP
| ABS_AUTOHIDE
;
952 case ABM_GETTASKBARPOS
:
953 GetWindowRect(data
->hWnd
, &rec
);
958 SetActiveWindow(data
->hWnd
);
961 case ABM_GETAUTOHIDEBAR
:
962 return 0; /* pretend there is no autohide bar */
965 /* cbSize, hWnd, and uCallbackMessage are used. All other ignored */
966 SetWindowPos(data
->hWnd
,HWND_TOP
,0,0,0,0,SWP_SHOWWINDOW
|SWP_NOMOVE
|SWP_NOSIZE
);
970 GetWindowRect(data
->hWnd
, &(data
->rc
));
974 FIXME("ABM_REMOVE broken\n");
975 /* FIXME: this is wrong; should it be DestroyWindow instead? */
976 /*CloseHandle(data->hWnd);*/
979 case ABM_SETAUTOHIDEBAR
:
980 SetWindowPos(data
->hWnd
,HWND_TOP
,rec
.left
+1000,rec
.top
,
981 width
,height
,SWP_SHOWWINDOW
);
985 data
->uEdge
=(ABE_RIGHT
| ABE_LEFT
);
986 SetWindowPos(data
->hWnd
,HWND_TOP
,data
->rc
.left
,data
->rc
.top
,
987 width
,height
,SWP_SHOWWINDOW
);
990 case ABM_WINDOWPOSCHANGED
:
997 /*************************************************************************
998 * SHHelpShortcuts_RunDLLA [SHELL32.@]
1001 DWORD WINAPI
SHHelpShortcuts_RunDLLA(DWORD dwArg1
, DWORD dwArg2
, DWORD dwArg3
, DWORD dwArg4
)
1003 FIXME("(%x, %x, %x, %x) stub!\n", dwArg1
, dwArg2
, dwArg3
, dwArg4
);
1007 /*************************************************************************
1008 * SHHelpShortcuts_RunDLLA [SHELL32.@]
1011 DWORD WINAPI
SHHelpShortcuts_RunDLLW(DWORD dwArg1
, DWORD dwArg2
, DWORD dwArg3
, DWORD dwArg4
)
1013 FIXME("(%x, %x, %x, %x) stub!\n", dwArg1
, dwArg2
, dwArg3
, dwArg4
);
1017 /*************************************************************************
1018 * SHLoadInProc [SHELL32.@]
1019 * Create an instance of specified object class from within
1020 * the shell process and release it immediately
1022 HRESULT WINAPI
SHLoadInProc (REFCLSID rclsid
)
1026 TRACE("%s\n", debugstr_guid(rclsid
));
1028 CoCreateInstance(rclsid
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IUnknown
,&ptr
);
1031 return DISP_E_MEMBERNOTFOUND
;
1034 static VOID
SetRegTextData(HWND hWnd
, HKEY hKey
, LPCWSTR Value
, UINT uID
)
1040 if( RegQueryValueExW(hKey
, Value
, NULL
, &dwType
, NULL
, &dwBufferSize
) == ERROR_SUCCESS
)
1042 if(dwType
== REG_SZ
)
1044 lpBuffer
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, dwBufferSize
);
1048 if( RegQueryValueExW(hKey
, Value
, NULL
, &dwType
, (LPBYTE
)lpBuffer
, &dwBufferSize
) == ERROR_SUCCESS
)
1050 SetDlgItemTextW(hWnd
, uID
, lpBuffer
);
1053 HeapFree(GetProcessHeap(), 0, lpBuffer
);
1059 INT_PTR CALLBACK
AboutAuthorsDlgProc( HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1065 const char* const *pstr
= SHELL_Authors
;
1067 // Add the authors to the list
1068 SendDlgItemMessageW( hWnd
, IDC_ABOUT_AUTHORS_LISTBOX
, WM_SETREDRAW
, FALSE
, 0 );
1074 /* authors list is in utf-8 format */
1075 MultiByteToWideChar( CP_UTF8
, 0, *pstr
, -1, name
, sizeof(name
)/sizeof(WCHAR
) );
1076 SendDlgItemMessageW( hWnd
, IDC_ABOUT_AUTHORS_LISTBOX
, LB_ADDSTRING
, (WPARAM
)-1, (LPARAM
)name
);
1080 SendDlgItemMessageW( hWnd
, IDC_ABOUT_AUTHORS_LISTBOX
, WM_SETREDRAW
, TRUE
, 0 );
1088 /*************************************************************************
1089 * AboutDlgProc (internal)
1091 static INT_PTR CALLBACK
AboutDlgProc( HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1093 static DWORD cxLogoBmp
;
1094 static DWORD cyLogoBmp
;
1095 static HBITMAP hLogoBmp
;
1096 static HWND hWndAuthors
;
1102 ABOUT_INFO
*info
= (ABOUT_INFO
*)lParam
;
1106 const WCHAR szRegKey
[] = L
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion";
1108 MEMORYSTATUSEX MemStat
;
1109 WCHAR szAppTitle
[512];
1110 WCHAR szAppTitleTemplate
[512];
1111 WCHAR szAuthorsText
[20];
1113 // Preload the ROS bitmap
1114 hLogoBmp
= (HBITMAP
)LoadImage(shell32_hInstance
, MAKEINTRESOURCE(IDB_REACTOS
), IMAGE_BITMAP
, 0, 0, LR_DEFAULTCOLOR
);
1120 GetObject( hLogoBmp
, sizeof(BITMAP
), &bmpLogo
);
1122 cxLogoBmp
= bmpLogo
.bmWidth
;
1123 cyLogoBmp
= bmpLogo
.bmHeight
;
1126 // Set App-specific stuff (icon, app name, szOtherStuff string)
1127 SendDlgItemMessageW(hWnd
, IDC_ABOUT_ICON
, STM_SETICON
, (WPARAM
)info
->hIcon
, 0);
1129 GetWindowTextW( hWnd
, szAppTitleTemplate
, sizeof(szAppTitleTemplate
) / sizeof(WCHAR
) );
1130 swprintf( szAppTitle
, szAppTitleTemplate
, info
->szApp
);
1131 SetWindowTextW( hWnd
, szAppTitle
);
1133 SetDlgItemTextW( hWnd
, IDC_ABOUT_APPNAME
, info
->szApp
);
1134 SetDlgItemTextW( hWnd
, IDC_ABOUT_OTHERSTUFF
, info
->szOtherStuff
);
1136 // Set the registered user and organization name
1137 if(RegOpenKeyExW( HKEY_LOCAL_MACHINE
, szRegKey
, 0, KEY_QUERY_VALUE
, &hRegKey
) == ERROR_SUCCESS
)
1139 SetRegTextData( hWnd
, hRegKey
, L
"RegisteredOwner", IDC_ABOUT_REG_USERNAME
);
1140 SetRegTextData( hWnd
, hRegKey
, L
"RegisteredOrganization", IDC_ABOUT_REG_ORGNAME
);
1142 RegCloseKey( hRegKey
);
1145 // Set the value for the installed physical memory
1146 MemStat
.dwLength
= sizeof(MemStat
);
1147 if( GlobalMemoryStatusEx(&MemStat
) )
1151 if (MemStat
.ullTotalPhys
> 1024 * 1024 * 1024)
1154 WCHAR szDecimalSeparator
[4];
1157 // We're dealing with GBs or more
1158 MemStat
.ullTotalPhys
/= 1024 * 1024;
1160 if (MemStat
.ullTotalPhys
> 1024 * 1024)
1162 // We're dealing with TBs or more
1163 MemStat
.ullTotalPhys
/= 1024;
1165 if (MemStat
.ullTotalPhys
> 1024 * 1024)
1167 // We're dealing with PBs or more
1168 MemStat
.ullTotalPhys
/= 1024;
1170 dTotalPhys
= (double)MemStat
.ullTotalPhys
/ 1024;
1171 wcscpy( szUnits
, L
"PB" );
1175 dTotalPhys
= (double)MemStat
.ullTotalPhys
/ 1024;
1176 wcscpy( szUnits
, L
"TB" );
1181 dTotalPhys
= (double)MemStat
.ullTotalPhys
/ 1024;
1182 wcscpy( szUnits
, L
"GB" );
1185 // We need the decimal point of the current locale to display the RAM size correctly
1186 if (GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SDECIMAL
,
1188 sizeof(szDecimalSeparator
) / sizeof(WCHAR
)) > 0)
1193 uIntegral
= (UINT
)dTotalPhys
;
1194 uDecimals
= (UCHAR
)((UINT
)(dTotalPhys
* 100) - uIntegral
* 100);
1196 // Display the RAM size with 2 decimals
1197 swprintf(szBuf
, L
"%u%s%02u %s", uIntegral
, szDecimalSeparator
, uDecimals
, szUnits
);
1202 // We're dealing with MBs, don't show any decimals
1203 swprintf( szBuf
, L
"%u MB", (UINT
)MemStat
.ullTotalPhys
/ 1024 / 1024 );
1206 SetDlgItemTextW( hWnd
, IDC_ABOUT_PHYSMEM
, szBuf
);
1209 // Add the Authors dialog
1210 hWndAuthors
= CreateDialogW( shell32_hInstance
, MAKEINTRESOURCEW(IDD_ABOUT_AUTHORS
), hWnd
, AboutAuthorsDlgProc
);
1211 LoadStringW( shell32_hInstance
, IDS_SHELL_ABOUT_AUTHORS
, szAuthorsText
, sizeof(szAuthorsText
) / sizeof(WCHAR
) );
1212 SetDlgItemTextW( hWnd
, IDC_ABOUT_AUTHORS
, szAuthorsText
);
1226 hdc
= BeginPaint(hWnd
, &ps
);
1227 hdcMem
= CreateCompatibleDC(hdc
);
1231 SelectObject(hdcMem
, hLogoBmp
);
1232 BitBlt(hdc
, 0, 0, cxLogoBmp
, cyLogoBmp
, hdcMem
, 0, 0, SRCCOPY
);
1237 EndPaint(hWnd
, &ps
);
1247 EndDialog(hWnd
, TRUE
);
1250 case IDC_ABOUT_AUTHORS
:
1252 static BOOL bShowingAuthors
= FALSE
;
1253 WCHAR szAuthorsText
[20];
1257 LoadStringW( shell32_hInstance
, IDS_SHELL_ABOUT_AUTHORS
, szAuthorsText
, sizeof(szAuthorsText
) / sizeof(WCHAR
) );
1258 ShowWindow( hWndAuthors
, SW_HIDE
);
1262 LoadStringW( shell32_hInstance
, IDS_SHELL_ABOUT_BACK
, szAuthorsText
, sizeof(szAuthorsText
) / sizeof(WCHAR
) );
1263 ShowWindow( hWndAuthors
, SW_SHOW
);
1266 SetDlgItemTextW( hWnd
, IDC_ABOUT_AUTHORS
, szAuthorsText
);
1267 bShowingAuthors
= !bShowingAuthors
;
1274 EndDialog(hWnd
, TRUE
);
1282 /*************************************************************************
1283 * ShellAboutA [SHELL32.288]
1285 BOOL WINAPI
ShellAboutA( HWND hWnd
, LPCSTR szApp
, LPCSTR szOtherStuff
, HICON hIcon
)
1288 LPWSTR appW
= NULL
, otherW
= NULL
;
1293 len
= MultiByteToWideChar(CP_ACP
, 0, szApp
, -1, NULL
, 0);
1294 appW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1295 MultiByteToWideChar(CP_ACP
, 0, szApp
, -1, appW
, len
);
1299 len
= MultiByteToWideChar(CP_ACP
, 0, szOtherStuff
, -1, NULL
, 0);
1300 otherW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1301 MultiByteToWideChar(CP_ACP
, 0, szOtherStuff
, -1, otherW
, len
);
1304 ret
= ShellAboutW(hWnd
, appW
, otherW
, hIcon
);
1306 HeapFree(GetProcessHeap(), 0, otherW
);
1307 HeapFree(GetProcessHeap(), 0, appW
);
1312 /*************************************************************************
1313 * ShellAboutW [SHELL32.289]
1315 BOOL WINAPI
ShellAboutW( HWND hWnd
, LPCWSTR szApp
, LPCWSTR szOtherStuff
,
1320 DLGTEMPLATE
*DlgTemplate
;
1325 // DialogBoxIndirectParamW will be called with the hInstance of the calling application, so we have to preload the dialog template
1326 hRes
= FindResourceW(shell32_hInstance
, MAKEINTRESOURCEW(IDD_ABOUT
), (LPWSTR
)RT_DIALOG
);
1330 DlgTemplate
= (DLGTEMPLATE
*)LoadResource(shell32_hInstance
, hRes
);
1335 info
.szOtherStuff
= szOtherStuff
;
1336 info
.hIcon
= hIcon
? hIcon
: LoadIconW( 0, (LPWSTR
)IDI_WINLOGO
);
1338 bRet
= DialogBoxIndirectParamW((HINSTANCE
)GetWindowLongPtrW( hWnd
, GWLP_HINSTANCE
),
1339 DlgTemplate
, hWnd
, AboutDlgProc
, (LPARAM
)&info
);
1343 /*************************************************************************
1344 * FreeIconList (SHELL32.@)
1346 void WINAPI
FreeIconList( DWORD dw
)
1348 FIXME("%x: stub\n",dw
);
1351 /*************************************************************************
1352 * SHLoadNonloadedIconOverlayIdentifiers (SHELL32.@)
1354 HRESULT WINAPI
SHLoadNonloadedIconOverlayIdentifiers( VOID
)