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