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