Don't mistake frames for bytes.
[wine/multimedia.git] / dlls / shell32 / shell32_main.c
blob4a85a99cbb1a4c1881f5b2312e54a5bc553c1db4
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"
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 HGLOBAL hargv;
89 LPWSTR *argv;
90 LPCWSTR cs;
91 LPWSTR arg,s,d;
92 LPWSTR cmdline;
93 int in_quotes,bcount;
95 if (*lpCmdline==0)
97 /* Return the path to the executable */
98 DWORD len, size=16;
100 hargv=GlobalAlloc(size, 0);
101 argv=GlobalLock(hargv);
102 for (;;)
104 len = GetModuleFileNameW(0, (LPWSTR)(argv+1), size-sizeof(LPWSTR));
105 if (!len)
107 GlobalFree(hargv);
108 return NULL;
110 if (len < size) break;
111 size*=2;
112 hargv=GlobalReAlloc(hargv, size, 0);
113 argv=GlobalLock(hargv);
115 argv[0]=(LPWSTR)(argv+1);
116 if (numargs)
117 *numargs=2;
119 return argv;
122 /* to get a writeable copy */
123 argc=0;
124 bcount=0;
125 in_quotes=0;
126 cs=lpCmdline;
127 while (1)
129 if (*cs==0 || ((*cs==0x0009 || *cs==0x0020) && !in_quotes))
131 /* space */
132 argc++;
133 /* skip the remaining spaces */
134 while (*cs==0x0009 || *cs==0x0020) {
135 cs++;
137 if (*cs==0)
138 break;
139 bcount=0;
140 continue;
142 else if (*cs==0x005c)
144 /* '\', count them */
145 bcount++;
147 else if ((*cs==0x0022) && ((bcount & 1)==0))
149 /* unescaped '"' */
150 in_quotes=!in_quotes;
151 bcount=0;
153 else
155 /* a regular character */
156 bcount=0;
158 cs++;
160 /* Allocate in a single lump, the string array, and the strings that go with it.
161 * This way the caller can make a single GlobalFree call to free both, as per MSDN.
163 hargv=GlobalAlloc(0, argc*sizeof(LPWSTR)+(strlenW(lpCmdline)+1)*sizeof(WCHAR));
164 argv=GlobalLock(hargv);
165 if (!argv)
166 return NULL;
167 cmdline=(LPWSTR)(argv+argc);
168 strcpyW(cmdline, lpCmdline);
170 argc=0;
171 bcount=0;
172 in_quotes=0;
173 arg=d=s=cmdline;
174 while (*s)
176 if ((*s==0x0009 || *s==0x0020) && !in_quotes)
178 /* Close the argument and copy it */
179 *d=0;
180 argv[argc++]=arg;
182 /* skip the remaining spaces */
183 do {
184 s++;
185 } while (*s==0x0009 || *s==0x0020);
187 /* Start with a new argument */
188 arg=d=s;
189 bcount=0;
191 else if (*s==0x005c)
193 /* '\\' */
194 *d++=*s++;
195 bcount++;
197 else if (*s==0x0022)
199 /* '"' */
200 if ((bcount & 1)==0)
202 /* Preceded by an even number of '\', this is half that
203 * number of '\', plus a quote which we erase.
205 d-=bcount/2;
206 in_quotes=!in_quotes;
207 s++;
209 else
211 /* Preceded by an odd number of '\', this is half that
212 * number of '\' followed by a '"'
214 d=d-bcount/2-1;
215 *d++='"';
216 s++;
218 bcount=0;
220 else
222 /* a regular character */
223 *d++=*s++;
224 bcount=0;
227 if (*arg)
229 *d='\0';
230 argv[argc++]=arg;
232 if (numargs)
233 *numargs=argc;
235 return argv;
238 #define SHGFI_KNOWN_FLAGS \
239 (SHGFI_SMALLICON | SHGFI_OPENICON | SHGFI_SHELLICONSIZE | SHGFI_PIDL | \
240 SHGFI_USEFILEATTRIBUTES | SHGFI_ADDOVERLAYS | SHGFI_OVERLAYINDEX | \
241 SHGFI_ICON | SHGFI_DISPLAYNAME | SHGFI_TYPENAME | SHGFI_ATTRIBUTES | \
242 SHGFI_ICONLOCATION | SHGFI_EXETYPE | SHGFI_SYSICONINDEX | \
243 SHGFI_LINKOVERLAY | SHGFI_SELECTED | SHGFI_ATTR_SPECIFIED)
245 /*************************************************************************
246 * SHGetFileInfoW [SHELL32.@]
249 DWORD WINAPI SHGetFileInfoW(LPCWSTR path,DWORD dwFileAttributes,
250 SHFILEINFOW *psfi, UINT sizeofpsfi, UINT flags )
252 WCHAR szLocation[MAX_PATH], szFullPath[MAX_PATH];
253 int iIndex;
254 DWORD ret = TRUE, dwAttributes = 0;
255 IShellFolder * psfParent = NULL;
256 IExtractIconW * pei = NULL;
257 LPITEMIDLIST pidlLast = NULL, pidl = NULL;
258 HRESULT hr = S_OK;
259 BOOL IconNotYetLoaded=TRUE;
261 TRACE("%s fattr=0x%lx sfi=%p(attr=0x%08lx) size=0x%x flags=0x%x\n",
262 (flags & SHGFI_PIDL)? "pidl" : debugstr_w(path), dwFileAttributes,
263 psfi, psfi->dwAttributes, sizeofpsfi, flags);
265 if ( (flags & SHGFI_USEFILEATTRIBUTES) &&
266 (flags & (SHGFI_ATTRIBUTES|SHGFI_EXETYPE|SHGFI_PIDL)))
267 return FALSE;
269 /* windows initializes this values regardless of the flags */
270 if (psfi != NULL)
272 psfi->szDisplayName[0] = '\0';
273 psfi->szTypeName[0] = '\0';
274 psfi->iIcon = 0;
277 if (!(flags & SHGFI_PIDL))
279 /* SHGitFileInfo should work with absolute and relative paths */
280 if (PathIsRelativeW(path))
282 GetCurrentDirectoryW(MAX_PATH, szLocation);
283 PathCombineW(szFullPath, szLocation, path);
285 else
287 lstrcpynW(szFullPath, path, MAX_PATH);
291 if (flags & SHGFI_EXETYPE)
293 BOOL status = FALSE;
294 HANDLE hfile;
295 DWORD BinaryType;
296 IMAGE_DOS_HEADER mz_header;
297 IMAGE_NT_HEADERS nt;
298 DWORD len;
299 char magic[4];
301 if (flags != SHGFI_EXETYPE)
302 return 0;
304 status = GetBinaryTypeW (szFullPath, &BinaryType);
305 if (!status)
306 return 0;
307 if ((BinaryType == SCS_DOS_BINARY) || (BinaryType == SCS_PIF_BINARY))
308 return 0x4d5a;
310 hfile = CreateFileW( szFullPath, GENERIC_READ, FILE_SHARE_READ,
311 NULL, OPEN_EXISTING, 0, 0 );
312 if ( hfile == INVALID_HANDLE_VALUE )
313 return 0;
316 * The next section is adapted from MODULE_GetBinaryType, as we need
317 * to examine the image header to get OS and version information. We
318 * know from calling GetBinaryTypeA that the image is valid and either
319 * an NE or PE, so much error handling can be omitted.
320 * Seek to the start of the file and read the header information.
323 SetFilePointer( hfile, 0, NULL, SEEK_SET );
324 ReadFile( hfile, &mz_header, sizeof(mz_header), &len, NULL );
326 SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
327 ReadFile( hfile, magic, sizeof(magic), &len, NULL );
328 if ( *(DWORD*)magic == IMAGE_NT_SIGNATURE )
330 SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
331 ReadFile( hfile, &nt, sizeof(nt), &len, NULL );
332 CloseHandle( hfile );
333 if (nt.OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_GUI)
335 return IMAGE_NT_SIGNATURE |
336 (nt.OptionalHeader.MajorSubsystemVersion << 24) |
337 (nt.OptionalHeader.MinorSubsystemVersion << 16);
339 return IMAGE_NT_SIGNATURE;
341 else if ( *(WORD*)magic == IMAGE_OS2_SIGNATURE )
343 IMAGE_OS2_HEADER ne;
344 SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
345 ReadFile( hfile, &ne, sizeof(ne), &len, NULL );
346 CloseHandle( hfile );
347 if (ne.ne_exetyp == 2)
348 return IMAGE_OS2_SIGNATURE | (ne.ne_expver << 16);
349 return 0;
351 CloseHandle( hfile );
352 return 0;
356 * psfi is NULL normally to query EXE type. If it is NULL, none of the
357 * below makes sense anyway. Windows allows this and just returns FALSE
359 if (psfi == NULL)
360 return FALSE;
363 * translate the path into a pidl only when SHGFI_USEFILEATTRIBUTES
364 * is not specified.
365 * The pidl functions fail on not existing file names
368 if (flags & SHGFI_PIDL)
370 pidl = ILClone((LPCITEMIDLIST)path);
372 else if (!(flags & SHGFI_USEFILEATTRIBUTES))
374 hr = SHILCreateFromPathW(szFullPath, &pidl, &dwAttributes);
377 if ((flags & SHGFI_PIDL) || !(flags & SHGFI_USEFILEATTRIBUTES))
379 /* get the parent shellfolder */
380 if (pidl)
382 hr = SHBindToParent( pidl, &IID_IShellFolder, (LPVOID*)&psfParent,
383 (LPCITEMIDLIST*)&pidlLast );
384 ILFree(pidl);
386 else
388 ERR("pidl is null!\n");
389 return FALSE;
393 /* get the attributes of the child */
394 if (SUCCEEDED(hr) && (flags & SHGFI_ATTRIBUTES))
396 if (!(flags & SHGFI_ATTR_SPECIFIED))
398 psfi->dwAttributes = 0xffffffff;
400 IShellFolder_GetAttributesOf( psfParent, 1, (LPCITEMIDLIST*)&pidlLast,
401 &(psfi->dwAttributes) );
404 /* get the displayname */
405 if (SUCCEEDED(hr) && (flags & SHGFI_DISPLAYNAME))
407 if (flags & SHGFI_USEFILEATTRIBUTES)
409 lstrcpyW (psfi->szDisplayName, PathFindFileNameW(szFullPath));
411 else
413 STRRET str;
414 hr = IShellFolder_GetDisplayNameOf( psfParent, pidlLast,
415 SHGDN_INFOLDER, &str);
416 StrRetToStrNW (psfi->szDisplayName, MAX_PATH, &str, pidlLast);
420 /* get the type name */
421 if (SUCCEEDED(hr) && (flags & SHGFI_TYPENAME))
423 static const WCHAR szFile[] = { 'F','i','l','e',0 };
424 static const WCHAR szDashFile[] = { '-','f','i','l','e',0 };
426 if (!(flags & SHGFI_USEFILEATTRIBUTES))
428 char ftype[80];
430 _ILGetFileType(pidlLast, ftype, 80);
431 MultiByteToWideChar(CP_ACP, 0, ftype, -1, psfi->szTypeName, 80 );
433 else
435 if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
436 strcatW (psfi->szTypeName, szFile);
437 else
439 WCHAR sTemp[64];
441 lstrcpyW(sTemp,PathFindExtensionW(szFullPath));
442 if (!( HCR_MapTypeToValueW(sTemp, sTemp, 64, TRUE) &&
443 HCR_MapTypeToValueW(sTemp, psfi->szTypeName, 80, FALSE )))
445 lstrcpynW (psfi->szTypeName, sTemp, 64);
446 strcatW (psfi->szTypeName, szDashFile);
452 /* ### icons ###*/
453 if (flags & SHGFI_ADDOVERLAYS)
454 FIXME("SHGFI_ADDOVERLAYS unhandled\n");
456 if (flags & SHGFI_OVERLAYINDEX)
457 FIXME("SHGFI_OVERLAYINDEX unhandled\n");
459 if (flags & SHGFI_LINKOVERLAY)
460 FIXME("set icon to link, stub\n");
462 if (flags & SHGFI_SELECTED)
463 FIXME("set icon to selected, stub\n");
465 if (flags & SHGFI_SHELLICONSIZE)
466 FIXME("set icon to shell size, stub\n");
468 /* get the iconlocation */
469 if (SUCCEEDED(hr) && (flags & SHGFI_ICONLOCATION ))
471 UINT uDummy,uFlags;
473 hr = IShellFolder_GetUIObjectOf(psfParent, 0, 1,
474 (LPCITEMIDLIST*)&pidlLast, &IID_IExtractIconA,
475 &uDummy, (LPVOID*)&pei);
476 if (SUCCEEDED(hr))
478 hr = IExtractIconW_GetIconLocation(pei,
479 (flags & SHGFI_OPENICON)? GIL_OPENICON : 0,
480 szLocation, MAX_PATH, &iIndex, &uFlags);
481 psfi->iIcon = iIndex;
483 if (uFlags != GIL_NOTFILENAME)
484 lstrcpyW (psfi->szDisplayName, szLocation);
485 else
486 ret = FALSE;
488 IExtractIconA_Release(pei);
492 /* get icon index (or load icon)*/
493 if (SUCCEEDED(hr) && (flags & (SHGFI_ICON | SHGFI_SYSICONINDEX)))
495 if (flags & SHGFI_USEFILEATTRIBUTES)
497 WCHAR sTemp [MAX_PATH];
498 WCHAR * szExt;
499 DWORD dwNr=0;
501 lstrcpynW(sTemp, szFullPath, MAX_PATH);
503 if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
504 psfi->iIcon = 2;
505 else
507 static const WCHAR p1W[] = {'%','1',0};
509 psfi->iIcon = 0;
510 szExt = (LPWSTR) PathFindExtensionW(sTemp);
511 if ( szExt &&
512 HCR_MapTypeToValueW(szExt, sTemp, MAX_PATH, TRUE) &&
513 HCR_GetDefaultIconW(sTemp, sTemp, MAX_PATH, &dwNr))
515 if (!lstrcmpW(p1W,sTemp)) /* icon is in the file */
516 strcpyW(sTemp, szFullPath);
518 if (flags & SHGFI_SYSICONINDEX)
520 psfi->iIcon = SIC_GetIconIndex(sTemp,dwNr);
521 if (psfi->iIcon == -1)
522 psfi->iIcon = 0;
524 else
526 IconNotYetLoaded=FALSE;
527 if (flags & SHGFI_SMALLICON)
528 PrivateExtractIconsW( sTemp,dwNr,
529 GetSystemMetrics( SM_CXSMICON ),
530 GetSystemMetrics( SM_CYSMICON ),
531 &psfi->hIcon, 0, 1, 0);
532 else
533 PrivateExtractIconsW( sTemp, dwNr,
534 GetSystemMetrics( SM_CXICON),
535 GetSystemMetrics( SM_CYICON),
536 &psfi->hIcon, 0, 1, 0);
537 psfi->iIcon = dwNr;
542 else
544 if (!(PidlToSicIndex(psfParent, pidlLast, !(flags & SHGFI_SMALLICON),
545 (flags & SHGFI_OPENICON)? GIL_OPENICON : 0, &(psfi->iIcon))))
547 ret = FALSE;
550 if (ret)
552 if (flags & SHGFI_SMALLICON)
553 ret = (DWORD) ShellSmallIconList;
554 else
555 ret = (DWORD) ShellBigIconList;
559 /* icon handle */
560 if (SUCCEEDED(hr) && (flags & SHGFI_ICON) && IconNotYetLoaded)
562 if (flags & SHGFI_SMALLICON)
563 psfi->hIcon = ImageList_GetIcon( ShellSmallIconList, psfi->iIcon, ILD_NORMAL);
564 else
565 psfi->hIcon = ImageList_GetIcon( ShellBigIconList, psfi->iIcon, ILD_NORMAL);
568 if (flags & ~SHGFI_KNOWN_FLAGS)
569 FIXME("unknown flags %08x\n", flags & ~SHGFI_KNOWN_FLAGS);
571 if (psfParent)
572 IShellFolder_Release(psfParent);
574 if (hr != S_OK)
575 ret = FALSE;
577 if (pidlLast)
578 SHFree(pidlLast);
580 #ifdef MORE_DEBUG
581 TRACE ("icon=%p index=0x%08x attr=0x%08lx name=%s type=%s ret=0x%08lx\n",
582 psfi->hIcon, psfi->iIcon, psfi->dwAttributes,
583 debugstr_w(psfi->szDisplayName), debugstr_w(psfi->szTypeName), ret);
584 #endif
586 return ret;
589 /*************************************************************************
590 * SHGetFileInfoA [SHELL32.@]
592 DWORD WINAPI SHGetFileInfoA(LPCSTR path,DWORD dwFileAttributes,
593 SHFILEINFOA *psfi, UINT sizeofpsfi,
594 UINT flags )
596 INT len;
597 LPWSTR temppath;
598 DWORD ret;
599 SHFILEINFOW temppsfi;
601 if (flags & SHGFI_PIDL)
603 /* path contains a pidl */
604 temppath = (LPWSTR) path;
606 else
608 len = MultiByteToWideChar(CP_ACP, 0, path, -1, NULL, 0);
609 temppath = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
610 MultiByteToWideChar(CP_ACP, 0, path, -1, temppath, len);
613 if (psfi && (flags & SHGFI_ATTR_SPECIFIED))
614 temppsfi.dwAttributes=psfi->dwAttributes;
616 if (psfi == NULL)
617 ret = SHGetFileInfoW(temppath, dwFileAttributes, NULL, sizeof(temppsfi), flags);
618 else
619 ret = SHGetFileInfoW(temppath, dwFileAttributes, &temppsfi, sizeof(temppsfi), flags);
621 if (psfi)
623 if(flags & SHGFI_ICON)
624 psfi->hIcon=temppsfi.hIcon;
625 if(flags & (SHGFI_SYSICONINDEX|SHGFI_ICON|SHGFI_ICONLOCATION))
626 psfi->iIcon=temppsfi.iIcon;
627 if(flags & SHGFI_ATTRIBUTES)
628 psfi->dwAttributes=temppsfi.dwAttributes;
629 if(flags & (SHGFI_DISPLAYNAME|SHGFI_ICONLOCATION))
631 WideCharToMultiByte(CP_ACP, 0, temppsfi.szDisplayName, -1,
632 psfi->szDisplayName, sizeof(psfi->szDisplayName), NULL, NULL);
634 if(flags & SHGFI_TYPENAME)
636 WideCharToMultiByte(CP_ACP, 0, temppsfi.szTypeName, -1,
637 psfi->szTypeName, sizeof(psfi->szTypeName), NULL, NULL);
641 if (!(flags & SHGFI_PIDL))
642 HeapFree(GetProcessHeap(), 0, temppath);
644 return ret;
647 /*************************************************************************
648 * DuplicateIcon [SHELL32.@]
650 HICON WINAPI DuplicateIcon( HINSTANCE hInstance, HICON hIcon)
652 ICONINFO IconInfo;
653 HICON hDupIcon = 0;
655 TRACE("%p %p\n", hInstance, hIcon);
657 if (GetIconInfo(hIcon, &IconInfo))
659 hDupIcon = CreateIconIndirect(&IconInfo);
661 /* clean up hbmMask and hbmColor */
662 DeleteObject(IconInfo.hbmMask);
663 DeleteObject(IconInfo.hbmColor);
666 return hDupIcon;
669 /*************************************************************************
670 * ExtractIconA [SHELL32.@]
672 HICON WINAPI ExtractIconA(HINSTANCE hInstance, LPCSTR lpszFile, UINT nIconIndex)
674 HICON ret;
675 INT len = MultiByteToWideChar(CP_ACP, 0, lpszFile, -1, NULL, 0);
676 LPWSTR lpwstrFile = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
678 TRACE("%p %s %d\n", hInstance, lpszFile, nIconIndex);
680 MultiByteToWideChar(CP_ACP, 0, lpszFile, -1, lpwstrFile, len);
681 ret = ExtractIconW(hInstance, lpwstrFile, nIconIndex);
682 HeapFree(GetProcessHeap(), 0, lpwstrFile);
684 return ret;
687 /*************************************************************************
688 * ExtractIconW [SHELL32.@]
690 HICON WINAPI ExtractIconW(HINSTANCE hInstance, LPCWSTR lpszFile, UINT nIconIndex)
692 HICON hIcon = NULL;
693 UINT ret;
694 UINT cx = GetSystemMetrics(SM_CXICON), cy = GetSystemMetrics(SM_CYICON);
696 TRACE("%p %s %d\n", hInstance, debugstr_w(lpszFile), nIconIndex);
698 if (nIconIndex == 0xFFFFFFFF)
700 ret = PrivateExtractIconsW(lpszFile, 0, cx, cy, NULL, NULL, 0, LR_DEFAULTCOLOR);
701 if (ret != 0xFFFFFFFF && ret)
702 return (HICON)ret;
703 return NULL;
705 else
706 ret = PrivateExtractIconsW(lpszFile, nIconIndex, cx, cy, &hIcon, NULL, 1, LR_DEFAULTCOLOR);
708 if (ret == 0xFFFFFFFF)
709 return (HICON)1;
710 else if (ret > 0 && hIcon)
711 return hIcon;
713 return NULL;
716 typedef struct
718 LPCWSTR szApp;
719 LPCWSTR szOtherStuff;
720 HICON hIcon;
721 HFONT hFont;
722 } ABOUT_INFO;
724 #define IDC_STATIC_TEXT1 100
725 #define IDC_STATIC_TEXT2 101
726 #define IDC_LISTBOX 99
727 #define IDC_WINE_TEXT 98
729 #define DROP_FIELD_TOP (-15)
730 #define DROP_FIELD_HEIGHT 15
732 static BOOL __get_dropline( HWND hWnd, LPRECT lprect )
734 HWND hWndCtl = GetDlgItem(hWnd, IDC_WINE_TEXT);
736 if( hWndCtl )
738 GetWindowRect( hWndCtl, lprect );
739 MapWindowPoints( 0, hWnd, (LPPOINT)lprect, 2 );
740 lprect->bottom = (lprect->top += DROP_FIELD_TOP);
741 return TRUE;
743 return FALSE;
746 /*************************************************************************
747 * SHAppBarMessage [SHELL32.@]
749 UINT WINAPI SHAppBarMessage(DWORD msg, PAPPBARDATA data)
751 int width=data->rc.right - data->rc.left;
752 int height=data->rc.bottom - data->rc.top;
753 RECT rec=data->rc;
755 switch (msg)
757 case ABM_GETSTATE:
758 return ABS_ALWAYSONTOP | ABS_AUTOHIDE;
759 case ABM_GETTASKBARPOS:
760 GetWindowRect(data->hWnd, &rec);
761 data->rc=rec;
762 return TRUE;
763 case ABM_ACTIVATE:
764 SetActiveWindow(data->hWnd);
765 return TRUE;
766 case ABM_GETAUTOHIDEBAR:
767 data->hWnd=GetActiveWindow();
768 return TRUE;
769 case ABM_NEW:
770 SetWindowPos(data->hWnd,HWND_TOP,rec.left,rec.top,
771 width,height,SWP_SHOWWINDOW);
772 return TRUE;
773 case ABM_QUERYPOS:
774 GetWindowRect(data->hWnd, &(data->rc));
775 return TRUE;
776 case ABM_REMOVE:
777 FIXME("ABM_REMOVE broken\n");
778 /* FIXME: this is wrong; should it be DestroyWindow instead? */
779 /*CloseHandle(data->hWnd);*/
780 return TRUE;
781 case ABM_SETAUTOHIDEBAR:
782 SetWindowPos(data->hWnd,HWND_TOP,rec.left+1000,rec.top,
783 width,height,SWP_SHOWWINDOW);
784 return TRUE;
785 case ABM_SETPOS:
786 data->uEdge=(ABE_RIGHT | ABE_LEFT);
787 SetWindowPos(data->hWnd,HWND_TOP,data->rc.left,data->rc.top,
788 width,height,SWP_SHOWWINDOW);
789 return TRUE;
790 case ABM_WINDOWPOSCHANGED:
791 return TRUE;
793 return FALSE;
796 /*************************************************************************
797 * SHHelpShortcuts_RunDLLA [SHELL32.@]
800 DWORD WINAPI SHHelpShortcuts_RunDLLA(DWORD dwArg1, DWORD dwArg2, DWORD dwArg3, DWORD dwArg4)
802 FIXME("(%lx, %lx, %lx, %lx) stub!\n", dwArg1, dwArg2, dwArg3, dwArg4);
803 return 0;
806 /*************************************************************************
807 * SHHelpShortcuts_RunDLLA [SHELL32.@]
810 DWORD WINAPI SHHelpShortcuts_RunDLLW(DWORD dwArg1, DWORD dwArg2, DWORD dwArg3, DWORD dwArg4)
812 FIXME("(%lx, %lx, %lx, %lx) stub!\n", dwArg1, dwArg2, dwArg3, dwArg4);
813 return 0;
816 /*************************************************************************
817 * SHLoadInProc [SHELL32.@]
818 * Create an instance of specified object class from within
819 * the shell process and release it immediately
821 HRESULT WINAPI SHLoadInProc (REFCLSID rclsid)
823 void *ptr = NULL;
825 TRACE("%s\n", debugstr_guid(rclsid));
827 CoCreateInstance(rclsid, NULL, CLSCTX_INPROC_SERVER, &IID_IUnknown,&ptr);
828 if(ptr)
830 IUnknown * pUnk = ptr;
831 IUnknown_Release(pUnk);
832 return NOERROR;
834 return DISP_E_MEMBERNOTFOUND;
837 /*************************************************************************
838 * AboutDlgProc (internal)
840 INT_PTR CALLBACK AboutDlgProc( HWND hWnd, UINT msg, WPARAM wParam,
841 LPARAM lParam )
843 HWND hWndCtl;
845 TRACE("\n");
847 switch(msg)
849 case WM_INITDIALOG:
851 ABOUT_INFO *info = (ABOUT_INFO *)lParam;
852 WCHAR Template[512], AppTitle[512];
854 if (info)
856 const char* const *pstr = SHELL_Authors;
857 SendDlgItemMessageW(hWnd, stc1, STM_SETICON,(WPARAM)info->hIcon, 0);
858 GetWindowTextW( hWnd, Template, sizeof(Template)/sizeof(WCHAR) );
859 sprintfW( AppTitle, Template, info->szApp );
860 SetWindowTextW( hWnd, AppTitle );
861 SetWindowTextW( GetDlgItem(hWnd, IDC_STATIC_TEXT1), info->szApp );
862 SetWindowTextW( GetDlgItem(hWnd, IDC_STATIC_TEXT2), info->szOtherStuff );
863 hWndCtl = GetDlgItem(hWnd, IDC_LISTBOX);
864 SendMessageW( hWndCtl, WM_SETREDRAW, 0, 0 );
865 SendMessageW( hWndCtl, WM_SETFONT, (WPARAM)info->hFont, 0 );
866 while (*pstr)
868 WCHAR name[64];
869 /* authors list is in iso-8859-1 format */
870 MultiByteToWideChar( 28591, 0, *pstr, -1, name, sizeof(name)/sizeof(WCHAR) );
871 SendMessageW( hWndCtl, LB_ADDSTRING, (WPARAM)-1, (LPARAM)name );
872 pstr++;
874 SendMessageW( hWndCtl, WM_SETREDRAW, 1, 0 );
877 return 1;
879 case WM_PAINT:
881 RECT rect;
882 PAINTSTRUCT ps;
883 HDC hDC = BeginPaint( hWnd, &ps );
885 if (__get_dropline( hWnd, &rect ))
887 SelectObject( hDC, GetStockObject( BLACK_PEN ) );
888 MoveToEx( hDC, rect.left, rect.top, NULL );
889 LineTo( hDC, rect.right, rect.bottom );
891 EndPaint( hWnd, &ps );
893 break;
895 case WM_COMMAND:
896 if (wParam == IDOK || wParam == IDCANCEL)
898 EndDialog(hWnd, TRUE);
899 return TRUE;
901 break;
902 case WM_CLOSE:
903 EndDialog(hWnd, TRUE);
904 break;
907 return 0;
911 /*************************************************************************
912 * ShellAboutA [SHELL32.288]
914 BOOL WINAPI ShellAboutA( HWND hWnd, LPCSTR szApp, LPCSTR szOtherStuff, HICON hIcon )
916 BOOL ret;
917 LPWSTR appW = NULL, otherW = NULL;
918 int len;
920 if (szApp)
922 len = MultiByteToWideChar(CP_ACP, 0, szApp, -1, NULL, 0);
923 appW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
924 MultiByteToWideChar(CP_ACP, 0, szApp, -1, appW, len);
926 if (szOtherStuff)
928 len = MultiByteToWideChar(CP_ACP, 0, szOtherStuff, -1, NULL, 0);
929 otherW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
930 MultiByteToWideChar(CP_ACP, 0, szOtherStuff, -1, otherW, len);
933 ret = ShellAboutW(hWnd, appW, otherW, hIcon);
935 HeapFree(GetProcessHeap(), 0, otherW);
936 HeapFree(GetProcessHeap(), 0, appW);
937 return ret;
941 /*************************************************************************
942 * ShellAboutW [SHELL32.289]
944 BOOL WINAPI ShellAboutW( HWND hWnd, LPCWSTR szApp, LPCWSTR szOtherStuff,
945 HICON hIcon )
947 ABOUT_INFO info;
948 LOGFONTW logFont;
949 HRSRC hRes;
950 LPVOID template;
951 BOOL bRet;
952 static const WCHAR wszSHELL_ABOUT_MSGBOX[] =
953 {'S','H','E','L','L','_','A','B','O','U','T','_','M','S','G','B','O','X',0};
955 TRACE("\n");
957 if(!(hRes = FindResourceW(shell32_hInstance, wszSHELL_ABOUT_MSGBOX, (LPWSTR)RT_DIALOG)))
958 return FALSE;
959 if(!(template = (LPVOID)LoadResource(shell32_hInstance, hRes)))
960 return FALSE;
961 info.szApp = szApp;
962 info.szOtherStuff = szOtherStuff;
963 info.hIcon = hIcon ? hIcon : LoadIconW( 0, (LPWSTR)IDI_WINLOGO );
965 SystemParametersInfoW( SPI_GETICONTITLELOGFONT, 0, &logFont, 0 );
966 info.hFont = CreateFontIndirectW( &logFont );
968 bRet = DialogBoxIndirectParamW((HINSTANCE)GetWindowLongPtrW( hWnd, GWLP_HINSTANCE ),
969 template, hWnd, AboutDlgProc, (LPARAM)&info );
970 DeleteObject(info.hFont);
971 return bRet;
974 /*************************************************************************
975 * FreeIconList (SHELL32.@)
977 void WINAPI FreeIconList( DWORD dw )
979 FIXME("%lx: stub\n",dw);
983 /*************************************************************************
984 * ShellDDEInit (SHELL32.@)
986 void WINAPI ShellDDEInit(BOOL start)
988 FIXME("stub: %d\n", start);
991 /***********************************************************************
992 * DllGetVersion [SHELL32.@]
994 * Retrieves version information of the 'SHELL32.DLL'
996 * PARAMS
997 * pdvi [O] pointer to version information structure.
999 * RETURNS
1000 * Success: S_OK
1001 * Failure: E_INVALIDARG
1003 * NOTES
1004 * Returns version of a shell32.dll from IE4.01 SP1.
1007 HRESULT WINAPI SHELL32_DllGetVersion (DLLVERSIONINFO *pdvi)
1009 /* FIXME: shouldn't these values come from the version resource? */
1010 if (pdvi->cbSize == sizeof(DLLVERSIONINFO) ||
1011 pdvi->cbSize == sizeof(DLLVERSIONINFO2))
1013 pdvi->dwMajorVersion = WINE_FILEVERSION_MAJOR;
1014 pdvi->dwMinorVersion = WINE_FILEVERSION_MINOR;
1015 pdvi->dwBuildNumber = WINE_FILEVERSION_BUILD;
1016 pdvi->dwPlatformID = WINE_FILEVERSION_PLATFORMID;
1017 if (pdvi->cbSize == sizeof(DLLVERSIONINFO2))
1019 DLLVERSIONINFO2 *pdvi2 = (DLLVERSIONINFO2 *)pdvi;
1021 pdvi2->dwFlags = 0;
1022 pdvi2->ullVersion = MAKEDLLVERULL(WINE_FILEVERSION_MAJOR,
1023 WINE_FILEVERSION_MINOR,
1024 WINE_FILEVERSION_BUILD,
1025 WINE_FILEVERSION_PLATFORMID);
1027 TRACE("%lu.%lu.%lu.%lu\n",
1028 pdvi->dwMajorVersion, pdvi->dwMinorVersion,
1029 pdvi->dwBuildNumber, pdvi->dwPlatformID);
1030 return S_OK;
1032 else
1034 WARN("wrong DLLVERSIONINFO size from app\n");
1035 return E_INVALIDARG;
1039 /*************************************************************************
1040 * global variables of the shell32.dll
1041 * all are once per process
1044 HINSTANCE shell32_hInstance = 0;
1045 HIMAGELIST ShellSmallIconList = 0;
1046 HIMAGELIST ShellBigIconList = 0;
1049 /*************************************************************************
1050 * SHELL32 DllMain
1052 * NOTES
1053 * calling oleinitialize here breaks sone apps.
1055 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
1057 TRACE("%p 0x%lx %p\n", hinstDLL, fdwReason, fImpLoad);
1059 switch (fdwReason)
1061 case DLL_PROCESS_ATTACH:
1062 shell32_hInstance = hinstDLL;
1063 DisableThreadLibraryCalls(shell32_hInstance);
1065 /* get full path to this DLL for IExtractIconW_fnGetIconLocation() */
1066 GetModuleFileNameW(hinstDLL, swShell32Name, MAX_PATH);
1067 swShell32Name[MAX_PATH - 1] = '\0';
1069 InitCommonControlsEx(NULL);
1071 SIC_Initialize();
1072 SYSTRAY_Init();
1073 InitChangeNotifications();
1074 break;
1076 case DLL_PROCESS_DETACH:
1077 shell32_hInstance = 0;
1078 SIC_Destroy();
1079 FreeChangeNotifications();
1080 break;
1082 return TRUE;
1085 /*************************************************************************
1086 * DllInstall [SHELL32.@]
1088 * PARAMETERS
1090 * BOOL bInstall - TRUE for install, FALSE for uninstall
1091 * LPCWSTR pszCmdLine - command line (unused by shell32?)
1094 HRESULT WINAPI SHELL32_DllInstall(BOOL bInstall, LPCWSTR cmdline)
1096 FIXME("%s %s: stub\n", bInstall ? "TRUE":"FALSE", debugstr_w(cmdline));
1097 return S_OK; /* indicate success */
1100 /***********************************************************************
1101 * DllCanUnloadNow (SHELL32.@)
1103 HRESULT WINAPI SHELL32_DllCanUnloadNow(void)
1105 FIXME("stub\n");
1106 return S_FALSE;