Correct failing test and transform it into a bunch of another tests.
[wine.git] / dlls / shell32 / shell32_main.c
blob52d6ddc8ee81c4c75bc63a5178353227ed85443e
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 #define SHGFI_KNOWN_FLAGS \
301 (SHGFI_SMALLICON | SHGFI_OPENICON | SHGFI_SHELLICONSIZE | SHGFI_PIDL | \
302 SHGFI_USEFILEATTRIBUTES | SHGFI_ADDOVERLAYS | SHGFI_OVERLAYINDEX | \
303 SHGFI_ICON | SHGFI_DISPLAYNAME | SHGFI_TYPENAME | SHGFI_ATTRIBUTES | \
304 SHGFI_ICONLOCATION | SHGFI_EXETYPE | SHGFI_SYSICONINDEX | \
305 SHGFI_LINKOVERLAY | SHGFI_SELECTED | SHGFI_ATTR_SPECIFIED)
307 /*************************************************************************
308 * SHGetFileInfoW [SHELL32.@]
311 DWORD WINAPI SHGetFileInfoW(LPCWSTR path,DWORD dwFileAttributes,
312 SHFILEINFOW *psfi, UINT sizeofpsfi, UINT flags )
314 WCHAR szLocation[MAX_PATH], szFullPath[MAX_PATH];
315 int iIndex;
316 DWORD ret = TRUE, dwAttributes = 0;
317 IShellFolder * psfParent = NULL;
318 IExtractIconW * pei = NULL;
319 LPITEMIDLIST pidlLast = NULL, pidl = NULL;
320 HRESULT hr = S_OK;
321 BOOL IconNotYetLoaded=TRUE;
323 TRACE("%s fattr=0x%lx sfi=%p(attr=0x%08lx) size=0x%x flags=0x%x\n",
324 (flags & SHGFI_PIDL)? "pidl" : debugstr_w(path), dwFileAttributes,
325 psfi, psfi->dwAttributes, sizeofpsfi, flags);
327 if ( (flags & SHGFI_USEFILEATTRIBUTES) &&
328 (flags & (SHGFI_ATTRIBUTES|SHGFI_EXETYPE|SHGFI_PIDL)))
329 return FALSE;
331 /* windows initializes this values regardless of the flags */
332 if (psfi != NULL)
334 psfi->szDisplayName[0] = '\0';
335 psfi->szTypeName[0] = '\0';
336 psfi->iIcon = 0;
339 if (!(flags & SHGFI_PIDL))
341 /* SHGetFileInfo should work with absolute and relative paths */
342 if (PathIsRelativeW(path))
344 GetCurrentDirectoryW(MAX_PATH, szLocation);
345 PathCombineW(szFullPath, szLocation, path);
347 else
349 lstrcpynW(szFullPath, path, MAX_PATH);
353 if (flags & SHGFI_EXETYPE)
355 if (flags != SHGFI_EXETYPE)
356 return 0;
357 return shgfi_get_exe_type(szFullPath);
361 * psfi is NULL normally to query EXE type. If it is NULL, none of the
362 * below makes sense anyway. Windows allows this and just returns FALSE
364 if (psfi == NULL)
365 return FALSE;
368 * translate the path into a pidl only when SHGFI_USEFILEATTRIBUTES
369 * is not specified.
370 * The pidl functions fail on not existing file names
373 if (flags & SHGFI_PIDL)
375 pidl = ILClone((LPCITEMIDLIST)path);
377 else if (!(flags & SHGFI_USEFILEATTRIBUTES))
379 hr = SHILCreateFromPathW(szFullPath, &pidl, &dwAttributes);
382 if ((flags & SHGFI_PIDL) || !(flags & SHGFI_USEFILEATTRIBUTES))
384 /* get the parent shellfolder */
385 if (pidl)
387 hr = SHBindToParent( pidl, &IID_IShellFolder, (LPVOID*)&psfParent,
388 (LPCITEMIDLIST*)&pidlLast );
389 ILFree(pidl);
391 else
393 ERR("pidl is null!\n");
394 return FALSE;
398 /* get the attributes of the child */
399 if (SUCCEEDED(hr) && (flags & SHGFI_ATTRIBUTES))
401 if (!(flags & SHGFI_ATTR_SPECIFIED))
403 psfi->dwAttributes = 0xffffffff;
405 IShellFolder_GetAttributesOf( psfParent, 1, (LPCITEMIDLIST*)&pidlLast,
406 &(psfi->dwAttributes) );
409 /* get the displayname */
410 if (SUCCEEDED(hr) && (flags & SHGFI_DISPLAYNAME))
412 if (flags & SHGFI_USEFILEATTRIBUTES)
414 lstrcpyW (psfi->szDisplayName, PathFindFileNameW(szFullPath));
416 else
418 STRRET str;
419 hr = IShellFolder_GetDisplayNameOf( psfParent, pidlLast,
420 SHGDN_INFOLDER, &str);
421 StrRetToStrNW (psfi->szDisplayName, MAX_PATH, &str, pidlLast);
425 /* get the type name */
426 if (SUCCEEDED(hr) && (flags & SHGFI_TYPENAME))
428 static const WCHAR szFile[] = { 'F','i','l','e',0 };
429 static const WCHAR szDashFile[] = { '-','f','i','l','e',0 };
431 if (!(flags & SHGFI_USEFILEATTRIBUTES))
433 char ftype[80];
435 _ILGetFileType(pidlLast, ftype, 80);
436 MultiByteToWideChar(CP_ACP, 0, ftype, -1, psfi->szTypeName, 80 );
438 else
440 if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
441 strcatW (psfi->szTypeName, szFile);
442 else
444 WCHAR sTemp[64];
446 lstrcpyW(sTemp,PathFindExtensionW(szFullPath));
447 if (!( HCR_MapTypeToValueW(sTemp, sTemp, 64, TRUE) &&
448 HCR_MapTypeToValueW(sTemp, psfi->szTypeName, 80, FALSE )))
450 lstrcpynW (psfi->szTypeName, sTemp, 64);
451 strcatW (psfi->szTypeName, szDashFile);
457 /* ### icons ###*/
458 if (flags & SHGFI_ADDOVERLAYS)
459 FIXME("SHGFI_ADDOVERLAYS unhandled\n");
461 if (flags & SHGFI_OVERLAYINDEX)
462 FIXME("SHGFI_OVERLAYINDEX unhandled\n");
464 if (flags & SHGFI_LINKOVERLAY)
465 FIXME("set icon to link, stub\n");
467 if (flags & SHGFI_SELECTED)
468 FIXME("set icon to selected, stub\n");
470 if (flags & SHGFI_SHELLICONSIZE)
471 FIXME("set icon to shell size, stub\n");
473 /* get the iconlocation */
474 if (SUCCEEDED(hr) && (flags & SHGFI_ICONLOCATION ))
476 UINT uDummy,uFlags;
478 hr = IShellFolder_GetUIObjectOf(psfParent, 0, 1,
479 (LPCITEMIDLIST*)&pidlLast, &IID_IExtractIconA,
480 &uDummy, (LPVOID*)&pei);
481 if (SUCCEEDED(hr))
483 hr = IExtractIconW_GetIconLocation(pei,
484 (flags & SHGFI_OPENICON)? GIL_OPENICON : 0,
485 szLocation, MAX_PATH, &iIndex, &uFlags);
486 psfi->iIcon = iIndex;
488 if (uFlags != GIL_NOTFILENAME)
489 lstrcpyW (psfi->szDisplayName, szLocation);
490 else
491 ret = FALSE;
493 IExtractIconA_Release(pei);
497 /* get icon index (or load icon)*/
498 if (SUCCEEDED(hr) && (flags & (SHGFI_ICON | SHGFI_SYSICONINDEX)))
500 if (flags & SHGFI_USEFILEATTRIBUTES)
502 WCHAR sTemp [MAX_PATH];
503 WCHAR * szExt;
504 DWORD dwNr=0;
506 lstrcpynW(sTemp, szFullPath, MAX_PATH);
508 if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
509 psfi->iIcon = SIC_GetIconIndex(swShell32Name, -IDI_SHELL_FOLDER, 0);
510 else
512 static const WCHAR p1W[] = {'%','1',0};
514 psfi->iIcon = 0;
515 szExt = (LPWSTR) PathFindExtensionW(sTemp);
516 if ( szExt &&
517 HCR_MapTypeToValueW(szExt, sTemp, MAX_PATH, TRUE) &&
518 HCR_GetDefaultIconW(sTemp, sTemp, MAX_PATH, &dwNr))
520 if (!lstrcmpW(p1W,sTemp)) /* icon is in the file */
521 strcpyW(sTemp, szFullPath);
523 if (flags & SHGFI_SYSICONINDEX)
525 psfi->iIcon = SIC_GetIconIndex(sTemp,dwNr,0);
526 if (psfi->iIcon == -1)
527 psfi->iIcon = 0;
529 else
531 IconNotYetLoaded=FALSE;
532 if (flags & SHGFI_SMALLICON)
533 PrivateExtractIconsW( sTemp,dwNr,
534 GetSystemMetrics( SM_CXSMICON ),
535 GetSystemMetrics( SM_CYSMICON ),
536 &psfi->hIcon, 0, 1, 0);
537 else
538 PrivateExtractIconsW( sTemp, dwNr,
539 GetSystemMetrics( SM_CXICON),
540 GetSystemMetrics( SM_CYICON),
541 &psfi->hIcon, 0, 1, 0);
542 psfi->iIcon = dwNr;
547 else
549 if (!(PidlToSicIndex(psfParent, pidlLast, !(flags & SHGFI_SMALLICON),
550 (flags & SHGFI_OPENICON)? GIL_OPENICON : 0, &(psfi->iIcon))))
552 ret = FALSE;
555 if (ret)
557 if (flags & SHGFI_SMALLICON)
558 ret = (DWORD) ShellSmallIconList;
559 else
560 ret = (DWORD) ShellBigIconList;
564 /* icon handle */
565 if (SUCCEEDED(hr) && (flags & SHGFI_ICON) && IconNotYetLoaded)
567 if (flags & SHGFI_SMALLICON)
568 psfi->hIcon = ImageList_GetIcon( ShellSmallIconList, psfi->iIcon, ILD_NORMAL);
569 else
570 psfi->hIcon = ImageList_GetIcon( ShellBigIconList, psfi->iIcon, ILD_NORMAL);
573 if (flags & ~SHGFI_KNOWN_FLAGS)
574 FIXME("unknown flags %08x\n", flags & ~SHGFI_KNOWN_FLAGS);
576 if (psfParent)
577 IShellFolder_Release(psfParent);
579 if (hr != S_OK)
580 ret = FALSE;
582 if (pidlLast)
583 SHFree(pidlLast);
585 #ifdef MORE_DEBUG
586 TRACE ("icon=%p index=0x%08x attr=0x%08lx name=%s type=%s ret=0x%08lx\n",
587 psfi->hIcon, psfi->iIcon, psfi->dwAttributes,
588 debugstr_w(psfi->szDisplayName), debugstr_w(psfi->szTypeName), ret);
589 #endif
591 return ret;
594 /*************************************************************************
595 * SHGetFileInfoA [SHELL32.@]
597 DWORD WINAPI SHGetFileInfoA(LPCSTR path,DWORD dwFileAttributes,
598 SHFILEINFOA *psfi, UINT sizeofpsfi,
599 UINT flags )
601 INT len;
602 LPWSTR temppath;
603 DWORD ret;
604 SHFILEINFOW temppsfi;
606 if (flags & SHGFI_PIDL)
608 /* path contains a pidl */
609 temppath = (LPWSTR) path;
611 else
613 len = MultiByteToWideChar(CP_ACP, 0, path, -1, NULL, 0);
614 temppath = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
615 MultiByteToWideChar(CP_ACP, 0, path, -1, temppath, len);
618 if (psfi && (flags & SHGFI_ATTR_SPECIFIED))
619 temppsfi.dwAttributes=psfi->dwAttributes;
621 if (psfi == NULL)
622 ret = SHGetFileInfoW(temppath, dwFileAttributes, NULL, sizeof(temppsfi), flags);
623 else
624 ret = SHGetFileInfoW(temppath, dwFileAttributes, &temppsfi, sizeof(temppsfi), flags);
626 if (psfi)
628 if(flags & SHGFI_ICON)
629 psfi->hIcon=temppsfi.hIcon;
630 if(flags & (SHGFI_SYSICONINDEX|SHGFI_ICON|SHGFI_ICONLOCATION))
631 psfi->iIcon=temppsfi.iIcon;
632 if(flags & SHGFI_ATTRIBUTES)
633 psfi->dwAttributes=temppsfi.dwAttributes;
634 if(flags & (SHGFI_DISPLAYNAME|SHGFI_ICONLOCATION))
636 WideCharToMultiByte(CP_ACP, 0, temppsfi.szDisplayName, -1,
637 psfi->szDisplayName, sizeof(psfi->szDisplayName), NULL, NULL);
639 if(flags & SHGFI_TYPENAME)
641 WideCharToMultiByte(CP_ACP, 0, temppsfi.szTypeName, -1,
642 psfi->szTypeName, sizeof(psfi->szTypeName), NULL, NULL);
646 if (!(flags & SHGFI_PIDL))
647 HeapFree(GetProcessHeap(), 0, temppath);
649 return ret;
652 /*************************************************************************
653 * DuplicateIcon [SHELL32.@]
655 HICON WINAPI DuplicateIcon( HINSTANCE hInstance, HICON hIcon)
657 ICONINFO IconInfo;
658 HICON hDupIcon = 0;
660 TRACE("%p %p\n", hInstance, hIcon);
662 if (GetIconInfo(hIcon, &IconInfo))
664 hDupIcon = CreateIconIndirect(&IconInfo);
666 /* clean up hbmMask and hbmColor */
667 DeleteObject(IconInfo.hbmMask);
668 DeleteObject(IconInfo.hbmColor);
671 return hDupIcon;
674 /*************************************************************************
675 * ExtractIconA [SHELL32.@]
677 HICON WINAPI ExtractIconA(HINSTANCE hInstance, LPCSTR lpszFile, UINT nIconIndex)
679 HICON ret;
680 INT len = MultiByteToWideChar(CP_ACP, 0, lpszFile, -1, NULL, 0);
681 LPWSTR lpwstrFile = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
683 TRACE("%p %s %d\n", hInstance, lpszFile, nIconIndex);
685 MultiByteToWideChar(CP_ACP, 0, lpszFile, -1, lpwstrFile, len);
686 ret = ExtractIconW(hInstance, lpwstrFile, nIconIndex);
687 HeapFree(GetProcessHeap(), 0, lpwstrFile);
689 return ret;
692 /*************************************************************************
693 * ExtractIconW [SHELL32.@]
695 HICON WINAPI ExtractIconW(HINSTANCE hInstance, LPCWSTR lpszFile, UINT nIconIndex)
697 HICON hIcon = NULL;
698 UINT ret;
699 UINT cx = GetSystemMetrics(SM_CXICON), cy = GetSystemMetrics(SM_CYICON);
701 TRACE("%p %s %d\n", hInstance, debugstr_w(lpszFile), nIconIndex);
703 if (nIconIndex == 0xFFFFFFFF)
705 ret = PrivateExtractIconsW(lpszFile, 0, cx, cy, NULL, NULL, 0, LR_DEFAULTCOLOR);
706 if (ret != 0xFFFFFFFF && ret)
707 return (HICON)ret;
708 return NULL;
710 else
711 ret = PrivateExtractIconsW(lpszFile, nIconIndex, cx, cy, &hIcon, NULL, 1, LR_DEFAULTCOLOR);
713 if (ret == 0xFFFFFFFF)
714 return (HICON)1;
715 else if (ret > 0 && hIcon)
716 return hIcon;
718 return NULL;
721 /*************************************************************************
722 * Printer_LoadIconsW [SHELL32.205]
724 VOID WINAPI Printer_LoadIconsW(LPCWSTR wsPrinterName, HICON * pLargeIcon, HICON * pSmallIcon)
726 INT iconindex=IDI_SHELL_PRINTER;
728 TRACE("(%s, %p, %p)\n", debugstr_w(wsPrinterName), pLargeIcon, pSmallIcon);
730 /* We should check if wsPrinterName is
731 1. the Default Printer or not
732 2. connected or not
733 3. a Local Printer or a Network-Printer
734 and use different Icons
736 if((wsPrinterName != NULL) && (wsPrinterName[0] != 0))
738 FIXME("(select Icon by PrinterName %s not implemented)\n", debugstr_w(wsPrinterName));
741 if(pLargeIcon != NULL)
742 *pLargeIcon = LoadImageW(shell32_hInstance,
743 (LPCWSTR) MAKEINTRESOURCE(iconindex), IMAGE_ICON,
744 0, 0, LR_DEFAULTCOLOR|LR_DEFAULTSIZE);
746 if(pSmallIcon != NULL)
747 *pSmallIcon = LoadImageW(shell32_hInstance,
748 (LPCWSTR) MAKEINTRESOURCE(iconindex), IMAGE_ICON,
749 16, 16, LR_DEFAULTCOLOR);
752 /*************************************************************************
753 * Printers_RegisterWindowW [SHELL32.213]
754 * used by "printui.dll":
755 * find the Window of the given Type for the specific Printer and
756 * return the already existent hwnd or open a new window
758 BOOL WINAPI Printers_RegisterWindowW(LPCWSTR wsPrinter, DWORD dwType,
759 HANDLE * phClassPidl, HWND * phwnd)
761 FIXME("(%s, %lx, %p (%p), %p (%p)) stub!\n", debugstr_w(wsPrinter), dwType,
762 phClassPidl, (phClassPidl != NULL) ? *(phClassPidl) : NULL,
763 phwnd, (phwnd != NULL) ? *(phwnd) : NULL);
765 return FALSE;
768 /*************************************************************************
769 * Printers_UnregisterWindow [SHELL32.214]
771 VOID WINAPI Printers_UnregisterWindow(HANDLE hClassPidl, HWND hwnd)
773 FIXME("(%p, %p) stub!\n", hClassPidl, hwnd);
776 /*************************************************************************/
778 typedef struct
780 LPCWSTR szApp;
781 LPCWSTR szOtherStuff;
782 HICON hIcon;
783 HFONT hFont;
784 } ABOUT_INFO;
786 #define IDC_STATIC_TEXT1 100
787 #define IDC_STATIC_TEXT2 101
788 #define IDC_LISTBOX 99
789 #define IDC_WINE_TEXT 98
791 #define DROP_FIELD_TOP (-15)
792 #define DROP_FIELD_HEIGHT 15
794 static BOOL __get_dropline( HWND hWnd, LPRECT lprect )
796 HWND hWndCtl = GetDlgItem(hWnd, IDC_WINE_TEXT);
798 if( hWndCtl )
800 GetWindowRect( hWndCtl, lprect );
801 MapWindowPoints( 0, hWnd, (LPPOINT)lprect, 2 );
802 lprect->bottom = (lprect->top += DROP_FIELD_TOP);
803 return TRUE;
805 return FALSE;
808 /*************************************************************************
809 * SHAppBarMessage [SHELL32.@]
811 UINT WINAPI SHAppBarMessage(DWORD msg, PAPPBARDATA data)
813 int width=data->rc.right - data->rc.left;
814 int height=data->rc.bottom - data->rc.top;
815 RECT rec=data->rc;
817 switch (msg)
819 case ABM_GETSTATE:
820 return ABS_ALWAYSONTOP | ABS_AUTOHIDE;
821 case ABM_GETTASKBARPOS:
822 GetWindowRect(data->hWnd, &rec);
823 data->rc=rec;
824 return TRUE;
825 case ABM_ACTIVATE:
826 SetActiveWindow(data->hWnd);
827 return TRUE;
828 case ABM_GETAUTOHIDEBAR:
829 data->hWnd=GetActiveWindow();
830 return TRUE;
831 case ABM_NEW:
832 SetWindowPos(data->hWnd,HWND_TOP,rec.left,rec.top,
833 width,height,SWP_SHOWWINDOW);
834 return TRUE;
835 case ABM_QUERYPOS:
836 GetWindowRect(data->hWnd, &(data->rc));
837 return TRUE;
838 case ABM_REMOVE:
839 FIXME("ABM_REMOVE broken\n");
840 /* FIXME: this is wrong; should it be DestroyWindow instead? */
841 /*CloseHandle(data->hWnd);*/
842 return TRUE;
843 case ABM_SETAUTOHIDEBAR:
844 SetWindowPos(data->hWnd,HWND_TOP,rec.left+1000,rec.top,
845 width,height,SWP_SHOWWINDOW);
846 return TRUE;
847 case ABM_SETPOS:
848 data->uEdge=(ABE_RIGHT | ABE_LEFT);
849 SetWindowPos(data->hWnd,HWND_TOP,data->rc.left,data->rc.top,
850 width,height,SWP_SHOWWINDOW);
851 return TRUE;
852 case ABM_WINDOWPOSCHANGED:
853 return TRUE;
855 return FALSE;
858 /*************************************************************************
859 * SHHelpShortcuts_RunDLLA [SHELL32.@]
862 DWORD WINAPI SHHelpShortcuts_RunDLLA(DWORD dwArg1, DWORD dwArg2, DWORD dwArg3, DWORD dwArg4)
864 FIXME("(%lx, %lx, %lx, %lx) stub!\n", dwArg1, dwArg2, dwArg3, dwArg4);
865 return 0;
868 /*************************************************************************
869 * SHHelpShortcuts_RunDLLA [SHELL32.@]
872 DWORD WINAPI SHHelpShortcuts_RunDLLW(DWORD dwArg1, DWORD dwArg2, DWORD dwArg3, DWORD dwArg4)
874 FIXME("(%lx, %lx, %lx, %lx) stub!\n", dwArg1, dwArg2, dwArg3, dwArg4);
875 return 0;
878 /*************************************************************************
879 * SHLoadInProc [SHELL32.@]
880 * Create an instance of specified object class from within
881 * the shell process and release it immediately
883 HRESULT WINAPI SHLoadInProc (REFCLSID rclsid)
885 void *ptr = NULL;
887 TRACE("%s\n", debugstr_guid(rclsid));
889 CoCreateInstance(rclsid, NULL, CLSCTX_INPROC_SERVER, &IID_IUnknown,&ptr);
890 if(ptr)
892 IUnknown * pUnk = ptr;
893 IUnknown_Release(pUnk);
894 return NOERROR;
896 return DISP_E_MEMBERNOTFOUND;
899 /*************************************************************************
900 * AboutDlgProc (internal)
902 INT_PTR CALLBACK AboutDlgProc( HWND hWnd, UINT msg, WPARAM wParam,
903 LPARAM lParam )
905 HWND hWndCtl;
907 TRACE("\n");
909 switch(msg)
911 case WM_INITDIALOG:
913 ABOUT_INFO *info = (ABOUT_INFO *)lParam;
914 WCHAR Template[512], AppTitle[512];
916 if (info)
918 const char* const *pstr = SHELL_Authors;
919 SendDlgItemMessageW(hWnd, stc1, STM_SETICON,(WPARAM)info->hIcon, 0);
920 GetWindowTextW( hWnd, Template, sizeof(Template)/sizeof(WCHAR) );
921 sprintfW( AppTitle, Template, info->szApp );
922 SetWindowTextW( hWnd, AppTitle );
923 SetWindowTextW( GetDlgItem(hWnd, IDC_STATIC_TEXT1), info->szApp );
924 SetWindowTextW( GetDlgItem(hWnd, IDC_STATIC_TEXT2), info->szOtherStuff );
925 hWndCtl = GetDlgItem(hWnd, IDC_LISTBOX);
926 SendMessageW( hWndCtl, WM_SETREDRAW, 0, 0 );
927 SendMessageW( hWndCtl, WM_SETFONT, (WPARAM)info->hFont, 0 );
928 while (*pstr)
930 WCHAR name[64];
931 /* authors list is in iso-8859-1 format */
932 MultiByteToWideChar( 28591, 0, *pstr, -1, name, sizeof(name)/sizeof(WCHAR) );
933 SendMessageW( hWndCtl, LB_ADDSTRING, (WPARAM)-1, (LPARAM)name );
934 pstr++;
936 SendMessageW( hWndCtl, WM_SETREDRAW, 1, 0 );
939 return 1;
941 case WM_PAINT:
943 RECT rect;
944 PAINTSTRUCT ps;
945 HDC hDC = BeginPaint( hWnd, &ps );
947 if (__get_dropline( hWnd, &rect ))
949 SelectObject( hDC, GetStockObject( BLACK_PEN ) );
950 MoveToEx( hDC, rect.left, rect.top, NULL );
951 LineTo( hDC, rect.right, rect.bottom );
953 EndPaint( hWnd, &ps );
955 break;
957 case WM_COMMAND:
958 if (wParam == IDOK || wParam == IDCANCEL)
960 EndDialog(hWnd, TRUE);
961 return TRUE;
963 break;
964 case WM_CLOSE:
965 EndDialog(hWnd, TRUE);
966 break;
969 return 0;
973 /*************************************************************************
974 * ShellAboutA [SHELL32.288]
976 BOOL WINAPI ShellAboutA( HWND hWnd, LPCSTR szApp, LPCSTR szOtherStuff, HICON hIcon )
978 BOOL ret;
979 LPWSTR appW = NULL, otherW = NULL;
980 int len;
982 if (szApp)
984 len = MultiByteToWideChar(CP_ACP, 0, szApp, -1, NULL, 0);
985 appW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
986 MultiByteToWideChar(CP_ACP, 0, szApp, -1, appW, len);
988 if (szOtherStuff)
990 len = MultiByteToWideChar(CP_ACP, 0, szOtherStuff, -1, NULL, 0);
991 otherW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
992 MultiByteToWideChar(CP_ACP, 0, szOtherStuff, -1, otherW, len);
995 ret = ShellAboutW(hWnd, appW, otherW, hIcon);
997 HeapFree(GetProcessHeap(), 0, otherW);
998 HeapFree(GetProcessHeap(), 0, appW);
999 return ret;
1003 /*************************************************************************
1004 * ShellAboutW [SHELL32.289]
1006 BOOL WINAPI ShellAboutW( HWND hWnd, LPCWSTR szApp, LPCWSTR szOtherStuff,
1007 HICON hIcon )
1009 ABOUT_INFO info;
1010 LOGFONTW logFont;
1011 HRSRC hRes;
1012 LPVOID template;
1013 BOOL bRet;
1014 static const WCHAR wszSHELL_ABOUT_MSGBOX[] =
1015 {'S','H','E','L','L','_','A','B','O','U','T','_','M','S','G','B','O','X',0};
1017 TRACE("\n");
1019 if(!(hRes = FindResourceW(shell32_hInstance, wszSHELL_ABOUT_MSGBOX, (LPWSTR)RT_DIALOG)))
1020 return FALSE;
1021 if(!(template = (LPVOID)LoadResource(shell32_hInstance, hRes)))
1022 return FALSE;
1023 info.szApp = szApp;
1024 info.szOtherStuff = szOtherStuff;
1025 info.hIcon = hIcon ? hIcon : LoadIconW( 0, (LPWSTR)IDI_WINLOGO );
1027 SystemParametersInfoW( SPI_GETICONTITLELOGFONT, 0, &logFont, 0 );
1028 info.hFont = CreateFontIndirectW( &logFont );
1030 bRet = DialogBoxIndirectParamW((HINSTANCE)GetWindowLongPtrW( hWnd, GWLP_HINSTANCE ),
1031 template, hWnd, AboutDlgProc, (LPARAM)&info );
1032 DeleteObject(info.hFont);
1033 return bRet;
1036 /*************************************************************************
1037 * FreeIconList (SHELL32.@)
1039 void WINAPI FreeIconList( DWORD dw )
1041 FIXME("%lx: stub\n",dw);
1045 /***********************************************************************
1046 * DllGetVersion [SHELL32.@]
1048 * Retrieves version information of the 'SHELL32.DLL'
1050 * PARAMS
1051 * pdvi [O] pointer to version information structure.
1053 * RETURNS
1054 * Success: S_OK
1055 * Failure: E_INVALIDARG
1057 * NOTES
1058 * Returns version of a shell32.dll from IE4.01 SP1.
1061 HRESULT WINAPI DllGetVersion (DLLVERSIONINFO *pdvi)
1063 /* FIXME: shouldn't these values come from the version resource? */
1064 if (pdvi->cbSize == sizeof(DLLVERSIONINFO) ||
1065 pdvi->cbSize == sizeof(DLLVERSIONINFO2))
1067 pdvi->dwMajorVersion = WINE_FILEVERSION_MAJOR;
1068 pdvi->dwMinorVersion = WINE_FILEVERSION_MINOR;
1069 pdvi->dwBuildNumber = WINE_FILEVERSION_BUILD;
1070 pdvi->dwPlatformID = WINE_FILEVERSION_PLATFORMID;
1071 if (pdvi->cbSize == sizeof(DLLVERSIONINFO2))
1073 DLLVERSIONINFO2 *pdvi2 = (DLLVERSIONINFO2 *)pdvi;
1075 pdvi2->dwFlags = 0;
1076 pdvi2->ullVersion = MAKEDLLVERULL(WINE_FILEVERSION_MAJOR,
1077 WINE_FILEVERSION_MINOR,
1078 WINE_FILEVERSION_BUILD,
1079 WINE_FILEVERSION_PLATFORMID);
1081 TRACE("%lu.%lu.%lu.%lu\n",
1082 pdvi->dwMajorVersion, pdvi->dwMinorVersion,
1083 pdvi->dwBuildNumber, pdvi->dwPlatformID);
1084 return S_OK;
1086 else
1088 WARN("wrong DLLVERSIONINFO size from app\n");
1089 return E_INVALIDARG;
1093 /*************************************************************************
1094 * global variables of the shell32.dll
1095 * all are once per process
1098 HINSTANCE shell32_hInstance = 0;
1099 HIMAGELIST ShellSmallIconList = 0;
1100 HIMAGELIST ShellBigIconList = 0;
1103 /*************************************************************************
1104 * SHELL32 DllMain
1106 * NOTES
1107 * calling oleinitialize here breaks sone apps.
1109 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
1111 TRACE("%p 0x%lx %p\n", hinstDLL, fdwReason, fImpLoad);
1113 switch (fdwReason)
1115 case DLL_PROCESS_ATTACH:
1116 shell32_hInstance = hinstDLL;
1117 DisableThreadLibraryCalls(shell32_hInstance);
1119 /* get full path to this DLL for IExtractIconW_fnGetIconLocation() */
1120 GetModuleFileNameW(hinstDLL, swShell32Name, MAX_PATH);
1121 swShell32Name[MAX_PATH - 1] = '\0';
1123 InitCommonControlsEx(NULL);
1125 SIC_Initialize();
1126 SYSTRAY_Init();
1127 InitChangeNotifications();
1128 break;
1130 case DLL_PROCESS_DETACH:
1131 shell32_hInstance = 0;
1132 SIC_Destroy();
1133 FreeChangeNotifications();
1134 break;
1136 return TRUE;
1139 /*************************************************************************
1140 * DllInstall [SHELL32.@]
1142 * PARAMETERS
1144 * BOOL bInstall - TRUE for install, FALSE for uninstall
1145 * LPCWSTR pszCmdLine - command line (unused by shell32?)
1148 HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline)
1150 FIXME("%s %s: stub\n", bInstall ? "TRUE":"FALSE", debugstr_w(cmdline));
1151 return S_OK; /* indicate success */
1154 /***********************************************************************
1155 * DllCanUnloadNow (SHELL32.@)
1157 HRESULT WINAPI DllCanUnloadNow(void)
1159 FIXME("stub\n");
1160 return S_FALSE;