Do not allow creation of not aligned EMF records by GDI code.
[wine.git] / dlls / shell32 / shell32_main.c
blobdf979bffc2e106079d8d9821799177f30d66c361
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 #include "windef.h"
30 #include "winbase.h"
31 #include "winerror.h"
32 #include "winreg.h"
33 #include "dlgs.h"
34 #include "shellapi.h"
35 #include "winuser.h"
36 #include "wingdi.h"
37 #include "shlobj.h"
38 #include "shlguid.h"
39 #include "shlwapi.h"
41 #include "undocshell.h"
42 #include "pidl.h"
43 #include "shell32_main.h"
45 #include "wine/debug.h"
46 #include "wine/unicode.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(shell);
50 extern const char * const SHELL_Authors[];
52 #define MORE_DEBUG 1
53 /*************************************************************************
54 * CommandLineToArgvW [SHELL32.@]
56 * We must interpret the quotes in the command line to rebuild the argv
57 * array correctly:
58 * - arguments are separated by spaces or tabs
59 * - quotes serve as optional argument delimiters
60 * '"a b"' -> 'a b'
61 * - escaped quotes must be converted back to '"'
62 * '\"' -> '"'
63 * - an odd number of '\'s followed by '"' correspond to half that number
64 * of '\' followed by a '"' (extension of the above)
65 * '\\\"' -> '\"'
66 * '\\\\\"' -> '\\"'
67 * - an even number of '\'s followed by a '"' correspond to half that number
68 * of '\', plus a regular quote serving as an argument delimiter (which
69 * means it does not appear in the result)
70 * 'a\\"b c"' -> 'a\b c'
71 * 'a\\\\"b c"' -> 'a\\b c'
72 * - '\' that are not followed by a '"' are copied literally
73 * 'a\b' -> 'a\b'
74 * 'a\\b' -> 'a\\b'
76 * Note:
77 * '\t' == 0x0009
78 * ' ' == 0x0020
79 * '"' == 0x0022
80 * '\\' == 0x005c
82 LPWSTR* WINAPI CommandLineToArgvW(LPCWSTR lpCmdline, int* numargs)
84 DWORD argc;
85 HGLOBAL hargv;
86 LPWSTR *argv;
87 LPCWSTR cs;
88 LPWSTR arg,s,d;
89 LPWSTR cmdline;
90 int in_quotes,bcount;
92 if (*lpCmdline==0) {
93 /* Return the path to the executable */
94 DWORD len, size=16;
96 hargv=GlobalAlloc(size, 0);
97 argv=GlobalLock(hargv);
98 for (;;) {
99 len = GetModuleFileNameW(0, (LPWSTR)(argv+1), size-sizeof(LPWSTR));
100 if (!len) {
101 GlobalFree(hargv);
102 return NULL;
104 if (len < size) break;
105 size*=2;
106 hargv=GlobalReAlloc(hargv, size, 0);
107 argv=GlobalLock(hargv);
109 argv[0]=(LPWSTR)(argv+1);
110 if (numargs)
111 *numargs=2;
113 return argv;
116 /* to get a writeable copy */
117 argc=0;
118 bcount=0;
119 in_quotes=0;
120 cs=lpCmdline;
121 while (1) {
122 if (*cs==0 || ((*cs==0x0009 || *cs==0x0020) && !in_quotes)) {
123 /* space */
124 argc++;
125 /* skip the remaining spaces */
126 while (*cs==0x0009 || *cs==0x0020) {
127 cs++;
129 if (*cs==0)
130 break;
131 bcount=0;
132 continue;
133 } else if (*cs==0x005c) {
134 /* '\', count them */
135 bcount++;
136 } else if ((*cs==0x0022) && ((bcount & 1)==0)) {
137 /* unescaped '"' */
138 in_quotes=!in_quotes;
139 bcount=0;
140 } else {
141 /* a regular character */
142 bcount=0;
144 cs++;
146 /* Allocate in a single lump, the string array, and the strings that go with it.
147 * This way the caller can make a single GlobalFree call to free both, as per MSDN.
149 hargv=GlobalAlloc(0, argc*sizeof(LPWSTR)+(strlenW(lpCmdline)+1)*sizeof(WCHAR));
150 argv=GlobalLock(hargv);
151 if (!argv)
152 return NULL;
153 cmdline=(LPWSTR)(argv+argc);
154 strcpyW(cmdline, lpCmdline);
156 argc=0;
157 bcount=0;
158 in_quotes=0;
159 arg=d=s=cmdline;
160 while (*s) {
161 if ((*s==0x0009 || *s==0x0020) && !in_quotes) {
162 /* Close the argument and copy it */
163 *d=0;
164 argv[argc++]=arg;
166 /* skip the remaining spaces */
167 do {
168 s++;
169 } while (*s==0x0009 || *s==0x0020);
171 /* Start with a new argument */
172 arg=d=s;
173 bcount=0;
174 } else if (*s==0x005c) {
175 /* '\\' */
176 *d++=*s++;
177 bcount++;
178 } else if (*s==0x0022) {
179 /* '"' */
180 if ((bcount & 1)==0) {
181 /* Preceeded by an even number of '\', this is half that
182 * number of '\', plus a quote which we erase.
184 d-=bcount/2;
185 in_quotes=!in_quotes;
186 s++;
187 } else {
188 /* Preceeded by an odd number of '\', this is half that
189 * number of '\' followed by a '"'
191 d=d-bcount/2-1;
192 *d++='"';
193 s++;
195 bcount=0;
196 } else {
197 /* a regular character */
198 *d++=*s++;
199 bcount=0;
202 if (*arg) {
203 *d='\0';
204 argv[argc++]=arg;
206 if (numargs)
207 *numargs=argc;
209 return argv;
212 /*************************************************************************
213 * SHGetFileInfoA [SHELL32.@]
217 DWORD WINAPI SHGetFileInfoW(LPCWSTR path,DWORD dwFileAttributes,
218 SHFILEINFOW *psfi, UINT sizeofpsfi,
219 UINT flags )
221 WCHAR szLocation[MAX_PATH], szFullPath[MAX_PATH];
222 int iIndex;
223 DWORD ret = TRUE, dwAttributes = 0;
224 IShellFolder * psfParent = NULL;
225 IExtractIconW * pei = NULL;
226 LPITEMIDLIST pidlLast = NULL, pidl = NULL;
227 HRESULT hr = S_OK;
228 BOOL IconNotYetLoaded=TRUE;
230 TRACE("(%s fattr=0x%lx sfi=%p(attr=0x%08lx) size=0x%x flags=0x%x)\n",
231 (flags & SHGFI_PIDL)? "pidl" : debugstr_w(path), dwFileAttributes, psfi, psfi->dwAttributes, sizeofpsfi, flags);
233 if ((flags & SHGFI_USEFILEATTRIBUTES) && (flags & (SHGFI_ATTRIBUTES|SHGFI_EXETYPE|SHGFI_PIDL)))
234 return FALSE;
236 /* windows initializes this values regardless of the flags */
237 if (psfi != NULL) {
238 psfi->szDisplayName[0] = '\0';
239 psfi->szTypeName[0] = '\0';
240 psfi->iIcon = 0;
243 if (!(flags & SHGFI_PIDL)){
244 /* SHGitFileInfo should work with absolute and relative paths */
245 if (PathIsRelativeW(path)){
246 GetCurrentDirectoryW(MAX_PATH, szLocation);
247 PathCombineW(szFullPath, szLocation, path);
248 } else {
249 lstrcpynW(szFullPath, path, MAX_PATH);
253 if (flags & SHGFI_EXETYPE) {
254 BOOL status = FALSE;
255 HANDLE hfile;
256 DWORD BinaryType;
257 IMAGE_DOS_HEADER mz_header;
258 IMAGE_NT_HEADERS nt;
259 DWORD len;
260 char magic[4];
262 if (flags != SHGFI_EXETYPE) return 0;
264 status = GetBinaryTypeW (szFullPath, &BinaryType);
265 if (!status) return 0;
266 if ((BinaryType == SCS_DOS_BINARY)
267 || (BinaryType == SCS_PIF_BINARY)) return 0x4d5a;
269 hfile = CreateFileW( szFullPath, GENERIC_READ, FILE_SHARE_READ,
270 NULL, OPEN_EXISTING, 0, 0 );
271 if ( hfile == INVALID_HANDLE_VALUE ) return 0;
273 /* The next section is adapted from MODULE_GetBinaryType, as we need
274 * to examine the image header to get OS and version information. We
275 * know from calling GetBinaryTypeA that the image is valid and either
276 * an NE or PE, so much error handling can be omitted.
277 * Seek to the start of the file and read the header information.
280 SetFilePointer( hfile, 0, NULL, SEEK_SET );
281 ReadFile( hfile, &mz_header, sizeof(mz_header), &len, NULL );
283 SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
284 ReadFile( hfile, magic, sizeof(magic), &len, NULL );
285 if ( *(DWORD*)magic == IMAGE_NT_SIGNATURE )
287 SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
288 ReadFile( hfile, &nt, sizeof(nt), &len, NULL );
289 CloseHandle( hfile );
290 if (nt.OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_GUI) {
291 return IMAGE_NT_SIGNATURE
292 | (nt.OptionalHeader.MajorSubsystemVersion << 24)
293 | (nt.OptionalHeader.MinorSubsystemVersion << 16);
295 return IMAGE_NT_SIGNATURE;
297 else if ( *(WORD*)magic == IMAGE_OS2_SIGNATURE )
299 IMAGE_OS2_HEADER ne;
300 SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
301 ReadFile( hfile, &ne, sizeof(ne), &len, NULL );
302 CloseHandle( hfile );
303 if (ne.ne_exetyp == 2) return IMAGE_OS2_SIGNATURE
304 | (ne.ne_expver << 16);
305 return 0;
307 CloseHandle( hfile );
308 return 0;
311 /* psfi is NULL normally to query EXE type. If it is NULL, none of the
312 * below makes sense anyway. Windows allows this and just returns FALSE */
313 if (psfi == NULL) return FALSE;
315 /* translate the path into a pidl only when SHGFI_USEFILEATTRIBUTES
316 * is not specified.
317 The pidl functions fail on not existing file names */
319 if (flags & SHGFI_PIDL) {
320 pidl = ILClone((LPCITEMIDLIST)path);
321 } else if (!(flags & SHGFI_USEFILEATTRIBUTES)) {
322 hr = SHILCreateFromPathW(szFullPath, &pidl, &dwAttributes);
325 if ((flags & SHGFI_PIDL) || !(flags & SHGFI_USEFILEATTRIBUTES))
327 /* get the parent shellfolder */
328 if (pidl) {
329 hr = SHBindToParent(pidl, &IID_IShellFolder, (LPVOID*)&psfParent, (LPCITEMIDLIST*)&pidlLast);
330 ILFree(pidl);
331 } else {
332 ERR("pidl is null!\n");
333 return FALSE;
337 /* get the attributes of the child */
338 if (SUCCEEDED(hr) && (flags & SHGFI_ATTRIBUTES))
340 if (!(flags & SHGFI_ATTR_SPECIFIED))
342 psfi->dwAttributes = 0xffffffff;
344 IShellFolder_GetAttributesOf(psfParent, 1, (LPCITEMIDLIST*)&pidlLast, &(psfi->dwAttributes));
347 /* get the displayname */
348 if (SUCCEEDED(hr) && (flags & SHGFI_DISPLAYNAME))
350 if (flags & SHGFI_USEFILEATTRIBUTES)
352 lstrcpyW (psfi->szDisplayName, PathFindFileNameW(szFullPath));
354 else
356 STRRET str;
357 hr = IShellFolder_GetDisplayNameOf(psfParent, pidlLast, SHGDN_INFOLDER, &str);
358 StrRetToStrNW (psfi->szDisplayName, MAX_PATH, &str, pidlLast);
362 /* get the type name */
363 if (SUCCEEDED(hr) && (flags & SHGFI_TYPENAME))
365 static const WCHAR szFile[] = { 'F','i','l','e',0 };
366 static const WCHAR szDashFile[] = { '-','f','i','l','e',0 };
367 if (!(flags & SHGFI_USEFILEATTRIBUTES))
369 char ftype[80];
370 _ILGetFileType(pidlLast, ftype, 80);
371 MultiByteToWideChar(CP_ACP, 0, ftype, -1, psfi->szTypeName, 80 );
373 else
375 if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
376 strcatW (psfi->szTypeName, szFile);
377 else
379 WCHAR sTemp[64];
380 lstrcpyW(sTemp,PathFindExtensionW(szFullPath));
381 if (!( HCR_MapTypeToValueW(sTemp, sTemp, 64, TRUE)
382 && HCR_MapTypeToValueW(sTemp, psfi->szTypeName, 80, FALSE )))
384 lstrcpynW (psfi->szTypeName, sTemp, 64);
385 strcatW (psfi->szTypeName, szDashFile);
391 /* ### icons ###*/
392 if (flags & SHGFI_LINKOVERLAY)
393 FIXME("set icon to link, stub\n");
395 if (flags & SHGFI_SELECTED)
396 FIXME("set icon to selected, stub\n");
398 if (flags & SHGFI_SHELLICONSIZE)
399 FIXME("set icon to shell size, stub\n");
401 /* get the iconlocation */
402 if (SUCCEEDED(hr) && (flags & SHGFI_ICONLOCATION ))
404 UINT uDummy,uFlags;
405 hr = IShellFolder_GetUIObjectOf(psfParent, 0, 1, (LPCITEMIDLIST*)&pidlLast, &IID_IExtractIconA, &uDummy, (LPVOID*)&pei);
407 if (SUCCEEDED(hr))
409 hr = IExtractIconW_GetIconLocation(pei, (flags & SHGFI_OPENICON)? GIL_OPENICON : 0,szLocation, MAX_PATH, &iIndex, &uFlags);
410 psfi->iIcon = iIndex;
412 if(uFlags != GIL_NOTFILENAME)
413 lstrcpyW (psfi->szDisplayName, szLocation);
414 else
415 ret = FALSE;
417 IExtractIconA_Release(pei);
421 /* get icon index (or load icon)*/
422 if (SUCCEEDED(hr) && (flags & (SHGFI_ICON | SHGFI_SYSICONINDEX)))
425 if (flags & SHGFI_USEFILEATTRIBUTES)
427 WCHAR sTemp [MAX_PATH];
428 WCHAR * szExt;
429 DWORD dwNr=0;
431 lstrcpynW(sTemp, szFullPath, MAX_PATH);
433 if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
434 psfi->iIcon = 2;
435 else
437 static const WCHAR p1W[] = {'%','1',0};
438 psfi->iIcon = 0;
439 szExt = (LPWSTR) PathFindExtensionW(sTemp);
440 if ( szExt && HCR_MapTypeToValueW(szExt, sTemp, MAX_PATH, TRUE)
441 && HCR_GetDefaultIconW(sTemp, sTemp, MAX_PATH, &dwNr))
443 if (!lstrcmpW(p1W,sTemp)) /* icon is in the file */
444 strcpyW(sTemp, szFullPath);
446 if (flags & SHGFI_SYSICONINDEX)
448 psfi->iIcon = SIC_GetIconIndex(sTemp,dwNr);
449 if (psfi->iIcon == -1) psfi->iIcon = 0;
451 else
453 IconNotYetLoaded=FALSE;
454 PrivateExtractIconsW(sTemp,dwNr,(flags & SHGFI_SMALLICON) ?
455 GetSystemMetrics(SM_CXSMICON) : GetSystemMetrics(SM_CXICON),
456 (flags & SHGFI_SMALLICON) ? GetSystemMetrics(SM_CYSMICON) :
457 GetSystemMetrics(SM_CYICON), &psfi->hIcon,0,1,0);
458 psfi->iIcon = dwNr;
463 else
465 if (!(PidlToSicIndex(psfParent, pidlLast, !(flags & SHGFI_SMALLICON),
466 (flags & SHGFI_OPENICON)? GIL_OPENICON : 0, &(psfi->iIcon))))
468 ret = FALSE;
471 if (ret)
473 ret = (DWORD) ((flags & SHGFI_SMALLICON) ? ShellSmallIconList : ShellBigIconList);
477 /* icon handle */
478 if (SUCCEEDED(hr) && (flags & SHGFI_ICON) && IconNotYetLoaded)
479 psfi->hIcon = ImageList_GetIcon((flags & SHGFI_SMALLICON) ? ShellSmallIconList:ShellBigIconList, psfi->iIcon, ILD_NORMAL);
481 if (flags & (SHGFI_UNKNOWN1 | SHGFI_UNKNOWN2 | SHGFI_UNKNOWN3))
482 FIXME("unknown attribute!\n");
484 if (psfParent)
485 IShellFolder_Release(psfParent);
487 if (hr != S_OK)
488 ret = FALSE;
490 if(pidlLast) SHFree(pidlLast);
491 #ifdef MORE_DEBUG
492 TRACE ("icon=%p index=0x%08x attr=0x%08lx name=%s type=%s ret=0x%08lx\n",
493 psfi->hIcon, psfi->iIcon, psfi->dwAttributes, debugstr_w(psfi->szDisplayName), debugstr_w(psfi->szTypeName), ret);
494 #endif
495 return ret;
498 /*************************************************************************
499 * SHGetFileInfoW [SHELL32.@]
502 DWORD WINAPI SHGetFileInfoA(LPCSTR path,DWORD dwFileAttributes,
503 SHFILEINFOA *psfi, UINT sizeofpsfi,
504 UINT flags )
506 INT len;
507 LPWSTR temppath;
508 DWORD ret;
509 SHFILEINFOW temppsfi;
511 if (flags & SHGFI_PIDL) {
512 /* path contains a pidl */
513 temppath = (LPWSTR) path;
514 } else {
515 len = MultiByteToWideChar(CP_ACP, 0, path, -1, NULL, 0);
516 temppath = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
517 MultiByteToWideChar(CP_ACP, 0, path, -1, temppath, len);
520 if(psfi && (flags & SHGFI_ATTR_SPECIFIED))
521 temppsfi.dwAttributes=psfi->dwAttributes;
523 ret = SHGetFileInfoW(temppath, dwFileAttributes, (psfi == NULL)? NULL : &temppsfi, sizeof(temppsfi), flags);
525 if (psfi)
527 if(flags & SHGFI_ICON)
528 psfi->hIcon=temppsfi.hIcon;
529 if(flags & (SHGFI_SYSICONINDEX|SHGFI_ICON|SHGFI_ICONLOCATION))
530 psfi->iIcon=temppsfi.iIcon;
531 if(flags & SHGFI_ATTRIBUTES)
532 psfi->dwAttributes=temppsfi.dwAttributes;
533 if(flags & (SHGFI_DISPLAYNAME|SHGFI_ICONLOCATION))
534 WideCharToMultiByte(CP_ACP, 0, temppsfi.szDisplayName, -1, psfi->szDisplayName, sizeof(psfi->szDisplayName), NULL, NULL);
535 if(flags & SHGFI_TYPENAME)
536 WideCharToMultiByte(CP_ACP, 0, temppsfi.szTypeName, -1, psfi->szTypeName, sizeof(psfi->szTypeName), NULL, NULL);
538 if(!(flags & SHGFI_PIDL)) HeapFree(GetProcessHeap(), 0, temppath);
539 return ret;
542 /*************************************************************************
543 * SHGetFileInfo [SHELL32.@]
545 DWORD WINAPI SHGetFileInfoAW(
546 LPCVOID path,
547 DWORD dwFileAttributes,
548 LPVOID psfi,
549 UINT sizeofpsfi,
550 UINT flags)
552 if(SHELL_OsIsUnicode())
553 return SHGetFileInfoW(path, dwFileAttributes, psfi, sizeofpsfi, flags );
554 return SHGetFileInfoA(path, dwFileAttributes, psfi, sizeofpsfi, flags );
557 /*************************************************************************
558 * DuplicateIcon [SHELL32.@]
560 HICON WINAPI DuplicateIcon( HINSTANCE hInstance, HICON hIcon)
562 ICONINFO IconInfo;
563 HICON hDupIcon = 0;
565 TRACE("(%p, %p)\n", hInstance, hIcon);
567 if(GetIconInfo(hIcon, &IconInfo))
569 hDupIcon = CreateIconIndirect(&IconInfo);
571 /* clean up hbmMask and hbmColor */
572 DeleteObject(IconInfo.hbmMask);
573 DeleteObject(IconInfo.hbmColor);
576 return hDupIcon;
579 /*************************************************************************
580 * ExtractIconA [SHELL32.@]
582 HICON WINAPI ExtractIconA(HINSTANCE hInstance, LPCSTR lpszFile, UINT nIconIndex)
584 HICON ret;
585 INT len = MultiByteToWideChar(CP_ACP, 0, lpszFile, -1, NULL, 0);
586 LPWSTR lpwstrFile = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
588 TRACE("%p %s %d\n", hInstance, lpszFile, nIconIndex);
590 MultiByteToWideChar(CP_ACP, 0, lpszFile, -1, lpwstrFile, len);
591 ret = ExtractIconW(hInstance, lpwstrFile, nIconIndex);
592 HeapFree(GetProcessHeap(), 0, lpwstrFile);
593 return ret;
596 /*************************************************************************
597 * ExtractIconW [SHELL32.@]
599 HICON WINAPI ExtractIconW(HINSTANCE hInstance, LPCWSTR lpszFile, UINT nIconIndex)
601 HICON hIcon = NULL;
602 UINT ret;
603 UINT cx = GetSystemMetrics(SM_CXICON), cy = GetSystemMetrics(SM_CYICON);
605 TRACE("%p %s %d\n", hInstance, debugstr_w(lpszFile), nIconIndex);
607 if (nIconIndex == 0xFFFFFFFF) {
608 ret = PrivateExtractIconsW(lpszFile, 0, cx, cy, NULL, NULL, 0, LR_DEFAULTCOLOR);
609 if (ret != 0xFFFFFFFF && ret)
610 return (HICON)ret;
611 return NULL;
613 else
614 ret = PrivateExtractIconsW(lpszFile, nIconIndex, cx, cy, &hIcon, NULL, 1, LR_DEFAULTCOLOR);
616 if (ret == 0xFFFFFFFF)
617 return (HICON)1;
618 else if (ret > 0 && hIcon)
619 return hIcon;
620 return NULL;
623 typedef struct
625 LPCWSTR szApp;
626 LPCWSTR szOtherStuff;
627 HICON hIcon;
628 } ABOUT_INFO;
630 #define IDC_STATIC_TEXT 100
631 #define IDC_LISTBOX 99
632 #define IDC_WINE_TEXT 98
634 #define DROP_FIELD_TOP (-15)
635 #define DROP_FIELD_HEIGHT 15
637 static HFONT hIconTitleFont;
639 static BOOL __get_dropline( HWND hWnd, LPRECT lprect )
640 { HWND hWndCtl = GetDlgItem(hWnd, IDC_WINE_TEXT);
641 if( hWndCtl )
642 { GetWindowRect( hWndCtl, lprect );
643 MapWindowPoints( 0, hWnd, (LPPOINT)lprect, 2 );
644 lprect->bottom = (lprect->top += DROP_FIELD_TOP);
645 return TRUE;
647 return FALSE;
650 /*************************************************************************
651 * SHAppBarMessage [SHELL32.@]
653 UINT WINAPI SHAppBarMessage(DWORD msg, PAPPBARDATA data)
655 int width=data->rc.right - data->rc.left;
656 int height=data->rc.bottom - data->rc.top;
657 RECT rec=data->rc;
658 switch (msg)
659 { case ABM_GETSTATE:
660 return ABS_ALWAYSONTOP | ABS_AUTOHIDE;
661 case ABM_GETTASKBARPOS:
662 GetWindowRect(data->hWnd, &rec);
663 data->rc=rec;
664 return TRUE;
665 case ABM_ACTIVATE:
666 SetActiveWindow(data->hWnd);
667 return TRUE;
668 case ABM_GETAUTOHIDEBAR:
669 data->hWnd=GetActiveWindow();
670 return TRUE;
671 case ABM_NEW:
672 SetWindowPos(data->hWnd,HWND_TOP,rec.left,rec.top,
673 width,height,SWP_SHOWWINDOW);
674 return TRUE;
675 case ABM_QUERYPOS:
676 GetWindowRect(data->hWnd, &(data->rc));
677 return TRUE;
678 case ABM_REMOVE:
679 FIXME("ABM_REMOVE broken\n");
680 /* FIXME: this is wrong; should it be DestroyWindow instead? */
681 /*CloseHandle(data->hWnd);*/
682 return TRUE;
683 case ABM_SETAUTOHIDEBAR:
684 SetWindowPos(data->hWnd,HWND_TOP,rec.left+1000,rec.top,
685 width,height,SWP_SHOWWINDOW);
686 return TRUE;
687 case ABM_SETPOS:
688 data->uEdge=(ABE_RIGHT | ABE_LEFT);
689 SetWindowPos(data->hWnd,HWND_TOP,data->rc.left,data->rc.top,
690 width,height,SWP_SHOWWINDOW);
691 return TRUE;
692 case ABM_WINDOWPOSCHANGED:
693 return TRUE;
695 return FALSE;
698 /*************************************************************************
699 * SHHelpShortcuts_RunDLL [SHELL32.@]
702 DWORD WINAPI SHHelpShortcuts_RunDLL (DWORD dwArg1, DWORD dwArg2, DWORD dwArg3, DWORD dwArg4)
703 { FIXME("(%lx, %lx, %lx, %lx) empty stub!\n",
704 dwArg1, dwArg2, dwArg3, dwArg4);
706 return 0;
709 /*************************************************************************
710 * SHLoadInProc [SHELL32.@]
711 * Create an instance of specified object class from within
712 * the shell process and release it immediately
715 DWORD WINAPI SHLoadInProc (REFCLSID rclsid)
717 void *ptr = NULL;
719 TRACE("%s\n", debugstr_guid(rclsid));
721 CoCreateInstance(rclsid, NULL, CLSCTX_INPROC_SERVER, &IID_IUnknown,&ptr);
722 if(ptr)
724 IUnknown * pUnk = ptr;
725 IUnknown_Release(pUnk);
726 return NOERROR;
728 return DISP_E_MEMBERNOTFOUND;
731 /*************************************************************************
732 * AboutDlgProc (internal)
734 INT_PTR CALLBACK AboutDlgProc( HWND hWnd, UINT msg, WPARAM wParam,
735 LPARAM lParam )
737 HWND hWndCtl;
739 TRACE("\n");
741 switch(msg)
743 case WM_INITDIALOG:
745 ABOUT_INFO *info = (ABOUT_INFO *)lParam;
746 WCHAR Template[512], AppTitle[512];
748 if (info)
750 const char* const *pstr = SHELL_Authors;
751 SendDlgItemMessageW(hWnd, stc1, STM_SETICON,(WPARAM)info->hIcon, 0);
752 GetWindowTextW( hWnd, Template, sizeof(Template)/sizeof(WCHAR) );
753 sprintfW( AppTitle, Template, info->szApp );
754 SetWindowTextW( hWnd, AppTitle );
755 SetWindowTextW( GetDlgItem(hWnd, IDC_STATIC_TEXT), info->szOtherStuff );
756 hWndCtl = GetDlgItem(hWnd, IDC_LISTBOX);
757 SendMessageW( hWndCtl, WM_SETREDRAW, 0, 0 );
758 if (!hIconTitleFont)
760 LOGFONTW logFont;
761 SystemParametersInfoW( SPI_GETICONTITLELOGFONT, 0, &logFont, 0 );
762 hIconTitleFont = CreateFontIndirectW( &logFont );
764 SendMessageW( hWndCtl, WM_SETFONT, (WPARAM)hIconTitleFont, 0 );
765 while (*pstr)
767 WCHAR name[64];
768 /* authors list is in iso-8859-1 format */
769 MultiByteToWideChar( 28591, 0, *pstr, -1, name, sizeof(name)/sizeof(WCHAR) );
770 SendMessageW( hWndCtl, LB_ADDSTRING, (WPARAM)-1, (LPARAM)name );
771 pstr++;
773 SendMessageW( hWndCtl, WM_SETREDRAW, 1, 0 );
776 return 1;
778 case WM_PAINT:
779 { RECT rect;
780 PAINTSTRUCT ps;
781 HDC hDC = BeginPaint( hWnd, &ps );
783 if( __get_dropline( hWnd, &rect ) ) {
784 SelectObject( hDC, GetStockObject( BLACK_PEN ) );
785 MoveToEx( hDC, rect.left, rect.top, NULL );
786 LineTo( hDC, rect.right, rect.bottom );
788 EndPaint( hWnd, &ps );
790 break;
792 case WM_COMMAND:
793 if (wParam == IDOK || wParam == IDCANCEL)
795 EndDialog(hWnd, TRUE);
796 return TRUE;
798 break;
799 case WM_CLOSE:
800 EndDialog(hWnd, TRUE);
801 break;
804 return 0;
808 /*************************************************************************
809 * ShellAboutA [SHELL32.288]
811 BOOL WINAPI ShellAboutA( HWND hWnd, LPCSTR szApp, LPCSTR szOtherStuff, HICON hIcon )
813 BOOL ret;
814 LPWSTR appW = NULL, otherW = NULL;
815 int len;
817 if (szApp)
819 len = MultiByteToWideChar(CP_ACP, 0, szApp, -1, NULL, 0);
820 appW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
821 MultiByteToWideChar(CP_ACP, 0, szApp, -1, appW, len);
823 if (szOtherStuff)
825 len = MultiByteToWideChar(CP_ACP, 0, szOtherStuff, -1, NULL, 0);
826 otherW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
827 MultiByteToWideChar(CP_ACP, 0, szOtherStuff, -1, otherW, len);
830 ret = ShellAboutW(hWnd, appW, otherW, hIcon);
832 if (otherW) HeapFree(GetProcessHeap(), 0, otherW);
833 if (appW) HeapFree(GetProcessHeap(), 0, appW);
834 return ret;
838 /*************************************************************************
839 * ShellAboutW [SHELL32.289]
841 BOOL WINAPI ShellAboutW( HWND hWnd, LPCWSTR szApp, LPCWSTR szOtherStuff,
842 HICON hIcon )
844 ABOUT_INFO info;
845 HRSRC hRes;
846 LPVOID template;
848 TRACE("\n");
850 if(!(hRes = FindResourceA(shell32_hInstance, "SHELL_ABOUT_MSGBOX", (LPSTR)RT_DIALOG)))
851 return FALSE;
852 if(!(template = (LPVOID)LoadResource(shell32_hInstance, hRes)))
853 return FALSE;
854 info.szApp = szApp;
855 info.szOtherStuff = szOtherStuff;
856 info.hIcon = hIcon ? hIcon : LoadIconW( 0, (LPWSTR)IDI_WINLOGO );
857 return DialogBoxIndirectParamW((HINSTANCE)GetWindowLongW( hWnd, GWL_HINSTANCE ),
858 template, hWnd, AboutDlgProc, (LPARAM)&info );
861 /*************************************************************************
862 * FreeIconList (SHELL32.@)
864 void WINAPI FreeIconList( DWORD dw )
865 { FIXME("(%lx): stub\n",dw);
869 /*************************************************************************
870 * ShellDDEInit (SHELL32.@)
872 void WINAPI ShellDDEInit(BOOL start)
874 FIXME("stub: %d\n", start);
877 /***********************************************************************
878 * DllGetVersion [SHELL32.@]
880 * Retrieves version information of the 'SHELL32.DLL'
882 * PARAMS
883 * pdvi [O] pointer to version information structure.
885 * RETURNS
886 * Success: S_OK
887 * Failure: E_INVALIDARG
889 * NOTES
890 * Returns version of a shell32.dll from IE4.01 SP1.
893 HRESULT WINAPI SHELL32_DllGetVersion (DLLVERSIONINFO *pdvi)
895 if (pdvi->cbSize != sizeof(DLLVERSIONINFO))
897 WARN("wrong DLLVERSIONINFO size from app\n");
898 return E_INVALIDARG;
901 pdvi->dwMajorVersion = 4;
902 pdvi->dwMinorVersion = 72;
903 pdvi->dwBuildNumber = 3110;
904 pdvi->dwPlatformID = 1;
906 TRACE("%lu.%lu.%lu.%lu\n",
907 pdvi->dwMajorVersion, pdvi->dwMinorVersion,
908 pdvi->dwBuildNumber, pdvi->dwPlatformID);
910 return S_OK;
912 /*************************************************************************
913 * global variables of the shell32.dll
914 * all are once per process
917 HINSTANCE shell32_hInstance = 0;
918 HIMAGELIST ShellSmallIconList = 0;
919 HIMAGELIST ShellBigIconList = 0;
922 /*************************************************************************
923 * SHELL32 DllMain
925 * NOTES
926 * calling oleinitialize here breaks sone apps.
929 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
931 TRACE("%p 0x%lx %p\n", hinstDLL, fdwReason, fImpLoad);
933 switch (fdwReason)
935 case DLL_PROCESS_ATTACH:
936 shell32_hInstance = hinstDLL;
937 DisableThreadLibraryCalls(shell32_hInstance);
939 /* get full path to this DLL for IExtractIconW_fnGetIconLocation() */
940 GetModuleFileNameW(hinstDLL, swShell32Name, MAX_PATH);
941 swShell32Name[MAX_PATH - 1] = '\0';
943 InitCommonControlsEx(NULL);
945 SIC_Initialize();
946 SYSTRAY_Init();
947 InitChangeNotifications();
948 break;
950 case DLL_PROCESS_DETACH:
951 shell32_hInstance = 0;
952 SIC_Destroy();
953 FreeChangeNotifications();
954 break;
956 return TRUE;
959 /*************************************************************************
960 * DllInstall [SHELL32.@]
962 * PARAMETERS
964 * BOOL bInstall - TRUE for install, FALSE for uninstall
965 * LPCWSTR pszCmdLine - command line (unused by shell32?)
968 HRESULT WINAPI SHELL32_DllInstall(BOOL bInstall, LPCWSTR cmdline)
970 FIXME("(%s, %s): stub!\n", bInstall ? "TRUE":"FALSE", debugstr_w(cmdline));
972 return S_OK; /* indicate success */
975 /***********************************************************************
976 * DllCanUnloadNow (SHELL32.@)
978 HRESULT WINAPI SHELL32_DllCanUnloadNow(void)
980 FIXME("(void): stub\n");
982 return S_FALSE;