[SHELL32_NEW]
[reactos.git] / dll / win32 / shell32 / shell32_main.cpp
1 /*
2 * Shell basics
3 *
4 * Copyright 1998 Marcus Meissner
5 * Copyright 1998 Juergen Schmied (jsch) * <juergen.schmied@metronet.de>
6 *
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.
11 *
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.
16 *
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
20 */
21
22 #include <precomp.h>
23 #include "shfldr_fs.h"
24 #include "shfldr_mycomp.h"
25 #include "shfldr_desktop.h"
26 #include "shellitem.h"
27 #include "shelllink.h"
28 #include "dragdrophelper.h"
29 #include "shfldr_cpanel.h"
30 #include "autocomplete.h"
31 #include "shfldr_mydocuments.h"
32 #include "shfldr_netplaces.h"
33 #include "shfldr_fonts.h"
34 #include "shfldr_printers.h"
35 #include "shfldr_admintools.h"
36 #include "shfldr_recyclebin.h"
37 #include "she_ocmenu.h"
38 #include "shv_item_new.h"
39 #include "startmenu.h"
40
41 WINE_DEFAULT_DEBUG_CHANNEL(shell);
42
43 const char * const SHELL_Authors[] = { "Copyright 1993-2009 WINE team", "Copyright 1998-2009 ReactOS Team", 0 };
44
45 #define MORE_DEBUG 1
46 /*************************************************************************
47 * CommandLineToArgvW [SHELL32.@]
48 *
49 * We must interpret the quotes in the command line to rebuild the argv
50 * array correctly:
51 * - arguments are separated by spaces or tabs
52 * - quotes serve as optional argument delimiters
53 * '"a b"' -> 'a b'
54 * - escaped quotes must be converted back to '"'
55 * '\"' -> '"'
56 * - an odd number of '\'s followed by '"' correspond to half that number
57 * of '\' followed by a '"' (extension of the above)
58 * '\\\"' -> '\"'
59 * '\\\\\"' -> '\\"'
60 * - an even number of '\'s followed by a '"' correspond to half that number
61 * of '\', plus a regular quote serving as an argument delimiter (which
62 * means it does not appear in the result)
63 * 'a\\"b c"' -> 'a\b c'
64 * 'a\\\\"b c"' -> 'a\\b c'
65 * - '\' that are not followed by a '"' are copied literally
66 * 'a\b' -> 'a\b'
67 * 'a\\b' -> 'a\\b'
68 *
69 * Note:
70 * '\t' == 0x0009
71 * ' ' == 0x0020
72 * '"' == 0x0022
73 * '\\' == 0x005c
74 */
75 LPWSTR* WINAPI CommandLineToArgvW(LPCWSTR lpCmdline, int* numargs)
76 {
77 DWORD argc;
78 LPWSTR *argv;
79 LPCWSTR cs;
80 LPWSTR arg,s,d;
81 LPWSTR cmdline;
82 int in_quotes,bcount;
83
84 if (*lpCmdline==0)
85 {
86 /* Return the path to the executable */
87 DWORD len, size=16;
88
89 argv = (LPWSTR *)LocalAlloc(LMEM_FIXED, size);
90 for (;;)
91 {
92 len = GetModuleFileNameW(0, (LPWSTR)(argv+1), (size-sizeof(LPWSTR))/sizeof(WCHAR));
93 if (!len)
94 {
95 LocalFree(argv);
96 return NULL;
97 }
98 if (len < size) break;
99 size*=2;
100 argv = (LPWSTR *)LocalReAlloc(argv, size, 0);
101 }
102 argv[0]=(LPWSTR)(argv+1);
103 if (numargs)
104 *numargs=1;
105
106 return argv;
107 }
108
109 /* to get a writable copy */
110 argc=0;
111 bcount=0;
112 in_quotes=0;
113 cs=lpCmdline;
114 while (1)
115 {
116 if (*cs==0 || ((*cs==0x0009 || *cs==0x0020) && !in_quotes))
117 {
118 /* space */
119 argc++;
120 /* skip the remaining spaces */
121 while (*cs==0x0009 || *cs==0x0020) {
122 cs++;
123 }
124 if (*cs==0)
125 break;
126 bcount=0;
127 continue;
128 }
129 else if (*cs==0x005c)
130 {
131 /* '\', count them */
132 bcount++;
133 }
134 else if ((*cs==0x0022) && ((bcount & 1)==0))
135 {
136 /* unescaped '"' */
137 in_quotes=!in_quotes;
138 bcount=0;
139 }
140 else
141 {
142 /* a regular character */
143 bcount=0;
144 }
145 cs++;
146 }
147 /* Allocate in a single lump, the string array, and the strings that go with it.
148 * This way the caller can make a single GlobalFree call to free both, as per MSDN.
149 */
150 argv = (LPWSTR *)LocalAlloc(LMEM_FIXED, argc*sizeof(LPWSTR)+(wcslen(lpCmdline)+1)*sizeof(WCHAR));
151 if (!argv)
152 return NULL;
153 cmdline=(LPWSTR)(argv+argc);
154 wcscpy(cmdline, lpCmdline);
155
156 argc=0;
157 bcount=0;
158 in_quotes=0;
159 arg=d=s=cmdline;
160 while (*s)
161 {
162 if ((*s==0x0009 || *s==0x0020) && !in_quotes)
163 {
164 /* Close the argument and copy it */
165 *d=0;
166 argv[argc++]=arg;
167
168 /* skip the remaining spaces */
169 do {
170 s++;
171 } while (*s==0x0009 || *s==0x0020);
172
173 /* Start with a new argument */
174 arg=d=s;
175 bcount=0;
176 }
177 else if (*s==0x005c)
178 {
179 /* '\\' */
180 *d++=*s++;
181 bcount++;
182 }
183 else if (*s==0x0022)
184 {
185 /* '"' */
186 if ((bcount & 1)==0)
187 {
188 /* Preceded by an even number of '\', this is half that
189 * number of '\', plus a quote which we erase.
190 */
191 d-=bcount/2;
192 in_quotes=!in_quotes;
193 s++;
194 }
195 else
196 {
197 /* Preceded by an odd number of '\', this is half that
198 * number of '\' followed by a '"'
199 */
200 d=d-bcount/2-1;
201 *d++='"';
202 s++;
203 }
204 bcount=0;
205 }
206 else
207 {
208 /* a regular character */
209 *d++=*s++;
210 bcount=0;
211 }
212 }
213 if (*arg)
214 {
215 *d='\0';
216 argv[argc++]=arg;
217 }
218 if (numargs)
219 *numargs=argc;
220
221 return argv;
222 }
223
224 static DWORD shgfi_get_exe_type(LPCWSTR szFullPath)
225 {
226 BOOL status = FALSE;
227 HANDLE hfile;
228 DWORD BinaryType;
229 IMAGE_DOS_HEADER mz_header;
230 IMAGE_NT_HEADERS nt;
231 DWORD len;
232 char magic[4];
233
234 status = GetBinaryTypeW (szFullPath, &BinaryType);
235 if (!status)
236 return 0;
237 if (BinaryType == SCS_DOS_BINARY || BinaryType == SCS_PIF_BINARY)
238 return 0x4d5a;
239
240 hfile = CreateFileW( szFullPath, GENERIC_READ, FILE_SHARE_READ,
241 NULL, OPEN_EXISTING, 0, 0 );
242 if ( hfile == INVALID_HANDLE_VALUE )
243 return 0;
244
245 /*
246 * The next section is adapted from MODULE_GetBinaryType, as we need
247 * to examine the image header to get OS and version information. We
248 * know from calling GetBinaryTypeA that the image is valid and either
249 * an NE or PE, so much error handling can be omitted.
250 * Seek to the start of the file and read the header information.
251 */
252
253 SetFilePointer( hfile, 0, NULL, SEEK_SET );
254 ReadFile( hfile, &mz_header, sizeof(mz_header), &len, NULL );
255
256 SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
257 ReadFile( hfile, magic, sizeof(magic), &len, NULL );
258 if ( *(DWORD*)magic == IMAGE_NT_SIGNATURE )
259 {
260 SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
261 ReadFile( hfile, &nt, sizeof(nt), &len, NULL );
262 CloseHandle( hfile );
263 /* DLL files are not executable and should return 0 */
264 if (nt.FileHeader.Characteristics & IMAGE_FILE_DLL)
265 return 0;
266 if (nt.OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_GUI)
267 {
268 return IMAGE_NT_SIGNATURE |
269 (nt.OptionalHeader.MajorSubsystemVersion << 24) |
270 (nt.OptionalHeader.MinorSubsystemVersion << 16);
271 }
272 return IMAGE_NT_SIGNATURE;
273 }
274 else if ( *(WORD*)magic == IMAGE_OS2_SIGNATURE )
275 {
276 IMAGE_OS2_HEADER ne;
277 SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
278 ReadFile( hfile, &ne, sizeof(ne), &len, NULL );
279 CloseHandle( hfile );
280 if (ne.ne_exetyp == 2)
281 return IMAGE_OS2_SIGNATURE | (ne.ne_expver << 16);
282 return 0;
283 }
284 CloseHandle( hfile );
285 return 0;
286 }
287
288 /*************************************************************************
289 * SHELL_IsShortcut [internal]
290 *
291 * Decide if an item id list points to a shell shortcut
292 */
293 BOOL SHELL_IsShortcut(LPCITEMIDLIST pidlLast)
294 {
295 char szTemp[MAX_PATH];
296 HKEY keyCls;
297 BOOL ret = FALSE;
298
299 if (_ILGetExtension(pidlLast, szTemp, MAX_PATH) &&
300 HCR_MapTypeToValueA(szTemp, szTemp, MAX_PATH, TRUE))
301 {
302 if (ERROR_SUCCESS == RegOpenKeyExA(HKEY_CLASSES_ROOT, szTemp, 0, KEY_QUERY_VALUE, &keyCls))
303 {
304 if (ERROR_SUCCESS == RegQueryValueExA(keyCls, "IsShortcut", NULL, NULL, NULL, NULL))
305 ret = TRUE;
306
307 RegCloseKey(keyCls);
308 }
309 }
310
311 return ret;
312 }
313
314 #define SHGFI_KNOWN_FLAGS \
315 (SHGFI_SMALLICON | SHGFI_OPENICON | SHGFI_SHELLICONSIZE | SHGFI_PIDL | \
316 SHGFI_USEFILEATTRIBUTES | SHGFI_ADDOVERLAYS | SHGFI_OVERLAYINDEX | \
317 SHGFI_ICON | SHGFI_DISPLAYNAME | SHGFI_TYPENAME | SHGFI_ATTRIBUTES | \
318 SHGFI_ICONLOCATION | SHGFI_EXETYPE | SHGFI_SYSICONINDEX | \
319 SHGFI_LINKOVERLAY | SHGFI_SELECTED | SHGFI_ATTR_SPECIFIED)
320
321 /*************************************************************************
322 * SHGetFileInfoW [SHELL32.@]
323 *
324 */
325 DWORD_PTR WINAPI SHGetFileInfoW(LPCWSTR path,DWORD dwFileAttributes,
326 SHFILEINFOW *psfi, UINT sizeofpsfi, UINT flags )
327 {
328 WCHAR szLocation[MAX_PATH], szFullPath[MAX_PATH];
329 int iIndex;
330 DWORD_PTR ret = TRUE;
331 DWORD dwAttributes = 0;
332 CComPtr<IShellFolder> psfParent;
333 CComPtr<IExtractIconW> pei;
334 LPITEMIDLIST pidlLast = NULL, pidl = NULL;
335 HRESULT hr = S_OK;
336 BOOL IconNotYetLoaded=TRUE;
337 UINT uGilFlags = 0;
338
339 TRACE("%s fattr=0x%x sfi=%p(attr=0x%08x) size=0x%x flags=0x%x\n",
340 (flags & SHGFI_PIDL)? "pidl" : debugstr_w(path), dwFileAttributes,
341 psfi, psfi->dwAttributes, sizeofpsfi, flags);
342
343 if ( (flags & SHGFI_USEFILEATTRIBUTES) &&
344 (flags & (SHGFI_ATTRIBUTES|SHGFI_EXETYPE|SHGFI_PIDL)))
345 return FALSE;
346 if (!path)
347 return FALSE;
348
349 /* windows initializes these values regardless of the flags */
350 if (psfi != NULL)
351 {
352 psfi->szDisplayName[0] = '\0';
353 psfi->szTypeName[0] = '\0';
354 psfi->iIcon = 0;
355 }
356
357 if (!(flags & SHGFI_PIDL))
358 {
359 /* SHGetFileInfo should work with absolute and relative paths */
360 if (PathIsRelativeW(path))
361 {
362 GetCurrentDirectoryW(MAX_PATH, szLocation);
363 PathCombineW(szFullPath, szLocation, path);
364 }
365 else
366 {
367 lstrcpynW(szFullPath, path, MAX_PATH);
368 }
369 }
370
371 if (flags & SHGFI_EXETYPE)
372 {
373 if (flags != SHGFI_EXETYPE)
374 return 0;
375 return shgfi_get_exe_type(szFullPath);
376 }
377
378 /*
379 * psfi is NULL normally to query EXE type. If it is NULL, none of the
380 * below makes sense anyway. Windows allows this and just returns FALSE
381 */
382 if (psfi == NULL)
383 return FALSE;
384
385 /*
386 * translate the path into a pidl only when SHGFI_USEFILEATTRIBUTES
387 * is not specified.
388 * The pidl functions fail on not existing file names
389 */
390
391 if (flags & SHGFI_PIDL)
392 {
393 pidl = ILClone((LPCITEMIDLIST)path);
394 }
395 else if (!(flags & SHGFI_USEFILEATTRIBUTES))
396 {
397 hr = SHILCreateFromPathW(szFullPath, &pidl, &dwAttributes);
398 }
399
400 if ((flags & SHGFI_PIDL) || !(flags & SHGFI_USEFILEATTRIBUTES))
401 {
402 /* get the parent shellfolder */
403 if (pidl)
404 {
405 hr = SHBindToParent( pidl, IID_IShellFolder, (LPVOID*)&psfParent,
406 (LPCITEMIDLIST*)&pidlLast );
407 if (SUCCEEDED(hr))
408 pidlLast = ILClone(pidlLast);
409 ILFree(pidl);
410 }
411 else
412 {
413 ERR("pidl is null!\n");
414 return FALSE;
415 }
416 }
417
418 /* get the attributes of the child */
419 if (SUCCEEDED(hr) && (flags & SHGFI_ATTRIBUTES))
420 {
421 if (!(flags & SHGFI_ATTR_SPECIFIED))
422 {
423 psfi->dwAttributes = 0xffffffff;
424 }
425 if (psfParent != NULL)
426 psfParent->GetAttributesOf(1, (LPCITEMIDLIST*)&pidlLast,
427 &(psfi->dwAttributes) );
428 }
429
430 /* get the displayname */
431 if (SUCCEEDED(hr) && (flags & SHGFI_DISPLAYNAME))
432 {
433 if (flags & SHGFI_USEFILEATTRIBUTES)
434 {
435 wcscpy (psfi->szDisplayName, PathFindFileNameW(szFullPath));
436 }
437 else
438 {
439 STRRET str;
440 hr = psfParent->GetDisplayNameOf(pidlLast,
441 SHGDN_INFOLDER, &str);
442 StrRetToStrNW (psfi->szDisplayName, MAX_PATH, &str, pidlLast);
443 }
444 }
445
446 /* get the type name */
447 if (SUCCEEDED(hr) && (flags & SHGFI_TYPENAME))
448 {
449 static const WCHAR szFile[] = { 'F','i','l','e',0 };
450 static const WCHAR szDashFile[] = { '-','f','i','l','e',0 };
451
452 if (!(flags & SHGFI_USEFILEATTRIBUTES))
453 {
454 char ftype[80];
455
456 _ILGetFileType(pidlLast, ftype, 80);
457 MultiByteToWideChar(CP_ACP, 0, ftype, -1, psfi->szTypeName, 80 );
458 }
459 else
460 {
461 if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
462 wcscat (psfi->szTypeName, szFile);
463 else
464 {
465 WCHAR sTemp[64];
466
467 wcscpy(sTemp,PathFindExtensionW(szFullPath));
468 if (!( HCR_MapTypeToValueW(sTemp, sTemp, 64, TRUE) &&
469 HCR_MapTypeToValueW(sTemp, psfi->szTypeName, 80, FALSE )))
470 {
471 lstrcpynW (psfi->szTypeName, sTemp, 64);
472 wcscat (psfi->szTypeName, szDashFile);
473 }
474 }
475 }
476 }
477
478 /* ### icons ###*/
479 if (flags & SHGFI_OPENICON)
480 uGilFlags |= GIL_OPENICON;
481
482 if (flags & SHGFI_LINKOVERLAY)
483 uGilFlags |= GIL_FORSHORTCUT;
484 else if ((flags&SHGFI_ADDOVERLAYS) ||
485 (flags&(SHGFI_ICON|SHGFI_SMALLICON))==SHGFI_ICON)
486 {
487 if (SHELL_IsShortcut(pidlLast))
488 uGilFlags |= GIL_FORSHORTCUT;
489 }
490
491 if (flags & SHGFI_OVERLAYINDEX)
492 FIXME("SHGFI_OVERLAYINDEX unhandled\n");
493
494 if (flags & SHGFI_SELECTED)
495 FIXME("set icon to selected, stub\n");
496
497 if (flags & SHGFI_SHELLICONSIZE)
498 FIXME("set icon to shell size, stub\n");
499
500 /* get the iconlocation */
501 if (SUCCEEDED(hr) && (flags & SHGFI_ICONLOCATION ))
502 {
503 UINT uDummy,uFlags;
504
505 if (flags & SHGFI_USEFILEATTRIBUTES)
506 {
507 if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
508 {
509 wcscpy(psfi->szDisplayName, swShell32Name);
510 psfi->iIcon = -IDI_SHELL_FOLDER;
511 }
512 else
513 {
514 WCHAR* szExt;
515 static const WCHAR p1W[] = {'%','1',0};
516 WCHAR sTemp [MAX_PATH];
517
518 szExt = PathFindExtensionW(szFullPath);
519 TRACE("szExt=%s\n", debugstr_w(szExt));
520 if ( szExt &&
521 HCR_MapTypeToValueW(szExt, sTemp, MAX_PATH, TRUE) &&
522 HCR_GetDefaultIconW(sTemp, sTemp, MAX_PATH, &psfi->iIcon))
523 {
524 if (lstrcmpW(p1W, sTemp))
525 wcscpy(psfi->szDisplayName, sTemp);
526 else
527 {
528 /* the icon is in the file */
529 wcscpy(psfi->szDisplayName, szFullPath);
530 }
531 }
532 else
533 ret = FALSE;
534 }
535 }
536 else
537 {
538 hr = psfParent->GetUIObjectOf(0, 1,
539 (LPCITEMIDLIST*)&pidlLast, IID_IExtractIconW,
540 &uDummy, (LPVOID*)&pei);
541 if (SUCCEEDED(hr))
542 {
543 hr = pei->GetIconLocation(uGilFlags,
544 szLocation, MAX_PATH, &iIndex, &uFlags);
545
546 if (uFlags & GIL_NOTFILENAME)
547 ret = FALSE;
548 else
549 {
550 wcscpy (psfi->szDisplayName, szLocation);
551 psfi->iIcon = iIndex;
552 }
553 }
554 }
555 }
556
557 /* get icon index (or load icon)*/
558 if (SUCCEEDED(hr) && (flags & (SHGFI_ICON | SHGFI_SYSICONINDEX)))
559 {
560 if (flags & SHGFI_USEFILEATTRIBUTES && !(flags & SHGFI_PIDL))
561 {
562 WCHAR sTemp [MAX_PATH];
563 WCHAR * szExt;
564 int icon_idx=0;
565
566 lstrcpynW(sTemp, szFullPath, MAX_PATH);
567
568 if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
569 psfi->iIcon = SIC_GetIconIndex(swShell32Name, -IDI_SHELL_FOLDER, 0);
570 else
571 {
572 static const WCHAR p1W[] = {'%','1',0};
573
574 psfi->iIcon = 0;
575 szExt = PathFindExtensionW(sTemp);
576 if ( szExt &&
577 HCR_MapTypeToValueW(szExt, sTemp, MAX_PATH, TRUE) &&
578 HCR_GetDefaultIconW(sTemp, sTemp, MAX_PATH, &icon_idx))
579 {
580 if (!lstrcmpW(p1W,sTemp)) /* icon is in the file */
581 wcscpy(sTemp, szFullPath);
582
583 if (flags & SHGFI_SYSICONINDEX)
584 {
585 psfi->iIcon = SIC_GetIconIndex(sTemp,icon_idx,0);
586 if (psfi->iIcon == -1)
587 psfi->iIcon = 0;
588 }
589 else
590 {
591 UINT ret;
592 if (flags & SHGFI_SMALLICON)
593 ret = PrivateExtractIconsW( sTemp,icon_idx,
594 GetSystemMetrics( SM_CXSMICON ),
595 GetSystemMetrics( SM_CYSMICON ),
596 &psfi->hIcon, 0, 1, 0);
597 else
598 ret = PrivateExtractIconsW( sTemp, icon_idx,
599 GetSystemMetrics( SM_CXICON),
600 GetSystemMetrics( SM_CYICON),
601 &psfi->hIcon, 0, 1, 0);
602 if (ret != 0 && ret != 0xFFFFFFFF)
603 {
604 IconNotYetLoaded=FALSE;
605 psfi->iIcon = icon_idx;
606 }
607 }
608 }
609 }
610 }
611 else
612 {
613 if (!(PidlToSicIndex(psfParent, pidlLast, !(flags & SHGFI_SMALLICON),
614 uGilFlags, &(psfi->iIcon))))
615 {
616 ret = FALSE;
617 }
618 }
619 if (ret && (flags & SHGFI_SYSICONINDEX))
620 {
621 if (flags & SHGFI_SMALLICON)
622 ret = (DWORD_PTR) ShellSmallIconList;
623 else
624 ret = (DWORD_PTR) ShellBigIconList;
625 }
626 }
627
628 /* icon handle */
629 if (SUCCEEDED(hr) && (flags & SHGFI_ICON) && IconNotYetLoaded)
630 {
631 if (flags & SHGFI_SMALLICON)
632 psfi->hIcon = ImageList_GetIcon( ShellSmallIconList, psfi->iIcon, ILD_NORMAL);
633 else
634 psfi->hIcon = ImageList_GetIcon( ShellBigIconList, psfi->iIcon, ILD_NORMAL);
635 }
636
637 if (flags & ~SHGFI_KNOWN_FLAGS)
638 FIXME("unknown flags %08x\n", flags & ~SHGFI_KNOWN_FLAGS);
639
640 if (hr != S_OK)
641 ret = FALSE;
642
643 SHFree(pidlLast);
644
645 #ifdef MORE_DEBUG
646 TRACE ("icon=%p index=0x%08x attr=0x%08x name=%s type=%s ret=0x%08lx\n",
647 psfi->hIcon, psfi->iIcon, psfi->dwAttributes,
648 debugstr_w(psfi->szDisplayName), debugstr_w(psfi->szTypeName), ret);
649 #endif
650
651 return ret;
652 }
653
654 /*************************************************************************
655 * SHGetFileInfoA [SHELL32.@]
656 *
657 * Note:
658 * MSVBVM60.__vbaNew2 expects this function to return a value in range
659 * 1 .. 0x7fff when the function succeeds and flags does not contain
660 * SHGFI_EXETYPE or SHGFI_SYSICONINDEX (see bug 7701)
661 */
662 DWORD_PTR WINAPI SHGetFileInfoA(LPCSTR path,DWORD dwFileAttributes,
663 SHFILEINFOA *psfi, UINT sizeofpsfi,
664 UINT flags )
665 {
666 INT len;
667 LPWSTR temppath = NULL;
668 LPCWSTR pathW;
669 DWORD ret;
670 SHFILEINFOW temppsfi;
671
672 if (flags & SHGFI_PIDL)
673 {
674 /* path contains a pidl */
675 pathW = (LPCWSTR)path;
676 }
677 else
678 {
679 len = MultiByteToWideChar(CP_ACP, 0, path, -1, NULL, 0);
680 temppath = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
681 MultiByteToWideChar(CP_ACP, 0, path, -1, temppath, len);
682 pathW = temppath;
683 }
684
685 if (psfi && (flags & SHGFI_ATTR_SPECIFIED))
686 temppsfi.dwAttributes=psfi->dwAttributes;
687
688 if (psfi == NULL)
689 ret = SHGetFileInfoW(pathW, dwFileAttributes, NULL, sizeof(temppsfi), flags);
690 else
691 ret = SHGetFileInfoW(pathW, dwFileAttributes, &temppsfi, sizeof(temppsfi), flags);
692
693 if (psfi)
694 {
695 if(flags & SHGFI_ICON)
696 psfi->hIcon=temppsfi.hIcon;
697 if(flags & (SHGFI_SYSICONINDEX|SHGFI_ICON|SHGFI_ICONLOCATION))
698 psfi->iIcon=temppsfi.iIcon;
699 if(flags & SHGFI_ATTRIBUTES)
700 psfi->dwAttributes=temppsfi.dwAttributes;
701 if(flags & (SHGFI_DISPLAYNAME|SHGFI_ICONLOCATION))
702 {
703 WideCharToMultiByte(CP_ACP, 0, temppsfi.szDisplayName, -1,
704 psfi->szDisplayName, sizeof(psfi->szDisplayName), NULL, NULL);
705 }
706 if(flags & SHGFI_TYPENAME)
707 {
708 WideCharToMultiByte(CP_ACP, 0, temppsfi.szTypeName, -1,
709 psfi->szTypeName, sizeof(psfi->szTypeName), NULL, NULL);
710 }
711 }
712
713 HeapFree(GetProcessHeap(), 0, temppath);
714
715 return ret;
716 }
717
718 /*************************************************************************
719 * DuplicateIcon [SHELL32.@]
720 */
721 EXTERN_C HICON WINAPI DuplicateIcon( HINSTANCE hInstance, HICON hIcon)
722 {
723 ICONINFO IconInfo;
724 HICON hDupIcon = 0;
725
726 TRACE("%p %p\n", hInstance, hIcon);
727
728 if (GetIconInfo(hIcon, &IconInfo))
729 {
730 hDupIcon = CreateIconIndirect(&IconInfo);
731
732 /* clean up hbmMask and hbmColor */
733 DeleteObject(IconInfo.hbmMask);
734 DeleteObject(IconInfo.hbmColor);
735 }
736
737 return hDupIcon;
738 }
739
740 /*************************************************************************
741 * ExtractIconA [SHELL32.@]
742 */
743 HICON WINAPI ExtractIconA(HINSTANCE hInstance, LPCSTR lpszFile, UINT nIconIndex)
744 {
745 HICON ret;
746 INT len = MultiByteToWideChar(CP_ACP, 0, lpszFile, -1, NULL, 0);
747 LPWSTR lpwstrFile = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
748
749 TRACE("%p %s %d\n", hInstance, lpszFile, nIconIndex);
750
751 MultiByteToWideChar(CP_ACP, 0, lpszFile, -1, lpwstrFile, len);
752 ret = ExtractIconW(hInstance, lpwstrFile, nIconIndex);
753 HeapFree(GetProcessHeap(), 0, lpwstrFile);
754
755 return ret;
756 }
757
758 /*************************************************************************
759 * ExtractIconW [SHELL32.@]
760 */
761 HICON WINAPI ExtractIconW(HINSTANCE hInstance, LPCWSTR lpszFile, UINT nIconIndex)
762 {
763 HICON hIcon = NULL;
764 UINT ret;
765 UINT cx = GetSystemMetrics(SM_CXICON), cy = GetSystemMetrics(SM_CYICON);
766
767 TRACE("%p %s %d\n", hInstance, debugstr_w(lpszFile), nIconIndex);
768
769 if (nIconIndex == 0xFFFFFFFF)
770 {
771 ret = PrivateExtractIconsW(lpszFile, 0, cx, cy, NULL, NULL, 0, LR_DEFAULTCOLOR);
772 if (ret != 0xFFFFFFFF && ret)
773 return (HICON)(UINT_PTR)ret;
774 return NULL;
775 }
776 else
777 ret = PrivateExtractIconsW(lpszFile, nIconIndex, cx, cy, &hIcon, NULL, 1, LR_DEFAULTCOLOR);
778
779 if (ret == 0xFFFFFFFF)
780 return (HICON)1;
781 else if (ret > 0 && hIcon)
782 return hIcon;
783
784 return NULL;
785 }
786
787 /*************************************************************************
788 * Printer_LoadIconsW [SHELL32.205]
789 */
790 EXTERN_C VOID WINAPI Printer_LoadIconsW(LPCWSTR wsPrinterName, HICON * pLargeIcon, HICON * pSmallIcon)
791 {
792 INT iconindex=IDI_SHELL_PRINTERS_FOLDER;
793
794 TRACE("(%s, %p, %p)\n", debugstr_w(wsPrinterName), pLargeIcon, pSmallIcon);
795
796 /* We should check if wsPrinterName is
797 1. the Default Printer or not
798 2. connected or not
799 3. a Local Printer or a Network-Printer
800 and use different Icons
801 */
802 if((wsPrinterName != NULL) && (wsPrinterName[0] != 0))
803 {
804 FIXME("(select Icon by PrinterName %s not implemented)\n", debugstr_w(wsPrinterName));
805 }
806
807 if(pLargeIcon != NULL)
808 *pLargeIcon = (HICON)LoadImageW(shell32_hInstance,
809 (LPCWSTR) MAKEINTRESOURCE(iconindex), IMAGE_ICON,
810 0, 0, LR_DEFAULTCOLOR|LR_DEFAULTSIZE);
811
812 if(pSmallIcon != NULL)
813 *pSmallIcon = (HICON)LoadImageW(shell32_hInstance,
814 (LPCWSTR) MAKEINTRESOURCE(iconindex), IMAGE_ICON,
815 16, 16, LR_DEFAULTCOLOR);
816 }
817
818 /*************************************************************************
819 * Printers_RegisterWindowW [SHELL32.213]
820 * used by "printui.dll":
821 * find the Window of the given Type for the specific Printer and
822 * return the already existent hwnd or open a new window
823 */
824 EXTERN_C BOOL WINAPI Printers_RegisterWindowW(LPCWSTR wsPrinter, DWORD dwType,
825 HANDLE * phClassPidl, HWND * phwnd)
826 {
827 FIXME("(%s, %x, %p (%p), %p (%p)) stub!\n", debugstr_w(wsPrinter), dwType,
828 phClassPidl, (phClassPidl != NULL) ? *(phClassPidl) : NULL,
829 phwnd, (phwnd != NULL) ? *(phwnd) : NULL);
830
831 return FALSE;
832 }
833
834 /*************************************************************************
835 * Printers_UnregisterWindow [SHELL32.214]
836 */
837 EXTERN_C VOID WINAPI Printers_UnregisterWindow(HANDLE hClassPidl, HWND hwnd)
838 {
839 FIXME("(%p, %p) stub!\n", hClassPidl, hwnd);
840 }
841
842 /*************************************************************************/
843
844 typedef struct
845 {
846 LPCWSTR szApp;
847 LPCWSTR szOtherStuff;
848 HICON hIcon;
849 } ABOUT_INFO;
850
851 #define DROP_FIELD_TOP (-15)
852 #define DROP_FIELD_HEIGHT 15
853
854 /*************************************************************************
855 * SHAppBarMessage [SHELL32.@]
856 */
857 UINT_PTR WINAPI SHAppBarMessage(DWORD msg, PAPPBARDATA data)
858 {
859 int width=data->rc.right - data->rc.left;
860 int height=data->rc.bottom - data->rc.top;
861 RECT rec=data->rc;
862
863 TRACE("msg=%d, data={cb=%d, hwnd=%p, callback=%x, edge=%d, rc=%s, lparam=%lx}\n",
864 msg, data->cbSize, data->hWnd, data->uCallbackMessage, data->uEdge,
865 wine_dbgstr_rect(&data->rc), data->lParam);
866
867 switch (msg)
868 {
869 case ABM_GETSTATE:
870 return ABS_ALWAYSONTOP | ABS_AUTOHIDE;
871 case ABM_GETTASKBARPOS:
872 GetWindowRect(data->hWnd, &rec);
873 data->rc=rec;
874 return TRUE;
875 case ABM_ACTIVATE:
876 SetActiveWindow(data->hWnd);
877 return TRUE;
878 case ABM_GETAUTOHIDEBAR:
879 return 0; /* pretend there is no autohide bar */
880 case ABM_NEW:
881 /* cbSize, hWnd, and uCallbackMessage are used. All other ignored */
882 SetWindowPos(data->hWnd,HWND_TOP,0,0,0,0,SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE);
883 return TRUE;
884 case ABM_QUERYPOS:
885 GetWindowRect(data->hWnd, &(data->rc));
886 return TRUE;
887 case ABM_REMOVE:
888 FIXME("ABM_REMOVE broken\n");
889 /* FIXME: this is wrong; should it be DestroyWindow instead? */
890 /*CloseHandle(data->hWnd);*/
891 return TRUE;
892 case ABM_SETAUTOHIDEBAR:
893 SetWindowPos(data->hWnd,HWND_TOP,rec.left+1000,rec.top,
894 width,height,SWP_SHOWWINDOW);
895 return TRUE;
896 case ABM_SETPOS:
897 data->uEdge=(ABE_RIGHT | ABE_LEFT);
898 SetWindowPos(data->hWnd,HWND_TOP,data->rc.left,data->rc.top,
899 width,height,SWP_SHOWWINDOW);
900 return TRUE;
901 case ABM_WINDOWPOSCHANGED:
902 return TRUE;
903 }
904 return FALSE;
905 }
906
907 /*************************************************************************
908 * SHHelpShortcuts_RunDLLA [SHELL32.@]
909 *
910 */
911 EXTERN_C DWORD WINAPI SHHelpShortcuts_RunDLLA(DWORD dwArg1, DWORD dwArg2, DWORD dwArg3, DWORD dwArg4)
912 {
913 FIXME("(%x, %x, %x, %x) stub!\n", dwArg1, dwArg2, dwArg3, dwArg4);
914 return 0;
915 }
916
917 /*************************************************************************
918 * SHHelpShortcuts_RunDLLA [SHELL32.@]
919 *
920 */
921 EXTERN_C DWORD WINAPI SHHelpShortcuts_RunDLLW(DWORD dwArg1, DWORD dwArg2, DWORD dwArg3, DWORD dwArg4)
922 {
923 FIXME("(%x, %x, %x, %x) stub!\n", dwArg1, dwArg2, dwArg3, dwArg4);
924 return 0;
925 }
926
927 /*************************************************************************
928 * SHLoadInProc [SHELL32.@]
929 * Create an instance of specified object class from within
930 * the shell process and release it immediately
931 */
932 EXTERN_C HRESULT WINAPI SHLoadInProc (REFCLSID rclsid)
933 {
934 CComPtr<IUnknown> ptr;
935
936 TRACE("%s\n", debugstr_guid(&rclsid));
937
938 CoCreateInstance(rclsid, NULL, CLSCTX_INPROC_SERVER, IID_IUnknown, (void **)&ptr);
939 if (ptr)
940 return NOERROR;
941 return DISP_E_MEMBERNOTFOUND;
942 }
943
944 static VOID SetRegTextData(HWND hWnd, HKEY hKey, LPCWSTR Value, UINT uID)
945 {
946 DWORD dwBufferSize;
947 DWORD dwType;
948 LPWSTR lpBuffer;
949
950 if( RegQueryValueExW(hKey, Value, NULL, &dwType, NULL, &dwBufferSize) == ERROR_SUCCESS )
951 {
952 if(dwType == REG_SZ)
953 {
954 lpBuffer = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, dwBufferSize);
955
956 if(lpBuffer)
957 {
958 if( RegQueryValueExW(hKey, Value, NULL, &dwType, (LPBYTE)lpBuffer, &dwBufferSize) == ERROR_SUCCESS )
959 {
960 SetDlgItemTextW(hWnd, uID, lpBuffer);
961 }
962
963 HeapFree(GetProcessHeap(), 0, lpBuffer);
964 }
965 }
966 }
967 }
968
969 INT_PTR CALLBACK AboutAuthorsDlgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
970 {
971 switch(msg)
972 {
973 case WM_INITDIALOG:
974 {
975 const char* const *pstr = SHELL_Authors;
976
977 // Add the authors to the list
978 SendDlgItemMessageW( hWnd, IDC_SHELL_ABOUT_AUTHORS_LISTBOX, WM_SETREDRAW, FALSE, 0 );
979
980 while (*pstr)
981 {
982 WCHAR name[64];
983
984 /* authors list is in utf-8 format */
985 MultiByteToWideChar( CP_UTF8, 0, *pstr, -1, name, sizeof(name)/sizeof(WCHAR) );
986 SendDlgItemMessageW( hWnd, IDC_SHELL_ABOUT_AUTHORS_LISTBOX, LB_ADDSTRING, (WPARAM)-1, (LPARAM)name );
987 pstr++;
988 }
989
990 SendDlgItemMessageW( hWnd, IDC_SHELL_ABOUT_AUTHORS_LISTBOX, WM_SETREDRAW, TRUE, 0 );
991
992 return TRUE;
993 }
994 }
995
996 return FALSE;
997 }
998 /*************************************************************************
999 * AboutDlgProc (internal)
1000 */
1001 INT_PTR CALLBACK AboutDlgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
1002 {
1003 static DWORD cxLogoBmp;
1004 static DWORD cyLogoBmp;
1005 static HBITMAP hLogoBmp;
1006 static HWND hWndAuthors;
1007
1008 switch(msg)
1009 {
1010 case WM_INITDIALOG:
1011 {
1012 ABOUT_INFO *info = (ABOUT_INFO *)lParam;
1013
1014 if (info)
1015 {
1016 const WCHAR szRegKey[] = L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion";
1017 HKEY hRegKey;
1018 MEMORYSTATUSEX MemStat;
1019 WCHAR szAppTitle[512];
1020 WCHAR szAppTitleTemplate[512];
1021 WCHAR szAuthorsText[20];
1022
1023 // Preload the ROS bitmap
1024 hLogoBmp = (HBITMAP)LoadImage(shell32_hInstance, MAKEINTRESOURCE(IDB_SHELL_ABOUT_LOGO_24BPP), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
1025
1026 if(hLogoBmp)
1027 {
1028 BITMAP bmpLogo;
1029
1030 GetObject( hLogoBmp, sizeof(BITMAP), &bmpLogo );
1031
1032 cxLogoBmp = bmpLogo.bmWidth;
1033 cyLogoBmp = bmpLogo.bmHeight;
1034 }
1035
1036 // Set App-specific stuff (icon, app name, szOtherStuff string)
1037 SendDlgItemMessageW(hWnd, IDC_SHELL_ABOUT_ICON, STM_SETICON, (WPARAM)info->hIcon, 0);
1038
1039 GetWindowTextW( hWnd, szAppTitleTemplate, sizeof(szAppTitleTemplate) / sizeof(WCHAR) );
1040 swprintf( szAppTitle, szAppTitleTemplate, info->szApp );
1041 SetWindowTextW( hWnd, szAppTitle );
1042
1043 SetDlgItemTextW( hWnd, IDC_SHELL_ABOUT_APPNAME, info->szApp );
1044 SetDlgItemTextW( hWnd, IDC_SHELL_ABOUT_OTHERSTUFF, info->szOtherStuff );
1045
1046 // Set the registered user and organization name
1047 if(RegOpenKeyExW( HKEY_LOCAL_MACHINE, szRegKey, 0, KEY_QUERY_VALUE, &hRegKey ) == ERROR_SUCCESS)
1048 {
1049 SetRegTextData( hWnd, hRegKey, L"RegisteredOwner", IDC_SHELL_ABOUT_REG_USERNAME );
1050 SetRegTextData( hWnd, hRegKey, L"RegisteredOrganization", IDC_SHELL_ABOUT_REG_ORGNAME );
1051
1052 RegCloseKey( hRegKey );
1053 }
1054
1055 // Set the value for the installed physical memory
1056 MemStat.dwLength = sizeof(MemStat);
1057 if( GlobalMemoryStatusEx(&MemStat) )
1058 {
1059 WCHAR szBuf[12];
1060
1061 if (MemStat.ullTotalPhys > 1024 * 1024 * 1024)
1062 {
1063 double dTotalPhys;
1064 WCHAR szDecimalSeparator[4];
1065 WCHAR szUnits[3];
1066
1067 // We're dealing with GBs or more
1068 MemStat.ullTotalPhys /= 1024 * 1024;
1069
1070 if (MemStat.ullTotalPhys > 1024 * 1024)
1071 {
1072 // We're dealing with TBs or more
1073 MemStat.ullTotalPhys /= 1024;
1074
1075 if (MemStat.ullTotalPhys > 1024 * 1024)
1076 {
1077 // We're dealing with PBs or more
1078 MemStat.ullTotalPhys /= 1024;
1079
1080 dTotalPhys = (double)MemStat.ullTotalPhys / 1024;
1081 wcscpy( szUnits, L"PB" );
1082 }
1083 else
1084 {
1085 dTotalPhys = (double)MemStat.ullTotalPhys / 1024;
1086 wcscpy( szUnits, L"TB" );
1087 }
1088 }
1089 else
1090 {
1091 dTotalPhys = (double)MemStat.ullTotalPhys / 1024;
1092 wcscpy( szUnits, L"GB" );
1093 }
1094
1095 // We need the decimal point of the current locale to display the RAM size correctly
1096 if( GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, szDecimalSeparator, sizeof(szDecimalSeparator) / sizeof(WCHAR)) > 0)
1097 {
1098 UCHAR uDecimals;
1099 UINT uIntegral;
1100
1101 uIntegral = (UINT)dTotalPhys;
1102 uDecimals = (UCHAR)((UINT)(dTotalPhys * 100) - uIntegral * 100);
1103
1104 // Display the RAM size with 2 decimals
1105 swprintf(szBuf, L"%u%s%02u %s", uIntegral, szDecimalSeparator, uDecimals, szUnits);
1106 }
1107 }
1108 else
1109 {
1110 // We're dealing with MBs, don't show any decimals
1111 swprintf( szBuf, L"%u MB", (UINT)MemStat.ullTotalPhys / 1024 / 1024 );
1112 }
1113
1114 SetDlgItemTextW( hWnd, IDC_SHELL_ABOUT_PHYSMEM, szBuf);
1115 }
1116
1117 // Add the Authors dialog
1118 hWndAuthors = CreateDialogW( shell32_hInstance, MAKEINTRESOURCEW(IDD_SHELL_ABOUT_AUTHORS), hWnd, AboutAuthorsDlgProc );
1119 LoadStringW( shell32_hInstance, IDS_SHELL_ABOUT_AUTHORS, szAuthorsText, sizeof(szAuthorsText) / sizeof(WCHAR) );
1120 SetDlgItemTextW( hWnd, IDC_SHELL_ABOUT_AUTHORS, szAuthorsText );
1121 }
1122
1123 return TRUE;
1124 }
1125
1126 case WM_PAINT:
1127 {
1128 if(hLogoBmp)
1129 {
1130 PAINTSTRUCT ps;
1131 HDC hdc;
1132 HDC hdcMem;
1133
1134 hdc = BeginPaint(hWnd, &ps);
1135 hdcMem = CreateCompatibleDC(hdc);
1136
1137 if(hdcMem)
1138 {
1139 SelectObject(hdcMem, hLogoBmp);
1140 BitBlt(hdc, 0, 0, cxLogoBmp, cyLogoBmp, hdcMem, 0, 0, SRCCOPY);
1141
1142 DeleteDC(hdcMem);
1143 }
1144
1145 EndPaint(hWnd, &ps);
1146 }
1147
1148 break;
1149 }
1150
1151 case WM_COMMAND:
1152 switch(wParam)
1153 {
1154 case IDOK:
1155 case IDCANCEL:
1156 EndDialog(hWnd, TRUE);
1157 return TRUE;
1158
1159 case IDC_SHELL_ABOUT_AUTHORS:
1160 {
1161 static BOOL bShowingAuthors = FALSE;
1162 WCHAR szAuthorsText[20];
1163
1164 if(bShowingAuthors)
1165 {
1166 LoadStringW( shell32_hInstance, IDS_SHELL_ABOUT_AUTHORS, szAuthorsText, sizeof(szAuthorsText) / sizeof(WCHAR) );
1167 ShowWindow( hWndAuthors, SW_HIDE );
1168 }
1169 else
1170 {
1171 LoadStringW( shell32_hInstance, IDS_SHELL_ABOUT_BACK, szAuthorsText, sizeof(szAuthorsText) / sizeof(WCHAR) );
1172 ShowWindow( hWndAuthors, SW_SHOW );
1173 }
1174
1175 SetDlgItemTextW( hWnd, IDC_SHELL_ABOUT_AUTHORS, szAuthorsText );
1176 bShowingAuthors = !bShowingAuthors;
1177 return TRUE;
1178 }
1179 }
1180 break;
1181
1182 case WM_CLOSE:
1183 EndDialog(hWnd, TRUE);
1184 break;
1185 }
1186
1187 return FALSE;
1188 }
1189
1190
1191 /*************************************************************************
1192 * ShellAboutA [SHELL32.288]
1193 */
1194 BOOL WINAPI ShellAboutA( HWND hWnd, LPCSTR szApp, LPCSTR szOtherStuff, HICON hIcon )
1195 {
1196 BOOL ret;
1197 LPWSTR appW = NULL, otherW = NULL;
1198 int len;
1199
1200 if (szApp)
1201 {
1202 len = MultiByteToWideChar(CP_ACP, 0, szApp, -1, NULL, 0);
1203 appW = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1204 MultiByteToWideChar(CP_ACP, 0, szApp, -1, appW, len);
1205 }
1206 if (szOtherStuff)
1207 {
1208 len = MultiByteToWideChar(CP_ACP, 0, szOtherStuff, -1, NULL, 0);
1209 otherW = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1210 MultiByteToWideChar(CP_ACP, 0, szOtherStuff, -1, otherW, len);
1211 }
1212
1213 ret = ShellAboutW(hWnd, appW, otherW, hIcon);
1214
1215 HeapFree(GetProcessHeap(), 0, otherW);
1216 HeapFree(GetProcessHeap(), 0, appW);
1217 return ret;
1218 }
1219
1220
1221 /*************************************************************************
1222 * ShellAboutW [SHELL32.289]
1223 */
1224 BOOL WINAPI ShellAboutW( HWND hWnd, LPCWSTR szApp, LPCWSTR szOtherStuff,
1225 HICON hIcon )
1226 {
1227 ABOUT_INFO info;
1228 HRSRC hRes;
1229 DLGTEMPLATE *DlgTemplate;
1230 BOOL bRet;
1231
1232 TRACE("\n");
1233
1234 // DialogBoxIndirectParamW will be called with the hInstance of the calling application, so we have to preload the dialog template
1235 if(!(hRes = FindResourceW(shell32_hInstance, MAKEINTRESOURCEW(IDD_SHELL_ABOUT), (LPWSTR)RT_DIALOG)))
1236 return FALSE;
1237 if(!(DlgTemplate = (DLGTEMPLATE *)LoadResource(shell32_hInstance, hRes)))
1238 return FALSE;
1239
1240 info.szApp = szApp;
1241 info.szOtherStuff = szOtherStuff;
1242 info.hIcon = hIcon ? hIcon : LoadIconW( 0, (LPWSTR)IDI_WINLOGO );
1243
1244 bRet = DialogBoxIndirectParamW((HINSTANCE)GetWindowLongPtrW( hWnd, GWLP_HINSTANCE ),
1245 DlgTemplate, hWnd, AboutDlgProc, (LPARAM)&info );
1246 return bRet;
1247 }
1248
1249 /*************************************************************************
1250 * FreeIconList (SHELL32.@)
1251 */
1252 EXTERN_C void WINAPI FreeIconList( DWORD dw )
1253 {
1254 FIXME("%x: stub\n",dw);
1255 }
1256
1257 /*************************************************************************
1258 * SHLoadNonloadedIconOverlayIdentifiers (SHELL32.@)
1259 */
1260 EXTERN_C HRESULT WINAPI SHLoadNonloadedIconOverlayIdentifiers( VOID )
1261 {
1262 FIXME("stub\n");
1263 return S_OK;
1264 }
1265
1266 class CShell32Module : public CComModule
1267 {
1268 public:
1269 };
1270
1271
1272 BEGIN_OBJECT_MAP(ObjectMap)
1273 OBJECT_ENTRY(CLSID_ShellFSFolder, CFSFolder)
1274 OBJECT_ENTRY(CLSID_MyComputer, CDrivesFolder)
1275 OBJECT_ENTRY(CLSID_ShellDesktop, CDesktopFolder)
1276 OBJECT_ENTRY(CLSID_ShellItem, ShellItem)
1277 OBJECT_ENTRY(CLSID_ShellLink, ShellLink)
1278 OBJECT_ENTRY(CLSID_DragDropHelper, IDropTargetHelperImpl)
1279 OBJECT_ENTRY(CLSID_ControlPanel, CControlPanelFolder)
1280 OBJECT_ENTRY(CLSID_AutoComplete, CAutoComplete)
1281 OBJECT_ENTRY(CLSID_MyDocuments, CMyDocsFolder)
1282 OBJECT_ENTRY(CLSID_NetworkPlaces, CNetFolder)
1283 OBJECT_ENTRY(CLSID_FontsFolderShortcut, CFontsFolder)
1284 OBJECT_ENTRY(CLSID_Printers, CPrinterFolder)
1285 OBJECT_ENTRY(CLSID_AdminFolderShortcut, CAdminToolsFolder)
1286 OBJECT_ENTRY(CLSID_RecycleBin, CBitBucket)
1287 OBJECT_ENTRY(CLSID_OpenWithMenu, COpenWithMenu)
1288 OBJECT_ENTRY(CLSID_NewMenu, CNewMenu)
1289 OBJECT_ENTRY(CLSID_StartMenu, CStartMenuCallback)
1290 OBJECT_ENTRY(CLSID_MenuBandSite, CMenuBandSite)
1291 END_OBJECT_MAP()
1292
1293 CShell32Module gModule;
1294
1295
1296 /*
1297 static const struct {
1298 REFIID riid;
1299 LPFNCREATEINSTANCE lpfnCI;
1300 } InterfaceTable[] = {
1301 {CLSID_ShellFSFolder, &IFSFolder_Constructor},
1302 {CLSID_MyComputer, &ISF_MyComputer_Constructor},
1303 {CLSID_ShellDesktop, &ISF_Desktop_Constructor},
1304 {CLSID_ShellItem, &IShellItem_Constructor},
1305 {CLSID_ShellLink, &IShellLink_Constructor},
1306 {CLSID_DragDropHelper, &IDropTargetHelper_Constructor},
1307 {CLSID_ControlPanel, &IControlPanel_Constructor},
1308 {CLSID_AutoComplete, &IAutoComplete_Constructor},
1309 {CLSID_MyDocuments, &ISF_MyDocuments_Constructor},
1310 {CLSID_NetworkPlaces, &ISF_NetworkPlaces_Constructor},
1311 {CLSID_FontsFolderShortcut, &ISF_Fonts_Constructor},
1312 {CLSID_Printers, &ISF_Printers_Constructor},
1313 {CLSID_AdminFolderShortcut, &ISF_AdminTools_Constructor},
1314 {CLSID_RecycleBin, &RecycleBin_Constructor},
1315 {CLSID_OpenWithMenu, &SHEOW_Constructor},
1316 {CLSID_NewMenu, &INewItem_Constructor},
1317 {CLSID_StartMenu, &StartMenu_Constructor},
1318 {CLSID_MenuBandSite, &MenuBandSite_Constructor},
1319 };
1320 */
1321
1322 /***********************************************************************
1323 * DllGetVersion [SHELL32.@]
1324 *
1325 * Retrieves version information of the 'SHELL32.DLL'
1326 *
1327 * PARAMS
1328 * pdvi [O] pointer to version information structure.
1329 *
1330 * RETURNS
1331 * Success: S_OK
1332 * Failure: E_INVALIDARG
1333 *
1334 * NOTES
1335 * Returns version of a shell32.dll from IE4.01 SP1.
1336 */
1337
1338 STDAPI DllGetVersion(DLLVERSIONINFO *pdvi)
1339 {
1340 /* FIXME: shouldn't these values come from the version resource? */
1341 if (pdvi->cbSize == sizeof(DLLVERSIONINFO) ||
1342 pdvi->cbSize == sizeof(DLLVERSIONINFO2))
1343 {
1344 pdvi->dwMajorVersion = WINE_FILEVERSION_MAJOR;
1345 pdvi->dwMinorVersion = WINE_FILEVERSION_MINOR;
1346 pdvi->dwBuildNumber = WINE_FILEVERSION_BUILD;
1347 pdvi->dwPlatformID = WINE_FILEVERSION_PLATFORMID;
1348 if (pdvi->cbSize == sizeof(DLLVERSIONINFO2))
1349 {
1350 DLLVERSIONINFO2 *pdvi2 = (DLLVERSIONINFO2 *)pdvi;
1351
1352 pdvi2->dwFlags = 0;
1353 pdvi2->ullVersion = MAKEDLLVERULL(WINE_FILEVERSION_MAJOR,
1354 WINE_FILEVERSION_MINOR,
1355 WINE_FILEVERSION_BUILD,
1356 WINE_FILEVERSION_PLATFORMID);
1357 }
1358 TRACE("%u.%u.%u.%u\n",
1359 pdvi->dwMajorVersion, pdvi->dwMinorVersion,
1360 pdvi->dwBuildNumber, pdvi->dwPlatformID);
1361 return S_OK;
1362 }
1363 else
1364 {
1365 WARN("wrong DLLVERSIONINFO size from app\n");
1366 return E_INVALIDARG;
1367 }
1368 }
1369
1370 /*************************************************************************
1371 * global variables of the shell32.dll
1372 * all are once per process
1373 *
1374 */
1375 HINSTANCE shell32_hInstance;
1376 HIMAGELIST ShellSmallIconList = 0;
1377 HIMAGELIST ShellBigIconList = 0;
1378
1379 void *operator new (size_t, void *buf)
1380 {
1381 return buf;
1382 }
1383
1384 /*************************************************************************
1385 * SHELL32 DllMain
1386 *
1387 * NOTES
1388 * calling oleinitialize here breaks sone apps.
1389 */
1390 STDAPI_(BOOL) DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID fImpLoad)
1391 {
1392 TRACE("%p 0x%x %p\n", hInstance, dwReason, fImpLoad);
1393 if (dwReason == DLL_PROCESS_ATTACH)
1394 {
1395 /* HACK - the global constructors don't run, so I placement new them here */
1396 new (&gModule) CShell32Module;
1397 new (&_AtlWinModule) CAtlWinModule;
1398 new (&_AtlBaseModule) CAtlBaseModule;
1399 new (&_AtlComModule) CAtlComModule;
1400
1401 shell32_hInstance = hInstance;
1402 gModule.Init(ObjectMap, hInstance, NULL);
1403
1404 DisableThreadLibraryCalls (hInstance);
1405
1406 /* get full path to this DLL for IExtractIconW_fnGetIconLocation() */
1407 GetModuleFileNameW(hInstance, swShell32Name, MAX_PATH);
1408 swShell32Name[MAX_PATH - 1] = '\0';
1409
1410 InitCommonControlsEx(NULL);
1411
1412 SIC_Initialize();
1413 InitChangeNotifications();
1414 InitIconOverlays();
1415 }
1416 else if (dwReason == DLL_PROCESS_DETACH)
1417 {
1418 shell32_hInstance = NULL;
1419 SIC_Destroy();
1420 FreeChangeNotifications();
1421 gModule.Term();
1422 }
1423 return TRUE;
1424 }
1425
1426 /***********************************************************************
1427 * DllCanUnloadNow (SHELL32.@)
1428 */
1429 STDAPI DllCanUnloadNow()
1430 {
1431 return gModule.DllCanUnloadNow();
1432 }
1433
1434 /*************************************************************************
1435 * DllGetClassObject [SHELL32.@]
1436 * SHDllGetClassObject [SHELL32.128]
1437 */
1438 STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
1439 {
1440 HRESULT hResult;
1441
1442 TRACE("CLSID:%s,IID:%s\n", shdebugstr_guid(&rclsid), shdebugstr_guid(&riid));
1443
1444 hResult = gModule.DllGetClassObject(rclsid, riid, ppv);
1445 TRACE("-- pointer to class factory: %p\n", *ppv);
1446 return hResult;
1447 }
1448
1449 /***********************************************************************
1450 * DllRegisterServer (BROWSEUI.@)
1451 */
1452 STDAPI DllRegisterServer()
1453 {
1454 return gModule.DllRegisterServer(FALSE);
1455 }
1456
1457 /***********************************************************************
1458 * DllUnregisterServer (BROWSEUI.@)
1459 */
1460 STDAPI DllUnregisterServer()
1461 {
1462 return gModule.DllUnregisterServer(FALSE);
1463 }
1464
1465 /*************************************************************************
1466 * DllInstall [SHELL32.@]
1467 *
1468 * PARAMETERS
1469 *
1470 * BOOL bInstall - TRUE for install, FALSE for uninstall
1471 * LPCWSTR pszCmdLine - command line (unused by shell32?)
1472 */
1473
1474 HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline)
1475 {
1476 FIXME("%s %s: stub\n", bInstall ? "TRUE":"FALSE", debugstr_w(cmdline));
1477 return S_OK; /* indicate success */
1478 }