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