shell32: Fix folder icon index when read from registry.
[wine/multimedia.git] / dlls / shell32 / shell32_main.c
blob8febaaaad0cc75b0da257253a891e8b44f7bb300
1 /*
2 * Shell basics
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "config.h"
24 #include <stdlib.h>
25 #include <string.h>
26 #include <stdarg.h>
27 #include <stdio.h>
29 #define COBJMACROS
31 #include "windef.h"
32 #include "winbase.h"
33 #include "winerror.h"
34 #include "winreg.h"
35 #include "dlgs.h"
36 #include "shellapi.h"
37 #include "winuser.h"
38 #include "wingdi.h"
39 #include "shlobj.h"
40 #include "shlguid.h"
41 #include "shlwapi.h"
43 #include "undocshell.h"
44 #include "pidl.h"
45 #include "shell32_main.h"
46 #include "version.h"
47 #include "shresdef.h"
49 #include "wine/debug.h"
50 #include "wine/unicode.h"
52 WINE_DEFAULT_DEBUG_CHANNEL(shell);
54 extern const char * const SHELL_Authors[];
56 #define MORE_DEBUG 1
57 /*************************************************************************
58 * CommandLineToArgvW [SHELL32.@]
60 * We must interpret the quotes in the command line to rebuild the argv
61 * array correctly:
62 * - arguments are separated by spaces or tabs
63 * - quotes serve as optional argument delimiters
64 * '"a b"' -> 'a b'
65 * - escaped quotes must be converted back to '"'
66 * '\"' -> '"'
67 * - an odd number of '\'s followed by '"' correspond to half that number
68 * of '\' followed by a '"' (extension of the above)
69 * '\\\"' -> '\"'
70 * '\\\\\"' -> '\\"'
71 * - an even number of '\'s followed by a '"' correspond to half that number
72 * of '\', plus a regular quote serving as an argument delimiter (which
73 * means it does not appear in the result)
74 * 'a\\"b c"' -> 'a\b c'
75 * 'a\\\\"b c"' -> 'a\\b c'
76 * - '\' that are not followed by a '"' are copied literally
77 * 'a\b' -> 'a\b'
78 * 'a\\b' -> 'a\\b'
80 * Note:
81 * '\t' == 0x0009
82 * ' ' == 0x0020
83 * '"' == 0x0022
84 * '\\' == 0x005c
86 LPWSTR* WINAPI CommandLineToArgvW(LPCWSTR lpCmdline, int* numargs)
88 DWORD argc;
89 HGLOBAL hargv;
90 LPWSTR *argv;
91 LPCWSTR cs;
92 LPWSTR arg,s,d;
93 LPWSTR cmdline;
94 int in_quotes,bcount;
96 if (*lpCmdline==0)
98 /* Return the path to the executable */
99 DWORD len, size=16;
101 hargv=GlobalAlloc(size, 0);
102 argv=GlobalLock(hargv);
103 for (;;)
105 len = GetModuleFileNameW(0, (LPWSTR)(argv+1), size-sizeof(LPWSTR));
106 if (!len)
108 GlobalFree(hargv);
109 return NULL;
111 if (len < size) break;
112 size*=2;
113 hargv=GlobalReAlloc(hargv, size, 0);
114 argv=GlobalLock(hargv);
116 argv[0]=(LPWSTR)(argv+1);
117 if (numargs)
118 *numargs=2;
120 return argv;
123 /* to get a writeable copy */
124 argc=0;
125 bcount=0;
126 in_quotes=0;
127 cs=lpCmdline;
128 while (1)
130 if (*cs==0 || ((*cs==0x0009 || *cs==0x0020) && !in_quotes))
132 /* space */
133 argc++;
134 /* skip the remaining spaces */
135 while (*cs==0x0009 || *cs==0x0020) {
136 cs++;
138 if (*cs==0)
139 break;
140 bcount=0;
141 continue;
143 else if (*cs==0x005c)
145 /* '\', count them */
146 bcount++;
148 else if ((*cs==0x0022) && ((bcount & 1)==0))
150 /* unescaped '"' */
151 in_quotes=!in_quotes;
152 bcount=0;
154 else
156 /* a regular character */
157 bcount=0;
159 cs++;
161 /* Allocate in a single lump, the string array, and the strings that go with it.
162 * This way the caller can make a single GlobalFree call to free both, as per MSDN.
164 hargv=GlobalAlloc(0, argc*sizeof(LPWSTR)+(strlenW(lpCmdline)+1)*sizeof(WCHAR));
165 argv=GlobalLock(hargv);
166 if (!argv)
167 return NULL;
168 cmdline=(LPWSTR)(argv+argc);
169 strcpyW(cmdline, lpCmdline);
171 argc=0;
172 bcount=0;
173 in_quotes=0;
174 arg=d=s=cmdline;
175 while (*s)
177 if ((*s==0x0009 || *s==0x0020) && !in_quotes)
179 /* Close the argument and copy it */
180 *d=0;
181 argv[argc++]=arg;
183 /* skip the remaining spaces */
184 do {
185 s++;
186 } while (*s==0x0009 || *s==0x0020);
188 /* Start with a new argument */
189 arg=d=s;
190 bcount=0;
192 else if (*s==0x005c)
194 /* '\\' */
195 *d++=*s++;
196 bcount++;
198 else if (*s==0x0022)
200 /* '"' */
201 if ((bcount & 1)==0)
203 /* Preceded by an even number of '\', this is half that
204 * number of '\', plus a quote which we erase.
206 d-=bcount/2;
207 in_quotes=!in_quotes;
208 s++;
210 else
212 /* Preceded by an odd number of '\', this is half that
213 * number of '\' followed by a '"'
215 d=d-bcount/2-1;
216 *d++='"';
217 s++;
219 bcount=0;
221 else
223 /* a regular character */
224 *d++=*s++;
225 bcount=0;
228 if (*arg)
230 *d='\0';
231 argv[argc++]=arg;
233 if (numargs)
234 *numargs=argc;
236 return argv;
239 static DWORD shgfi_get_exe_type(LPCWSTR szFullPath)
241 BOOL status = FALSE;
242 HANDLE hfile;
243 DWORD BinaryType;
244 IMAGE_DOS_HEADER mz_header;
245 IMAGE_NT_HEADERS nt;
246 DWORD len;
247 char magic[4];
249 status = GetBinaryTypeW (szFullPath, &BinaryType);
250 if (!status)
251 return 0;
252 if (BinaryType == SCS_DOS_BINARY || BinaryType == SCS_PIF_BINARY)
253 return 0x4d5a;
255 hfile = CreateFileW( szFullPath, GENERIC_READ, FILE_SHARE_READ,
256 NULL, OPEN_EXISTING, 0, 0 );
257 if ( hfile == INVALID_HANDLE_VALUE )
258 return 0;
261 * The next section is adapted from MODULE_GetBinaryType, as we need
262 * to examine the image header to get OS and version information. We
263 * know from calling GetBinaryTypeA that the image is valid and either
264 * an NE or PE, so much error handling can be omitted.
265 * Seek to the start of the file and read the header information.
268 SetFilePointer( hfile, 0, NULL, SEEK_SET );
269 ReadFile( hfile, &mz_header, sizeof(mz_header), &len, NULL );
271 SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
272 ReadFile( hfile, magic, sizeof(magic), &len, NULL );
273 if ( *(DWORD*)magic == IMAGE_NT_SIGNATURE )
275 SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
276 ReadFile( hfile, &nt, sizeof(nt), &len, NULL );
277 CloseHandle( hfile );
278 if (nt.OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_GUI)
280 return IMAGE_NT_SIGNATURE |
281 (nt.OptionalHeader.MajorSubsystemVersion << 24) |
282 (nt.OptionalHeader.MinorSubsystemVersion << 16);
284 return IMAGE_NT_SIGNATURE;
286 else if ( *(WORD*)magic == IMAGE_OS2_SIGNATURE )
288 IMAGE_OS2_HEADER ne;
289 SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
290 ReadFile( hfile, &ne, sizeof(ne), &len, NULL );
291 CloseHandle( hfile );
292 if (ne.ne_exetyp == 2)
293 return IMAGE_OS2_SIGNATURE | (ne.ne_expver << 16);
294 return 0;
296 CloseHandle( hfile );
297 return 0;
300 /*************************************************************************
301 * SHELL_IsShortcut [internal]
303 * Decide if an item id list points to a shell shortcut
305 BOOL SHELL_IsShortcut(LPCITEMIDLIST pidlLast)
307 char szTemp[MAX_PATH];
308 HKEY keyCls;
309 BOOL ret = FALSE;
311 if (_ILGetExtension(pidlLast, szTemp, MAX_PATH) &&
312 HCR_MapTypeToValueA(szTemp, szTemp, MAX_PATH, TRUE))
314 if (ERROR_SUCCESS == RegOpenKeyExA(HKEY_CLASSES_ROOT, szTemp, 0, KEY_QUERY_VALUE, &keyCls))
316 if (ERROR_SUCCESS == RegQueryValueExA(keyCls, "IsShortcut", NULL, NULL, NULL, NULL))
317 ret = TRUE;
319 RegCloseKey(keyCls);
323 return ret;
326 #define SHGFI_KNOWN_FLAGS \
327 (SHGFI_SMALLICON | SHGFI_OPENICON | SHGFI_SHELLICONSIZE | SHGFI_PIDL | \
328 SHGFI_USEFILEATTRIBUTES | SHGFI_ADDOVERLAYS | SHGFI_OVERLAYINDEX | \
329 SHGFI_ICON | SHGFI_DISPLAYNAME | SHGFI_TYPENAME | SHGFI_ATTRIBUTES | \
330 SHGFI_ICONLOCATION | SHGFI_EXETYPE | SHGFI_SYSICONINDEX | \
331 SHGFI_LINKOVERLAY | SHGFI_SELECTED | SHGFI_ATTR_SPECIFIED)
333 /*************************************************************************
334 * SHGetFileInfoW [SHELL32.@]
337 DWORD_PTR WINAPI SHGetFileInfoW(LPCWSTR path,DWORD dwFileAttributes,
338 SHFILEINFOW *psfi, UINT sizeofpsfi, UINT flags )
340 WCHAR szLocation[MAX_PATH], szFullPath[MAX_PATH];
341 int iIndex;
342 DWORD_PTR ret = TRUE;
343 DWORD dwAttributes = 0;
344 IShellFolder * psfParent = NULL;
345 IExtractIconW * pei = NULL;
346 LPITEMIDLIST pidlLast = NULL, pidl = NULL;
347 HRESULT hr = S_OK;
348 BOOL IconNotYetLoaded=TRUE;
349 UINT uGilFlags = 0;
351 TRACE("%s fattr=0x%lx sfi=%p(attr=0x%08lx) size=0x%x flags=0x%x\n",
352 (flags & SHGFI_PIDL)? "pidl" : debugstr_w(path), dwFileAttributes,
353 psfi, psfi->dwAttributes, sizeofpsfi, flags);
355 if ( (flags & SHGFI_USEFILEATTRIBUTES) &&
356 (flags & (SHGFI_ATTRIBUTES|SHGFI_EXETYPE|SHGFI_PIDL)))
357 return FALSE;
359 /* windows initializes this values regardless of the flags */
360 if (psfi != NULL)
362 psfi->szDisplayName[0] = '\0';
363 psfi->szTypeName[0] = '\0';
364 psfi->iIcon = 0;
367 if (!(flags & SHGFI_PIDL))
369 /* SHGetFileInfo should work with absolute and relative paths */
370 if (PathIsRelativeW(path))
372 GetCurrentDirectoryW(MAX_PATH, szLocation);
373 PathCombineW(szFullPath, szLocation, path);
375 else
377 lstrcpynW(szFullPath, path, MAX_PATH);
381 if (flags & SHGFI_EXETYPE)
383 if (flags != SHGFI_EXETYPE)
384 return 0;
385 return shgfi_get_exe_type(szFullPath);
389 * psfi is NULL normally to query EXE type. If it is NULL, none of the
390 * below makes sense anyway. Windows allows this and just returns FALSE
392 if (psfi == NULL)
393 return FALSE;
396 * translate the path into a pidl only when SHGFI_USEFILEATTRIBUTES
397 * is not specified.
398 * The pidl functions fail on not existing file names
401 if (flags & SHGFI_PIDL)
403 pidl = ILClone((LPCITEMIDLIST)path);
405 else if (!(flags & SHGFI_USEFILEATTRIBUTES))
407 hr = SHILCreateFromPathW(szFullPath, &pidl, &dwAttributes);
410 if ((flags & SHGFI_PIDL) || !(flags & SHGFI_USEFILEATTRIBUTES))
412 /* get the parent shellfolder */
413 if (pidl)
415 hr = SHBindToParent( pidl, &IID_IShellFolder, (LPVOID*)&psfParent,
416 (LPCITEMIDLIST*)&pidlLast );
417 if (SUCCEEDED(hr))
418 pidlLast = ILClone(pidlLast);
419 ILFree(pidl);
421 else
423 ERR("pidl is null!\n");
424 return FALSE;
428 /* get the attributes of the child */
429 if (SUCCEEDED(hr) && (flags & SHGFI_ATTRIBUTES))
431 if (!(flags & SHGFI_ATTR_SPECIFIED))
433 psfi->dwAttributes = 0xffffffff;
435 IShellFolder_GetAttributesOf( psfParent, 1, (LPCITEMIDLIST*)&pidlLast,
436 &(psfi->dwAttributes) );
439 /* get the displayname */
440 if (SUCCEEDED(hr) && (flags & SHGFI_DISPLAYNAME))
442 if (flags & SHGFI_USEFILEATTRIBUTES)
444 lstrcpyW (psfi->szDisplayName, PathFindFileNameW(szFullPath));
446 else
448 STRRET str;
449 hr = IShellFolder_GetDisplayNameOf( psfParent, pidlLast,
450 SHGDN_INFOLDER, &str);
451 StrRetToStrNW (psfi->szDisplayName, MAX_PATH, &str, pidlLast);
455 /* get the type name */
456 if (SUCCEEDED(hr) && (flags & SHGFI_TYPENAME))
458 static const WCHAR szFile[] = { 'F','i','l','e',0 };
459 static const WCHAR szDashFile[] = { '-','f','i','l','e',0 };
461 if (!(flags & SHGFI_USEFILEATTRIBUTES))
463 char ftype[80];
465 _ILGetFileType(pidlLast, ftype, 80);
466 MultiByteToWideChar(CP_ACP, 0, ftype, -1, psfi->szTypeName, 80 );
468 else
470 if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
471 strcatW (psfi->szTypeName, szFile);
472 else
474 WCHAR sTemp[64];
476 lstrcpyW(sTemp,PathFindExtensionW(szFullPath));
477 if (!( HCR_MapTypeToValueW(sTemp, sTemp, 64, TRUE) &&
478 HCR_MapTypeToValueW(sTemp, psfi->szTypeName, 80, FALSE )))
480 lstrcpynW (psfi->szTypeName, sTemp, 64);
481 strcatW (psfi->szTypeName, szDashFile);
487 /* ### icons ###*/
488 if (flags & SHGFI_OPENICON)
489 uGilFlags |= GIL_OPENICON;
491 if (flags & SHGFI_LINKOVERLAY)
492 uGilFlags |= GIL_FORSHORTCUT;
493 else if ((flags&SHGFI_ADDOVERLAYS) ||
494 (flags&(SHGFI_ICON|SHGFI_SMALLICON))==SHGFI_ICON)
496 if (SHELL_IsShortcut(pidlLast))
497 uGilFlags |= GIL_FORSHORTCUT;
500 if (flags & SHGFI_OVERLAYINDEX)
501 FIXME("SHGFI_OVERLAYINDEX unhandled\n");
503 if (flags & SHGFI_SELECTED)
504 FIXME("set icon to selected, stub\n");
506 if (flags & SHGFI_SHELLICONSIZE)
507 FIXME("set icon to shell size, stub\n");
509 /* get the iconlocation */
510 if (SUCCEEDED(hr) && (flags & SHGFI_ICONLOCATION ))
512 UINT uDummy,uFlags;
514 hr = IShellFolder_GetUIObjectOf(psfParent, 0, 1,
515 (LPCITEMIDLIST*)&pidlLast, &IID_IExtractIconA,
516 &uDummy, (LPVOID*)&pei);
517 if (SUCCEEDED(hr))
519 hr = IExtractIconW_GetIconLocation(pei, uGilFlags,
520 szLocation, MAX_PATH, &iIndex, &uFlags);
521 psfi->iIcon = iIndex;
523 if (!(uFlags & GIL_NOTFILENAME))
524 lstrcpyW (psfi->szDisplayName, szLocation);
525 else
526 ret = FALSE;
528 IExtractIconA_Release(pei);
532 /* get icon index (or load icon)*/
533 if (SUCCEEDED(hr) && (flags & (SHGFI_ICON | SHGFI_SYSICONINDEX)))
535 if (flags & SHGFI_USEFILEATTRIBUTES)
537 WCHAR sTemp [MAX_PATH];
538 WCHAR * szExt;
539 int icon_idx=0;
541 lstrcpynW(sTemp, szFullPath, MAX_PATH);
543 if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
544 psfi->iIcon = SIC_GetIconIndex(swShell32Name, -IDI_SHELL_FOLDER, 0);
545 else
547 static const WCHAR p1W[] = {'%','1',0};
549 psfi->iIcon = 0;
550 szExt = (LPWSTR) PathFindExtensionW(sTemp);
551 if ( szExt &&
552 HCR_MapTypeToValueW(szExt, sTemp, MAX_PATH, TRUE) &&
553 HCR_GetDefaultIconW(sTemp, sTemp, MAX_PATH, &icon_idx))
555 if (!lstrcmpW(p1W,sTemp)) /* icon is in the file */
556 strcpyW(sTemp, szFullPath);
558 if (flags & SHGFI_SYSICONINDEX)
560 psfi->iIcon = SIC_GetIconIndex(sTemp,icon_idx,0);
561 if (psfi->iIcon == -1)
562 psfi->iIcon = 0;
564 else
566 IconNotYetLoaded=FALSE;
567 if (flags & SHGFI_SMALLICON)
568 PrivateExtractIconsW( sTemp,icon_idx,
569 GetSystemMetrics( SM_CXSMICON ),
570 GetSystemMetrics( SM_CYSMICON ),
571 &psfi->hIcon, 0, 1, 0);
572 else
573 PrivateExtractIconsW( sTemp, icon_idx,
574 GetSystemMetrics( SM_CXICON),
575 GetSystemMetrics( SM_CYICON),
576 &psfi->hIcon, 0, 1, 0);
577 psfi->iIcon = icon_idx;
582 else
584 if (!(PidlToSicIndex(psfParent, pidlLast, !(flags & SHGFI_SMALLICON),
585 uGilFlags, &(psfi->iIcon))))
587 ret = FALSE;
590 if (ret)
592 if (flags & SHGFI_SMALLICON)
593 ret = (DWORD_PTR) ShellSmallIconList;
594 else
595 ret = (DWORD_PTR) ShellBigIconList;
599 /* icon handle */
600 if (SUCCEEDED(hr) && (flags & SHGFI_ICON) && IconNotYetLoaded)
602 if (flags & SHGFI_SMALLICON)
603 psfi->hIcon = ImageList_GetIcon( ShellSmallIconList, psfi->iIcon, ILD_NORMAL);
604 else
605 psfi->hIcon = ImageList_GetIcon( ShellBigIconList, psfi->iIcon, ILD_NORMAL);
608 if (flags & ~SHGFI_KNOWN_FLAGS)
609 FIXME("unknown flags %08x\n", flags & ~SHGFI_KNOWN_FLAGS);
611 if (psfParent)
612 IShellFolder_Release(psfParent);
614 if (hr != S_OK)
615 ret = FALSE;
617 if (pidlLast)
618 SHFree(pidlLast);
620 #ifdef MORE_DEBUG
621 TRACE ("icon=%p index=0x%08x attr=0x%08lx name=%s type=%s ret=0x%08lx\n",
622 psfi->hIcon, psfi->iIcon, psfi->dwAttributes,
623 debugstr_w(psfi->szDisplayName), debugstr_w(psfi->szTypeName), ret);
624 #endif
626 return ret;
629 /*************************************************************************
630 * SHGetFileInfoA [SHELL32.@]
632 DWORD_PTR WINAPI SHGetFileInfoA(LPCSTR path,DWORD dwFileAttributes,
633 SHFILEINFOA *psfi, UINT sizeofpsfi,
634 UINT flags )
636 INT len;
637 LPWSTR temppath;
638 DWORD ret;
639 SHFILEINFOW temppsfi;
641 if (flags & SHGFI_PIDL)
643 /* path contains a pidl */
644 temppath = (LPWSTR) path;
646 else
648 len = MultiByteToWideChar(CP_ACP, 0, path, -1, NULL, 0);
649 temppath = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
650 MultiByteToWideChar(CP_ACP, 0, path, -1, temppath, len);
653 if (psfi && (flags & SHGFI_ATTR_SPECIFIED))
654 temppsfi.dwAttributes=psfi->dwAttributes;
656 if (psfi == NULL)
657 ret = SHGetFileInfoW(temppath, dwFileAttributes, NULL, sizeof(temppsfi), flags);
658 else
659 ret = SHGetFileInfoW(temppath, dwFileAttributes, &temppsfi, sizeof(temppsfi), flags);
661 if (psfi)
663 if(flags & SHGFI_ICON)
664 psfi->hIcon=temppsfi.hIcon;
665 if(flags & (SHGFI_SYSICONINDEX|SHGFI_ICON|SHGFI_ICONLOCATION))
666 psfi->iIcon=temppsfi.iIcon;
667 if(flags & SHGFI_ATTRIBUTES)
668 psfi->dwAttributes=temppsfi.dwAttributes;
669 if(flags & (SHGFI_DISPLAYNAME|SHGFI_ICONLOCATION))
671 WideCharToMultiByte(CP_ACP, 0, temppsfi.szDisplayName, -1,
672 psfi->szDisplayName, sizeof(psfi->szDisplayName), NULL, NULL);
674 if(flags & SHGFI_TYPENAME)
676 WideCharToMultiByte(CP_ACP, 0, temppsfi.szTypeName, -1,
677 psfi->szTypeName, sizeof(psfi->szTypeName), NULL, NULL);
681 if (!(flags & SHGFI_PIDL))
682 HeapFree(GetProcessHeap(), 0, temppath);
684 return ret;
687 /*************************************************************************
688 * DuplicateIcon [SHELL32.@]
690 HICON WINAPI DuplicateIcon( HINSTANCE hInstance, HICON hIcon)
692 ICONINFO IconInfo;
693 HICON hDupIcon = 0;
695 TRACE("%p %p\n", hInstance, hIcon);
697 if (GetIconInfo(hIcon, &IconInfo))
699 hDupIcon = CreateIconIndirect(&IconInfo);
701 /* clean up hbmMask and hbmColor */
702 DeleteObject(IconInfo.hbmMask);
703 DeleteObject(IconInfo.hbmColor);
706 return hDupIcon;
709 /*************************************************************************
710 * ExtractIconA [SHELL32.@]
712 HICON WINAPI ExtractIconA(HINSTANCE hInstance, LPCSTR lpszFile, UINT nIconIndex)
714 HICON ret;
715 INT len = MultiByteToWideChar(CP_ACP, 0, lpszFile, -1, NULL, 0);
716 LPWSTR lpwstrFile = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
718 TRACE("%p %s %d\n", hInstance, lpszFile, nIconIndex);
720 MultiByteToWideChar(CP_ACP, 0, lpszFile, -1, lpwstrFile, len);
721 ret = ExtractIconW(hInstance, lpwstrFile, nIconIndex);
722 HeapFree(GetProcessHeap(), 0, lpwstrFile);
724 return ret;
727 /*************************************************************************
728 * ExtractIconW [SHELL32.@]
730 HICON WINAPI ExtractIconW(HINSTANCE hInstance, LPCWSTR lpszFile, UINT nIconIndex)
732 HICON hIcon = NULL;
733 UINT ret;
734 UINT cx = GetSystemMetrics(SM_CXICON), cy = GetSystemMetrics(SM_CYICON);
736 TRACE("%p %s %d\n", hInstance, debugstr_w(lpszFile), nIconIndex);
738 if (nIconIndex == 0xFFFFFFFF)
740 ret = PrivateExtractIconsW(lpszFile, 0, cx, cy, NULL, NULL, 0, LR_DEFAULTCOLOR);
741 if (ret != 0xFFFFFFFF && ret)
742 return (HICON)(UINT_PTR)ret;
743 return NULL;
745 else
746 ret = PrivateExtractIconsW(lpszFile, nIconIndex, cx, cy, &hIcon, NULL, 1, LR_DEFAULTCOLOR);
748 if (ret == 0xFFFFFFFF)
749 return (HICON)1;
750 else if (ret > 0 && hIcon)
751 return hIcon;
753 return NULL;
756 /*************************************************************************
757 * Printer_LoadIconsW [SHELL32.205]
759 VOID WINAPI Printer_LoadIconsW(LPCWSTR wsPrinterName, HICON * pLargeIcon, HICON * pSmallIcon)
761 INT iconindex=IDI_SHELL_PRINTER;
763 TRACE("(%s, %p, %p)\n", debugstr_w(wsPrinterName), pLargeIcon, pSmallIcon);
765 /* We should check if wsPrinterName is
766 1. the Default Printer or not
767 2. connected or not
768 3. a Local Printer or a Network-Printer
769 and use different Icons
771 if((wsPrinterName != NULL) && (wsPrinterName[0] != 0))
773 FIXME("(select Icon by PrinterName %s not implemented)\n", debugstr_w(wsPrinterName));
776 if(pLargeIcon != NULL)
777 *pLargeIcon = LoadImageW(shell32_hInstance,
778 (LPCWSTR) MAKEINTRESOURCE(iconindex), IMAGE_ICON,
779 0, 0, LR_DEFAULTCOLOR|LR_DEFAULTSIZE);
781 if(pSmallIcon != NULL)
782 *pSmallIcon = LoadImageW(shell32_hInstance,
783 (LPCWSTR) MAKEINTRESOURCE(iconindex), IMAGE_ICON,
784 16, 16, LR_DEFAULTCOLOR);
787 /*************************************************************************
788 * Printers_RegisterWindowW [SHELL32.213]
789 * used by "printui.dll":
790 * find the Window of the given Type for the specific Printer and
791 * return the already existent hwnd or open a new window
793 BOOL WINAPI Printers_RegisterWindowW(LPCWSTR wsPrinter, DWORD dwType,
794 HANDLE * phClassPidl, HWND * phwnd)
796 FIXME("(%s, %lx, %p (%p), %p (%p)) stub!\n", debugstr_w(wsPrinter), dwType,
797 phClassPidl, (phClassPidl != NULL) ? *(phClassPidl) : NULL,
798 phwnd, (phwnd != NULL) ? *(phwnd) : NULL);
800 return FALSE;
803 /*************************************************************************
804 * Printers_UnregisterWindow [SHELL32.214]
806 VOID WINAPI Printers_UnregisterWindow(HANDLE hClassPidl, HWND hwnd)
808 FIXME("(%p, %p) stub!\n", hClassPidl, hwnd);
811 /*************************************************************************/
813 typedef struct
815 LPCWSTR szApp;
816 LPCWSTR szOtherStuff;
817 HICON hIcon;
818 HFONT hFont;
819 } ABOUT_INFO;
821 #define IDC_STATIC_TEXT1 100
822 #define IDC_STATIC_TEXT2 101
823 #define IDC_LISTBOX 99
824 #define IDC_WINE_TEXT 98
826 #define DROP_FIELD_TOP (-15)
827 #define DROP_FIELD_HEIGHT 15
829 static BOOL __get_dropline( HWND hWnd, LPRECT lprect )
831 HWND hWndCtl = GetDlgItem(hWnd, IDC_WINE_TEXT);
833 if( hWndCtl )
835 GetWindowRect( hWndCtl, lprect );
836 MapWindowPoints( 0, hWnd, (LPPOINT)lprect, 2 );
837 lprect->bottom = (lprect->top += DROP_FIELD_TOP);
838 return TRUE;
840 return FALSE;
843 /*************************************************************************
844 * SHAppBarMessage [SHELL32.@]
846 UINT WINAPI SHAppBarMessage(DWORD msg, PAPPBARDATA data)
848 int width=data->rc.right - data->rc.left;
849 int height=data->rc.bottom - data->rc.top;
850 RECT rec=data->rc;
852 switch (msg)
854 case ABM_GETSTATE:
855 return ABS_ALWAYSONTOP | ABS_AUTOHIDE;
856 case ABM_GETTASKBARPOS:
857 GetWindowRect(data->hWnd, &rec);
858 data->rc=rec;
859 return TRUE;
860 case ABM_ACTIVATE:
861 SetActiveWindow(data->hWnd);
862 return TRUE;
863 case ABM_GETAUTOHIDEBAR:
864 data->hWnd=GetActiveWindow();
865 return TRUE;
866 case ABM_NEW:
867 SetWindowPos(data->hWnd,HWND_TOP,rec.left,rec.top,
868 width,height,SWP_SHOWWINDOW);
869 return TRUE;
870 case ABM_QUERYPOS:
871 GetWindowRect(data->hWnd, &(data->rc));
872 return TRUE;
873 case ABM_REMOVE:
874 FIXME("ABM_REMOVE broken\n");
875 /* FIXME: this is wrong; should it be DestroyWindow instead? */
876 /*CloseHandle(data->hWnd);*/
877 return TRUE;
878 case ABM_SETAUTOHIDEBAR:
879 SetWindowPos(data->hWnd,HWND_TOP,rec.left+1000,rec.top,
880 width,height,SWP_SHOWWINDOW);
881 return TRUE;
882 case ABM_SETPOS:
883 data->uEdge=(ABE_RIGHT | ABE_LEFT);
884 SetWindowPos(data->hWnd,HWND_TOP,data->rc.left,data->rc.top,
885 width,height,SWP_SHOWWINDOW);
886 return TRUE;
887 case ABM_WINDOWPOSCHANGED:
888 return TRUE;
890 return FALSE;
893 /*************************************************************************
894 * SHHelpShortcuts_RunDLLA [SHELL32.@]
897 DWORD WINAPI SHHelpShortcuts_RunDLLA(DWORD dwArg1, DWORD dwArg2, DWORD dwArg3, DWORD dwArg4)
899 FIXME("(%lx, %lx, %lx, %lx) stub!\n", dwArg1, dwArg2, dwArg3, dwArg4);
900 return 0;
903 /*************************************************************************
904 * SHHelpShortcuts_RunDLLA [SHELL32.@]
907 DWORD WINAPI SHHelpShortcuts_RunDLLW(DWORD dwArg1, DWORD dwArg2, DWORD dwArg3, DWORD dwArg4)
909 FIXME("(%lx, %lx, %lx, %lx) stub!\n", dwArg1, dwArg2, dwArg3, dwArg4);
910 return 0;
913 /*************************************************************************
914 * SHLoadInProc [SHELL32.@]
915 * Create an instance of specified object class from within
916 * the shell process and release it immediately
918 HRESULT WINAPI SHLoadInProc (REFCLSID rclsid)
920 void *ptr = NULL;
922 TRACE("%s\n", debugstr_guid(rclsid));
924 CoCreateInstance(rclsid, NULL, CLSCTX_INPROC_SERVER, &IID_IUnknown,&ptr);
925 if(ptr)
927 IUnknown * pUnk = ptr;
928 IUnknown_Release(pUnk);
929 return NOERROR;
931 return DISP_E_MEMBERNOTFOUND;
934 /*************************************************************************
935 * AboutDlgProc (internal)
937 INT_PTR CALLBACK AboutDlgProc( HWND hWnd, UINT msg, WPARAM wParam,
938 LPARAM lParam )
940 HWND hWndCtl;
942 TRACE("\n");
944 switch(msg)
946 case WM_INITDIALOG:
948 ABOUT_INFO *info = (ABOUT_INFO *)lParam;
949 WCHAR Template[512], AppTitle[512];
951 if (info)
953 const char* const *pstr = SHELL_Authors;
954 SendDlgItemMessageW(hWnd, stc1, STM_SETICON,(WPARAM)info->hIcon, 0);
955 GetWindowTextW( hWnd, Template, sizeof(Template)/sizeof(WCHAR) );
956 sprintfW( AppTitle, Template, info->szApp );
957 SetWindowTextW( hWnd, AppTitle );
958 SetWindowTextW( GetDlgItem(hWnd, IDC_STATIC_TEXT1), info->szApp );
959 SetWindowTextW( GetDlgItem(hWnd, IDC_STATIC_TEXT2), info->szOtherStuff );
960 hWndCtl = GetDlgItem(hWnd, IDC_LISTBOX);
961 SendMessageW( hWndCtl, WM_SETREDRAW, 0, 0 );
962 SendMessageW( hWndCtl, WM_SETFONT, (WPARAM)info->hFont, 0 );
963 while (*pstr)
965 WCHAR name[64];
966 /* authors list is in iso-8859-1 format */
967 MultiByteToWideChar( 28591, 0, *pstr, -1, name, sizeof(name)/sizeof(WCHAR) );
968 SendMessageW( hWndCtl, LB_ADDSTRING, (WPARAM)-1, (LPARAM)name );
969 pstr++;
971 SendMessageW( hWndCtl, WM_SETREDRAW, 1, 0 );
974 return 1;
976 case WM_PAINT:
978 RECT rect;
979 PAINTSTRUCT ps;
980 HDC hDC = BeginPaint( hWnd, &ps );
982 if (__get_dropline( hWnd, &rect ))
984 SelectObject( hDC, GetStockObject( BLACK_PEN ) );
985 MoveToEx( hDC, rect.left, rect.top, NULL );
986 LineTo( hDC, rect.right, rect.bottom );
988 EndPaint( hWnd, &ps );
990 break;
992 case WM_COMMAND:
993 if (wParam == IDOK || wParam == IDCANCEL)
995 EndDialog(hWnd, TRUE);
996 return TRUE;
998 break;
999 case WM_CLOSE:
1000 EndDialog(hWnd, TRUE);
1001 break;
1004 return 0;
1008 /*************************************************************************
1009 * ShellAboutA [SHELL32.288]
1011 BOOL WINAPI ShellAboutA( HWND hWnd, LPCSTR szApp, LPCSTR szOtherStuff, HICON hIcon )
1013 BOOL ret;
1014 LPWSTR appW = NULL, otherW = NULL;
1015 int len;
1017 if (szApp)
1019 len = MultiByteToWideChar(CP_ACP, 0, szApp, -1, NULL, 0);
1020 appW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1021 MultiByteToWideChar(CP_ACP, 0, szApp, -1, appW, len);
1023 if (szOtherStuff)
1025 len = MultiByteToWideChar(CP_ACP, 0, szOtherStuff, -1, NULL, 0);
1026 otherW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1027 MultiByteToWideChar(CP_ACP, 0, szOtherStuff, -1, otherW, len);
1030 ret = ShellAboutW(hWnd, appW, otherW, hIcon);
1032 HeapFree(GetProcessHeap(), 0, otherW);
1033 HeapFree(GetProcessHeap(), 0, appW);
1034 return ret;
1038 /*************************************************************************
1039 * ShellAboutW [SHELL32.289]
1041 BOOL WINAPI ShellAboutW( HWND hWnd, LPCWSTR szApp, LPCWSTR szOtherStuff,
1042 HICON hIcon )
1044 ABOUT_INFO info;
1045 LOGFONTW logFont;
1046 HRSRC hRes;
1047 LPVOID template;
1048 BOOL bRet;
1049 static const WCHAR wszSHELL_ABOUT_MSGBOX[] =
1050 {'S','H','E','L','L','_','A','B','O','U','T','_','M','S','G','B','O','X',0};
1052 TRACE("\n");
1054 if(!(hRes = FindResourceW(shell32_hInstance, wszSHELL_ABOUT_MSGBOX, (LPWSTR)RT_DIALOG)))
1055 return FALSE;
1056 if(!(template = (LPVOID)LoadResource(shell32_hInstance, hRes)))
1057 return FALSE;
1058 info.szApp = szApp;
1059 info.szOtherStuff = szOtherStuff;
1060 info.hIcon = hIcon ? hIcon : LoadIconW( 0, (LPWSTR)IDI_WINLOGO );
1062 SystemParametersInfoW( SPI_GETICONTITLELOGFONT, 0, &logFont, 0 );
1063 info.hFont = CreateFontIndirectW( &logFont );
1065 bRet = DialogBoxIndirectParamW((HINSTANCE)GetWindowLongPtrW( hWnd, GWLP_HINSTANCE ),
1066 template, hWnd, AboutDlgProc, (LPARAM)&info );
1067 DeleteObject(info.hFont);
1068 return bRet;
1071 /*************************************************************************
1072 * FreeIconList (SHELL32.@)
1074 void WINAPI FreeIconList( DWORD dw )
1076 FIXME("%lx: stub\n",dw);
1080 /***********************************************************************
1081 * DllGetVersion [SHELL32.@]
1083 * Retrieves version information of the 'SHELL32.DLL'
1085 * PARAMS
1086 * pdvi [O] pointer to version information structure.
1088 * RETURNS
1089 * Success: S_OK
1090 * Failure: E_INVALIDARG
1092 * NOTES
1093 * Returns version of a shell32.dll from IE4.01 SP1.
1096 HRESULT WINAPI DllGetVersion (DLLVERSIONINFO *pdvi)
1098 /* FIXME: shouldn't these values come from the version resource? */
1099 if (pdvi->cbSize == sizeof(DLLVERSIONINFO) ||
1100 pdvi->cbSize == sizeof(DLLVERSIONINFO2))
1102 pdvi->dwMajorVersion = WINE_FILEVERSION_MAJOR;
1103 pdvi->dwMinorVersion = WINE_FILEVERSION_MINOR;
1104 pdvi->dwBuildNumber = WINE_FILEVERSION_BUILD;
1105 pdvi->dwPlatformID = WINE_FILEVERSION_PLATFORMID;
1106 if (pdvi->cbSize == sizeof(DLLVERSIONINFO2))
1108 DLLVERSIONINFO2 *pdvi2 = (DLLVERSIONINFO2 *)pdvi;
1110 pdvi2->dwFlags = 0;
1111 pdvi2->ullVersion = MAKEDLLVERULL(WINE_FILEVERSION_MAJOR,
1112 WINE_FILEVERSION_MINOR,
1113 WINE_FILEVERSION_BUILD,
1114 WINE_FILEVERSION_PLATFORMID);
1116 TRACE("%lu.%lu.%lu.%lu\n",
1117 pdvi->dwMajorVersion, pdvi->dwMinorVersion,
1118 pdvi->dwBuildNumber, pdvi->dwPlatformID);
1119 return S_OK;
1121 else
1123 WARN("wrong DLLVERSIONINFO size from app\n");
1124 return E_INVALIDARG;
1128 /*************************************************************************
1129 * global variables of the shell32.dll
1130 * all are once per process
1133 HINSTANCE shell32_hInstance = 0;
1134 HIMAGELIST ShellSmallIconList = 0;
1135 HIMAGELIST ShellBigIconList = 0;
1138 /*************************************************************************
1139 * SHELL32 DllMain
1141 * NOTES
1142 * calling oleinitialize here breaks sone apps.
1144 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
1146 TRACE("%p 0x%lx %p\n", hinstDLL, fdwReason, fImpLoad);
1148 switch (fdwReason)
1150 case DLL_PROCESS_ATTACH:
1151 shell32_hInstance = hinstDLL;
1152 DisableThreadLibraryCalls(shell32_hInstance);
1154 /* get full path to this DLL for IExtractIconW_fnGetIconLocation() */
1155 GetModuleFileNameW(hinstDLL, swShell32Name, MAX_PATH);
1156 swShell32Name[MAX_PATH - 1] = '\0';
1158 InitCommonControlsEx(NULL);
1160 SIC_Initialize();
1161 SYSTRAY_Init();
1162 InitChangeNotifications();
1163 break;
1165 case DLL_PROCESS_DETACH:
1166 shell32_hInstance = 0;
1167 SIC_Destroy();
1168 FreeChangeNotifications();
1169 break;
1171 return TRUE;
1174 /*************************************************************************
1175 * DllInstall [SHELL32.@]
1177 * PARAMETERS
1179 * BOOL bInstall - TRUE for install, FALSE for uninstall
1180 * LPCWSTR pszCmdLine - command line (unused by shell32?)
1183 HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline)
1185 FIXME("%s %s: stub\n", bInstall ? "TRUE":"FALSE", debugstr_w(cmdline));
1186 return S_OK; /* indicate success */
1189 /***********************************************************************
1190 * DllCanUnloadNow (SHELL32.@)
1192 HRESULT WINAPI DllCanUnloadNow(void)
1194 FIXME("stub\n");
1195 return S_FALSE;