Also silence IShellLinkA_fnSetShowCmd.
[wine] / dlls / shell32 / shell32_main.c
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #include "config.h"
23
24 #include <stdlib.h>
25 #include <string.h>
26 #include <stdio.h>
27
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"
36
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"
43
44 #include "wine/debug.h"
45 #include "wine/unicode.h"
46
47 WINE_DEFAULT_DEBUG_CHANNEL(shell);
48
49 #define MORE_DEBUG 1
50 /*************************************************************************
51  * CommandLineToArgvW                   [SHELL32.@]
52  *
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'
72  *
73  * Note:
74  * '\t' == 0x0009
75  * ' '  == 0x0020
76  * '"'  == 0x0022
77  * '\\' == 0x005c
78  */
79 LPWSTR* WINAPI CommandLineToArgvW(LPCWSTR lpCmdline, int* numargs)
80 {
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;
88
89     if (*lpCmdline==0) {
90         /* Return the path to the executable */
91         DWORD size;
92
93         hargv=0;
94         size=16;
95         do {
96             size*=2;
97             hargv=GlobalReAlloc(hargv, size, 0);
98             argv=GlobalLock(hargv);
99         } while (GetModuleFileNameW((HMODULE)0, (LPWSTR)(argv+1), size-sizeof(LPWSTR)) == 0);
100         argv[0]=(LPWSTR)(argv+1);
101         if (numargs)
102             *numargs=2;
103
104         return argv;
105     }
106
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++;
119             }
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;
134         }
135         cs++;
136     }
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.
139      */
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);
146
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;
156
157             /* skip the remaining spaces */
158             do {
159                 s++;
160             } while (*s==0x0009 || *s==0x0020);
161
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.
174                  */
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 '"'
181                  */
182                 d=d-bcount/2-1;
183                 *d++='"';
184                 s++;
185             }
186             bcount=0;
187         } else {
188             /* a regular character */
189             *d++=*s++;
190             bcount=0;
191         }
192     }
193     if (*arg) {
194         *d='\0';
195         argv[argc++]=arg;
196     }
197     if (numargs)
198         *numargs=argc;
199
200     return argv;
201 }
202
203 /*************************************************************************
204  * SHGetFileInfoA                       [SHELL32.@]
205  *
206  */
207
208 DWORD WINAPI SHGetFileInfoA(LPCSTR path,DWORD dwFileAttributes,
209                               SHFILEINFOA *psfi, UINT sizeofpsfi,
210                               UINT flags )
211 {
212         char szLocation[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;
220
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);
223
224         if ((flags & SHGFI_USEFILEATTRIBUTES) && (flags & (SHGFI_ATTRIBUTES|SHGFI_EXETYPE|SHGFI_PIDL)))
225           return FALSE;
226
227         /* windows initializes this values regardless of the flags */
228         psfi->szDisplayName[0] = '\0';
229         psfi->szTypeName[0] = '\0';
230         psfi->iIcon = 0;
231
232         if (flags & SHGFI_EXETYPE) {
233           BOOL status = FALSE;
234           HANDLE hfile;
235           DWORD BinaryType;
236           IMAGE_DOS_HEADER mz_header;
237           IMAGE_NT_HEADERS nt;
238           DWORD len;
239           char magic[4];
240
241           if (flags != SHGFI_EXETYPE) return 0;
242
243           status = GetBinaryTypeA (path, &BinaryType);
244           if (!status) return 0;
245           if ((BinaryType == SCS_DOS_BINARY)
246                 || (BinaryType == SCS_PIF_BINARY)) return 0x4d5a;
247
248           hfile = CreateFileA( path, GENERIC_READ, FILE_SHARE_READ,
249                 NULL, OPEN_EXISTING, 0, 0 );
250           if ( hfile == INVALID_HANDLE_VALUE ) return 0;
251
252         /* The next section is adapted from MODULE_GetBinaryType, as we need
253          * to examine the image header to get OS and version information. We
254          * know from calling GetBinaryTypeA that the image is valid and either
255          * an NE or PE, so much error handling can be omitted.
256          * Seek to the start of the file and read the header information.
257          */
258
259           SetFilePointer( hfile, 0, NULL, SEEK_SET );
260           ReadFile( hfile, &mz_header, sizeof(mz_header), &len, NULL );
261
262          SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
263          ReadFile( hfile, magic, sizeof(magic), &len, NULL );
264          if ( *(DWORD*)magic      == IMAGE_NT_SIGNATURE )
265          {
266              SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
267              ReadFile( hfile, &nt, sizeof(nt), &len, NULL );
268               CloseHandle( hfile );
269               if (nt.OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_GUI) {
270                  return IMAGE_NT_SIGNATURE
271                         | (nt.OptionalHeader.MajorSubsystemVersion << 24)
272                         | (nt.OptionalHeader.MinorSubsystemVersion << 16);
273               }
274               return IMAGE_NT_SIGNATURE;
275           }
276          else if ( *(WORD*)magic == IMAGE_OS2_SIGNATURE )
277          {
278              IMAGE_OS2_HEADER ne;
279              SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
280              ReadFile( hfile, &ne, sizeof(ne), &len, NULL );
281               CloseHandle( hfile );
282              if (ne.ne_exetyp == 2) return IMAGE_OS2_SIGNATURE
283                         | (ne.ne_expver << 16);
284               return 0;
285           }
286           CloseHandle( hfile );
287           return 0;
288       }
289
290
291         /* translate the path into a pidl only when SHGFI_USEFILEATTRIBUTES in not specified
292            the pidl functions fail on not existing file names */
293
294         if (flags & SHGFI_PIDL) {
295             pidl = ILClone((LPCITEMIDLIST)path);
296         } else if (!(flags & SHGFI_USEFILEATTRIBUTES)) {
297             hr = SHILCreateFromPathA(path, &pidl, &dwAttributes);
298         }
299
300         if ((flags & SHGFI_PIDL) || !(flags & SHGFI_USEFILEATTRIBUTES))
301         {
302            /* get the parent shellfolder */
303            if (pidl) {
304               hr = SHBindToParent( pidl, &IID_IShellFolder, (LPVOID*)&psfParent, &pidlLast);
305               ILFree(pidl);
306            } else {
307               ERR("pidl is null!\n");
308               return FALSE;
309            }
310         }
311
312         /* get the attributes of the child */
313         if (SUCCEEDED(hr) && (flags & SHGFI_ATTRIBUTES))
314         {
315           if (!(flags & SHGFI_ATTR_SPECIFIED))
316           {
317             psfi->dwAttributes = 0xffffffff;
318           }
319           IShellFolder_GetAttributesOf(psfParent, 1 , &pidlLast, &(psfi->dwAttributes));
320         }
321
322         /* get the displayname */
323         if (SUCCEEDED(hr) && (flags & SHGFI_DISPLAYNAME))
324         {
325           if (flags & SHGFI_USEFILEATTRIBUTES)
326           {
327             strcpy (psfi->szDisplayName, PathFindFileNameA(path));
328           }
329           else
330           {
331             STRRET str;
332             hr = IShellFolder_GetDisplayNameOf(psfParent, pidlLast, SHGDN_INFOLDER, &str);
333             StrRetToStrNA (psfi->szDisplayName, MAX_PATH, &str, pidlLast);
334           }
335         }
336
337         /* get the type name */
338         if (SUCCEEDED(hr) && (flags & SHGFI_TYPENAME))
339         {
340             if (!(flags & SHGFI_USEFILEATTRIBUTES))
341                 _ILGetFileType(pidlLast, psfi->szTypeName, 80);
342             else
343             {
344                 if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
345                    strcat (psfi->szTypeName, "File");
346                 else 
347                 {
348                    char sTemp[64];
349                    strcpy(sTemp,PathFindExtensionA(path));
350                    if (!( HCR_MapTypeToValue(sTemp, sTemp, 64, TRUE)
351                         && HCR_MapTypeToValue(sTemp, psfi->szTypeName, 80, FALSE )))
352                    {
353                        lstrcpynA (psfi->szTypeName, sTemp, 64);
354                        strcat (psfi->szTypeName, "-file");
355                    }
356                 }
357             }
358         }
359
360         /* ### icons ###*/
361         if (flags & SHGFI_LINKOVERLAY)
362           FIXME("set icon to link, stub\n");
363
364         if (flags & SHGFI_SELECTED)
365           FIXME("set icon to selected, stub\n");
366
367         if (flags & SHGFI_SHELLICONSIZE)
368           FIXME("set icon to shell size, stub\n");
369
370         /* get the iconlocation */
371         if (SUCCEEDED(hr) && (flags & SHGFI_ICONLOCATION ))
372         {
373           UINT uDummy,uFlags;
374           hr = IShellFolder_GetUIObjectOf(psfParent, 0, 1, &pidlLast, &IID_IExtractIconA, &uDummy, (LPVOID*)&pei);
375
376           if (SUCCEEDED(hr))
377           {
378            hr = IExtractIconA_GetIconLocation(pei, (flags & SHGFI_OPENICON)? GIL_OPENICON : 0,szLocation, MAX_PATH, &iIndex, &uFlags);
379             /* FIXME what to do with the index? */
380
381             if(uFlags != GIL_NOTFILENAME)
382              strcpy (psfi->szDisplayName, szLocation);
383             else
384               ret = FALSE;
385
386             IExtractIconA_Release(pei);
387           }
388         }
389
390         /* get icon index (or load icon)*/
391         if (SUCCEEDED(hr) && (flags & (SHGFI_ICON | SHGFI_SYSICONINDEX)))
392         {
393
394           if (flags & SHGFI_USEFILEATTRIBUTES)
395           {
396             char sTemp [MAX_PATH];
397             char * szExt;
398             DWORD dwNr=0;
399
400             lstrcpynA(sTemp, path, MAX_PATH);
401
402             if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
403                psfi->iIcon = 2;
404             else
405             {
406                psfi->iIcon = 0;
407                szExt = (LPSTR) PathFindExtensionA(sTemp);
408                if ( szExt && HCR_MapTypeToValue(szExt, sTemp, MAX_PATH, TRUE)
409                    && HCR_GetDefaultIcon(sTemp, sTemp, MAX_PATH, &dwNr))
410                {
411                   if (!strcmp("%1",sTemp))            /* icon is in the file */
412                      strcpy(sTemp, path);
413           
414                   if (flags & SHGFI_SYSICONINDEX) 
415                   {    
416                       psfi->iIcon = SIC_GetIconIndex(sTemp,dwNr);
417                       if (psfi->iIcon == -1) psfi->iIcon = 0;
418                   } 
419                   else 
420                   {
421                       IconNotYetLoaded=FALSE;
422                       PrivateExtractIconsA(sTemp,dwNr,(flags&SHGFI_LARGEICON) ? 
423                         GetSystemMetrics(SM_CXICON) : GetSystemMetrics(SM_CXSMICON),
424                         (flags&SHGFI_LARGEICON) ? GetSystemMetrics(SM_CYICON) :
425                         GetSystemMetrics(SM_CYSMICON), &psfi->hIcon,0,1,0);
426                       psfi->iIcon = dwNr;
427                   }
428                }
429             }
430           }
431           else
432           {
433             if (!(PidlToSicIndex(psfParent, pidlLast, (flags & SHGFI_LARGEICON),
434               (flags & SHGFI_OPENICON)? GIL_OPENICON : 0, &(psfi->iIcon))))
435             {
436               ret = FALSE;
437             }
438           }
439           if (ret)
440           {
441             ret = (DWORD) ((flags & SHGFI_LARGEICON) ? ShellBigIconList : ShellSmallIconList);
442           }
443         }
444
445         /* icon handle */
446         if (SUCCEEDED(hr) && (flags & SHGFI_ICON) && IconNotYetLoaded)
447           psfi->hIcon = ImageList_GetIcon((flags & SHGFI_LARGEICON) ? ShellBigIconList:ShellSmallIconList, psfi->iIcon, ILD_NORMAL);
448
449         if (flags & (SHGFI_UNKNOWN1 | SHGFI_UNKNOWN2 | SHGFI_UNKNOWN3))
450           FIXME("unknown attribute!\n");
451
452         if (psfParent)
453           IShellFolder_Release(psfParent);
454
455         if (hr != S_OK)
456           ret = FALSE;
457
458         if(pidlLast) SHFree(pidlLast);
459 #ifdef MORE_DEBUG
460         TRACE ("icon=0x%08x index=0x%08x attr=0x%08lx name=%s type=%s ret=0x%08lx\n",
461                 psfi->hIcon, psfi->iIcon, psfi->dwAttributes, psfi->szDisplayName, psfi->szTypeName, ret);
462 #endif
463         return ret;
464 }
465
466 /*************************************************************************
467  * SHGetFileInfoW                       [SHELL32.@]
468  */
469
470 DWORD WINAPI SHGetFileInfoW(LPCWSTR path,DWORD dwFileAttributes,
471                               SHFILEINFOW *psfi, UINT sizeofpsfi,
472                               UINT flags )
473 {
474         INT len;
475         LPSTR temppath;
476         DWORD ret;
477         SHFILEINFOA temppsfi;
478
479         len = WideCharToMultiByte(CP_ACP, 0, path, -1, NULL, 0, NULL, NULL);
480         temppath = HeapAlloc(GetProcessHeap(), 0, len);
481         WideCharToMultiByte(CP_ACP, 0, path, -1, temppath, len, NULL, NULL);
482
483        if(flags & SHGFI_ATTR_SPECIFIED)
484                temppsfi.dwAttributes=psfi->dwAttributes;
485
486         ret = SHGetFileInfoA(temppath, dwFileAttributes, &temppsfi, sizeof(temppsfi), flags);
487
488        if(flags & SHGFI_ICON)
489                psfi->hIcon=temppsfi.hIcon;
490        if(flags & (SHGFI_SYSICONINDEX|SHGFI_ICON|SHGFI_ICONLOCATION))
491                psfi->iIcon=temppsfi.iIcon;
492        if(flags & SHGFI_ATTRIBUTES)
493                psfi->dwAttributes=temppsfi.dwAttributes;
494        if(flags & (SHGFI_DISPLAYNAME|SHGFI_ICONLOCATION))
495                MultiByteToWideChar(CP_ACP, 0, temppsfi.szDisplayName, -1, psfi->szDisplayName, sizeof(psfi->szDisplayName));
496        if(flags & SHGFI_TYPENAME)
497                MultiByteToWideChar(CP_ACP, 0, temppsfi.szTypeName, -1, psfi->szTypeName, sizeof(psfi->szTypeName));
498
499         HeapFree(GetProcessHeap(), 0, temppath);
500
501         return ret;
502 }
503
504 /*************************************************************************
505  * SHGetFileInfo                        [SHELL32.@]
506  */
507 DWORD WINAPI SHGetFileInfoAW(
508         LPCVOID path,
509         DWORD dwFileAttributes,
510         LPVOID psfi,
511         UINT sizeofpsfi,
512         UINT flags)
513 {
514         if(SHELL_OsIsUnicode())
515           return SHGetFileInfoW(path, dwFileAttributes, psfi, sizeofpsfi, flags );
516         return SHGetFileInfoA(path, dwFileAttributes, psfi, sizeofpsfi, flags );
517 }
518
519 /*************************************************************************
520  * DuplicateIcon                        [SHELL32.@]
521  */
522 HICON WINAPI DuplicateIcon( HINSTANCE hInstance, HICON hIcon)
523 {
524     ICONINFO IconInfo;
525     HICON hDupIcon = 0;
526
527     TRACE("(%04x, %04x)\n", hInstance, hIcon);
528
529     if(GetIconInfo(hIcon, &IconInfo))
530     {
531         hDupIcon = CreateIconIndirect(&IconInfo);
532
533         /* clean up hbmMask and hbmColor */
534         DeleteObject(IconInfo.hbmMask);
535         DeleteObject(IconInfo.hbmColor);
536     }
537
538     return hDupIcon;
539 }
540
541
542 /*************************************************************************
543  * ExtractIconA                         [SHELL32.@]
544  *
545  * FIXME
546  *  if the filename is not a file return 1
547  */
548 HICON WINAPI ExtractIconA( HINSTANCE hInstance, LPCSTR lpszExeFileName,
549         UINT nIconIndex )
550 {   HGLOBAL16 handle = InternalExtractIcon16(hInstance,lpszExeFileName,nIconIndex, 1);
551     TRACE("\n");
552     if( handle )
553     {
554         HICON16* ptr = (HICON16*)GlobalLock16(handle);
555         HICON16  hIcon = *ptr;
556
557         GlobalFree16(handle);
558         return HICON_32(hIcon);
559     }
560     return 0;
561 }
562
563 /*************************************************************************
564  * ExtractIconW                         [SHELL32.@]
565  *
566  * FIXME: if the filename is not a file return 1
567  */
568 HICON WINAPI ExtractIconW( HINSTANCE hInstance, LPCWSTR lpszExeFileName,
569         UINT nIconIndex )
570 { LPSTR  exefn;
571   HICON  ret;
572   TRACE("\n");
573
574   exefn = HEAP_strdupWtoA(GetProcessHeap(),0,lpszExeFileName);
575   ret = ExtractIconA(hInstance,exefn,nIconIndex);
576
577         HeapFree(GetProcessHeap(),0,exefn);
578         return ret;
579 }
580
581 typedef struct
582 { LPCSTR  szApp;
583     LPCSTR  szOtherStuff;
584     HICON hIcon;
585 } ABOUT_INFO;
586
587 #define         IDC_STATIC_TEXT         100
588 #define         IDC_LISTBOX             99
589 #define         IDC_WINE_TEXT           98
590
591 #define         DROP_FIELD_TOP          (-15)
592 #define         DROP_FIELD_HEIGHT       15
593
594 static HFONT hIconTitleFont;
595
596 static BOOL __get_dropline( HWND hWnd, LPRECT lprect )
597 { HWND hWndCtl = GetDlgItem(hWnd, IDC_WINE_TEXT);
598     if( hWndCtl )
599   { GetWindowRect( hWndCtl, lprect );
600         MapWindowPoints( 0, hWnd, (LPPOINT)lprect, 2 );
601         lprect->bottom = (lprect->top += DROP_FIELD_TOP);
602         return TRUE;
603     }
604     return FALSE;
605 }
606
607 /*************************************************************************
608  * SHAppBarMessage                      [SHELL32.@]
609  */
610 UINT WINAPI SHAppBarMessage(DWORD msg, PAPPBARDATA data)
611 {
612         int width=data->rc.right - data->rc.left;
613         int height=data->rc.bottom - data->rc.top;
614         RECT rec=data->rc;
615         switch (msg)
616         { case ABM_GETSTATE:
617                return ABS_ALWAYSONTOP | ABS_AUTOHIDE;
618           case ABM_GETTASKBARPOS:
619                GetWindowRect(data->hWnd, &rec);
620                data->rc=rec;
621                return TRUE;
622           case ABM_ACTIVATE:
623                SetActiveWindow(data->hWnd);
624                return TRUE;
625           case ABM_GETAUTOHIDEBAR:
626                data->hWnd=GetActiveWindow();
627                return TRUE;
628           case ABM_NEW:
629                SetWindowPos(data->hWnd,HWND_TOP,rec.left,rec.top,
630                                         width,height,SWP_SHOWWINDOW);
631                return TRUE;
632           case ABM_QUERYPOS:
633                GetWindowRect(data->hWnd, &(data->rc));
634                return TRUE;
635           case ABM_REMOVE:
636                FIXME("ABM_REMOVE broken\n");
637                /* FIXME: this is wrong; should it be DestroyWindow instead? */
638                /*CloseHandle(data->hWnd);*/
639                return TRUE;
640           case ABM_SETAUTOHIDEBAR:
641                SetWindowPos(data->hWnd,HWND_TOP,rec.left+1000,rec.top,
642                                        width,height,SWP_SHOWWINDOW);
643                return TRUE;
644           case ABM_SETPOS:
645                data->uEdge=(ABE_RIGHT | ABE_LEFT);
646                SetWindowPos(data->hWnd,HWND_TOP,data->rc.left,data->rc.top,
647                                   width,height,SWP_SHOWWINDOW);
648                return TRUE;
649           case ABM_WINDOWPOSCHANGED:
650                return TRUE;
651           }
652       return FALSE;
653 }
654
655 /*************************************************************************
656  * SHHelpShortcuts_RunDLL               [SHELL32.@]
657  *
658  */
659 DWORD WINAPI SHHelpShortcuts_RunDLL (DWORD dwArg1, DWORD dwArg2, DWORD dwArg3, DWORD dwArg4)
660 { FIXME("(%lx, %lx, %lx, %lx) empty stub!\n",
661         dwArg1, dwArg2, dwArg3, dwArg4);
662
663   return 0;
664 }
665
666 /*************************************************************************
667  * SHLoadInProc                         [SHELL32.@]
668  * Create an instance of specified object class from within
669  * the shell process and release it immediately
670  */
671
672 DWORD WINAPI SHLoadInProc (REFCLSID rclsid)
673 {
674         IUnknown * pUnk = NULL;
675         TRACE("%s\n", debugstr_guid(rclsid));
676
677         CoCreateInstance(rclsid, NULL, CLSCTX_INPROC_SERVER, &IID_IUnknown,(LPVOID*)pUnk);
678         if(pUnk)
679         {
680           IUnknown_Release(pUnk);
681           return NOERROR;
682         }
683         return DISP_E_MEMBERNOTFOUND;
684 }
685
686 /*************************************************************************
687  * AboutDlgProc                 (internal)
688  */
689 INT_PTR CALLBACK AboutDlgProc( HWND hWnd, UINT msg, WPARAM wParam,
690                               LPARAM lParam )
691 {   HWND hWndCtl;
692     char Template[512], AppTitle[512];
693
694     TRACE("\n");
695
696     switch(msg)
697     { case WM_INITDIALOG:
698       { ABOUT_INFO *info = (ABOUT_INFO *)lParam;
699             if (info)
700         { const char* const *pstr = SHELL_People;
701                 SendDlgItemMessageA(hWnd, stc1, STM_SETICON,(WPARAM)info->hIcon, 0);
702                 GetWindowTextA( hWnd, Template, sizeof(Template) );
703                 sprintf( AppTitle, Template, info->szApp );
704                 SetWindowTextA( hWnd, AppTitle );
705                 SetWindowTextA( GetDlgItem(hWnd, IDC_STATIC_TEXT),
706                                   info->szOtherStuff );
707                 hWndCtl = GetDlgItem(hWnd, IDC_LISTBOX);
708                 SendMessageA( hWndCtl, WM_SETREDRAW, 0, 0 );
709                 if (!hIconTitleFont)
710                 {
711                     LOGFONTA logFont;
712                     SystemParametersInfoA( SPI_GETICONTITLELOGFONT, 0, &logFont, 0 );
713                     hIconTitleFont = CreateFontIndirectA( &logFont );
714                 }
715                 SendMessageA( hWndCtl, WM_SETFONT, hIconTitleFont, 0 );
716                 while (*pstr)
717           { SendMessageA( hWndCtl, LB_ADDSTRING, (WPARAM)-1, (LPARAM)*pstr );
718                     pstr++;
719                 }
720                 SendMessageA( hWndCtl, WM_SETREDRAW, 1, 0 );
721             }
722         }
723         return 1;
724
725     case WM_PAINT:
726       { RECT rect;
727             PAINTSTRUCT ps;
728             HDC hDC = BeginPaint( hWnd, &ps );
729
730             if( __get_dropline( hWnd, &rect ) ) {
731                 SelectObject( hDC, GetStockObject( BLACK_PEN ) );
732                 MoveToEx( hDC, rect.left, rect.top, NULL );
733                 LineTo( hDC, rect.right, rect.bottom );
734             }
735             EndPaint( hWnd, &ps );
736         }
737         break;
738
739 #if 0  /* FIXME: should use DoDragDrop */
740     case WM_LBTRACKPOINT:
741         hWndCtl = GetDlgItem(hWnd, IDC_LISTBOX);
742         if( (INT16)GetKeyState( VK_CONTROL ) < 0 )
743       { if( DragDetect( hWndCtl, *((LPPOINT)&lParam) ) )
744         { INT idx = SendMessageA( hWndCtl, LB_GETCURSEL, 0, 0 );
745                 if( idx != -1 )
746           { INT length = SendMessageA( hWndCtl, LB_GETTEXTLEN, (WPARAM)idx, 0 );
747                     HGLOBAL16 hMemObj = GlobalAlloc16( GMEM_MOVEABLE, length + 1 );
748                     char* pstr = (char*)GlobalLock16( hMemObj );
749
750                     if( pstr )
751             { HCURSOR hCursor = LoadCursorA( 0, MAKEINTRESOURCEA(OCR_DRAGOBJECT) );
752                         SendMessageA( hWndCtl, LB_GETTEXT, (WPARAM)idx, (LPARAM)pstr );
753                         SendMessageA( hWndCtl, LB_DELETESTRING, (WPARAM)idx, 0 );
754                         UpdateWindow( hWndCtl );
755                         if( !DragObject16((HWND16)hWnd, (HWND16)hWnd, DRAGOBJ_DATA, 0, (WORD)hMemObj, hCursor) )
756                             SendMessageA( hWndCtl, LB_ADDSTRING, (WPARAM)-1, (LPARAM)pstr );
757                     }
758             if( hMemObj )
759               GlobalFree16( hMemObj );
760                 }
761             }
762         }
763         break;
764 #endif
765
766     case WM_QUERYDROPOBJECT:
767         if( wParam == 0 )
768       { LPDRAGINFO16 lpDragInfo = MapSL((SEGPTR)lParam);
769             if( lpDragInfo && lpDragInfo->wFlags == DRAGOBJ_DATA )
770         { RECT rect;
771                 if( __get_dropline( hWnd, &rect ) )
772           { POINT pt;
773             pt.x=lpDragInfo->pt.x;
774             pt.x=lpDragInfo->pt.y;
775                     rect.bottom += DROP_FIELD_HEIGHT;
776                     if( PtInRect( &rect, pt ) )
777             { SetWindowLongA( hWnd, DWL_MSGRESULT, 1 );
778                         return TRUE;
779                     }
780                 }
781             }
782         }
783         break;
784
785     case WM_DROPOBJECT:
786         if( wParam == (WPARAM)hWnd )
787       { LPDRAGINFO16 lpDragInfo = MapSL((SEGPTR)lParam);
788             if( lpDragInfo && lpDragInfo->wFlags == DRAGOBJ_DATA && lpDragInfo->hList )
789         { char* pstr = (char*)GlobalLock16( (HGLOBAL16)(lpDragInfo->hList) );
790                 if( pstr )
791           { static char __appendix_str[] = " with";
792
793                     hWndCtl = GetDlgItem( hWnd, IDC_WINE_TEXT );
794                     SendMessageA( hWndCtl, WM_GETTEXT, 512, (LPARAM)Template );
795                     if( !strncmp( Template, "WINE", 4 ) )
796                         SetWindowTextA( GetDlgItem(hWnd, IDC_STATIC_TEXT), Template );
797                     else
798           { char* pch = Template + strlen(Template) - strlen(__appendix_str);
799                         *pch = '\0';
800                         SendMessageA( GetDlgItem(hWnd, IDC_LISTBOX), LB_ADDSTRING,
801                                         (WPARAM)-1, (LPARAM)Template );
802                     }
803
804                     strcpy( Template, pstr );
805                     strcat( Template, __appendix_str );
806                     SetWindowTextA( hWndCtl, Template );
807                     SetWindowLongA( hWnd, DWL_MSGRESULT, 1 );
808                     return TRUE;
809                 }
810             }
811         }
812         break;
813
814     case WM_COMMAND:
815         if (wParam == IDOK)
816     {  EndDialog(hWnd, TRUE);
817             return TRUE;
818         }
819         break;
820     case WM_CLOSE:
821       EndDialog(hWnd, TRUE);
822       break;
823     }
824
825     return 0;
826 }
827
828
829 /*************************************************************************
830  * ShellAboutA                          [SHELL32.288]
831  */
832 BOOL WINAPI ShellAboutA( HWND hWnd, LPCSTR szApp, LPCSTR szOtherStuff,
833                              HICON hIcon )
834 {   ABOUT_INFO info;
835     HRSRC hRes;
836     LPVOID template;
837     TRACE("\n");
838
839     if(!(hRes = FindResourceA(shell32_hInstance, "SHELL_ABOUT_MSGBOX", RT_DIALOGA)))
840         return FALSE;
841     if(!(template = (LPVOID)LoadResource(shell32_hInstance, hRes)))
842         return FALSE;
843
844     info.szApp        = szApp;
845     info.szOtherStuff = szOtherStuff;
846     info.hIcon        = hIcon;
847     if (!hIcon) info.hIcon = LoadIconA( 0, IDI_WINLOGOA );
848     return DialogBoxIndirectParamA( GetWindowLongA( hWnd, GWL_HINSTANCE ),
849                                       template, hWnd, AboutDlgProc, (LPARAM)&info );
850 }
851
852
853 /*************************************************************************
854  * ShellAboutW                          [SHELL32.289]
855  */
856 BOOL WINAPI ShellAboutW( HWND hWnd, LPCWSTR szApp, LPCWSTR szOtherStuff,
857                              HICON hIcon )
858 {   BOOL ret;
859     ABOUT_INFO info;
860     HRSRC hRes;
861     LPVOID template;
862
863     TRACE("\n");
864
865     if(!(hRes = FindResourceA(shell32_hInstance, "SHELL_ABOUT_MSGBOX", RT_DIALOGA)))
866         return FALSE;
867     if(!(template = (LPVOID)LoadResource(shell32_hInstance, hRes)))
868         return FALSE;
869
870     info.szApp        = HEAP_strdupWtoA( GetProcessHeap(), 0, szApp );
871     info.szOtherStuff = HEAP_strdupWtoA( GetProcessHeap(), 0, szOtherStuff );
872     info.hIcon        = hIcon;
873     if (!hIcon) info.hIcon = LoadIconA( 0, IDI_WINLOGOA );
874     ret = DialogBoxIndirectParamA( GetWindowLongA( hWnd, GWL_HINSTANCE ),
875                                    template, hWnd, AboutDlgProc, (LPARAM)&info );
876     HeapFree( GetProcessHeap(), 0, (LPSTR)info.szApp );
877     HeapFree( GetProcessHeap(), 0, (LPSTR)info.szOtherStuff );
878     return ret;
879 }
880
881 /*************************************************************************
882  * FreeIconList (SHELL32.@)
883  */
884 void WINAPI FreeIconList( DWORD dw )
885 { FIXME("(%lx): stub\n",dw);
886 }
887
888 /***********************************************************************
889  * DllGetVersion [SHELL32.@]
890  *
891  * Retrieves version information of the 'SHELL32.DLL'
892  *
893  * PARAMS
894  *     pdvi [O] pointer to version information structure.
895  *
896  * RETURNS
897  *     Success: S_OK
898  *     Failure: E_INVALIDARG
899  *
900  * NOTES
901  *     Returns version of a shell32.dll from IE4.01 SP1.
902  */
903
904 HRESULT WINAPI SHELL32_DllGetVersion (DLLVERSIONINFO *pdvi)
905 {
906         if (pdvi->cbSize != sizeof(DLLVERSIONINFO))
907         {
908           WARN("wrong DLLVERSIONINFO size from app\n");
909           return E_INVALIDARG;
910         }
911
912         pdvi->dwMajorVersion = 4;
913         pdvi->dwMinorVersion = 72;
914         pdvi->dwBuildNumber = 3110;
915         pdvi->dwPlatformID = 1;
916
917         TRACE("%lu.%lu.%lu.%lu\n",
918            pdvi->dwMajorVersion, pdvi->dwMinorVersion,
919            pdvi->dwBuildNumber, pdvi->dwPlatformID);
920
921         return S_OK;
922 }
923 /*************************************************************************
924  * global variables of the shell32.dll
925  * all are once per process
926  *
927  */
928 void    (WINAPI *pDLLInitComctl)(LPVOID);
929
930 LPVOID  (WINAPI *pCOMCTL32_Alloc) (INT);
931 BOOL    (WINAPI *pCOMCTL32_Free) (LPVOID);
932
933 HANDLE  (WINAPI *pCreateMRUListA) (LPVOID lpcml);
934 DWORD   (WINAPI *pFreeMRUListA) (HANDLE hMRUList);
935 INT     (WINAPI *pAddMRUData) (HANDLE hList, LPCVOID lpData, DWORD cbData);
936 INT     (WINAPI *pFindMRUData) (HANDLE hList, LPCVOID lpData, DWORD cbData, LPINT lpRegNum);
937 INT     (WINAPI *pEnumMRUListA) (HANDLE hList, INT nItemPos, LPVOID lpBuffer, DWORD nBufferSize);
938
939 static HINSTANCE        hComctl32;
940
941 HINSTANCE       shell32_hInstance = 0;
942 HIMAGELIST      ShellSmallIconList = 0;
943 HIMAGELIST      ShellBigIconList = 0;
944
945
946 /*************************************************************************
947  * SHELL32 DllMain
948  *
949  * NOTES
950  *  calling oleinitialize here breaks sone apps.
951  */
952
953 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
954 {
955         TRACE("0x%x 0x%lx %p\n", hinstDLL, fdwReason, fImpLoad);
956
957         switch (fdwReason)
958         {
959           case DLL_PROCESS_ATTACH:
960             shell32_hInstance = hinstDLL;
961             hComctl32 = GetModuleHandleA("COMCTL32.DLL");
962             DisableThreadLibraryCalls(shell32_hInstance);
963
964             if (!hComctl32)
965             {
966               ERR("P A N I C SHELL32 loading failed\n");
967               return FALSE;
968             }
969
970             /* comctl32 */
971             pDLLInitComctl=(void*)GetProcAddress(hComctl32,"InitCommonControlsEx");
972             /* initialize the common controls */
973             if (pDLLInitComctl)
974             {
975               pDLLInitComctl(NULL);
976             }
977
978             SIC_Initialize();
979             SYSTRAY_Init();
980             InitChangeNotifications();
981             SHInitRestricted(NULL, NULL);
982             break;
983
984           case DLL_THREAD_ATTACH:
985             break;
986
987           case DLL_THREAD_DETACH:
988             break;
989
990           case DLL_PROCESS_DETACH:
991               shell32_hInstance = 0;
992               SIC_Destroy();
993               FreeChangeNotifications();
994               break;
995         }
996         return TRUE;
997 }
998
999 /*************************************************************************
1000  * DllInstall         [SHELL32.@]
1001  *
1002  * PARAMETERS
1003  *
1004  *    BOOL bInstall - TRUE for install, FALSE for uninstall
1005  *    LPCWSTR pszCmdLine - command line (unused by shell32?)
1006  */
1007
1008 HRESULT WINAPI SHELL32_DllInstall(BOOL bInstall, LPCWSTR cmdline)
1009 {
1010    FIXME("(%s, %s): stub!\n", bInstall ? "TRUE":"FALSE", debugstr_w(cmdline));
1011
1012    return S_OK;         /* indicate success */
1013 }
1014
1015 /***********************************************************************
1016  *              DllCanUnloadNow (SHELL32.@)
1017  */
1018 HRESULT WINAPI SHELL32_DllCanUnloadNow(void)
1019 {
1020     FIXME("(void): stub\n");
1021
1022     return S_FALSE;
1023 }