Fixed a typo in the previous SHGetFileInfo() patch.
[wine.git] / dlls / shell32 / shell32_main.c
blob2800beceb867bb5aa065a6100b34bdb7f8ec7c5d
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 <stdio.h>
28 #include "windef.h"
29 #include "winerror.h"
30 #include "winreg.h"
31 #include "dlgs.h"
32 #include "shellapi.h"
33 #include "shlobj.h"
34 #include "shlguid.h"
35 #include "shlwapi.h"
37 #include "undocshell.h"
38 #include "wine/winuser16.h"
39 #include "authors.h"
40 #include "heap.h"
41 #include "pidl.h"
42 #include "shell32_main.h"
44 #include "wine/debug.h"
45 #include "wine/unicode.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(shell);
49 #define MORE_DEBUG 1
50 /*************************************************************************
51 * CommandLineToArgvW [SHELL32.@]
53 * We must interpret the quotes in the command line to rebuild the argv
54 * array correctly:
55 * - arguments are separated by spaces or tabs
56 * - quotes serve as optional argument delimiters
57 * '"a b"' -> 'a b'
58 * - escaped quotes must be converted back to '"'
59 * '\"' -> '"'
60 * - an odd number of '\'s followed by '"' correspond to half that number
61 * of '\' followed by a '"' (extension of the above)
62 * '\\\"' -> '\"'
63 * '\\\\\"' -> '\\"'
64 * - an even number of '\'s followed by a '"' correspond to half that number
65 * of '\', plus a regular quote serving as an argument delimiter (which
66 * means it does not appear in the result)
67 * 'a\\"b c"' -> 'a\b c'
68 * 'a\\\\"b c"' -> 'a\\b c'
69 * - '\' that are not followed by a '"' are copied literally
70 * 'a\b' -> 'a\b'
71 * 'a\\b' -> 'a\\b'
73 * Note:
74 * '\t' == 0x0009
75 * ' ' == 0x0020
76 * '"' == 0x0022
77 * '\\' == 0x005c
79 LPWSTR* WINAPI CommandLineToArgvW(LPCWSTR lpCmdline, int* numargs)
81 DWORD argc;
82 HGLOBAL hargv;
83 LPWSTR *argv;
84 LPCWSTR cs;
85 LPWSTR arg,s,d;
86 LPWSTR cmdline;
87 int in_quotes,bcount;
89 if (*lpCmdline==0) {
90 /* Return the path to the executable */
91 DWORD size;
93 hargv=0;
94 size=16;
95 do {
96 size*=2;
97 hargv=GlobalReAlloc(hargv, size, 0);
98 argv=GlobalLock(hargv);
99 } while (GetModuleFileNameW(0, (LPWSTR)(argv+1), size-sizeof(LPWSTR)) == 0);
100 argv[0]=(LPWSTR)(argv+1);
101 if (numargs)
102 *numargs=2;
104 return argv;
107 /* to get a writeable copy */
108 argc=0;
109 bcount=0;
110 in_quotes=0;
111 cs=lpCmdline;
112 while (1) {
113 if (*cs==0 || ((*cs==0x0009 || *cs==0x0020) && !in_quotes)) {
114 /* space */
115 argc++;
116 /* skip the remaining spaces */
117 while (*cs==0x0009 || *cs==0x0020) {
118 cs++;
120 if (*cs==0)
121 break;
122 bcount=0;
123 continue;
124 } else if (*cs==0x005c) {
125 /* '\', count them */
126 bcount++;
127 } else if ((*cs==0x0022) && ((bcount & 1)==0)) {
128 /* unescaped '"' */
129 in_quotes=!in_quotes;
130 bcount=0;
131 } else {
132 /* a regular character */
133 bcount=0;
135 cs++;
137 /* Allocate in a single lump, the string array, and the strings that go with it.
138 * This way the caller can make a single GlobalFree call to free both, as per MSDN.
140 hargv=GlobalAlloc(0, argc*sizeof(LPWSTR)+(strlenW(lpCmdline)+1)*sizeof(WCHAR));
141 argv=GlobalLock(hargv);
142 if (!argv)
143 return NULL;
144 cmdline=(LPWSTR)(argv+argc);
145 strcpyW(cmdline, lpCmdline);
147 argc=0;
148 bcount=0;
149 in_quotes=0;
150 arg=d=s=cmdline;
151 while (*s) {
152 if ((*s==0x0009 || *s==0x0020) && !in_quotes) {
153 /* Close the argument and copy it */
154 *d=0;
155 argv[argc++]=arg;
157 /* skip the remaining spaces */
158 do {
159 s++;
160 } while (*s==0x0009 || *s==0x0020);
162 /* Start with a new argument */
163 arg=d=s;
164 bcount=0;
165 } else if (*s==0x005c) {
166 /* '\\' */
167 *d++=*s++;
168 bcount++;
169 } else if (*s==0x0022) {
170 /* '"' */
171 if ((bcount & 1)==0) {
172 /* Preceeded by an even number of '\', this is half that
173 * number of '\', plus a quote which we erase.
175 d-=bcount/2;
176 in_quotes=!in_quotes;
177 s++;
178 } else {
179 /* Preceeded by an odd number of '\', this is half that
180 * number of '\' followed by a '"'
182 d=d-bcount/2-1;
183 *d++='"';
184 s++;
186 bcount=0;
187 } else {
188 /* a regular character */
189 *d++=*s++;
190 bcount=0;
193 if (*arg) {
194 *d='\0';
195 argv[argc++]=arg;
197 if (numargs)
198 *numargs=argc;
200 return argv;
203 /*************************************************************************
204 * SHGetFileInfoA [SHELL32.@]
208 DWORD WINAPI SHGetFileInfoA(LPCSTR path,DWORD dwFileAttributes,
209 SHFILEINFOA *psfi, UINT sizeofpsfi,
210 UINT flags )
212 char szLocation[MAX_PATH], szFullPath[MAX_PATH];
213 int iIndex;
214 DWORD ret = TRUE, dwAttributes = 0;
215 IShellFolder * psfParent = NULL;
216 IExtractIconA * pei = NULL;
217 LPITEMIDLIST pidlLast = NULL, pidl = NULL;
218 HRESULT hr = S_OK;
219 BOOL IconNotYetLoaded=TRUE;
221 TRACE("(%s fattr=0x%lx sfi=%p(attr=0x%08lx) size=0x%x flags=0x%x)\n",
222 (flags & SHGFI_PIDL)? "pidl" : path, dwFileAttributes, psfi, psfi->dwAttributes, sizeofpsfi, flags);
224 if ((flags & SHGFI_USEFILEATTRIBUTES) && (flags & (SHGFI_ATTRIBUTES|SHGFI_EXETYPE|SHGFI_PIDL)))
225 return FALSE;
227 /* windows initializes this values regardless of the flags */
228 if (psfi != NULL) {
229 psfi->szDisplayName[0] = '\0';
230 psfi->szTypeName[0] = '\0';
231 psfi->iIcon = 0;
234 if (!(flags & SHGFI_PIDL)){
235 /* SHGitFileInfo should work with absolute and relative paths */
236 if (PathIsRelativeA(path)){
237 GetCurrentDirectoryA(MAX_PATH, szLocation);
238 PathCombineA(szFullPath, szLocation, path);
239 } else {
240 lstrcpynA(szFullPath, path, MAX_PATH);
244 if (flags & SHGFI_EXETYPE) {
245 BOOL status = FALSE;
246 HANDLE hfile;
247 DWORD BinaryType;
248 IMAGE_DOS_HEADER mz_header;
249 IMAGE_NT_HEADERS nt;
250 DWORD len;
251 char magic[4];
253 if (flags != SHGFI_EXETYPE) return 0;
255 status = GetBinaryTypeA (szFullPath, &BinaryType);
256 if (!status) return 0;
257 if ((BinaryType == SCS_DOS_BINARY)
258 || (BinaryType == SCS_PIF_BINARY)) return 0x4d5a;
260 hfile = CreateFileA( szFullPath, GENERIC_READ, FILE_SHARE_READ,
261 NULL, OPEN_EXISTING, 0, 0 );
262 if ( hfile == INVALID_HANDLE_VALUE ) return 0;
264 /* The next section is adapted from MODULE_GetBinaryType, as we need
265 * to examine the image header to get OS and version information. We
266 * know from calling GetBinaryTypeA that the image is valid and either
267 * an NE or PE, so much error handling can be omitted.
268 * Seek to the start of the file and read the header information.
271 SetFilePointer( hfile, 0, NULL, SEEK_SET );
272 ReadFile( hfile, &mz_header, sizeof(mz_header), &len, NULL );
274 SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
275 ReadFile( hfile, magic, sizeof(magic), &len, NULL );
276 if ( *(DWORD*)magic == IMAGE_NT_SIGNATURE )
278 SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
279 ReadFile( hfile, &nt, sizeof(nt), &len, NULL );
280 CloseHandle( hfile );
281 if (nt.OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_GUI) {
282 return IMAGE_NT_SIGNATURE
283 | (nt.OptionalHeader.MajorSubsystemVersion << 24)
284 | (nt.OptionalHeader.MinorSubsystemVersion << 16);
286 return IMAGE_NT_SIGNATURE;
288 else if ( *(WORD*)magic == IMAGE_OS2_SIGNATURE )
290 IMAGE_OS2_HEADER ne;
291 SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
292 ReadFile( hfile, &ne, sizeof(ne), &len, NULL );
293 CloseHandle( hfile );
294 if (ne.ne_exetyp == 2) return IMAGE_OS2_SIGNATURE
295 | (ne.ne_expver << 16);
296 return 0;
298 CloseHandle( hfile );
299 return 0;
302 /* psfi is NULL normally to query EXE type. If it is NULL, none of the
303 * below makes sense anyway. Windows allows this and just returns FALSE */
304 if (psfi == NULL) return FALSE;
306 /* translate the path into a pidl only when SHGFI_USEFILEATTRIBUTES
307 * is not specified.
308 The pidl functions fail on not existing file names */
310 if (flags & SHGFI_PIDL) {
311 pidl = ILClone((LPCITEMIDLIST)path);
312 } else if (!(flags & SHGFI_USEFILEATTRIBUTES)) {
313 hr = SHILCreateFromPathA(szFullPath, &pidl, &dwAttributes);
316 if ((flags & SHGFI_PIDL) || !(flags & SHGFI_USEFILEATTRIBUTES))
318 /* get the parent shellfolder */
319 if (pidl) {
320 hr = SHBindToParent( pidl, &IID_IShellFolder, (LPVOID*)&psfParent, &pidlLast);
321 ILFree(pidl);
322 } else {
323 ERR("pidl is null!\n");
324 return FALSE;
328 /* get the attributes of the child */
329 if (SUCCEEDED(hr) && (flags & SHGFI_ATTRIBUTES))
331 if (!(flags & SHGFI_ATTR_SPECIFIED))
333 psfi->dwAttributes = 0xffffffff;
335 IShellFolder_GetAttributesOf(psfParent, 1 , &pidlLast, &(psfi->dwAttributes));
338 /* get the displayname */
339 if (SUCCEEDED(hr) && (flags & SHGFI_DISPLAYNAME))
341 if (flags & SHGFI_USEFILEATTRIBUTES)
343 strcpy (psfi->szDisplayName, PathFindFileNameA(szFullPath));
345 else
347 STRRET str;
348 hr = IShellFolder_GetDisplayNameOf(psfParent, pidlLast, SHGDN_INFOLDER, &str);
349 StrRetToStrNA (psfi->szDisplayName, MAX_PATH, &str, pidlLast);
353 /* get the type name */
354 if (SUCCEEDED(hr) && (flags & SHGFI_TYPENAME))
356 if (!(flags & SHGFI_USEFILEATTRIBUTES))
357 _ILGetFileType(pidlLast, psfi->szTypeName, 80);
358 else
360 if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
361 strcat (psfi->szTypeName, "File");
362 else
364 char sTemp[64];
365 strcpy(sTemp,PathFindExtensionA(szFullPath));
366 if (!( HCR_MapTypeToValueA(sTemp, sTemp, 64, TRUE)
367 && HCR_MapTypeToValueA(sTemp, psfi->szTypeName, 80, FALSE )))
369 lstrcpynA (psfi->szTypeName, sTemp, 64);
370 strcat (psfi->szTypeName, "-file");
376 /* ### icons ###*/
377 if (flags & SHGFI_LINKOVERLAY)
378 FIXME("set icon to link, stub\n");
380 if (flags & SHGFI_SELECTED)
381 FIXME("set icon to selected, stub\n");
383 if (flags & SHGFI_SHELLICONSIZE)
384 FIXME("set icon to shell size, stub\n");
386 /* get the iconlocation */
387 if (SUCCEEDED(hr) && (flags & SHGFI_ICONLOCATION ))
389 UINT uDummy,uFlags;
390 hr = IShellFolder_GetUIObjectOf(psfParent, 0, 1, &pidlLast, &IID_IExtractIconA, &uDummy, (LPVOID*)&pei);
392 if (SUCCEEDED(hr))
394 hr = IExtractIconA_GetIconLocation(pei, (flags & SHGFI_OPENICON)? GIL_OPENICON : 0,szLocation, MAX_PATH, &iIndex, &uFlags);
395 psfi->iIcon = iIndex;
397 if(uFlags != GIL_NOTFILENAME)
398 strcpy (psfi->szDisplayName, szLocation);
399 else
400 ret = FALSE;
402 IExtractIconA_Release(pei);
406 /* get icon index (or load icon)*/
407 if (SUCCEEDED(hr) && (flags & (SHGFI_ICON | SHGFI_SYSICONINDEX)))
410 if (flags & SHGFI_USEFILEATTRIBUTES)
412 char sTemp [MAX_PATH];
413 char * szExt;
414 DWORD dwNr=0;
416 lstrcpynA(sTemp, szFullPath, MAX_PATH);
418 if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
419 psfi->iIcon = 2;
420 else
422 psfi->iIcon = 0;
423 szExt = (LPSTR) PathFindExtensionA(sTemp);
424 if ( szExt && HCR_MapTypeToValueA(szExt, sTemp, MAX_PATH, TRUE)
425 && HCR_GetDefaultIconA(sTemp, sTemp, MAX_PATH, &dwNr))
427 if (!strcmp("%1",sTemp)) /* icon is in the file */
428 strcpy(sTemp, szFullPath);
430 if (flags & SHGFI_SYSICONINDEX)
432 psfi->iIcon = SIC_GetIconIndex(sTemp,dwNr);
433 if (psfi->iIcon == -1) psfi->iIcon = 0;
435 else
437 IconNotYetLoaded=FALSE;
438 PrivateExtractIconsA(sTemp,dwNr,(flags & SHGFI_SMALLICON) ?
439 GetSystemMetrics(SM_CXSMICON) : GetSystemMetrics(SM_CXICON),
440 (flags & SHGFI_SMALLICON) ? GetSystemMetrics(SM_CYSMICON) :
441 GetSystemMetrics(SM_CYICON), &psfi->hIcon,0,1,0);
442 psfi->iIcon = dwNr;
447 else
449 if (!(PidlToSicIndex(psfParent, pidlLast, !(flags & SHGFI_SMALLICON),
450 (flags & SHGFI_OPENICON)? GIL_OPENICON : 0, &(psfi->iIcon))))
452 ret = FALSE;
455 if (ret)
457 ret = (DWORD) ((flags & SHGFI_SMALLICON) ? ShellSmallIconList : ShellBigIconList);
461 /* icon handle */
462 if (SUCCEEDED(hr) && (flags & SHGFI_ICON) && IconNotYetLoaded)
463 psfi->hIcon = ImageList_GetIcon((flags & SHGFI_SMALLICON) ? ShellSmallIconList:ShellBigIconList, psfi->iIcon, ILD_NORMAL);
465 if (flags & (SHGFI_UNKNOWN1 | SHGFI_UNKNOWN2 | SHGFI_UNKNOWN3))
466 FIXME("unknown attribute!\n");
468 if (psfParent)
469 IShellFolder_Release(psfParent);
471 if (hr != S_OK)
472 ret = FALSE;
474 if(pidlLast) SHFree(pidlLast);
475 #ifdef MORE_DEBUG
476 TRACE ("icon=%p index=0x%08x attr=0x%08lx name=%s type=%s ret=0x%08lx\n",
477 psfi->hIcon, psfi->iIcon, psfi->dwAttributes, psfi->szDisplayName, psfi->szTypeName, ret);
478 #endif
479 return ret;
482 /*************************************************************************
483 * SHGetFileInfoW [SHELL32.@]
486 DWORD WINAPI SHGetFileInfoW(LPCWSTR path,DWORD dwFileAttributes,
487 SHFILEINFOW *psfi, UINT sizeofpsfi,
488 UINT flags )
490 INT len;
491 LPSTR temppath;
492 DWORD ret;
493 SHFILEINFOA temppsfi;
495 if (flags & SHGFI_PIDL) {
496 /* path contains a pidl */
497 temppath = (LPSTR) path;
498 } else {
499 len = WideCharToMultiByte(CP_ACP, 0, path, -1, NULL, 0, NULL, NULL);
500 temppath = HeapAlloc(GetProcessHeap(), 0, len);
501 WideCharToMultiByte(CP_ACP, 0, path, -1, temppath, len, NULL, NULL);
504 if(psfi && (flags & SHGFI_ATTR_SPECIFIED))
505 temppsfi.dwAttributes=psfi->dwAttributes;
507 ret = SHGetFileInfoA(temppath, dwFileAttributes, (psfi == NULL)? NULL : &temppsfi, sizeof(temppsfi), flags);
509 if (psfi)
511 if(flags & SHGFI_ICON)
512 psfi->hIcon=temppsfi.hIcon;
513 if(flags & (SHGFI_SYSICONINDEX|SHGFI_ICON|SHGFI_ICONLOCATION))
514 psfi->iIcon=temppsfi.iIcon;
515 if(flags & SHGFI_ATTRIBUTES)
516 psfi->dwAttributes=temppsfi.dwAttributes;
517 if(flags & (SHGFI_DISPLAYNAME|SHGFI_ICONLOCATION))
518 MultiByteToWideChar(CP_ACP, 0, temppsfi.szDisplayName, -1, psfi->szDisplayName, sizeof(psfi->szDisplayName));
519 if(flags & SHGFI_TYPENAME)
520 MultiByteToWideChar(CP_ACP, 0, temppsfi.szTypeName, -1, psfi->szTypeName, sizeof(psfi->szTypeName));
522 if(!(flags & SHGFI_PIDL)) HeapFree(GetProcessHeap(), 0, temppath);
523 return ret;
526 /*************************************************************************
527 * SHGetFileInfo [SHELL32.@]
529 DWORD WINAPI SHGetFileInfoAW(
530 LPCVOID path,
531 DWORD dwFileAttributes,
532 LPVOID psfi,
533 UINT sizeofpsfi,
534 UINT flags)
536 if(SHELL_OsIsUnicode())
537 return SHGetFileInfoW(path, dwFileAttributes, psfi, sizeofpsfi, flags );
538 return SHGetFileInfoA(path, dwFileAttributes, psfi, sizeofpsfi, flags );
541 /*************************************************************************
542 * DuplicateIcon [SHELL32.@]
544 HICON WINAPI DuplicateIcon( HINSTANCE hInstance, HICON hIcon)
546 ICONINFO IconInfo;
547 HICON hDupIcon = 0;
549 TRACE("(%p, %p)\n", hInstance, hIcon);
551 if(GetIconInfo(hIcon, &IconInfo))
553 hDupIcon = CreateIconIndirect(&IconInfo);
555 /* clean up hbmMask and hbmColor */
556 DeleteObject(IconInfo.hbmMask);
557 DeleteObject(IconInfo.hbmColor);
560 return hDupIcon;
563 /*************************************************************************
564 * ExtractIconA [SHELL32.@]
566 HICON WINAPI ExtractIconA(HINSTANCE hInstance, LPCSTR lpszFile, UINT nIconIndex)
568 HICON ret;
569 INT len = MultiByteToWideChar(CP_ACP, 0, lpszFile, -1, NULL, 0);
570 LPWSTR lpwstrFile = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
572 TRACE("%p %s %d\n", hInstance, lpszFile, nIconIndex);
574 MultiByteToWideChar(CP_ACP, 0, lpszFile, -1, lpwstrFile, len);
575 ret = ExtractIconW(hInstance, lpwstrFile, nIconIndex);
576 HeapFree(GetProcessHeap(), 0, lpwstrFile);
577 return ret;
580 /*************************************************************************
581 * ExtractIconW [SHELL32.@]
583 HICON WINAPI ExtractIconW(HINSTANCE hInstance, LPCWSTR lpszFile, UINT nIconIndex)
585 HICON hIcon = NULL;
586 UINT ret;
587 UINT cx = GetSystemMetrics(SM_CXICON), cy = GetSystemMetrics(SM_CYICON);
589 TRACE("%p %s %d\n", hInstance, debugstr_w(lpszFile), nIconIndex);
591 if (nIconIndex == -1) {
592 ret = PrivateExtractIconsW(lpszFile, 0, cx, cy, NULL, NULL, 0, LR_DEFAULTCOLOR);
593 if (ret != 0xFFFFFFFF && ret)
594 return (HICON)ret;
595 return NULL;
597 else
598 ret = PrivateExtractIconsW(lpszFile, nIconIndex, cx, cy, &hIcon, NULL, 1, LR_DEFAULTCOLOR);
600 if (ret == 0xFFFFFFFF)
601 return (HICON)1;
602 else if (ret > 0 && hIcon)
603 return hIcon;
604 return NULL;
607 typedef struct
608 { LPCSTR szApp;
609 LPCSTR szOtherStuff;
610 HICON hIcon;
611 } ABOUT_INFO;
613 #define IDC_STATIC_TEXT 100
614 #define IDC_LISTBOX 99
615 #define IDC_WINE_TEXT 98
617 #define DROP_FIELD_TOP (-15)
618 #define DROP_FIELD_HEIGHT 15
620 static HFONT hIconTitleFont;
622 static BOOL __get_dropline( HWND hWnd, LPRECT lprect )
623 { HWND hWndCtl = GetDlgItem(hWnd, IDC_WINE_TEXT);
624 if( hWndCtl )
625 { GetWindowRect( hWndCtl, lprect );
626 MapWindowPoints( 0, hWnd, (LPPOINT)lprect, 2 );
627 lprect->bottom = (lprect->top += DROP_FIELD_TOP);
628 return TRUE;
630 return FALSE;
633 /*************************************************************************
634 * SHAppBarMessage [SHELL32.@]
636 UINT WINAPI SHAppBarMessage(DWORD msg, PAPPBARDATA data)
638 int width=data->rc.right - data->rc.left;
639 int height=data->rc.bottom - data->rc.top;
640 RECT rec=data->rc;
641 switch (msg)
642 { case ABM_GETSTATE:
643 return ABS_ALWAYSONTOP | ABS_AUTOHIDE;
644 case ABM_GETTASKBARPOS:
645 GetWindowRect(data->hWnd, &rec);
646 data->rc=rec;
647 return TRUE;
648 case ABM_ACTIVATE:
649 SetActiveWindow(data->hWnd);
650 return TRUE;
651 case ABM_GETAUTOHIDEBAR:
652 data->hWnd=GetActiveWindow();
653 return TRUE;
654 case ABM_NEW:
655 SetWindowPos(data->hWnd,HWND_TOP,rec.left,rec.top,
656 width,height,SWP_SHOWWINDOW);
657 return TRUE;
658 case ABM_QUERYPOS:
659 GetWindowRect(data->hWnd, &(data->rc));
660 return TRUE;
661 case ABM_REMOVE:
662 FIXME("ABM_REMOVE broken\n");
663 /* FIXME: this is wrong; should it be DestroyWindow instead? */
664 /*CloseHandle(data->hWnd);*/
665 return TRUE;
666 case ABM_SETAUTOHIDEBAR:
667 SetWindowPos(data->hWnd,HWND_TOP,rec.left+1000,rec.top,
668 width,height,SWP_SHOWWINDOW);
669 return TRUE;
670 case ABM_SETPOS:
671 data->uEdge=(ABE_RIGHT | ABE_LEFT);
672 SetWindowPos(data->hWnd,HWND_TOP,data->rc.left,data->rc.top,
673 width,height,SWP_SHOWWINDOW);
674 return TRUE;
675 case ABM_WINDOWPOSCHANGED:
676 return TRUE;
678 return FALSE;
681 /*************************************************************************
682 * SHHelpShortcuts_RunDLL [SHELL32.@]
685 DWORD WINAPI SHHelpShortcuts_RunDLL (DWORD dwArg1, DWORD dwArg2, DWORD dwArg3, DWORD dwArg4)
686 { FIXME("(%lx, %lx, %lx, %lx) empty stub!\n",
687 dwArg1, dwArg2, dwArg3, dwArg4);
689 return 0;
692 /*************************************************************************
693 * SHLoadInProc [SHELL32.@]
694 * Create an instance of specified object class from within
695 * the shell process and release it immediately
698 DWORD WINAPI SHLoadInProc (REFCLSID rclsid)
700 void *ptr = NULL;
702 TRACE("%s\n", debugstr_guid(rclsid));
704 CoCreateInstance(rclsid, NULL, CLSCTX_INPROC_SERVER, &IID_IUnknown,&ptr);
705 if(ptr)
707 IUnknown * pUnk = ptr;
708 IUnknown_Release(pUnk);
709 return NOERROR;
711 return DISP_E_MEMBERNOTFOUND;
714 /*************************************************************************
715 * AboutDlgProc (internal)
717 INT_PTR CALLBACK AboutDlgProc( HWND hWnd, UINT msg, WPARAM wParam,
718 LPARAM lParam )
719 { HWND hWndCtl;
720 char Template[512], AppTitle[512];
722 TRACE("\n");
724 switch(msg)
725 { case WM_INITDIALOG:
726 { ABOUT_INFO *info = (ABOUT_INFO *)lParam;
727 if (info)
728 { const char* const *pstr = SHELL_People;
729 SendDlgItemMessageA(hWnd, stc1, STM_SETICON,(WPARAM)info->hIcon, 0);
730 GetWindowTextA( hWnd, Template, sizeof(Template) );
731 sprintf( AppTitle, Template, info->szApp );
732 SetWindowTextA( hWnd, AppTitle );
733 SetWindowTextA( GetDlgItem(hWnd, IDC_STATIC_TEXT),
734 info->szOtherStuff );
735 hWndCtl = GetDlgItem(hWnd, IDC_LISTBOX);
736 SendMessageA( hWndCtl, WM_SETREDRAW, 0, 0 );
737 if (!hIconTitleFont)
739 LOGFONTA logFont;
740 SystemParametersInfoA( SPI_GETICONTITLELOGFONT, 0, &logFont, 0 );
741 hIconTitleFont = CreateFontIndirectA( &logFont );
743 SendMessageA( hWndCtl, WM_SETFONT, HICON_16(hIconTitleFont), 0 );
744 while (*pstr)
745 { SendMessageA( hWndCtl, LB_ADDSTRING, (WPARAM)-1, (LPARAM)*pstr );
746 pstr++;
748 SendMessageA( hWndCtl, WM_SETREDRAW, 1, 0 );
751 return 1;
753 case WM_PAINT:
754 { RECT rect;
755 PAINTSTRUCT ps;
756 HDC hDC = BeginPaint( hWnd, &ps );
758 if( __get_dropline( hWnd, &rect ) ) {
759 SelectObject( hDC, GetStockObject( BLACK_PEN ) );
760 MoveToEx( hDC, rect.left, rect.top, NULL );
761 LineTo( hDC, rect.right, rect.bottom );
763 EndPaint( hWnd, &ps );
765 break;
767 #if 0 /* FIXME: should use DoDragDrop */
768 case WM_LBTRACKPOINT:
769 hWndCtl = GetDlgItem(hWnd, IDC_LISTBOX);
770 if( (INT16)GetKeyState( VK_CONTROL ) < 0 )
771 { if( DragDetect( hWndCtl, *((LPPOINT)&lParam) ) )
772 { INT idx = SendMessageA( hWndCtl, LB_GETCURSEL, 0, 0 );
773 if( idx != -1 )
774 { INT length = SendMessageA( hWndCtl, LB_GETTEXTLEN, (WPARAM)idx, 0 );
775 HGLOBAL16 hMemObj = GlobalAlloc16( GMEM_MOVEABLE, length + 1 );
776 char* pstr = (char*)GlobalLock16( hMemObj );
778 if( pstr )
779 { HCURSOR hCursor = LoadCursorA( 0, MAKEINTRESOURCEA(OCR_DRAGOBJECT) );
780 SendMessageA( hWndCtl, LB_GETTEXT, (WPARAM)idx, (LPARAM)pstr );
781 SendMessageA( hWndCtl, LB_DELETESTRING, (WPARAM)idx, 0 );
782 UpdateWindow( hWndCtl );
783 if( !DragObject16((HWND16)hWnd, (HWND16)hWnd, DRAGOBJ_DATA, 0, (WORD)hMemObj, hCursor) )
784 SendMessageA( hWndCtl, LB_ADDSTRING, (WPARAM)-1, (LPARAM)pstr );
786 if( hMemObj )
787 GlobalFree16( hMemObj );
791 break;
792 #endif
794 case WM_QUERYDROPOBJECT:
795 if( wParam == 0 )
796 { LPDRAGINFO16 lpDragInfo = MapSL((SEGPTR)lParam);
797 if( lpDragInfo && lpDragInfo->wFlags == DRAGOBJ_DATA )
798 { RECT rect;
799 if( __get_dropline( hWnd, &rect ) )
800 { POINT pt;
801 pt.x=lpDragInfo->pt.x;
802 pt.x=lpDragInfo->pt.y;
803 rect.bottom += DROP_FIELD_HEIGHT;
804 if( PtInRect( &rect, pt ) )
805 { SetWindowLongA( hWnd, DWL_MSGRESULT, 1 );
806 return TRUE;
811 break;
813 case WM_DROPOBJECT:
814 if( wParam == (WPARAM)hWnd )
815 { LPDRAGINFO16 lpDragInfo = MapSL((SEGPTR)lParam);
816 if( lpDragInfo && lpDragInfo->wFlags == DRAGOBJ_DATA && lpDragInfo->hList )
817 { char* pstr = (char*)GlobalLock16( (HGLOBAL16)(lpDragInfo->hList) );
818 if( pstr )
819 { static char __appendix_str[] = " with";
821 hWndCtl = GetDlgItem( hWnd, IDC_WINE_TEXT );
822 SendMessageA( hWndCtl, WM_GETTEXT, 512, (LPARAM)Template );
823 if( !strncmp( Template, "WINE", 4 ) )
824 SetWindowTextA( GetDlgItem(hWnd, IDC_STATIC_TEXT), Template );
825 else
826 { char* pch = Template + strlen(Template) - strlen(__appendix_str);
827 *pch = '\0';
828 SendMessageA( GetDlgItem(hWnd, IDC_LISTBOX), LB_ADDSTRING,
829 (WPARAM)-1, (LPARAM)Template );
832 strcpy( Template, pstr );
833 strcat( Template, __appendix_str );
834 SetWindowTextA( hWndCtl, Template );
835 SetWindowLongA( hWnd, DWL_MSGRESULT, 1 );
836 return TRUE;
840 break;
842 case WM_COMMAND:
843 if (wParam == IDOK)
844 { EndDialog(hWnd, TRUE);
845 return TRUE;
847 break;
848 case WM_CLOSE:
849 EndDialog(hWnd, TRUE);
850 break;
853 return 0;
857 /*************************************************************************
858 * ShellAboutA [SHELL32.288]
860 BOOL WINAPI ShellAboutA( HWND hWnd, LPCSTR szApp, LPCSTR szOtherStuff,
861 HICON hIcon )
862 { ABOUT_INFO info;
863 HRSRC hRes;
864 LPVOID template;
865 TRACE("\n");
867 if(!(hRes = FindResourceA(shell32_hInstance, "SHELL_ABOUT_MSGBOX", RT_DIALOGA)))
868 return FALSE;
869 if(!(template = (LPVOID)LoadResource(shell32_hInstance, hRes)))
870 return FALSE;
872 info.szApp = szApp;
873 info.szOtherStuff = szOtherStuff;
874 info.hIcon = hIcon;
875 if (!hIcon) info.hIcon = LoadIconA( 0, IDI_WINLOGOA );
876 return DialogBoxIndirectParamA( (HINSTANCE)GetWindowLongA( hWnd, GWL_HINSTANCE ),
877 template, hWnd, AboutDlgProc, (LPARAM)&info );
881 /*************************************************************************
882 * ShellAboutW [SHELL32.289]
884 BOOL WINAPI ShellAboutW( HWND hWnd, LPCWSTR szApp, LPCWSTR szOtherStuff,
885 HICON hIcon )
886 { BOOL ret;
887 ABOUT_INFO info;
888 HRSRC hRes;
889 LPVOID template;
891 TRACE("\n");
893 if(!(hRes = FindResourceA(shell32_hInstance, "SHELL_ABOUT_MSGBOX", RT_DIALOGA)))
894 return FALSE;
895 if(!(template = (LPVOID)LoadResource(shell32_hInstance, hRes)))
896 return FALSE;
898 info.szApp = HEAP_strdupWtoA( GetProcessHeap(), 0, szApp );
899 info.szOtherStuff = HEAP_strdupWtoA( GetProcessHeap(), 0, szOtherStuff );
900 info.hIcon = hIcon;
901 if (!hIcon) info.hIcon = LoadIconA( 0, IDI_WINLOGOA );
902 ret = DialogBoxIndirectParamA((HINSTANCE)GetWindowLongA( hWnd, GWL_HINSTANCE ),
903 template, hWnd, AboutDlgProc, (LPARAM)&info );
904 HeapFree( GetProcessHeap(), 0, (LPSTR)info.szApp );
905 HeapFree( GetProcessHeap(), 0, (LPSTR)info.szOtherStuff );
906 return ret;
909 /*************************************************************************
910 * FreeIconList (SHELL32.@)
912 void WINAPI FreeIconList( DWORD dw )
913 { FIXME("(%lx): stub\n",dw);
916 /***********************************************************************
917 * DllGetVersion [SHELL32.@]
919 * Retrieves version information of the 'SHELL32.DLL'
921 * PARAMS
922 * pdvi [O] pointer to version information structure.
924 * RETURNS
925 * Success: S_OK
926 * Failure: E_INVALIDARG
928 * NOTES
929 * Returns version of a shell32.dll from IE4.01 SP1.
932 HRESULT WINAPI SHELL32_DllGetVersion (DLLVERSIONINFO *pdvi)
934 if (pdvi->cbSize != sizeof(DLLVERSIONINFO))
936 WARN("wrong DLLVERSIONINFO size from app\n");
937 return E_INVALIDARG;
940 pdvi->dwMajorVersion = 4;
941 pdvi->dwMinorVersion = 72;
942 pdvi->dwBuildNumber = 3110;
943 pdvi->dwPlatformID = 1;
945 TRACE("%lu.%lu.%lu.%lu\n",
946 pdvi->dwMajorVersion, pdvi->dwMinorVersion,
947 pdvi->dwBuildNumber, pdvi->dwPlatformID);
949 return S_OK;
951 /*************************************************************************
952 * global variables of the shell32.dll
953 * all are once per process
956 void (WINAPI *pDLLInitComctl)(LPVOID);
958 LPVOID (WINAPI *pCOMCTL32_Alloc) (INT);
959 BOOL (WINAPI *pCOMCTL32_Free) (LPVOID);
961 HANDLE (WINAPI *pCreateMRUListA) (LPVOID lpcml);
962 DWORD (WINAPI *pFreeMRUListA) (HANDLE hMRUList);
963 INT (WINAPI *pAddMRUData) (HANDLE hList, LPCVOID lpData, DWORD cbData);
964 INT (WINAPI *pFindMRUData) (HANDLE hList, LPCVOID lpData, DWORD cbData, LPINT lpRegNum);
965 INT (WINAPI *pEnumMRUListA) (HANDLE hList, INT nItemPos, LPVOID lpBuffer, DWORD nBufferSize);
967 static HINSTANCE hComctl32;
969 HINSTANCE shell32_hInstance = 0;
970 HIMAGELIST ShellSmallIconList = 0;
971 HIMAGELIST ShellBigIconList = 0;
974 /*************************************************************************
975 * SHELL32 DllMain
977 * NOTES
978 * calling oleinitialize here breaks sone apps.
981 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
983 TRACE("%p 0x%lx %p\n", hinstDLL, fdwReason, fImpLoad);
985 switch (fdwReason)
987 case DLL_PROCESS_ATTACH:
988 shell32_hInstance = hinstDLL;
989 hComctl32 = GetModuleHandleA("COMCTL32.DLL");
990 DisableThreadLibraryCalls(shell32_hInstance);
992 if (!hComctl32)
994 ERR("P A N I C SHELL32 loading failed\n");
995 return FALSE;
998 /* comctl32 */
999 pDLLInitComctl=(void*)GetProcAddress(hComctl32,"InitCommonControlsEx");
1000 /* initialize the common controls */
1001 if (pDLLInitComctl)
1003 pDLLInitComctl(NULL);
1006 SIC_Initialize();
1007 SYSTRAY_Init();
1008 InitChangeNotifications();
1009 SHInitRestricted(NULL, NULL);
1010 break;
1012 case DLL_PROCESS_DETACH:
1013 shell32_hInstance = 0;
1014 SIC_Destroy();
1015 FreeChangeNotifications();
1016 break;
1018 return TRUE;
1021 /*************************************************************************
1022 * DllInstall [SHELL32.@]
1024 * PARAMETERS
1026 * BOOL bInstall - TRUE for install, FALSE for uninstall
1027 * LPCWSTR pszCmdLine - command line (unused by shell32?)
1030 HRESULT WINAPI SHELL32_DllInstall(BOOL bInstall, LPCWSTR cmdline)
1032 FIXME("(%s, %s): stub!\n", bInstall ? "TRUE":"FALSE", debugstr_w(cmdline));
1034 return S_OK; /* indicate success */
1037 /***********************************************************************
1038 * DllCanUnloadNow (SHELL32.@)
1040 HRESULT WINAPI SHELL32_DllCanUnloadNow(void)
1042 FIXME("(void): stub\n");
1044 return S_FALSE;