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