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