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