push 585d938e6dafa7e4b71343fb5b928a9214e5518c
[wine/hacks.git] / dlls / shell32 / shell32_main.c
blob30265824b7b35f47b8595645443054e8a4166652
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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 "shlwapi.h"
42 #include "undocshell.h"
43 #include "pidl.h"
44 #include "shell32_main.h"
45 #include "version.h"
46 #include "shresdef.h"
48 #include "wine/debug.h"
49 #include "wine/unicode.h"
51 WINE_DEFAULT_DEBUG_CHANNEL(shell);
53 extern const char * const SHELL_Authors[];
55 #define MORE_DEBUG 1
56 /*************************************************************************
57 * CommandLineToArgvW [SHELL32.@]
59 * We must interpret the quotes in the command line to rebuild the argv
60 * array correctly:
61 * - arguments are separated by spaces or tabs
62 * - quotes serve as optional argument delimiters
63 * '"a b"' -> 'a b'
64 * - escaped quotes must be converted back to '"'
65 * '\"' -> '"'
66 * - an odd number of '\'s followed by '"' correspond to half that number
67 * of '\' followed by a '"' (extension of the above)
68 * '\\\"' -> '\"'
69 * '\\\\\"' -> '\\"'
70 * - an even number of '\'s followed by a '"' correspond to half that number
71 * of '\', plus a regular quote serving as an argument delimiter (which
72 * means it does not appear in the result)
73 * 'a\\"b c"' -> 'a\b c'
74 * 'a\\\\"b c"' -> 'a\\b c'
75 * - '\' that are not followed by a '"' are copied literally
76 * 'a\b' -> 'a\b'
77 * 'a\\b' -> 'a\\b'
79 * Note:
80 * '\t' == 0x0009
81 * ' ' == 0x0020
82 * '"' == 0x0022
83 * '\\' == 0x005c
85 LPWSTR* WINAPI CommandLineToArgvW(LPCWSTR lpCmdline, int* numargs)
87 DWORD argc;
88 LPWSTR *argv;
89 LPCWSTR cs;
90 LPWSTR arg,s,d;
91 LPWSTR cmdline;
92 int in_quotes,bcount;
94 if (*lpCmdline==0)
96 /* Return the path to the executable */
97 DWORD len, size=16;
99 argv=LocalAlloc(LMEM_FIXED, size);
100 for (;;)
102 len = GetModuleFileNameW(0, (LPWSTR)(argv+1), (size-sizeof(LPWSTR))/sizeof(WCHAR));
103 if (!len)
105 LocalFree(argv);
106 return NULL;
108 if (len < size) break;
109 size*=2;
110 argv=LocalReAlloc(argv, size, 0);
112 argv[0]=(LPWSTR)(argv+1);
113 if (numargs)
114 *numargs=2;
116 return argv;
119 /* to get a writable copy */
120 argc=0;
121 bcount=0;
122 in_quotes=0;
123 cs=lpCmdline;
124 while (1)
126 if (*cs==0 || ((*cs==0x0009 || *cs==0x0020) && !in_quotes))
128 /* space */
129 argc++;
130 /* skip the remaining spaces */
131 while (*cs==0x0009 || *cs==0x0020) {
132 cs++;
134 if (*cs==0)
135 break;
136 bcount=0;
137 continue;
139 else if (*cs==0x005c)
141 /* '\', count them */
142 bcount++;
144 else if ((*cs==0x0022) && ((bcount & 1)==0))
146 /* unescaped '"' */
147 in_quotes=!in_quotes;
148 bcount=0;
150 else
152 /* a regular character */
153 bcount=0;
155 cs++;
157 /* Allocate in a single lump, the string array, and the strings that go with it.
158 * This way the caller can make a single GlobalFree call to free both, as per MSDN.
160 argv=LocalAlloc(LMEM_FIXED, argc*sizeof(LPWSTR)+(strlenW(lpCmdline)+1)*sizeof(WCHAR));
161 if (!argv)
162 return NULL;
163 cmdline=(LPWSTR)(argv+argc);
164 strcpyW(cmdline, lpCmdline);
166 argc=0;
167 bcount=0;
168 in_quotes=0;
169 arg=d=s=cmdline;
170 while (*s)
172 if ((*s==0x0009 || *s==0x0020) && !in_quotes)
174 /* Close the argument and copy it */
175 *d=0;
176 argv[argc++]=arg;
178 /* skip the remaining spaces */
179 do {
180 s++;
181 } while (*s==0x0009 || *s==0x0020);
183 /* Start with a new argument */
184 arg=d=s;
185 bcount=0;
187 else if (*s==0x005c)
189 /* '\\' */
190 *d++=*s++;
191 bcount++;
193 else if (*s==0x0022)
195 /* '"' */
196 if ((bcount & 1)==0)
198 /* Preceded by an even number of '\', this is half that
199 * number of '\', plus a quote which we erase.
201 d-=bcount/2;
202 in_quotes=!in_quotes;
203 s++;
205 else
207 /* Preceded by an odd number of '\', this is half that
208 * number of '\' followed by a '"'
210 d=d-bcount/2-1;
211 *d++='"';
212 s++;
214 bcount=0;
216 else
218 /* a regular character */
219 *d++=*s++;
220 bcount=0;
223 if (*arg)
225 *d='\0';
226 argv[argc++]=arg;
228 if (numargs)
229 *numargs=argc;
231 return argv;
234 static DWORD shgfi_get_exe_type(LPCWSTR szFullPath)
236 BOOL status = FALSE;
237 HANDLE hfile;
238 DWORD BinaryType;
239 IMAGE_DOS_HEADER mz_header;
240 IMAGE_NT_HEADERS nt;
241 DWORD len;
242 char magic[4];
244 status = GetBinaryTypeW (szFullPath, &BinaryType);
245 if (!status)
246 return 0;
247 if (BinaryType == SCS_DOS_BINARY || BinaryType == SCS_PIF_BINARY)
248 return 0x4d5a;
250 hfile = CreateFileW( szFullPath, GENERIC_READ, FILE_SHARE_READ,
251 NULL, OPEN_EXISTING, 0, 0 );
252 if ( hfile == INVALID_HANDLE_VALUE )
253 return 0;
256 * The next section is adapted from MODULE_GetBinaryType, as we need
257 * to examine the image header to get OS and version information. We
258 * know from calling GetBinaryTypeA that the image is valid and either
259 * an NE or PE, so much error handling can be omitted.
260 * Seek to the start of the file and read the header information.
263 SetFilePointer( hfile, 0, NULL, SEEK_SET );
264 ReadFile( hfile, &mz_header, sizeof(mz_header), &len, NULL );
266 SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
267 ReadFile( hfile, magic, sizeof(magic), &len, NULL );
268 if ( *(DWORD*)magic == IMAGE_NT_SIGNATURE )
270 SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
271 ReadFile( hfile, &nt, sizeof(nt), &len, NULL );
272 CloseHandle( hfile );
273 /* DLL files are not executable and should return 0 */
274 if (nt.FileHeader.Characteristics & IMAGE_FILE_DLL)
275 return 0;
276 if (nt.OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_GUI)
278 return IMAGE_NT_SIGNATURE |
279 (nt.OptionalHeader.MajorSubsystemVersion << 24) |
280 (nt.OptionalHeader.MinorSubsystemVersion << 16);
282 return IMAGE_NT_SIGNATURE;
284 else if ( *(WORD*)magic == IMAGE_OS2_SIGNATURE )
286 IMAGE_OS2_HEADER ne;
287 SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
288 ReadFile( hfile, &ne, sizeof(ne), &len, NULL );
289 CloseHandle( hfile );
290 if (ne.ne_exetyp == 2)
291 return IMAGE_OS2_SIGNATURE | (ne.ne_expver << 16);
292 return 0;
294 CloseHandle( hfile );
295 return 0;
298 /*************************************************************************
299 * SHELL_IsShortcut [internal]
301 * Decide if an item id list points to a shell shortcut
303 BOOL SHELL_IsShortcut(LPCITEMIDLIST pidlLast)
305 char szTemp[MAX_PATH];
306 HKEY keyCls;
307 BOOL ret = FALSE;
309 if (_ILGetExtension(pidlLast, szTemp, MAX_PATH) &&
310 HCR_MapTypeToValueA(szTemp, szTemp, MAX_PATH, TRUE))
312 if (ERROR_SUCCESS == RegOpenKeyExA(HKEY_CLASSES_ROOT, szTemp, 0, KEY_QUERY_VALUE, &keyCls))
314 if (ERROR_SUCCESS == RegQueryValueExA(keyCls, "IsShortcut", NULL, NULL, NULL, NULL))
315 ret = TRUE;
317 RegCloseKey(keyCls);
321 return ret;
324 #define SHGFI_KNOWN_FLAGS \
325 (SHGFI_SMALLICON | SHGFI_OPENICON | SHGFI_SHELLICONSIZE | SHGFI_PIDL | \
326 SHGFI_USEFILEATTRIBUTES | SHGFI_ADDOVERLAYS | SHGFI_OVERLAYINDEX | \
327 SHGFI_ICON | SHGFI_DISPLAYNAME | SHGFI_TYPENAME | SHGFI_ATTRIBUTES | \
328 SHGFI_ICONLOCATION | SHGFI_EXETYPE | SHGFI_SYSICONINDEX | \
329 SHGFI_LINKOVERLAY | SHGFI_SELECTED | SHGFI_ATTR_SPECIFIED)
331 /*************************************************************************
332 * SHGetFileInfoW [SHELL32.@]
335 DWORD_PTR WINAPI SHGetFileInfoW(LPCWSTR path,DWORD dwFileAttributes,
336 SHFILEINFOW *psfi, UINT sizeofpsfi, UINT flags )
338 WCHAR szLocation[MAX_PATH], szFullPath[MAX_PATH];
339 int iIndex;
340 DWORD_PTR ret = TRUE;
341 DWORD dwAttributes = 0;
342 IShellFolder * psfParent = NULL;
343 IExtractIconW * pei = NULL;
344 LPITEMIDLIST pidlLast = NULL, pidl = NULL;
345 HRESULT hr = S_OK;
346 BOOL IconNotYetLoaded=TRUE;
347 UINT uGilFlags = 0;
349 TRACE("%s fattr=0x%x sfi=%p(attr=0x%08x) size=0x%x flags=0x%x\n",
350 (flags & SHGFI_PIDL)? "pidl" : debugstr_w(path), dwFileAttributes,
351 psfi, psfi->dwAttributes, sizeofpsfi, flags);
353 if ( (flags & SHGFI_USEFILEATTRIBUTES) &&
354 (flags & (SHGFI_ATTRIBUTES|SHGFI_EXETYPE|SHGFI_PIDL)))
355 return FALSE;
357 /* windows initializes these values regardless of the flags */
358 if (psfi != NULL)
360 psfi->szDisplayName[0] = '\0';
361 psfi->szTypeName[0] = '\0';
362 psfi->iIcon = 0;
365 if (!(flags & SHGFI_PIDL))
367 /* SHGetFileInfo should work with absolute and relative paths */
368 if (PathIsRelativeW(path))
370 GetCurrentDirectoryW(MAX_PATH, szLocation);
371 PathCombineW(szFullPath, szLocation, path);
373 else
375 lstrcpynW(szFullPath, path, MAX_PATH);
379 if (flags & SHGFI_EXETYPE)
381 if (flags != SHGFI_EXETYPE)
382 return 0;
383 return shgfi_get_exe_type(szFullPath);
387 * psfi is NULL normally to query EXE type. If it is NULL, none of the
388 * below makes sense anyway. Windows allows this and just returns FALSE
390 if (psfi == NULL)
391 return FALSE;
394 * translate the path into a pidl only when SHGFI_USEFILEATTRIBUTES
395 * is not specified.
396 * The pidl functions fail on not existing file names
399 if (flags & SHGFI_PIDL)
401 pidl = ILClone((LPCITEMIDLIST)path);
403 else if (!(flags & SHGFI_USEFILEATTRIBUTES))
405 hr = SHILCreateFromPathW(szFullPath, &pidl, &dwAttributes);
408 if ((flags & SHGFI_PIDL) || !(flags & SHGFI_USEFILEATTRIBUTES))
410 /* get the parent shellfolder */
411 if (pidl)
413 hr = SHBindToParent( pidl, &IID_IShellFolder, (LPVOID*)&psfParent,
414 (LPCITEMIDLIST*)&pidlLast );
415 if (SUCCEEDED(hr))
416 pidlLast = ILClone(pidlLast);
417 ILFree(pidl);
419 else
421 ERR("pidl is null!\n");
422 return FALSE;
426 /* get the attributes of the child */
427 if (SUCCEEDED(hr) && (flags & SHGFI_ATTRIBUTES))
429 if (!(flags & SHGFI_ATTR_SPECIFIED))
431 psfi->dwAttributes = 0xffffffff;
433 IShellFolder_GetAttributesOf( psfParent, 1, (LPCITEMIDLIST*)&pidlLast,
434 &(psfi->dwAttributes) );
437 /* get the displayname */
438 if (SUCCEEDED(hr) && (flags & SHGFI_DISPLAYNAME))
440 if (flags & SHGFI_USEFILEATTRIBUTES)
442 lstrcpyW (psfi->szDisplayName, PathFindFileNameW(szFullPath));
444 else
446 STRRET str;
447 hr = IShellFolder_GetDisplayNameOf( psfParent, pidlLast,
448 SHGDN_INFOLDER, &str);
449 StrRetToStrNW (psfi->szDisplayName, MAX_PATH, &str, pidlLast);
453 /* get the type name */
454 if (SUCCEEDED(hr) && (flags & SHGFI_TYPENAME))
456 static const WCHAR szFile[] = { 'F','i','l','e',0 };
457 static const WCHAR szDashFile[] = { '-','f','i','l','e',0 };
459 if (!(flags & SHGFI_USEFILEATTRIBUTES))
461 char ftype[80];
463 _ILGetFileType(pidlLast, ftype, 80);
464 MultiByteToWideChar(CP_ACP, 0, ftype, -1, psfi->szTypeName, 80 );
466 else
468 if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
469 strcatW (psfi->szTypeName, szFile);
470 else
472 WCHAR sTemp[64];
474 lstrcpyW(sTemp,PathFindExtensionW(szFullPath));
475 if (!( HCR_MapTypeToValueW(sTemp, sTemp, 64, TRUE) &&
476 HCR_MapTypeToValueW(sTemp, psfi->szTypeName, 80, FALSE )))
478 lstrcpynW (psfi->szTypeName, sTemp, 64);
479 strcatW (psfi->szTypeName, szDashFile);
485 /* ### icons ###*/
486 if (flags & SHGFI_OPENICON)
487 uGilFlags |= GIL_OPENICON;
489 if (flags & SHGFI_LINKOVERLAY)
490 uGilFlags |= GIL_FORSHORTCUT;
491 else if ((flags&SHGFI_ADDOVERLAYS) ||
492 (flags&(SHGFI_ICON|SHGFI_SMALLICON))==SHGFI_ICON)
494 if (SHELL_IsShortcut(pidlLast))
495 uGilFlags |= GIL_FORSHORTCUT;
498 if (flags & SHGFI_OVERLAYINDEX)
499 FIXME("SHGFI_OVERLAYINDEX unhandled\n");
501 if (flags & SHGFI_SELECTED)
502 FIXME("set icon to selected, stub\n");
504 if (flags & SHGFI_SHELLICONSIZE)
505 FIXME("set icon to shell size, stub\n");
507 /* get the iconlocation */
508 if (SUCCEEDED(hr) && (flags & SHGFI_ICONLOCATION ))
510 UINT uDummy,uFlags;
512 if (flags & SHGFI_USEFILEATTRIBUTES)
514 if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
516 lstrcpyW(psfi->szDisplayName, swShell32Name);
517 psfi->iIcon = -IDI_SHELL_FOLDER;
519 else
521 WCHAR* szExt;
522 static const WCHAR p1W[] = {'%','1',0};
523 WCHAR sTemp [MAX_PATH];
525 szExt = PathFindExtensionW(szFullPath);
526 TRACE("szExt=%s\n", debugstr_w(szExt));
527 if ( szExt &&
528 HCR_MapTypeToValueW(szExt, sTemp, MAX_PATH, TRUE) &&
529 HCR_GetDefaultIconW(sTemp, sTemp, MAX_PATH, &psfi->iIcon))
531 if (lstrcmpW(p1W, sTemp))
532 strcpyW(psfi->szDisplayName, sTemp);
533 else
535 /* the icon is in the file */
536 strcpyW(psfi->szDisplayName, szFullPath);
539 else
540 ret = FALSE;
543 else
545 hr = IShellFolder_GetUIObjectOf(psfParent, 0, 1,
546 (LPCITEMIDLIST*)&pidlLast, &IID_IExtractIconW,
547 &uDummy, (LPVOID*)&pei);
548 if (SUCCEEDED(hr))
550 hr = IExtractIconW_GetIconLocation(pei, uGilFlags,
551 szLocation, MAX_PATH, &iIndex, &uFlags);
553 if (uFlags & GIL_NOTFILENAME)
554 ret = FALSE;
555 else
557 lstrcpyW (psfi->szDisplayName, szLocation);
558 psfi->iIcon = iIndex;
560 IExtractIconW_Release(pei);
565 /* get icon index (or load icon)*/
566 if (SUCCEEDED(hr) && (flags & (SHGFI_ICON | SHGFI_SYSICONINDEX)))
568 if (flags & SHGFI_USEFILEATTRIBUTES)
570 WCHAR sTemp [MAX_PATH];
571 WCHAR * szExt;
572 int icon_idx=0;
574 lstrcpynW(sTemp, szFullPath, MAX_PATH);
576 if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
577 psfi->iIcon = SIC_GetIconIndex(swShell32Name, -IDI_SHELL_FOLDER, 0);
578 else
580 static const WCHAR p1W[] = {'%','1',0};
582 psfi->iIcon = 0;
583 szExt = PathFindExtensionW(sTemp);
584 if ( szExt &&
585 HCR_MapTypeToValueW(szExt, sTemp, MAX_PATH, TRUE) &&
586 HCR_GetDefaultIconW(sTemp, sTemp, MAX_PATH, &icon_idx))
588 if (!lstrcmpW(p1W,sTemp)) /* icon is in the file */
589 strcpyW(sTemp, szFullPath);
591 if (flags & SHGFI_SYSICONINDEX)
593 psfi->iIcon = SIC_GetIconIndex(sTemp,icon_idx,0);
594 if (psfi->iIcon == -1)
595 psfi->iIcon = 0;
597 else
599 IconNotYetLoaded=FALSE;
600 if (flags & SHGFI_SMALLICON)
601 PrivateExtractIconsW( sTemp,icon_idx,
602 GetSystemMetrics( SM_CXSMICON ),
603 GetSystemMetrics( SM_CYSMICON ),
604 &psfi->hIcon, 0, 1, 0);
605 else
606 PrivateExtractIconsW( sTemp, icon_idx,
607 GetSystemMetrics( SM_CXICON),
608 GetSystemMetrics( SM_CYICON),
609 &psfi->hIcon, 0, 1, 0);
610 psfi->iIcon = icon_idx;
615 else
617 if (!(PidlToSicIndex(psfParent, pidlLast, !(flags & SHGFI_SMALLICON),
618 uGilFlags, &(psfi->iIcon))))
620 ret = FALSE;
623 if (ret)
625 if (flags & SHGFI_SMALLICON)
626 ret = (DWORD_PTR) ShellSmallIconList;
627 else
628 ret = (DWORD_PTR) ShellBigIconList;
632 /* icon handle */
633 if (SUCCEEDED(hr) && (flags & SHGFI_ICON) && IconNotYetLoaded)
635 if (flags & SHGFI_SMALLICON)
636 psfi->hIcon = ImageList_GetIcon( ShellSmallIconList, psfi->iIcon, ILD_NORMAL);
637 else
638 psfi->hIcon = ImageList_GetIcon( ShellBigIconList, psfi->iIcon, ILD_NORMAL);
641 if (flags & ~SHGFI_KNOWN_FLAGS)
642 FIXME("unknown flags %08x\n", flags & ~SHGFI_KNOWN_FLAGS);
644 if (psfParent)
645 IShellFolder_Release(psfParent);
647 if (hr != S_OK)
648 ret = FALSE;
650 SHFree(pidlLast);
652 #ifdef MORE_DEBUG
653 TRACE ("icon=%p index=0x%08x attr=0x%08x name=%s type=%s ret=0x%08lx\n",
654 psfi->hIcon, psfi->iIcon, psfi->dwAttributes,
655 debugstr_w(psfi->szDisplayName), debugstr_w(psfi->szTypeName), ret);
656 #endif
658 return ret;
661 /*************************************************************************
662 * SHGetFileInfoA [SHELL32.@]
664 DWORD_PTR WINAPI SHGetFileInfoA(LPCSTR path,DWORD dwFileAttributes,
665 SHFILEINFOA *psfi, UINT sizeofpsfi,
666 UINT flags )
668 INT len;
669 LPWSTR temppath = NULL;
670 LPCWSTR pathW;
671 DWORD ret;
672 SHFILEINFOW temppsfi;
674 if (flags & SHGFI_PIDL)
676 /* path contains a pidl */
677 pathW = (LPCWSTR)path;
679 else
681 len = MultiByteToWideChar(CP_ACP, 0, path, -1, NULL, 0);
682 temppath = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
683 MultiByteToWideChar(CP_ACP, 0, path, -1, temppath, len);
684 pathW = temppath;
687 if (psfi && (flags & SHGFI_ATTR_SPECIFIED))
688 temppsfi.dwAttributes=psfi->dwAttributes;
690 if (psfi == NULL)
691 ret = SHGetFileInfoW(pathW, dwFileAttributes, NULL, sizeof(temppsfi), flags);
692 else
693 ret = SHGetFileInfoW(pathW, dwFileAttributes, &temppsfi, sizeof(temppsfi), flags);
695 if (psfi)
697 if(flags & SHGFI_ICON)
698 psfi->hIcon=temppsfi.hIcon;
699 if(flags & (SHGFI_SYSICONINDEX|SHGFI_ICON|SHGFI_ICONLOCATION))
700 psfi->iIcon=temppsfi.iIcon;
701 if(flags & SHGFI_ATTRIBUTES)
702 psfi->dwAttributes=temppsfi.dwAttributes;
703 if(flags & (SHGFI_DISPLAYNAME|SHGFI_ICONLOCATION))
705 WideCharToMultiByte(CP_ACP, 0, temppsfi.szDisplayName, -1,
706 psfi->szDisplayName, sizeof(psfi->szDisplayName), NULL, NULL);
708 if(flags & SHGFI_TYPENAME)
710 WideCharToMultiByte(CP_ACP, 0, temppsfi.szTypeName, -1,
711 psfi->szTypeName, sizeof(psfi->szTypeName), NULL, NULL);
715 HeapFree(GetProcessHeap(), 0, temppath);
717 return ret;
720 /*************************************************************************
721 * DuplicateIcon [SHELL32.@]
723 HICON WINAPI DuplicateIcon( HINSTANCE hInstance, HICON hIcon)
725 ICONINFO IconInfo;
726 HICON hDupIcon = 0;
728 TRACE("%p %p\n", hInstance, hIcon);
730 if (GetIconInfo(hIcon, &IconInfo))
732 hDupIcon = CreateIconIndirect(&IconInfo);
734 /* clean up hbmMask and hbmColor */
735 DeleteObject(IconInfo.hbmMask);
736 DeleteObject(IconInfo.hbmColor);
739 return hDupIcon;
742 /*************************************************************************
743 * ExtractIconA [SHELL32.@]
745 HICON WINAPI ExtractIconA(HINSTANCE hInstance, LPCSTR lpszFile, UINT nIconIndex)
747 HICON ret;
748 INT len = MultiByteToWideChar(CP_ACP, 0, lpszFile, -1, NULL, 0);
749 LPWSTR lpwstrFile = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
751 TRACE("%p %s %d\n", hInstance, lpszFile, nIconIndex);
753 MultiByteToWideChar(CP_ACP, 0, lpszFile, -1, lpwstrFile, len);
754 ret = ExtractIconW(hInstance, lpwstrFile, nIconIndex);
755 HeapFree(GetProcessHeap(), 0, lpwstrFile);
757 return ret;
760 /*************************************************************************
761 * ExtractIconW [SHELL32.@]
763 HICON WINAPI ExtractIconW(HINSTANCE hInstance, LPCWSTR lpszFile, UINT nIconIndex)
765 HICON hIcon = NULL;
766 UINT ret;
767 UINT cx = GetSystemMetrics(SM_CXICON), cy = GetSystemMetrics(SM_CYICON);
769 TRACE("%p %s %d\n", hInstance, debugstr_w(lpszFile), nIconIndex);
771 if (nIconIndex == 0xFFFFFFFF)
773 ret = PrivateExtractIconsW(lpszFile, 0, cx, cy, NULL, NULL, 0, LR_DEFAULTCOLOR);
774 if (ret != 0xFFFFFFFF && ret)
775 return (HICON)(UINT_PTR)ret;
776 return NULL;
778 else
779 ret = PrivateExtractIconsW(lpszFile, nIconIndex, cx, cy, &hIcon, NULL, 1, LR_DEFAULTCOLOR);
781 if (ret == 0xFFFFFFFF)
782 return (HICON)1;
783 else if (ret > 0 && hIcon)
784 return hIcon;
786 return NULL;
789 /*************************************************************************
790 * Printer_LoadIconsW [SHELL32.205]
792 VOID WINAPI Printer_LoadIconsW(LPCWSTR wsPrinterName, HICON * pLargeIcon, HICON * pSmallIcon)
794 INT iconindex=IDI_SHELL_PRINTER;
796 TRACE("(%s, %p, %p)\n", debugstr_w(wsPrinterName), pLargeIcon, pSmallIcon);
798 /* We should check if wsPrinterName is
799 1. the Default Printer or not
800 2. connected or not
801 3. a Local Printer or a Network-Printer
802 and use different Icons
804 if((wsPrinterName != NULL) && (wsPrinterName[0] != 0))
806 FIXME("(select Icon by PrinterName %s not implemented)\n", debugstr_w(wsPrinterName));
809 if(pLargeIcon != NULL)
810 *pLargeIcon = LoadImageW(shell32_hInstance,
811 (LPCWSTR) MAKEINTRESOURCE(iconindex), IMAGE_ICON,
812 0, 0, LR_DEFAULTCOLOR|LR_DEFAULTSIZE);
814 if(pSmallIcon != NULL)
815 *pSmallIcon = LoadImageW(shell32_hInstance,
816 (LPCWSTR) MAKEINTRESOURCE(iconindex), IMAGE_ICON,
817 16, 16, LR_DEFAULTCOLOR);
820 /*************************************************************************
821 * Printers_RegisterWindowW [SHELL32.213]
822 * used by "printui.dll":
823 * find the Window of the given Type for the specific Printer and
824 * return the already existent hwnd or open a new window
826 BOOL WINAPI Printers_RegisterWindowW(LPCWSTR wsPrinter, DWORD dwType,
827 HANDLE * phClassPidl, HWND * phwnd)
829 FIXME("(%s, %x, %p (%p), %p (%p)) stub!\n", debugstr_w(wsPrinter), dwType,
830 phClassPidl, (phClassPidl != NULL) ? *(phClassPidl) : NULL,
831 phwnd, (phwnd != NULL) ? *(phwnd) : NULL);
833 return FALSE;
836 /*************************************************************************
837 * Printers_UnregisterWindow [SHELL32.214]
839 VOID WINAPI Printers_UnregisterWindow(HANDLE hClassPidl, HWND hwnd)
841 FIXME("(%p, %p) stub!\n", hClassPidl, hwnd);
844 /*************************************************************************/
846 typedef struct
848 LPCWSTR szApp;
849 LPCWSTR szOtherStuff;
850 HICON hIcon;
851 HFONT hFont;
852 } ABOUT_INFO;
854 #define DROP_FIELD_TOP (-12)
856 static void paint_dropline( HDC hdc, HWND hWnd )
858 HWND hWndCtl = GetDlgItem(hWnd, IDC_ABOUT_WINE_TEXT);
859 RECT rect;
861 if (!hWndCtl) return;
862 GetWindowRect( hWndCtl, &rect );
863 MapWindowPoints( 0, hWnd, (LPPOINT)&rect, 2 );
864 rect.top += DROP_FIELD_TOP;
865 rect.bottom = rect.top + 2;
866 DrawEdge( hdc, &rect, BDR_SUNKENOUTER, BF_RECT );
869 /*************************************************************************
870 * SHAppBarMessage [SHELL32.@]
872 UINT_PTR WINAPI SHAppBarMessage(DWORD msg, PAPPBARDATA data)
874 int width=data->rc.right - data->rc.left;
875 int height=data->rc.bottom - data->rc.top;
876 RECT rec=data->rc;
878 FIXME("msg=%d, data={cb=%d, hwnd=%p, callback=%x, edge=%d, rc=%s, lparam=%lx}: stub\n",
879 msg, data->cbSize, data->hWnd, data->uCallbackMessage, data->uEdge,
880 wine_dbgstr_rect(&data->rc), data->lParam);
882 switch (msg)
884 case ABM_GETSTATE:
885 return ABS_ALWAYSONTOP | ABS_AUTOHIDE;
886 case ABM_GETTASKBARPOS:
887 /* FIXME: This is wrong. It should return the taskbar co-ords and edge from the monitor
888 which contains data->hWnd */
889 GetWindowRect(data->hWnd, &rec);
890 data->rc=rec;
891 return TRUE;
892 case ABM_ACTIVATE:
893 SetActiveWindow(data->hWnd);
894 return TRUE;
895 case ABM_GETAUTOHIDEBAR:
896 return 0; /* pretend there is no autohide bar */
897 case ABM_NEW:
898 /* cbSize, hWnd, and uCallbackMessage are used. All other ignored */
899 SetWindowPos(data->hWnd,HWND_TOP,0,0,0,0,SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE);
900 return TRUE;
901 case ABM_QUERYPOS:
902 GetWindowRect(data->hWnd, &(data->rc));
903 return TRUE;
904 case ABM_REMOVE:
905 FIXME("ABM_REMOVE broken\n");
906 /* FIXME: this is wrong; should it be DestroyWindow instead? */
907 /*CloseHandle(data->hWnd);*/
908 return TRUE;
909 case ABM_SETAUTOHIDEBAR:
910 SetWindowPos(data->hWnd,HWND_TOP,rec.left+1000,rec.top,
911 width,height,SWP_SHOWWINDOW);
912 return TRUE;
913 case ABM_SETPOS:
914 data->uEdge=(ABE_RIGHT | ABE_LEFT);
915 SetWindowPos(data->hWnd,HWND_TOP,data->rc.left,data->rc.top,
916 width,height,SWP_SHOWWINDOW);
917 return TRUE;
918 case ABM_WINDOWPOSCHANGED:
919 return TRUE;
921 return FALSE;
924 /*************************************************************************
925 * SHHelpShortcuts_RunDLLA [SHELL32.@]
928 DWORD WINAPI SHHelpShortcuts_RunDLLA(DWORD dwArg1, DWORD dwArg2, DWORD dwArg3, DWORD dwArg4)
930 FIXME("(%x, %x, %x, %x) stub!\n", dwArg1, dwArg2, dwArg3, dwArg4);
931 return 0;
934 /*************************************************************************
935 * SHHelpShortcuts_RunDLLA [SHELL32.@]
938 DWORD WINAPI SHHelpShortcuts_RunDLLW(DWORD dwArg1, DWORD dwArg2, DWORD dwArg3, DWORD dwArg4)
940 FIXME("(%x, %x, %x, %x) stub!\n", dwArg1, dwArg2, dwArg3, dwArg4);
941 return 0;
944 /*************************************************************************
945 * SHLoadInProc [SHELL32.@]
946 * Create an instance of specified object class from within
947 * the shell process and release it immediately
949 HRESULT WINAPI SHLoadInProc (REFCLSID rclsid)
951 void *ptr = NULL;
953 TRACE("%s\n", debugstr_guid(rclsid));
955 CoCreateInstance(rclsid, NULL, CLSCTX_INPROC_SERVER, &IID_IUnknown,&ptr);
956 if(ptr)
958 IUnknown * pUnk = ptr;
959 IUnknown_Release(pUnk);
960 return NOERROR;
962 return DISP_E_MEMBERNOTFOUND;
965 /*************************************************************************
966 * AboutDlgProc (internal)
968 INT_PTR CALLBACK AboutDlgProc( HWND hWnd, UINT msg, WPARAM wParam,
969 LPARAM lParam )
971 HWND hWndCtl;
973 TRACE("\n");
975 switch(msg)
977 case WM_INITDIALOG:
979 ABOUT_INFO *info = (ABOUT_INFO *)lParam;
980 WCHAR template[512], buffer[512], version[64];
981 extern const char *wine_get_build_id(void);
983 if (info)
985 const char* const *pstr = SHELL_Authors;
986 SendDlgItemMessageW(hWnd, stc1, STM_SETICON,(WPARAM)info->hIcon, 0);
987 GetWindowTextW( hWnd, template, sizeof(template)/sizeof(WCHAR) );
988 sprintfW( buffer, template, info->szApp );
989 SetWindowTextW( hWnd, buffer );
990 SetWindowTextW( GetDlgItem(hWnd, IDC_ABOUT_STATIC_TEXT1), info->szApp );
991 SetWindowTextW( GetDlgItem(hWnd, IDC_ABOUT_STATIC_TEXT2), info->szOtherStuff );
992 GetWindowTextW( GetDlgItem(hWnd, IDC_ABOUT_STATIC_TEXT3),
993 template, sizeof(template)/sizeof(WCHAR) );
994 MultiByteToWideChar( CP_UTF8, 0, wine_get_build_id(), -1,
995 version, sizeof(version)/sizeof(WCHAR) );
996 sprintfW( buffer, template, version );
997 SetWindowTextW( GetDlgItem(hWnd, IDC_ABOUT_STATIC_TEXT3), buffer );
998 hWndCtl = GetDlgItem(hWnd, IDC_ABOUT_LISTBOX);
999 SendMessageW( hWndCtl, WM_SETREDRAW, 0, 0 );
1000 SendMessageW( hWndCtl, WM_SETFONT, (WPARAM)info->hFont, 0 );
1001 while (*pstr)
1003 /* authors list is in utf-8 format */
1004 MultiByteToWideChar( CP_UTF8, 0, *pstr, -1, buffer, sizeof(buffer)/sizeof(WCHAR) );
1005 SendMessageW( hWndCtl, LB_ADDSTRING, (WPARAM)-1, (LPARAM)buffer );
1006 pstr++;
1008 SendMessageW( hWndCtl, WM_SETREDRAW, 1, 0 );
1011 return 1;
1013 case WM_PAINT:
1015 PAINTSTRUCT ps;
1016 HDC hDC = BeginPaint( hWnd, &ps );
1017 paint_dropline( hDC, hWnd );
1018 EndPaint( hWnd, &ps );
1020 break;
1022 case WM_COMMAND:
1023 if (wParam == IDOK || wParam == IDCANCEL)
1025 EndDialog(hWnd, TRUE);
1026 return TRUE;
1028 if (wParam == IDC_ABOUT_LICENSE)
1030 MSGBOXPARAMSW params;
1032 params.cbSize = sizeof(params);
1033 params.hwndOwner = hWnd;
1034 params.hInstance = shell32_hInstance;
1035 params.lpszText = MAKEINTRESOURCEW(IDS_LICENSE);
1036 params.lpszCaption = MAKEINTRESOURCEW(IDS_LICENSE_CAPTION);
1037 params.dwStyle = MB_ICONINFORMATION | MB_OK;
1038 params.lpszIcon = 0;
1039 params.dwContextHelpId = 0;
1040 params.lpfnMsgBoxCallback = NULL;
1041 params.dwLanguageId = LANG_NEUTRAL;
1042 MessageBoxIndirectW( &params );
1044 break;
1045 case WM_CLOSE:
1046 EndDialog(hWnd, TRUE);
1047 break;
1050 return 0;
1054 /*************************************************************************
1055 * ShellAboutA [SHELL32.288]
1057 BOOL WINAPI ShellAboutA( HWND hWnd, LPCSTR szApp, LPCSTR szOtherStuff, HICON hIcon )
1059 BOOL ret;
1060 LPWSTR appW = NULL, otherW = NULL;
1061 int len;
1063 if (szApp)
1065 len = MultiByteToWideChar(CP_ACP, 0, szApp, -1, NULL, 0);
1066 appW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1067 MultiByteToWideChar(CP_ACP, 0, szApp, -1, appW, len);
1069 if (szOtherStuff)
1071 len = MultiByteToWideChar(CP_ACP, 0, szOtherStuff, -1, NULL, 0);
1072 otherW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1073 MultiByteToWideChar(CP_ACP, 0, szOtherStuff, -1, otherW, len);
1076 ret = ShellAboutW(hWnd, appW, otherW, hIcon);
1078 HeapFree(GetProcessHeap(), 0, otherW);
1079 HeapFree(GetProcessHeap(), 0, appW);
1080 return ret;
1084 /*************************************************************************
1085 * ShellAboutW [SHELL32.289]
1087 BOOL WINAPI ShellAboutW( HWND hWnd, LPCWSTR szApp, LPCWSTR szOtherStuff,
1088 HICON hIcon )
1090 ABOUT_INFO info;
1091 LOGFONTW logFont;
1092 HRSRC hRes;
1093 LPVOID template;
1094 BOOL bRet;
1095 static const WCHAR wszSHELL_ABOUT_MSGBOX[] =
1096 {'S','H','E','L','L','_','A','B','O','U','T','_','M','S','G','B','O','X',0};
1098 TRACE("\n");
1100 if(!(hRes = FindResourceW(shell32_hInstance, wszSHELL_ABOUT_MSGBOX, (LPWSTR)RT_DIALOG)))
1101 return FALSE;
1102 if(!(template = LoadResource(shell32_hInstance, hRes)))
1103 return FALSE;
1104 if (!hIcon) hIcon = LoadImageW( 0, (LPWSTR)IDI_WINLOGO, IMAGE_ICON, 48, 48, LR_SHARED );
1105 info.szApp = szApp;
1106 info.szOtherStuff = szOtherStuff;
1107 info.hIcon = hIcon;
1109 SystemParametersInfoW( SPI_GETICONTITLELOGFONT, 0, &logFont, 0 );
1110 info.hFont = CreateFontIndirectW( &logFont );
1112 bRet = DialogBoxIndirectParamW((HINSTANCE)GetWindowLongPtrW( hWnd, GWLP_HINSTANCE ),
1113 template, hWnd, AboutDlgProc, (LPARAM)&info );
1114 DeleteObject(info.hFont);
1115 return bRet;
1118 /*************************************************************************
1119 * FreeIconList (SHELL32.@)
1121 void WINAPI FreeIconList( DWORD dw )
1123 FIXME("%x: stub\n",dw);
1126 /*************************************************************************
1127 * SHLoadNonloadedIconOverlayIdentifiers (SHELL32.@)
1129 HRESULT WINAPI SHLoadNonloadedIconOverlayIdentifiers( VOID )
1131 FIXME("stub\n");
1132 return S_OK;
1135 /***********************************************************************
1136 * DllGetVersion [SHELL32.@]
1138 * Retrieves version information of the 'SHELL32.DLL'
1140 * PARAMS
1141 * pdvi [O] pointer to version information structure.
1143 * RETURNS
1144 * Success: S_OK
1145 * Failure: E_INVALIDARG
1147 * NOTES
1148 * Returns version of a shell32.dll from IE4.01 SP1.
1151 HRESULT WINAPI DllGetVersion (DLLVERSIONINFO *pdvi)
1153 /* FIXME: shouldn't these values come from the version resource? */
1154 if (pdvi->cbSize == sizeof(DLLVERSIONINFO) ||
1155 pdvi->cbSize == sizeof(DLLVERSIONINFO2))
1157 pdvi->dwMajorVersion = WINE_FILEVERSION_MAJOR;
1158 pdvi->dwMinorVersion = WINE_FILEVERSION_MINOR;
1159 pdvi->dwBuildNumber = WINE_FILEVERSION_BUILD;
1160 pdvi->dwPlatformID = WINE_FILEVERSION_PLATFORMID;
1161 if (pdvi->cbSize == sizeof(DLLVERSIONINFO2))
1163 DLLVERSIONINFO2 *pdvi2 = (DLLVERSIONINFO2 *)pdvi;
1165 pdvi2->dwFlags = 0;
1166 pdvi2->ullVersion = MAKEDLLVERULL(WINE_FILEVERSION_MAJOR,
1167 WINE_FILEVERSION_MINOR,
1168 WINE_FILEVERSION_BUILD,
1169 WINE_FILEVERSION_PLATFORMID);
1171 TRACE("%u.%u.%u.%u\n",
1172 pdvi->dwMajorVersion, pdvi->dwMinorVersion,
1173 pdvi->dwBuildNumber, pdvi->dwPlatformID);
1174 return S_OK;
1176 else
1178 WARN("wrong DLLVERSIONINFO size from app\n");
1179 return E_INVALIDARG;
1183 /*************************************************************************
1184 * global variables of the shell32.dll
1185 * all are once per process
1188 HINSTANCE shell32_hInstance = 0;
1189 HIMAGELIST ShellSmallIconList = 0;
1190 HIMAGELIST ShellBigIconList = 0;
1193 /*************************************************************************
1194 * SHELL32 DllMain
1196 * NOTES
1197 * calling oleinitialize here breaks sone apps.
1199 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
1201 TRACE("%p 0x%x %p\n", hinstDLL, fdwReason, fImpLoad);
1203 switch (fdwReason)
1205 case DLL_PROCESS_ATTACH:
1206 shell32_hInstance = hinstDLL;
1207 DisableThreadLibraryCalls(shell32_hInstance);
1209 /* get full path to this DLL for IExtractIconW_fnGetIconLocation() */
1210 GetModuleFileNameW(hinstDLL, swShell32Name, MAX_PATH);
1211 swShell32Name[MAX_PATH - 1] = '\0';
1213 InitCommonControlsEx(NULL);
1215 SIC_Initialize();
1216 InitChangeNotifications();
1217 break;
1219 case DLL_PROCESS_DETACH:
1220 shell32_hInstance = 0;
1221 SIC_Destroy();
1222 FreeChangeNotifications();
1223 break;
1225 return TRUE;
1228 /*************************************************************************
1229 * DllInstall [SHELL32.@]
1231 * PARAMETERS
1233 * BOOL bInstall - TRUE for install, FALSE for uninstall
1234 * LPCWSTR pszCmdLine - command line (unused by shell32?)
1237 HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline)
1239 FIXME("%s %s: stub\n", bInstall ? "TRUE":"FALSE", debugstr_w(cmdline));
1240 return S_OK; /* indicate success */
1243 /***********************************************************************
1244 * DllCanUnloadNow (SHELL32.@)
1246 HRESULT WINAPI DllCanUnloadNow(void)
1248 FIXME("stub\n");
1249 return S_FALSE;