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